From 72d5b87b52fd4a1fb92819121e7f17b9118dac99 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Sat, 23 Dec 2023 18:12:13 +0100 Subject: [PATCH] encoding/cbor: clean --- core/encoding/cbor/coding.odin | 5 ++--- tests/core/encoding/cbor/test_core_cbor.odin | 23 ++++++-------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/core/encoding/cbor/coding.odin b/core/encoding/cbor/coding.odin index ee928f68e..9dd6d2639 100644 --- a/core/encoding/cbor/coding.odin +++ b/core/encoding/cbor/coding.odin @@ -316,9 +316,8 @@ _encode_progress_end :: proc(e: ^Encoder, is_begin: bool, tmp: runtime.Arena_Tem } _decode_header :: proc(r: io.Reader) -> (hdr: Header, err: io.Error) { - buf: [1]byte = --- - io.read_full(r, buf[:]) or_return - return Header(buf[0]), nil + hdr = Header(_decode_u8(r) or_return) + return } _header_split :: proc(hdr: Header) -> (Major, Add) { diff --git a/tests/core/encoding/cbor/test_core_cbor.odin b/tests/core/encoding/cbor/test_core_cbor.odin index 23bfbd3d8..0fb8b521f 100644 --- a/tests/core/encoding/cbor/test_core_cbor.odin +++ b/tests/core/encoding/cbor/test_core_cbor.odin @@ -799,15 +799,8 @@ test_encode_tags :: proc(t: ^testing.T) { // Helpers -buf: bytes.Buffer -stream := bytes.buffer_to_stream(&buf) -encoder := cbor.Encoder{cbor.ENCODE_FULLY_DETERMINISTIC, stream} - expect_decoding :: proc(t: ^testing.T, encoded: string, decoded: string, type: typeid, loc := #caller_location) { - bytes.buffer_reset(&buf) - bytes.buffer_write_string(&buf, encoded) - - res, err := cbor.decode(stream) + res, err := cbor.decode(encoded) defer cbor.destroy(res) expect_value(t, reflect.union_variant_typeid(res), type, loc) @@ -820,10 +813,7 @@ expect_decoding :: proc(t: ^testing.T, encoded: string, decoded: string, type: t } expect_tag :: proc(t: ^testing.T, encoded: string, nr: cbor.Tag_Number, value_decoded: string, loc := #caller_location) { - bytes.buffer_reset(&buf) - bytes.buffer_write_string(&buf, encoded) - - res, err := cbor.decode(stream) + res, err := cbor.decode(encoded) defer cbor.destroy(res) expect_value(t, err, nil, loc) @@ -841,10 +831,7 @@ expect_tag :: proc(t: ^testing.T, encoded: string, nr: cbor.Tag_Number, value_de } expect_float :: proc(t: ^testing.T, encoded: string, expected: $T, loc := #caller_location) where intrinsics.type_is_float(T) { - bytes.buffer_reset(&buf) - bytes.buffer_write_string(&buf, encoded) - - res, err := cbor.decode(stream) + res, err := cbor.decode(encoded) defer cbor.destroy(res) expect_value(t, reflect.union_variant_typeid(res), typeid_of(T), loc) @@ -862,6 +849,10 @@ expect_float :: proc(t: ^testing.T, encoded: string, expected: $T, loc := #calle } } +buf: bytes.Buffer +stream := bytes.buffer_to_stream(&buf) +encoder := cbor.Encoder{cbor.ENCODE_FULLY_DETERMINISTIC, stream} + expect_encoding :: proc(t: ^testing.T, val: cbor.Value, encoded: string, loc := #caller_location) { bytes.buffer_reset(&buf)