You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
parsing to a struct object container allows EOF error, field not updated. However the behavior is different when you parse to a dynamic container such as any
func genericDecode(typ reflect2.Type, dec ValDecoder, r *Reader) any {
ptr := typ.UnsafeNew()
dec.Decode(ptr, r)
if r.Error != nil {
return nil
}
obj := typ.UnsafeIndirect(ptr)
if reflect2.IsNil(obj) {
return nil
}
return obj
}
should parse to a dynamic eface container (nil any), also allow such EOF error? instead of throwing away the result?
I guess it might be a bit complicated regarding the missing value
func TestDecodeCompatible(t *testing.T) {
registry := NewAvroSchemaRegistry()
err := registry.AddSchema("xxxx", `{
"type": "record",
"name": "schemaV1",
"namespace": "org.hamba.avro",
"fields": [
{"name": "a", "type": "long", "default": 0}
]}`)
if err != nil {
t.Fatal(err)
}
type Object struct {
A int64 `avro:"a"`
}
schema1, err := registry.GetSchema("xxxxxx")
if err != nil {
t.Fatal(err)
}
buf := bytes.NewBuffer(nil)
err = schema1.NewEncoder(buf).Encode(&Object{A: 1})
if err != nil {
t.Fatal(err)
}
err = registry.AddSchema("xxxxxx", `{
"type": "record",
"name": "schemaV1",
"namespace": "org.hamba.avro",
"fields": [
{"name": "a", "type": "long", "default": 0},
{"name": "b", "type": "long", "default": 0}
]}`)
if err != nil {
t.Fatal(err)
}
type Object2 struct {
A int64 `avro:"a"`
B int64 `avro:"b"`
}
// var object2 Object2 // this works
var object2 any // this wont work
schema2, err := registry.GetSchema("xxxxxx")
if err != nil {
t.Fatal(err)
}
err = schema2.NewDecoder(buf).Decode(&object2)
if err != nil {
t.Fatal(err)
}
t.Logf("%+v", object2)
}
The text was updated successfully, but these errors were encountered:
parsing to a struct object container allows EOF error, field not updated. However the behavior is different when you parse to a dynamic container such as
any
should parse to a dynamic eface container (nil
any
), also allow such EOF error? instead of throwing away the result?I guess it might be a bit complicated regarding the missing value
The text was updated successfully, but these errors were encountered: