Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An endianness abstraction #74

Closed
oscbyspro opened this issue Aug 27, 2023 · 3 comments
Closed

An endianness abstraction #74

oscbyspro opened this issue Aug 27, 2023 · 3 comments
Labels
addition oh, so shiny!
Milestone

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Aug 27, 2023

I think I've come up with a nice abstraction for endianness. The idea is that a dynamic enum should be used insofar as it is viable, whereas NBKBigEndian and NBKLittleEndian can be used when performance matters more than binary size (and as a namespace for appropriate methods). As far I can tell, dynamic endianness sensitive collections are viable (#72).

@frozen public struct NBKBigEndian:    NBKEndianness { }
@frozen public struct NBKLittleEndian: NBKEndianness { }
@frozen public enum   NBKAnyEndian:    NBKEndianness { case bigEndian, littleEndian }

The latest edition:

enum NBKEndianness: Hashable {
    
    case little
    
    case big

    static var system: Self {
        #if _endian(little)
        return .little
        #elseif _endian(big)
        return .big
        #endif
    }
}
@oscbyspro oscbyspro added the addition oh, so shiny! label Aug 27, 2023
@oscbyspro oscbyspro added this to the v0.11.0 milestone Aug 27, 2023
@oscbyspro oscbyspro changed the title Endianness abstraction An endianness abstraction Aug 27, 2023
@oscbyspro oscbyspro added the maybe to do, or not to do? label Aug 27, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 27, 2023

Hm. I think I want the enum, but perhaps the protocol is premature. I'm not sure <Endianess> should be encouraged.

oscbyspro added a commit that referenced this issue Aug 28, 2023
oscbyspro added a commit that referenced this issue Aug 28, 2023
oscbyspro added a commit that referenced this issue Aug 30, 2023
@oscbyspro oscbyspro added maybe to do, or not to do? and removed maybe to do, or not to do? labels Aug 30, 2023
@oscbyspro oscbyspro reopened this Sep 3, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 3, 2023

Hm. I'll remove the rawValue and the ! operator. It's unused, and I don't want to overcommit.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Sep 3, 2023

An interesting observation: raw values make enum comparisons much faster prior to Swift 5.8. Meh.

@oscbyspro oscbyspro removed the maybe to do, or not to do? label Sep 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny!
Projects
None yet
Development

No branches or pull requests

1 participant