diff options
| author | Laytan Laats <laytanlaats@hotmail.com> | 2024-02-12 20:17:24 +0100 |
|---|---|---|
| committer | Laytan Laats <laytanlaats@hotmail.com> | 2024-03-04 17:26:19 +0100 |
| commit | 04bd3cc525e5ef366043ace552bd0f3aa7cdd4b8 (patch) | |
| tree | 4bc5b6c0f71908a4e672d05503660c0742acd424 | |
| parent | 9fc8587e2c2bff33a063531ef9045d48dc4a587e (diff) | |
encoding/cbor: rename `diagnose` to `to_diagnostic_format` to be clearer
| -rw-r--r-- | core/encoding/cbor/cbor.odin | 24 | ||||
| -rw-r--r-- | core/encoding/cbor/doc.odin | 4 | ||||
| -rw-r--r-- | tests/core/encoding/cbor/test_core_cbor.odin | 14 |
3 files changed, 21 insertions, 21 deletions
diff --git a/core/encoding/cbor/cbor.odin b/core/encoding/cbor/cbor.odin index f879a11aa..defae4163 100644 --- a/core/encoding/cbor/cbor.odin +++ b/core/encoding/cbor/cbor.odin @@ -307,23 +307,23 @@ destroy :: proc(val: Value, allocator := context.allocator) { } /* -diagnose either writes or returns a human-readable representation of the value, -optionally formatted, defined as the diagnostic format in section 8 of RFC 8949. +to_diagnostic_format either writes or returns a human-readable representation of the value, +optionally formatted, defined as the diagnostic format in [[RFC 8949 Section 8;https://www.rfc-editor.org/rfc/rfc8949.html#name-diagnostic-notation]]. Incidentally, if the CBOR does not contain any of the additional types defined on top of JSON this will also be valid JSON. */ -diagnose :: proc { - diagnostic_string, - diagnose_to_writer, +to_diagnostic_format :: proc { + to_diagnostic_format_string, + to_diagnostic_format_writer, } // Turns the given CBOR value into a human-readable string. // See docs on the proc group `diagnose` for more info. -diagnostic_string :: proc(val: Value, padding := 0, allocator := context.allocator) -> (string, mem.Allocator_Error) #optional_allocator_error { +to_diagnostic_format_string :: proc(val: Value, padding := 0, allocator := context.allocator) -> (string, mem.Allocator_Error) #optional_allocator_error { b := strings.builder_make(allocator) w := strings.to_stream(&b) - err := diagnose_to_writer(w, val, padding) + err := to_diagnostic_format_writer(w, val, padding) if err == .EOF { // The string builder stream only returns .EOF, and only if it can't write (out of memory). return "", .Out_Of_Memory @@ -335,7 +335,7 @@ diagnostic_string :: proc(val: Value, padding := 0, allocator := context.allocat // Writes the given CBOR value into the writer as human-readable text. // See docs on the proc group `diagnose` for more info. -diagnose_to_writer :: proc(w: io.Writer, val: Value, padding := 0) -> io.Error { +to_diagnostic_format_writer :: proc(w: io.Writer, val: Value, padding := 0) -> io.Error { @(require_results) indent :: proc(padding: int) -> int { padding := padding @@ -421,7 +421,7 @@ diagnose_to_writer :: proc(w: io.Writer, val: Value, padding := 0) -> io.Error { newline(w, padding) or_return for entry, i in v { - diagnose(w, entry, padding) or_return + to_diagnostic_format(w, entry, padding) or_return if i != len(v)-1 { comma(w, padding) or_return newline(w, padding) or_return @@ -444,9 +444,9 @@ diagnose_to_writer :: proc(w: io.Writer, val: Value, padding := 0) -> io.Error { newline(w, padding) or_return for entry, i in v { - diagnose(w, entry.key, padding) or_return + to_diagnostic_format(w, entry.key, padding) or_return io.write_string(w, ": ") or_return - diagnose(w, entry.value, padding) or_return + to_diagnostic_format(w, entry.value, padding) or_return if i != len(v)-1 { comma(w, padding) or_return newline(w, padding) or_return @@ -460,7 +460,7 @@ diagnose_to_writer :: proc(w: io.Writer, val: Value, padding := 0) -> io.Error { case ^Tag: io.write_u64(w, v.number) or_return io.write_string(w, "(") or_return - diagnose(w, v.value, padding) or_return + to_diagnostic_format(w, v.value, padding) or_return io.write_string(w, ")") or_return case Simple: io.write_string(w, "simple(") or_return diff --git a/core/encoding/cbor/doc.odin b/core/encoding/cbor/doc.odin index ee8ba23a0..77eac51cb 100644 --- a/core/encoding/cbor/doc.odin +++ b/core/encoding/cbor/doc.odin @@ -117,8 +117,8 @@ Example: assert(derr == nil) defer cbor.destroy(decoded) - // Turn the CBOR into a human readable representation. - diagnosis, eerr := cbor.diagnose(decoded) + // Turn the CBOR into a human readable representation defined as the diagnostic format in [[RFC 8949 Section 8;https://www.rfc-editor.org/rfc/rfc8949.html#name-diagnostic-notation]]. + diagnosis, eerr := cbor.to_diagnostic_format(decoded) assert(eerr == nil) defer delete(diagnosis) diff --git a/tests/core/encoding/cbor/test_core_cbor.odin b/tests/core/encoding/cbor/test_core_cbor.odin index 60c122a69..72244e1d3 100644 --- a/tests/core/encoding/cbor/test_core_cbor.odin +++ b/tests/core/encoding/cbor/test_core_cbor.odin @@ -212,7 +212,7 @@ test_marshalling :: proc(t: ^testing.T) { ev(t, derr, nil) defer cbor.destroy(decoded) - diagnosis, eerr := cbor.diagnose(decoded) + diagnosis, eerr := cbor.to_diagnostic_format(decoded) ev(t, eerr, nil) defer delete(diagnosis) @@ -379,7 +379,7 @@ test_marshalling_maybe :: proc(t: ^testing.T) { val, derr := cbor.decode(string(data)) expect_value(t, derr, nil) - expect_value(t, cbor.diagnose(val), "1") + expect_value(t, cbor.to_diagnostic_format(val), "1") maybe_dest: Maybe(int) uerr := cbor.unmarshal(string(data), &maybe_dest) @@ -396,7 +396,7 @@ test_marshalling_nil_maybe :: proc(t: ^testing.T) { val, derr := cbor.decode(string(data)) expect_value(t, derr, nil) - expect_value(t, cbor.diagnose(val), "nil") + expect_value(t, cbor.to_diagnostic_format(val), "nil") maybe_dest: Maybe(int) uerr := cbor.unmarshal(string(data), &maybe_dest) @@ -432,7 +432,7 @@ test_marshalling_union :: proc(t: ^testing.T) { val, derr := cbor.decode(string(data)) expect_value(t, derr, nil) - expect_value(t, cbor.diagnose(val, -1), `1010(["My_Distinct", "Hello, World!"])`) + expect_value(t, cbor.to_diagnostic_format(val, -1), `1010(["My_Distinct", "Hello, World!"])`) dest: My_Union uerr := cbor.unmarshal(string(data), &dest) @@ -455,7 +455,7 @@ test_marshalling_union :: proc(t: ^testing.T) { val, derr := cbor.decode(string(data)) expect_value(t, derr, nil) - expect_value(t, cbor.diagnose(val, -1), `1010(["My_Struct", {"my_enum": 1}])`) + expect_value(t, cbor.to_diagnostic_format(val, -1), `1010(["My_Struct", {"my_enum": 1}])`) dest: My_Union_No_Nil uerr := cbor.unmarshal(string(data), &dest) @@ -810,7 +810,7 @@ expect_decoding :: proc(t: ^testing.T, encoded: string, decoded: string, type: t expect_value(t, reflect.union_variant_typeid(res), type, loc) expect_value(t, err, nil, loc) - str := cbor.diagnose(res, padding=-1) + str := cbor.to_diagnostic_format(res, padding=-1) defer delete(str) expect_value(t, str, decoded, loc) @@ -825,7 +825,7 @@ expect_tag :: proc(t: ^testing.T, encoded: string, nr: cbor.Tag_Number, value_de if tag, is_tag := res.(^cbor.Tag); is_tag { expect_value(t, tag.number, nr, loc) - str := cbor.diagnose(tag, padding=-1) + str := cbor.to_diagnostic_format(tag, padding=-1) defer delete(str) expect_value(t, str, value_decoded, loc) |