mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-28 18:30:06 +00:00
encoding/cbor: handle binary having more fields than the struct by discarding
This commit is contained in:
@@ -382,6 +382,57 @@ test_lying_length_array :: proc(t: ^testing.T) {
|
||||
testing.expect_value(t, err, io.Error.Unexpected_EOF) // .Out_Of_Memory would be bad.
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_unmarshal_map_into_struct_partially :: proc(t: ^testing.T) {
|
||||
|
||||
// Tests that when unmarshalling into a struct that has less fields than the binary map has fields,
|
||||
// the additional fields in the binary are skipped and the rest of the binary is correctly decoded.
|
||||
|
||||
Foo :: struct {
|
||||
bar: struct {
|
||||
hello: string,
|
||||
world: string,
|
||||
},
|
||||
baz: int,
|
||||
}
|
||||
|
||||
Foo_More :: struct {
|
||||
bar: struct {
|
||||
hello: string,
|
||||
world: string,
|
||||
hellope: string,
|
||||
},
|
||||
baz: int,
|
||||
}
|
||||
more := Foo_More{
|
||||
bar = {
|
||||
hello = "hello",
|
||||
world = "world",
|
||||
hellope = "hellope",
|
||||
},
|
||||
baz = 4,
|
||||
}
|
||||
|
||||
more_bin, err := cbor.marshal(more)
|
||||
testing.expect_value(t, err, nil)
|
||||
|
||||
less := Foo{
|
||||
bar = {
|
||||
hello = "hello",
|
||||
world = "world",
|
||||
},
|
||||
baz = 4,
|
||||
}
|
||||
less_out: Foo
|
||||
uerr := cbor.unmarshal(string(more_bin), &less_out)
|
||||
testing.expect_value(t, uerr, nil)
|
||||
testing.expect_value(t, less, less_out)
|
||||
|
||||
delete(more_bin)
|
||||
delete(less_out.bar.hello)
|
||||
delete(less_out.bar.world)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_decode_unsigned :: proc(t: ^testing.T) {
|
||||
expect_decoding(t, "\x00", "0", u8)
|
||||
|
||||
Reference in New Issue
Block a user