From 172d8a53da5c91d7babaefc385b733b8860b8260 Mon Sep 17 00:00:00 2001 From: Sergey Vidyuk Date: Tue, 6 Feb 2018 23:27:20 +0000 Subject: [PATCH] add guid support --- decode_test.go | 6 ++++++ encode.go | 4 ++-- encode_test.go | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/decode_test.go b/decode_test.go index 60b7750..28c0bfc 100644 --- a/decode_test.go +++ b/decode_test.go @@ -29,6 +29,12 @@ func TestBool(t *testing.T) { // 01b var BoolVecBytes = []byte{0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01} +// 8c6b8b64-6815-6084-0a3e-178401251b68 +var GuidBytes = []byte{0x01, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0xfe, 0x8c, 0x6b, 0x8b, 0x64, 0x68, 0x15, 0x60, 0x84, 0x0a, 0x3e, 0x17, 0x84, 0x01, 0x25, 0x1b, 0x68} + +// 0x0 sv/: 16 cut `byte$til 32 +var GuidVecBytes = []byte{0x01, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f} + // 1i var IntBytes = []byte{0x01, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0xfa, 0x01, 0x00, 0x00, 0x00} diff --git a/encode.go b/encode.go index 445d0a4..39d0d56 100644 --- a/encode.go +++ b/encode.go @@ -55,7 +55,7 @@ func writeData(dbuf io.Writer, order binary.ByteOrder, data *K) (err error) { val = 0x00 } binary.Write(dbuf, order, val) - case -KI, -KJ, -KE, -KF: + case -KI, -KJ, -KE, -KF, -UU: binary.Write(dbuf, order, int8(data.Type)) binary.Write(dbuf, order, data.Data) case -KP: @@ -79,7 +79,7 @@ func writeData(dbuf io.Writer, order binary.ByteOrder, data *K) (err error) { for _, b := range tosend { binary.Write(dbuf, order, boolmap[b]) } - case KG, KI, KJ, KE, KF, KZ, KT, KD, KV, KU, KM, KN: + case KG, KI, KJ, KE, KF, KZ, KT, KD, KV, KU, KM, KN, UU: binary.Write(dbuf, order, int8(data.Type)) binary.Write(dbuf, order, data.Attr) // attributes binary.Write(dbuf, order, int32(reflect.ValueOf(data.Data).Len())) diff --git a/encode_test.go b/encode_test.go index 45bdc2d..fb7de48 100644 --- a/encode_test.go +++ b/encode_test.go @@ -5,6 +5,7 @@ import ( "errors" "time" //"fmt" + "github.com/nu7hatch/gouuid" "testing" ) @@ -41,6 +42,8 @@ var encodingTests = []struct { {"2013.06m +til 3", &K{KM, NONE, []Month{161, 162, 163}}, MonthVecBytes}, {"2018.01.26D01:49:00.884361000", &K{-KP, NONE, TimestampAsTime}, TimestampAsBytes}, {"2#2018.01.26D01:49:00.884361000", &K{KP, NONE, []time.Time{TimestampAsTime, TimestampAsTime}}, TimestampVectorAsBytes}, + {"8c6b8b64-6815-6084-0a3e-178401251b68", &K{-UU, NONE, uuid.UUID{0x8c, 0x6b, 0x8b, 0x64, 0x68, 0x15, 0x60, 0x84, 0x0a, 0x3e, 0x17, 0x84, 0x01, 0x25, 0x1b, 0x68}}, GuidBytes}, + {"0x0 sv/: 16 cut `byte$til 32", &K{UU, NONE, []uuid.UUID{{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}}}, GuidVecBytes}, } func TestEncoding(t *testing.T) {