-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNBKEndianness.swift
More file actions
46 lines (39 loc) · 1.67 KB
/
NBKEndianness.swift
File metadata and controls
46 lines (39 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//=----------------------------------------------------------------------------=
// This source file is part of the Numberick open source project.
//
// Copyright (c) 2023 Oscar Byström Ericsson
// Licensed under Apache License, Version 2.0
//
// See http://www.apache.org/licenses/LICENSE-2.0 for license information.
//=----------------------------------------------------------------------------=
//*============================================================================*
// MARK: * NBK x Endianness
//*============================================================================*
/// An enumeration of little and big endianness.
///
/// ### Static vs Dynamic
///
/// Some algorithms differ depending on endianness. Generic type parameterization
/// can express the difference, but dynamic solutions are often viable. This type
/// encurages the latter.
///
@frozen public enum NBKEndianness: Hashable, Sendable {
//=------------------------------------------------------------------------=
// MARK: State
//=------------------------------------------------------------------------=
/// A value representing a least-to-most-significant byte order.
case little
/// A value representing a most-to-least-significant byte order.
case big
//=------------------------------------------------------------------------=
// MARK: Initializers
//=------------------------------------------------------------------------=
/// Returns the current system's byte order.
@inlinable public static var system: Self {
#if _endian(little)
return .little
#elseif _endian(big)
return .big
#endif
}
}