Skip to content

Commit

Permalink
add guid support
Browse files Browse the repository at this point in the history
  • Loading branch information
sv committed Feb 6, 2018
1 parent d21d713 commit 172d8a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
4 changes: 2 additions & 2 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()))
Expand Down
3 changes: 3 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"time"
//"fmt"
"github.com/nu7hatch/gouuid"
"testing"
)

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 172d8a5

Please sign in to comment.