Fixed duration serialization

gql_cataclysm
noah metz 2023-10-16 10:03:51 -06:00
parent 95939fb020
commit 266e353c5f
3 changed files with 5 additions and 3 deletions

@ -138,7 +138,6 @@ func (ctx *Context)RegisterSignal(reflect_type reflect.Type, signal_type SignalT
return nil 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 { func (ctx *Context)RegisterExtension(reflect_type reflect.Type, ext_type ExtType, data interface{}) error {
_, exists := ctx.Extensions[ext_type] _, exists := ctx.Extensions[ext_type]
if exists == true { if exists == true {
@ -1193,7 +1192,7 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) {
if value == nil { if value == nil {
data = nil data = nil
} else { } else {
data := make([]byte, 8) data = make([]byte, 8)
binary.BigEndian.PutUint64(data, uint64(value.Int())) binary.BigEndian.PutUint64(data, uint64(value.Int()))
} }
return SerializedValue{ return SerializedValue{

@ -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_hash := SerializedType(binary.BigEndian.Uint64(field_hash_bytes))
field_info, exists := struct_info.FieldMap[field_hash] field_info, exists := struct_info.FieldMap[field_hash]
if exists == false { 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) field_value := struct_value.FieldByIndex(field_info.Index)

@ -4,6 +4,7 @@ import (
"testing" "testing"
"reflect" "reflect"
"fmt" "fmt"
"time"
) )
func TestSerializeTest(t *testing.T) { func TestSerializeTest(t *testing.T) {
@ -27,6 +28,8 @@ func TestSerializeBasic(t *testing.T) {
testSerializeComparable[int16](t, ctx, int16(-1234)) testSerializeComparable[int16](t, ctx, int16(-1234))
testSerializeComparable[int32](t, ctx, int32(-12345)) testSerializeComparable[int32](t, ctx, int32(-12345))
testSerializeComparable[int64](t, ctx, int64(-123456)) 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{123, 456, 789, 101112})
testSerializeSlice[[]int](t, ctx, ([]int)(nil)) testSerializeSlice[[]int](t, ctx, ([]int)(nil))
testSerializeSliceSlice[[][]int](t, ctx, [][]int{{123, 456, 789, 101112}, {3253, 2341, 735, 212}, {123, 51}, nil}) testSerializeSliceSlice[[][]int](t, ctx, [][]int{{123, 456, 789, 101112}, {3253, 2341, 735, 212}, {123, 51}, nil})