mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-24 06:35:00 -07:00
encoding/cbor: clean
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user