encoding/cbor: various fixes

- "null" is the proper way to represent the nil value in the diagnostic
  format
- hex encoding in diagnostic format was wrong
- struct keys weren't sorted the right deterministic way
This commit is contained in:
Laytan Laats
2024-08-09 21:56:54 +02:00
parent c5ed7083d2
commit 912f99abc8
4 changed files with 61 additions and 52 deletions
+3 -2
View File
@@ -3,6 +3,7 @@ package encoding_cbor
import "base:intrinsics"
import "core:encoding/json"
import "core:encoding/hex"
import "core:io"
import "core:mem"
import "core:strconv"
@@ -399,11 +400,11 @@ to_diagnostic_format_writer :: proc(w: io.Writer, val: Value, padding := 0) -> i
io.write_string(w, str) or_return
case bool: io.write_string(w, "true" if v else "false") or_return
case Nil: io.write_string(w, "nil") or_return
case Nil: io.write_string(w, "null") or_return
case Undefined: io.write_string(w, "undefined") or_return
case ^Bytes:
io.write_string(w, "h'") or_return
for b in v { io.write_int(w, int(b), 16) or_return }
hex.encode_into_writer(w, v^) or_return
io.write_string(w, "'") or_return
case ^Text:
io.write_string(w, `"`) or_return