mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-06 06:38:20 +00:00
encoding/cbor: fix order-dependent partial unmarshals
This commit is contained in:
@@ -661,8 +661,7 @@ _unmarshal_map :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header,
|
||||
unknown := length == -1
|
||||
fields := reflect.struct_fields_zipped(ti.id)
|
||||
|
||||
idx := 0
|
||||
for ; idx < len(fields) && (unknown || idx < length); idx += 1 {
|
||||
for idx := 0; unknown || idx < length; idx += 1 {
|
||||
// Decode key, keys can only be strings.
|
||||
key: string
|
||||
if keyv, kerr := decode_key(d, v, context.temp_allocator); unknown && kerr == .Break {
|
||||
@@ -710,16 +709,6 @@ _unmarshal_map :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header,
|
||||
_unmarshal_value(d, fany, _decode_header(r) or_return) or_return
|
||||
}
|
||||
|
||||
// If there are fields left in the map that did not get decoded into the struct, decode and discard them.
|
||||
if !unknown {
|
||||
for _ in idx..<length {
|
||||
key := err_conv(_decode_from_decoder(d, allocator=context.temp_allocator)) or_return
|
||||
destroy(key, context.temp_allocator)
|
||||
val := err_conv(_decode_from_decoder(d, allocator=context.temp_allocator)) or_return
|
||||
destroy(val, context.temp_allocator)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
case reflect.Type_Info_Map:
|
||||
|
||||
@@ -427,6 +427,7 @@ test_unmarshal_map_into_struct_partially :: proc(t: ^testing.T) {
|
||||
}
|
||||
|
||||
Foo_More :: struct {
|
||||
foo: bool,
|
||||
bar: struct {
|
||||
hello: string,
|
||||
world: string,
|
||||
@@ -436,6 +437,7 @@ test_unmarshal_map_into_struct_partially :: proc(t: ^testing.T) {
|
||||
baz: int,
|
||||
}
|
||||
more := Foo_More{
|
||||
foo = false,
|
||||
bar = {
|
||||
hello = "hello",
|
||||
world = "world",
|
||||
|
||||
Reference in New Issue
Block a user