MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / encode_as_msgpack

Function encode_as_msgpack

nodedb-columnar/src/memtable/column_data/push.rs:19–36  ·  view source on GitHub ↗

Encode a `Value` as MessagePack bytes for JSON/Array/Set/Record storage. For `Value::String` input, the string is first parsed as JSON so that downstream JSON path operators see a real structure rather than an opaque string literal.

(value: &Value, col_name: &str)

Source from the content-addressed store, hash-verified

17/// downstream JSON path operators see a real structure rather than an opaque
18/// string literal.
19fn encode_as_msgpack(value: &Value, col_name: &str) -> Result<Vec<u8>, ColumnarError> {
20 let to_encode: std::borrow::Cow<'_, Value> = match value {
21 Value::String(s) => {
22 let parsed = sonic_rs::from_str::<serde_json::Value>(s).map_err(|e| {
23 ColumnarError::JsonParse {
24 column: col_name.to_string(),
25 source: e,
26 }
27 })?;
28 std::borrow::Cow::Owned(Value::from(parsed))
29 }
30 other => std::borrow::Cow::Borrowed(other),
31 };
32 value_to_msgpack(&to_encode).map_err(|e| ColumnarError::MsgpackSerialize {
33 column: col_name.to_string(),
34 source: e,
35 })
36}
37
38/// Parse a PostgreSQL range literal into a structured Value.
39///

Callers 1

pushMethod · 0.85

Calls 2

value_to_msgpackFunction · 0.85
to_stringMethod · 0.80

Tested by

no test coverage detected