From 266e353c5fab76430f53e473cde46e7780f93ef3 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 16 Oct 2023 10:03:51 -0600 Subject: [PATCH] Fixed duration serialization --- context.go | 3 +-- serialize.go | 2 +- serialize_test.go | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index b590745..f6ad7b4 100644 --- a/context.go +++ b/context.go @@ -138,7 +138,6 @@ func (ctx *Context)RegisterSignal(reflect_type reflect.Type, signal_type SignalT return nil } -// Add a node to a context, returns an error if the def is invalid or already exists in the context func (ctx *Context)RegisterExtension(reflect_type reflect.Type, ext_type ExtType, data interface{}) error { _, exists := ctx.Extensions[ext_type] if exists == true { @@ -1193,7 +1192,7 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) { if value == nil { data = nil } else { - data := make([]byte, 8) + data = make([]byte, 8) binary.BigEndian.PutUint64(data, uint64(value.Int())) } return SerializedValue{ diff --git a/serialize.go b/serialize.go index 1a0f4b1..7e228c4 100644 --- a/serialize.go +++ b/serialize.go @@ -586,7 +586,7 @@ func DeserializeStruct(ctx *Context, struct_type reflect.Type) func(*Context, Se field_hash := SerializedType(binary.BigEndian.Uint64(field_hash_bytes)) field_info, exists := struct_info.FieldMap[field_hash] if exists == false { - return nil, nil, value, fmt.Errorf("Field 0x%x is not valid for %+v: %d", field_hash, struct_info.Type, i) + return nil, nil, value, fmt.Errorf("Field 0x%x is not valid for %+v: %+v", field_hash, struct_info.Type, struct_info.FieldMap) } field_value := struct_value.FieldByIndex(field_info.Index) diff --git a/serialize_test.go b/serialize_test.go index 8f43fcc..dfa11ef 100644 --- a/serialize_test.go +++ b/serialize_test.go @@ -4,6 +4,7 @@ import ( "testing" "reflect" "fmt" + "time" ) func TestSerializeTest(t *testing.T) { @@ -27,6 +28,8 @@ func TestSerializeBasic(t *testing.T) { testSerializeComparable[int16](t, ctx, int16(-1234)) testSerializeComparable[int32](t, ctx, int32(-12345)) testSerializeComparable[int64](t, ctx, int64(-123456)) + testSerializeComparable[time.Duration](t, ctx, time.Duration(100)) + testSerializeComparable[time.Time](t, ctx, time.Now()) testSerializeSlice[[]int](t, ctx, []int{123, 456, 789, 101112}) testSerializeSlice[[]int](t, ctx, ([]int)(nil)) testSerializeSliceSlice[[][]int](t, ctx, [][]int{{123, 456, 789, 101112}, {3253, 2341, 735, 212}, {123, 51}, nil})