|
|
@ -853,8 +853,8 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) {
|
|
|
|
|
|
|
|
|
|
|
|
err = ctx.RegisterKind(reflect.Slice, SliceType,
|
|
|
|
err = ctx.RegisterKind(reflect.Slice, SliceType,
|
|
|
|
func(ctx *Context, ctx_type SerializedType, reflect_type reflect.Type, value *reflect.Value) (SerializedValue, error) {
|
|
|
|
func(ctx *Context, ctx_type SerializedType, reflect_type reflect.Type, value *reflect.Value) (SerializedValue, error) {
|
|
|
|
var data []byte
|
|
|
|
|
|
|
|
type_stack := []SerializedType{ctx_type}
|
|
|
|
type_stack := []SerializedType{ctx_type}
|
|
|
|
|
|
|
|
var data []byte
|
|
|
|
if value == nil {
|
|
|
|
if value == nil {
|
|
|
|
data = nil
|
|
|
|
data = nil
|
|
|
|
} else if value.IsZero() {
|
|
|
|
} else if value.IsZero() {
|
|
|
@ -864,6 +864,7 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
data := make([]byte, 8)
|
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.BigEndian.PutUint64(data, uint64(value.Len()))
|
|
|
|
binary.BigEndian.PutUint64(data, uint64(value.Len()))
|
|
|
|
|
|
|
|
|
|
|
|
var element SerializedValue
|
|
|
|
var element SerializedValue
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
|
for i := 0; i < value.Len(); i += 1 {
|
|
|
|
for i := 0; i < value.Len(); i += 1 {
|
|
|
@ -874,20 +875,24 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data = append(data, element.Data...)
|
|
|
|
data = append(data, element.Data...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return SerializedValue{
|
|
|
|
return SerializedValue{
|
|
|
|
append(type_stack, element.TypeStack...),
|
|
|
|
append(type_stack, element.TypeStack...),
|
|
|
|
data,
|
|
|
|
data,
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
element, err := SerializeValue(ctx, reflect_type.Elem(), nil)
|
|
|
|
element, err := SerializeValue(ctx, reflect_type.Elem(), nil)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return SerializedValue{}, err
|
|
|
|
return SerializedValue{}, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return SerializedValue{
|
|
|
|
return SerializedValue{
|
|
|
|
append(type_stack, element.TypeStack...),
|
|
|
|
append(type_stack, element.TypeStack...),
|
|
|
|
data,
|
|
|
|
data,
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}, func(ctx *Context, value SerializedValue)(reflect.Type, *reflect.Value, SerializedValue, error){
|
|
|
|
},
|
|
|
|
|
|
|
|
func(ctx *Context, value SerializedValue)(reflect.Type, *reflect.Value, SerializedValue, error){
|
|
|
|
if value.Data == nil {
|
|
|
|
if value.Data == nil {
|
|
|
|
elem_type, _, _, err := DeserializeValue(ctx, value)
|
|
|
|
elem_type, _, _, err := DeserializeValue(ctx, value)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -956,14 +961,6 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: move functions for string serialize/deserialize out of RegisterKind
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
err = ctx.RegisterType(reflect.TypeOf(StringError("")), ErrorType, nil, nil)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = ctx.RegisterType(reflect.TypeOf(Tree{}), TreeType, func(ctx *Context, ctx_type SerializedType, reflect_type reflect.Type, value *reflect.Value)(SerializedValue,error){
|
|
|
|
err = ctx.RegisterType(reflect.TypeOf(Tree{}), TreeType, func(ctx *Context, ctx_type SerializedType, reflect_type reflect.Type, value *reflect.Value)(SerializedValue,error){
|
|
|
|
var data []byte
|
|
|
|
var data []byte
|
|
|
|
type_stack := []SerializedType{ctx_type}
|
|
|
|
type_stack := []SerializedType{ctx_type}
|
|
|
@ -1058,6 +1055,11 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = ctx.RegisterType(reflect.TypeOf(Changes{}), ChangesSerialized, SerializeSlice, DeserializeSlice[Changes](ctx))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = ctx.RegisterType(reflect.TypeOf(ExtType(0)), ExtTypeSerialized, SerializeUintN(8), DeserializeUintN[ExtType](8))
|
|
|
|
err = ctx.RegisterType(reflect.TypeOf(ExtType(0)), ExtTypeSerialized, SerializeUintN(8), DeserializeUintN[ExtType](8))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|