MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / write_value

Function write_value

atomic-canonical/src/jcs.rs:30–62  ·  view source on GitHub ↗
(out: &mut String, value: &Value)

Source from the content-addressed store, hash-verified

28}
29
30fn write_value(out: &mut String, value: &Value) {
31 match value {
32 Value::Null => out.push_str("null"),
33 Value::Bool(true) => out.push_str("true"),
34 Value::Bool(false) => out.push_str("false"),
35 Value::Number(n) => out.push_str(&n.to_string()),
36 Value::String(s) => write_json_string(out, s),
37 Value::Array(items) => {
38 out.push('[');
39 for (i, item) in items.iter().enumerate() {
40 if i > 0 {
41 out.push(',');
42 }
43 write_value(out, item);
44 }
45 out.push(']');
46 }
47 Value::Object(map) => {
48 let mut keys: Vec<&String> = map.keys().collect();
49 keys.sort_by(|a, b| a.encode_utf16().cmp(b.encode_utf16()));
50 out.push('{');
51 for (i, key) in keys.iter().enumerate() {
52 if i > 0 {
53 out.push(',');
54 }
55 write_json_string(out, key);
56 out.push(':');
57 write_value(out, &map[*key]);
58 }
59 out.push('}');
60 }
61 }
62}
63
64/// Emit a JSON string with standard escaping. `serde_json` produces a valid,
65/// minimally-escaped JSON string literal (quotes included), which matches JCS

Callers 1

canonicalizeFunction · 0.85

Calls 4

write_json_stringFunction · 0.85
cmpMethod · 0.80
pushMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected