From bdf540c282e68c936e3aafe81870e2e8b5fdd2b1 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Fri, 27 Oct 2023 13:25:50 -0700 Subject: [PATCH] initial commits --- README.md | 48 ++++++++++++++++--- encodebyte.go => enc/runes/encodebyte.go | 2 +- .../runes/encodebyte_test.go | 8 ++-- encodeint64.go | 17 +++---- encodeuint16.go | 5 +- encodeuint32.go | 9 ++-- encodeuint64.go | 17 +++---- 7 files changed, 73 insertions(+), 33 deletions(-) rename encodebyte.go => enc/runes/encodebyte.go (97%) rename encodebyte_test.go => enc/runes/encodebyte_test.go (97%) diff --git a/README.md b/README.md index c96cdd4..4543087 100644 --- a/README.md +++ b/README.md @@ -70,17 +70,34 @@ r1, r0 := hexadeca.EncodeRune(value, CustomSymbol) To hexadecimal encode a `byte` use any of these: ```go -import "sourcecode.social/reiver/go-hexadeca" +import "sourcecode.social/reiver/go-hexadeca/enc/bytes" // ... // value==254 -> mostSignificant=='f', leastSignificant=='e' -mostSignificant, leastSignificant := hexadeca.EncodeByteUsingLowerCaseSymbols(value) +mostSignificant, leastSignificant := hexadecabytes.EncodeByteUsingLowerCaseSymbols(value) // ... // value==254 -> mostSignificant=='F', leastSignificant=='E' -mostSignificant, leastSignificant := hexadeca.EncodeByteUsingUpperCaseSymbols(value) +mostSignificant, leastSignificant := hexadecabytes.EncodeByteUsingUpperCaseSymbols(value) + +``` + +Or: + +```go +import "sourcecode.social/reiver/go-hexadeca/enc/runes" + +// ... + +// value==254 -> mostSignificant=='f', leastSignificant=='e' +mostSignificant, leastSignificant := hexadecarunes.EncodeByteUsingLowerCaseSymbols(value) + +// ... + +// value==254 -> mostSignificant=='F', leastSignificant=='E' +mostSignificant, leastSignificant := hexadecarunes.EncodeByteUsingUpperCaseSymbols(value) ``` @@ -88,19 +105,38 @@ Or: ```go import ( - "sourcecode.social/reiver/go-hexadeca" + "sourcecode.social/reiver/go-hexadeca/enc/bytes" + "sourcecode.social/reiver/go-hexadeca/symbols/byte" +) + +// ... + +// value==254 -> mostSignificant=='f', leastSignificant=='e' +mostSignificant, leastSignificant := hexadecabytes.EncodeByte(value, bytesymbols.LowerCase) + +// ... + +// value==254 -> mostSignificant=='F', leastSignificant=='E' +mostSignificant, leastSignificant := hexadecabytes.EncodeByte(value, bytesymbols.UpperCase) +``` + +Or: + +```go +import ( + "sourcecode.social/reiver/go-hexadeca/enc/runes" "sourcecode.social/reiver/go-hexadeca/symbols/rune" ) // ... // value==254 -> mostSignificant=='f', leastSignificant=='e' -mostSignificant, leastSignificant := hexadeca.EncodeByte(value, runesymbols.LowerCase) +mostSignificant, leastSignificant := hexadecarunes.EncodeByte(value, runesymbols.LowerCase) // ... // value==254 -> mostSignificant=='F', leastSignificant=='E' -mostSignificant, leastSignificant := hexadeca.EncodeByte(value, runesymbols.UpperCase) +mostSignificant, leastSignificant := hexadecarunes.EncodeByte(value, runesymbols.UpperCase) ``` ## hexadecimal encode `uint16` diff --git a/encodebyte.go b/enc/runes/encodebyte.go similarity index 97% rename from encodebyte.go rename to enc/runes/encodebyte.go index f512482..2fb2f5f 100644 --- a/encodebyte.go +++ b/enc/runes/encodebyte.go @@ -1,4 +1,4 @@ -package hexadeca +package hexadecarunes import ( "sourcecode.social/reiver/go-hexadeca/symbols/rune" diff --git a/encodebyte_test.go b/enc/runes/encodebyte_test.go similarity index 97% rename from encodebyte_test.go rename to enc/runes/encodebyte_test.go index c202be6..4c2f03c 100644 --- a/encodebyte_test.go +++ b/enc/runes/encodebyte_test.go @@ -1,9 +1,9 @@ -package hexadeca_test +package hexadecarunes_test import ( "testing" - "sourcecode.social/reiver/go-hexadeca" + "sourcecode.social/reiver/go-hexadeca/enc/runes" ) func TestEncodeByteUsingLowerCaseSymbols(t *testing.T) { @@ -314,7 +314,7 @@ func TestEncodeByteUsingLowerCaseSymbols(t *testing.T) { for testNumber, test := range tests { - actualMostSignificant, actualLeastSignificant := hexadeca.EncodeByteUsingLowerCaseSymbols(test.Value) + actualMostSignificant, actualLeastSignificant := hexadecarunes.EncodeByteUsingLowerCaseSymbols(test.Value) { actual := actualMostSignificant @@ -652,7 +652,7 @@ func TestEncodeByteUsingUpperCaseSymbols(t *testing.T) { for testNumber, test := range tests { - actualMostSignificant, actualLeastSignificant := hexadeca.EncodeByteUsingUpperCaseSymbols(test.Value) + actualMostSignificant, actualLeastSignificant := hexadecarunes.EncodeByteUsingUpperCaseSymbols(test.Value) { actual := actualMostSignificant diff --git a/encodeint64.go b/encodeint64.go index bce6acb..af74662 100644 --- a/encodeint64.go +++ b/encodeint64.go @@ -1,18 +1,19 @@ package hexadeca import ( + "sourcecode.social/reiver/go-hexadeca/enc/runes" "sourcecode.social/reiver/go-hexadeca/symbols/rune" ) func EncodeInt64(value int64, symbolFunc func(byte)rune) (r15 rune, r14 rune, r13 rune, r12 rune, r11 rune, r10 rune, r9 rune, r8 rune, r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) { - r15, r14 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 7))), symbolFunc) - r13, r12 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 6))), symbolFunc) - r11, r10 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 5))), symbolFunc) - r9, r8 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 4))), symbolFunc) - r7, r6 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 3))), symbolFunc) - r5, r4 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 2))), symbolFunc) - r3, r2 = EncodeByte(byte(0x00000000000000ff & (value >> (8 ))), symbolFunc) - r1, r0 = EncodeByte(byte(0x00000000000000ff & value ), symbolFunc) + r15, r14 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 7))), symbolFunc) + r13, r12 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 6))), symbolFunc) + r11, r10 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 5))), symbolFunc) + r9, r8 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 4))), symbolFunc) + r7, r6 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 3))), symbolFunc) + r5, r4 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 2))), symbolFunc) + r3, r2 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 ))), symbolFunc) + r1, r0 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & value ), symbolFunc) return } diff --git a/encodeuint16.go b/encodeuint16.go index b0863f7..4251661 100644 --- a/encodeuint16.go +++ b/encodeuint16.go @@ -1,12 +1,13 @@ package hexadeca import ( + "sourcecode.social/reiver/go-hexadeca/enc/runes" "sourcecode.social/reiver/go-hexadeca/symbols/rune" ) func EncodeUint16(value uint16, symbolFunc func(byte)rune) (r3 rune, r2 rune, r1 rune, r0 rune) { - r3, r2 = EncodeByte(byte(0x00ff & (value >> (8 ))), symbolFunc) - r1, r0 = EncodeByte(byte(0x00ff & value ), symbolFunc) + r3, r2 = hexadecarunes.EncodeByte(byte(0x00ff & (value >> (8 ))), symbolFunc) + r1, r0 = hexadecarunes.EncodeByte(byte(0x00ff & value ), symbolFunc) return } diff --git a/encodeuint32.go b/encodeuint32.go index 7a1fa95..f3c397c 100644 --- a/encodeuint32.go +++ b/encodeuint32.go @@ -1,14 +1,15 @@ package hexadeca import ( + "sourcecode.social/reiver/go-hexadeca/enc/runes" "sourcecode.social/reiver/go-hexadeca/symbols/rune" ) func EncodeUint32(value uint32, symbolFunc func(byte)rune) (r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) { - r7, r6 = EncodeByte(byte(0x000000ff & (value >> (8 * 3))), symbolFunc) - r5, r4 = EncodeByte(byte(0x000000ff & (value >> (8 * 2))), symbolFunc) - r3, r2 = EncodeByte(byte(0x000000ff & (value >> (8 ))), symbolFunc) - r1, r0 = EncodeByte(byte(0x000000ff & value ), symbolFunc) + r7, r6 = hexadecarunes.EncodeByte(byte(0x000000ff & (value >> (8 * 3))), symbolFunc) + r5, r4 = hexadecarunes.EncodeByte(byte(0x000000ff & (value >> (8 * 2))), symbolFunc) + r3, r2 = hexadecarunes.EncodeByte(byte(0x000000ff & (value >> (8 ))), symbolFunc) + r1, r0 = hexadecarunes.EncodeByte(byte(0x000000ff & value ), symbolFunc) return } diff --git a/encodeuint64.go b/encodeuint64.go index 40adacd..215eba5 100644 --- a/encodeuint64.go +++ b/encodeuint64.go @@ -1,18 +1,19 @@ package hexadeca import ( + "sourcecode.social/reiver/go-hexadeca/enc/runes" "sourcecode.social/reiver/go-hexadeca/symbols/rune" ) func EncodeUint64(value uint64, symbolFunc func(byte)rune) (r15 rune, r14 rune, r13 rune, r12 rune, r11 rune, r10 rune, r9 rune, r8 rune, r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) { - r15, r14 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 7))), symbolFunc) - r13, r12 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 6))), symbolFunc) - r11, r10 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 5))), symbolFunc) - r9, r8 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 4))), symbolFunc) - r7, r6 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 3))), symbolFunc) - r5, r4 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 2))), symbolFunc) - r3, r2 = EncodeByte(byte(0x00000000000000ff & (value >> (8 ))), symbolFunc) - r1, r0 = EncodeByte(byte(0x00000000000000ff & value ), symbolFunc) + r15, r14 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 7))), symbolFunc) + r13, r12 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 6))), symbolFunc) + r11, r10 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 5))), symbolFunc) + r9, r8 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 4))), symbolFunc) + r7, r6 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 3))), symbolFunc) + r5, r4 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 * 2))), symbolFunc) + r3, r2 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & (value >> (8 ))), symbolFunc) + r1, r0 = hexadecarunes.EncodeByte(byte(0x00000000000000ff & value ), symbolFunc) return }