mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-20 05:20:28 +00:00
encoding/cbor: fix skipping of ignored/missing fields in struct unmarshal
This commit is contained in:
@@ -664,6 +664,8 @@ _unmarshal_map :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header,
|
||||
|
||||
// Skips unused map entries.
|
||||
if use_field_idx < 0 {
|
||||
val := err_conv(_decode_from_decoder(d, allocator=context.temp_allocator)) or_return
|
||||
destroy(val, context.temp_allocator)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,6 +392,7 @@ test_unmarshal_map_into_struct_partially :: proc(t: ^testing.T) {
|
||||
bar: struct {
|
||||
hello: string,
|
||||
world: string,
|
||||
foo: string `cbor:"-"`,
|
||||
},
|
||||
baz: int,
|
||||
}
|
||||
@@ -401,6 +402,7 @@ test_unmarshal_map_into_struct_partially :: proc(t: ^testing.T) {
|
||||
hello: string,
|
||||
world: string,
|
||||
hellope: string,
|
||||
foo: string,
|
||||
},
|
||||
baz: int,
|
||||
}
|
||||
@@ -409,6 +411,7 @@ test_unmarshal_map_into_struct_partially :: proc(t: ^testing.T) {
|
||||
hello = "hello",
|
||||
world = "world",
|
||||
hellope = "hellope",
|
||||
foo = "foo",
|
||||
},
|
||||
baz = 4,
|
||||
}
|
||||
@@ -426,7 +429,7 @@ test_unmarshal_map_into_struct_partially :: proc(t: ^testing.T) {
|
||||
less_out: Foo
|
||||
uerr := cbor.unmarshal(string(more_bin), &less_out)
|
||||
testing.expect_value(t, uerr, nil)
|
||||
testing.expect_value(t, less, less_out)
|
||||
testing.expect_value(t, less_out, less)
|
||||
|
||||
delete(more_bin)
|
||||
delete(less_out.bar.hello)
|
||||
|
||||
Reference in New Issue
Block a user