Documentation ¶
Index ¶
- Constants
- Variables
- func Add8(a, b, carryIn byte) (sum, carryOut byte)
- func Add8BigEndian(a, b []byte, carryIn byte) (sum []byte, carryOut byte)
- func AsBase16BigInt(b []byte) (string, error)deprecated
- func AsBase16Sprintf(b []byte) (string, error)deprecated
- func AsBase32BigInt(b []byte) (string, error)deprecated
- func AsBase62BigInt(b []byte) (string, error)deprecated
- func DecodeFromBase16(str string) ([]byte, error)
- func DecodeFromBase32(str string) ([]byte, error)
- func DecodeFromBase62(str string) ([]byte, error)
- func EncodeToBase16(b []byte) (string, error)
- func EncodeToBase32(b []byte) (string, error)
- func EncodeToBase62(b []byte) (string, error)
- func SliceEqual(a, b []uint8) bool
- func SortKeys[T any](m map[string]T) []string
- func ToAdjustedTimestamp(t time.Time) uint32
- func ToStandardizedTime(ts uint32) time.Time
- type CcId
- func NewCcId128WithFingerprint(timestamp uint32, fingerprint []byte, payload []byte) (CcId, error)
- func NewCcId160WithFingerprint(timestamp uint32, fingerprint []byte, payload []byte) (CcId, error)
- func NewCcId64WithFingerprint(timestamp uint32, fingerprint []byte, payload []byte) (CcId, error)
- func NewCcId96WithFingerprint(timestamp uint32, fingerprint []byte, payload []byte) (CcId, error)
- type CcId128
- func (id CcId128) AsBase16() string
- func (id CcId128) AsBase32() string
- func (id CcId128) AsBase62() string
- func (id CcId128) Bytes() []byte
- func (id CcId128) Fingerprint() []byte
- func (id CcId128) GoString() string
- func (id CcId128) Payload() []byte
- func (id CcId128) Size() byte
- func (id CcId128) String() string
- func (id CcId128) Time() time.Time
- func (id CcId128) Timestamp() uint32
- type CcId160
- func (id CcId160) AsBase16() string
- func (id CcId160) AsBase32() string
- func (id CcId160) AsBase62() string
- func (id CcId160) Bytes() []byte
- func (id CcId160) Fingerprint() []byte
- func (id CcId160) GoString() string
- func (id CcId160) Payload() []byte
- func (id CcId160) Size() byte
- func (id CcId160) String() string
- func (id CcId160) Time() time.Time
- func (id CcId160) Timestamp() uint32
- type CcId64
- func (id CcId64) AsBase16() string
- func (id CcId64) AsBase32() string
- func (id CcId64) AsBase62() string
- func (id CcId64) Bytes() []byte
- func (id CcId64) Fingerprint() []byte
- func (id CcId64) GoString() string
- func (id CcId64) Payload() []byte
- func (id CcId64) Size() byte
- func (id CcId64) String() string
- func (id CcId64) Time() time.Time
- func (id CcId64) Timestamp() uint32
- func (id CcId64) Uint64() uint64
- type CcId96
- func (id CcId96) AsBase16() string
- func (id CcId96) AsBase32() string
- func (id CcId96) AsBase62() string
- func (id CcId96) Bytes() []byte
- func (id CcId96) Fingerprint() []byte
- func (id CcId96) GoString() string
- func (id CcId96) Payload() []byte
- func (id CcId96) Size() byte
- func (id CcId96) String() string
- func (id CcId96) Time() time.Time
- func (id CcId96) Timestamp() uint32
- type CcIdCtor
- type CcIdMonotonicStrategy
- type CcIdTestCases
- type CcIdTestErrorCases
- type Clock
- type FiftyPercentMonotonicStrategy
- type IncreaseMonotonicStrategy
- type InvalidCharacterError
- type InvalidFingerprintSizeError
- type InvalidLengthError
- type InvalidPayloadSizeError
- type OverflowError
- type RealClock
Constants ¶
const ( Base16strSize64 = 16 Base16strSize96 = 24 Base16strSize128 = 32 Base16strSize160 = 40 )
const ( Base32strSize64 = 13 Base32strSize96 = 20 Base32strSize128 = 26 Base32strSize160 = 32 )
const ( Base62strSize64 = 11 Base62strSize96 = 17 Base62strSize128 = 22 Base62strSize160 = 27 )
const ( TimestampSize = 4 MaxFingerprintSize64 = 1 MaxFingerprintSize = 5 ByteSliceSize64 = 8 ByteSliceSize96 = 12 ByteSliceSize128 = 16 ByteSliceSize160 = 20 BASE62 = 62 BASE32 = 32 BASE16 = 16 )
Variables ¶
var TestCaseCcId128Map = map[string]CcIdTestCases{ "min id": { Fingerprint: nil, Bytes: []byte{0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}, Base62: "0000000P9MVMcaXWHEX8yi", Base32: "00000000820C20A1G7104GM2RC", Base16: "000000000102030405060708090A0B0C", GoString: "CcId{size: 16, timestamp: 0 (2014-05-13T16:53:20Z), payload: 0x0102030405060708090a0b0c}", // contains filtered or unexported fields }, "some id": { Fingerprint: nil, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc}, Base62: "0YLmNWVbf7YaOQib5nMzim", Base32: "0J6HB7G4926D25ASKQH2CTNEYC", Base16: "12345678112233445566778899AABBCC", GoString: "CcId{size: 16, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x112233445566778899aabbcc}", // contains filtered or unexported fields }, "some id fingerprint": { Fingerprint: []byte{0xdd, 0xee, 0xff}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0xdd, 0xee, 0xff, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99}, Base62: "0YLmNXq2QX11gZMcdEr1iL", Base32: "0J6HB7HQFEZW8J4CT4ANK7F24S", Base16: "12345678DDEEFF112233445566778899", GoString: "CcId{size: 16, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0xddeeff, payload: 0x112233445566778899}", // contains filtered or unexported fields }, "max id": { Fingerprint: nil, Bytes: []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, Base62: "7n42DGM5Tflk9n8mt7Fhc7", Base32: "7ZZZZZZZZZZZZZZZZZZZZZZZZZ", Base16: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", GoString: "CcId{size: 16, timestamp: 4294967295 (2150-06-19T23:21:35Z), payload: 0xffffffffffffffffffffffff}", // contains filtered or unexported fields }, "large payload": { Fingerprint: nil, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc}, Base62: "0YLmNWVbf7YaOQib5nMzim", Base32: "0J6HB7G4926D25ASKQH2CTNEYC", Base16: "12345678112233445566778899AABBCC", GoString: "CcId{size: 16, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x112233445566778899aabbcc}", // contains filtered or unexported fields }, "empty fingerprint": { Fingerprint: []byte{}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc}, Base62: "0YLmNWVbf7YaOQib5nMzim", Base32: "0J6HB7G4926D25ASKQH2CTNEYC", Base16: "12345678112233445566778899AABBCC", GoString: "CcId{size: 16, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x112233445566778899aabbcc}", // contains filtered or unexported fields }, "min fingerprint": { Fingerprint: []byte{0xdd}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0xdd, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb}, Base62: "0YLmNXpgne2KU0qObqHPwp", Base32: "0J6HB7HQ8H48SM8NB6EY49KANV", Base16: "12345678DD112233445566778899AABB", GoString: "CcId{size: 16, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0xdd, payload: 0x112233445566778899aabb}", // contains filtered or unexported fields }, "max fingerprint": { Fingerprint: []byte{0xbb, 0xcc, 0xdd, 0xee, 0xff}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}, Base62: "0YLmNXcIdJeuW33h8kJikR", Base32: "0J6HB7HEYCVQQFY4926D25ASKQ", Base16: "12345678BBCCDDEEFF11223344556677", GoString: "CcId{size: 16, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0xbbccddeeff, payload: 0x11223344556677}", // contains filtered or unexported fields }, "fingerprint large payload": { Fingerprint: []byte{0xdd, 0xee, 0xff}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0xdd, 0xee, 0xff, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99}, Base62: "0YLmNXq2QX11gZMcdEr1iL", Base32: "0J6HB7HQFEZW8J4CT4ANK7F24S", Base16: "12345678DDEEFF112233445566778899", GoString: "CcId{size: 16, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0xddeeff, payload: 0x112233445566778899}", // contains filtered or unexported fields }, }
var TestCaseCcId160Map = map[string]CcIdTestCases{ "min id": { Fingerprint: nil, Bytes: []byte{0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, Base62: "0000001tuWckR0Qgud2DqqiTysq", Base32: "00000001081G81860W40J2GB1G6GW3RG", Base16: "000000000102030405060708090A0B0C0D0E0F10", GoString: "CcId{size: 20, timestamp: 0 (2014-05-13T16:53:20Z), payload: 0x0102030405060708090a0b0c0d0e0f10}", // contains filtered or unexported fields }, "some id": { Fingerprint: nil, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01}, Base62: "2b2j6yknbhs3Jp7SXB5fMnkzNmj", Base32: "28T5CY0H48SM8NB6EY49KANVSKEYXZR1", Base16: "12345678112233445566778899AABBCCDDEEFF01", GoString: "CcId{size: 20, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x112233445566778899aabbccddeeff01}", // contains filtered or unexported fields }, "some id fingerprint": { Fingerprint: []byte{0xdd, 0xee, 0xff}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0xdd, 0xee, 0xff, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd}, Base62: "2b2j74zFdMosqaItZ9RHloJDeA9", Base32: "28T5CY6XXVZH28HK8HAPCXW8K6NBQK6X", Base16: "12345678DDEEFF112233445566778899AABBCCDD", GoString: "CcId{size: 20, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0xddeeff, payload: 0x112233445566778899aabbccdd}", // contains filtered or unexported fields }, "max id": { Fingerprint: nil, Bytes: []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, Base62: "aWgEPTl1tmebfsQzFP4bxwgy80V", Base32: "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ", Base16: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", GoString: "CcId{size: 20, timestamp: 4294967295 (2150-06-19T23:21:35Z), payload: 0xffffffffffffffffffffffffffffffff}", // contains filtered or unexported fields }, "large payload": { Fingerprint: nil, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01}, Base62: "2b2j6yknbhs3Jp7SXB5fMnkzNmj", Base32: "28T5CY0H48SM8NB6EY49KANVSKEYXZR1", Base16: "12345678112233445566778899AABBCCDDEEFF01", GoString: "CcId{size: 20, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x112233445566778899aabbccddeeff01}", // contains filtered or unexported fields }, "empty fingerprint": { Fingerprint: []byte{}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01}, Base62: "2b2j6yknbhs3Jp7SXB5fMnkzNmj", Base32: "28T5CY0H48SM8NB6EY49KANVSKEYXZR1", Base16: "12345678112233445566778899AABBCCDDEEFF01", GoString: "CcId{size: 20, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x112233445566778899aabbccddeeff01}", // contains filtered or unexported fields }, "min fingerprint": { Fingerprint: []byte{0xff}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0xff, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, Base62: "2b2j75zlyuoPcliOOIZr8T6RIcR", Base32: "28T5CY7Z24H36H2NCSVRH6DAQF6DVVQZ", Base16: "12345678FF112233445566778899AABBCCDDEEFF", GoString: "CcId{size: 20, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0xff, payload: 0x112233445566778899aabbccddeeff}", // contains filtered or unexported fields }, "max fingerprint": { Fingerprint: []byte{0xbb, 0xcc, 0xdd, 0xee, 0xff}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb}, Base62: "2b2j73wqIW2wyWMdozma2887Rpj", Base32: "28T5CY5VSKEYXZRH48SM8NB6EY49KANV", Base16: "12345678BBCCDDEEFF112233445566778899AABB", GoString: "CcId{size: 20, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0xbbccddeeff, payload: 0x112233445566778899aabb}", // contains filtered or unexported fields }, "fingerprint large payload": { Fingerprint: []byte{0xdd, 0xee, 0xff}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0xdd, 0xee, 0xff, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd}, Base62: "2b2j74zFdMosqaItZ9RHloJDeA9", Base32: "28T5CY6XXVZH28HK8HAPCXW8K6NBQK6X", Base16: "12345678DDEEFF112233445566778899AABBCCDD", GoString: "CcId{size: 20, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0xddeeff, payload: 0x112233445566778899aabbccdd}", // contains filtered or unexported fields }, }
var TestCaseCcId64Map = map[string]CcIdTestCases{ "min id": { Fingerprint: nil, Bytes: []byte{0, 0, 0, 0, 1, 2, 3, 4}, Base62: "00000018wom", Base32: "00000000G40R4", Base16: "0000000001020304", GoString: "CcId{size: 8, timestamp: 0 (2014-05-13T16:53:20Z), payload: 0x01020304}", // contains filtered or unexported fields }, "some id": { Fingerprint: nil, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78}, Base62: "1YtudRc1sam", Base32: "14D2PF0938NKR", Base16: "1234567812345678", GoString: "CcId{size: 8, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x12345678}", // contains filtered or unexported fields }, "some id fingerprint": { Fingerprint: []byte{0x99}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x99, 0x12, 0x34, 0x56}, Base62: "1YtudU59sta", Base32: "14D2PF2CH4D2P", Base16: "1234567899123456", GoString: "CcId{size: 8, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0x99, payload: 0x123456}", // contains filtered or unexported fields }, "max id": { Fingerprint: nil, Bytes: []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, Base62: "LygHa16AHYF", Base32: "FZZZZZZZZZZZZ", Base16: "FFFFFFFFFFFFFFFF", GoString: "CcId{size: 8, timestamp: 4294967295 (2150-06-19T23:21:35Z), payload: 0xffffffff}", // contains filtered or unexported fields }, "large payload": { Fingerprint: nil, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 1, 2, 3, 4}, Base62: "1YtudRIVJkC", Base32: "14D2PF00G40R4", Base16: "1234567801020304", GoString: "CcId{size: 8, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x01020304}", // contains filtered or unexported fields }, "empty fingerprint": { Fingerprint: []byte{}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 1, 2, 3, 4}, Base62: "1YtudRIVJkC", Base32: "14D2PF00G40R4", Base16: "1234567801020304", GoString: "CcId{size: 8, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x01020304}", // contains filtered or unexported fields }, "fingerprint": { Fingerprint: []byte{0x99}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x99, 1, 2, 3}, Base62: "1YtudU559iF", Base32: "14D2PF2CG20G3", Base16: "1234567899010203", GoString: "CcId{size: 8, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0x99, payload: 0x010203}", // contains filtered or unexported fields }, "fingerprint large payload": { Fingerprint: []byte{0x99}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x99, 1, 2, 3}, Base62: "1YtudU559iF", Base32: "14D2PF2CG20G3", Base16: "1234567899010203", GoString: "CcId{size: 8, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0x99, payload: 0x010203}", // contains filtered or unexported fields }, }
var TestCaseCcId96Map = map[string]CcIdTestCases{ "min id": { Fingerprint: nil, Bytes: []byte{0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}, Base62: "00000005McJmDgrvc", Base32: "0000000020G30G2GC1R8", Base16: "000000000102030405060708", GoString: "CcId{size: 12, timestamp: 0 (2014-05-13T16:53:20Z), payload: 0x0102030405060708}", // contains filtered or unexported fields }, "some id": { Fingerprint: nil, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}, Base62: "07KHzdKvYVTUKifX6", Base32: "04HMASW128HK8HAPCXW8", Base16: "123456781122334455667788", GoString: "CcId{size: 12, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x1122334455667788}", // contains filtered or unexported fields }, "some id fingerprint": { Fingerprint: []byte{0x99, 0xaa, 0xbb}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x99, 0xaa, 0xbb, 0x11, 0x22, 0x33, 0x44, 0x55}, Base62: "07KHzdWeJr1R43LQj", Base32: "04HMASW9KANV24H36H2N", Base16: "1234567899AABB1122334455", GoString: "CcId{size: 12, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0x99aabb, payload: 0x1122334455}", // contains filtered or unexported fields }, "max id": { Fingerprint: nil, Bytes: []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, Base62: "1f2SI9UJPXvb7vdJ1", Base32: "1ZZZZZZZZZZZZZZZZZZZ", Base16: "FFFFFFFFFFFFFFFFFFFFFFFF", GoString: "CcId{size: 12, timestamp: 4294967295 (2150-06-19T23:21:35Z), payload: 0xffffffffffffffff}", // contains filtered or unexported fields }, "large payload": { Fingerprint: nil, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 1, 2, 3, 4, 5, 6, 7, 8}, Base62: "07KHzdJXicN2nekfI", Base32: "04HMASW020G30G2GC1R8", Base16: "123456780102030405060708", GoString: "CcId{size: 12, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x0102030405060708}", // contains filtered or unexported fields }, "empty fingerprint": { Fingerprint: []byte{}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 1, 2, 3, 4, 5, 6, 7, 8}, Base62: "07KHzdJXicN2nekfI", Base32: "04HMASW020G30G2GC1R8", Base16: "123456780102030405060708", GoString: "CcId{size: 12, timestamp: 305419896 (2024-01-16T15:44:56Z), payload: 0x0102030405060708}", // contains filtered or unexported fields }, "min fingerprint": { Fingerprint: []byte{0x99}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x99, 1, 2, 3, 4, 5, 6, 7}, Base62: "07KHzdWan3RXAOmU3", Base32: "04HMASW9J0820C20A1G7", Base16: "123456789901020304050607", GoString: "CcId{size: 12, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0x99, payload: 0x01020304050607}", // contains filtered or unexported fields }, "max fingerprint": { Fingerprint: []byte{0x99, 0x88, 0x77, 0x66, 0x55}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x99, 0x88, 0x77, 0x66, 0x55, 1, 2, 3}, Base62: "07KHzdWdbgLit1TQR", Base32: "04HMASW9K23QCSAG20G3", Base16: "123456789988776655010203", GoString: "CcId{size: 12, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0x9988776655, payload: 0x010203}", // contains filtered or unexported fields }, "fingerprint large payload": { Fingerprint: []byte{0x99, 0x88, 0x77}, Bytes: []byte{0x12, 0x34, 0x56, 0x78, 0x99, 0x88, 0x77, 1, 2, 3, 4, 5}, Base62: "07KHzdWdbgE3rbRor", Base32: "04HMASW9K23Q04106105", Base16: "123456789988770102030405", GoString: "CcId{size: 12, timestamp: 305419896 (2024-01-16T15:44:56Z), fingerprint: 0x998877, payload: 0x0102030405}", // contains filtered or unexported fields }, }
Functions ¶
func Add8 ¶
Add8 adds two bytes and a carryIn byte and returns the sum and carryOut byte. The carryOut byte is 1 if the sum overflows, otherwise 0. The sum is truncated to 8 bits. 'a' and 'b' are the bytes to add. 'carryIn' is the carry in byte. 0 or 1.
func Add8BigEndian ¶
Add8BigEndian adds two byte slices and a carryIn byte and returns the sum byte slice and carryOut byte. The carryOut byte is 1 if the sum overflows, otherwise 0. 'a' and 'b' are the byte slices to add. 'carryIn' is the carry in byte. 0 or 1.
func AsBase16BigInt
deprecated
func AsBase16Sprintf
deprecated
func AsBase32BigInt
deprecated
func AsBase62BigInt
deprecated
func DecodeFromBase16 ¶
DecodeFromBase16 decodes a base16 string to a byte slice. The byte order is big endian.
func DecodeFromBase32 ¶
DecodeFromBase32 decodes a base32 string to a byte slice. The byte order is big endian.
func DecodeFromBase62 ¶
DecodeFromBase62 decodes a base62 string to a byte slice. The byte order is big endian. Implementation is based on ksuid quick algorithm.
func EncodeToBase16 ¶
EncodeToBase16 encodes a byte slice to a base16 string. The byte order is big endian.
func EncodeToBase32 ¶
EncodeToBase32 encodes a byte slice to a base32 string. The byte order is big endian.
func EncodeToBase62 ¶
EncodeToBase62 encodes a byte slice to a base62 string. The byte order is big endian. Implementation is based on ksuid quick algorithm.
func SliceEqual ¶
func ToAdjustedTimestamp ¶
ToAdjustedTimestamp converts a time.Time to a uint32 timestamp with custom epoch
func ToStandardizedTime ¶
ToStandardizedTime converts a uint32 timestamp with custom epoch to a UTC time.Time
Types ¶
type CcId ¶
type CcId interface { // Size returns the size of the CcId. Size() byte // Time returns the time associated with the CcId. Time() time.Time // Timestamp returns the timestamp of the CcId. Unix epoch in seconds. Timestamp() uint32 // Fingerprint returns the fingerprint of the CcId. Fingerprint() []byte // Payload returns random payload of the CcId. Payload() []byte // String returns the CcId as a base62 string. String() string // Bytes returns the CcId as a raw byte slice. Bytes() []byte // AsBase62 returns the CcId as a base62 string. AsBase62() string // (Encode: 95 MB/s / Decode: 155 MB/s) // AsBase32 returns the CcId as a base32 string. AsBase32() string // (Encode: 425 MB/s / Decode: 365 MB/s) // AsBase16 returns the CcId as a base16 string. AsBase16() string // (Encode: 680 MB/s / Decode: 490 MB/s) }
CcId represents a unique identifier with various properties. It provides methods for retrieving these properties and for exporting the identifier in different formats.
type CcId128 ¶
type CcId128 struct {
// contains filtered or unexported fields
}
var NilCcId128 CcId128
func (CcId128) Fingerprint ¶
type CcId160 ¶
type CcId160 struct {
// contains filtered or unexported fields
}
var NilCcId160 CcId160
func (CcId160) Fingerprint ¶
type CcId64 ¶
type CcId64 struct {
// contains filtered or unexported fields
}
var NilCcId64 CcId64
func (CcId64) Fingerprint ¶
type CcId96 ¶
type CcId96 struct {
// contains filtered or unexported fields
}
var NilCcId96 CcId96
func (CcId96) Fingerprint ¶
type CcIdMonotonicStrategy ¶
CcIdMonotonicStrategy is an interface for monotonic strategy It should return mutated payload and carry byte
func NewFiftyPercentMonotonicStrategy ¶
func NewFiftyPercentMonotonicStrategy(rd io.Reader) CcIdMonotonicStrategy
NewFiftyPercentMonotonicStrategy creates a new FiftyPercentMonotonicStrategy It will use the given io.Reader to generate random bytes
func NewIncreaseMonotonicStrategy ¶
func NewIncreaseMonotonicStrategy() CcIdMonotonicStrategy
NewIncreaseMonotonicStrategy creates a new IncreaseMonotonicStrategy
type CcIdTestCases ¶
type CcIdTestErrorCases ¶
type CcIdTestErrorCases struct {
// contains filtered or unexported fields
}
type FiftyPercentMonotonicStrategy ¶
type FiftyPercentMonotonicStrategy struct {
// contains filtered or unexported fields
}
FiftyPercentMonotonicStrategy is a monotonic strategy that increase payload by random value between 0 and 50% of payload bits size For example, if payload is 32 bits, it will increase payload by random value of 16 bits
func (*FiftyPercentMonotonicStrategy) Mutate ¶
func (s *FiftyPercentMonotonicStrategy) Mutate(v []byte) (res []byte, carry byte)
Mutate implements CcIdMonotonicStrategy interface It increases payload by random value between 0 and 50% of payload bits size If no data read, it will return 1 as carry to trigger next time tick
type IncreaseMonotonicStrategy ¶
type IncreaseMonotonicStrategy struct{}
IncreaseMonotonicStrategy is a monotonic strategy that increase payload by 1
type InvalidCharacterError ¶
func (InvalidCharacterError) Error ¶
func (e InvalidCharacterError) Error() string
type InvalidFingerprintSizeError ¶
func (InvalidFingerprintSizeError) Error ¶
func (e InvalidFingerprintSizeError) Error() string
type InvalidLengthError ¶
type InvalidLengthError byte
func (InvalidLengthError) Error ¶
func (e InvalidLengthError) Error() string
type InvalidPayloadSizeError ¶
func (InvalidPayloadSizeError) Error ¶
func (e InvalidPayloadSizeError) Error() string
type OverflowError ¶
type OverflowError byte
func (OverflowError) Error ¶
func (e OverflowError) Error() string