encoding/cbor: clean

This commit is contained in:
Laytan Laats
2023-12-23 18:12:13 +01:00
parent 154e0d41c6
commit 72d5b87b52
2 changed files with 9 additions and 19 deletions
+2 -3
View File
@@ -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) {
+7 -16
View File
@@ -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)