Add Bytes type for binary data

Related to #1652
This commit is contained in:
Tobie Morgan Hitchcock 2023-03-31 19:44:44 +01:00
parent 3408004c8c
commit cfb27e0929
2 changed files with 18 additions and 14 deletions

View file

@ -231,6 +231,7 @@ fn into_json(value: Value) -> serde_json::Result<JsonValue> {
Value::Array(arr) => Ok(JsonValue::Array(Array::try_from(arr)?.0)), Value::Array(arr) => Ok(JsonValue::Array(Array::try_from(arr)?.0)),
Value::Object(obj) => Ok(JsonValue::Object(Object::try_from(obj)?.0)), Value::Object(obj) => Ok(JsonValue::Object(Object::try_from(obj)?.0)),
Value::Geometry(geometry) => serde_json::to_value(geometry), Value::Geometry(geometry) => serde_json::to_value(geometry),
Value::Bytes(bytes) => serde_json::to_value(bytes),
Value::Param(param) => serde_json::to_value(param), Value::Param(param) => serde_json::to_value(param),
Value::Idiom(idiom) => serde_json::to_value(idiom), Value::Idiom(idiom) => serde_json::to_value(idiom),
Value::Table(table) => serde_json::to_value(table), Value::Table(table) => serde_json::to_value(table),

View file

@ -113,6 +113,7 @@ pub enum Value {
Array(Array), Array(Array),
Object(Object), Object(Object),
Geometry(Geometry), Geometry(Geometry),
Bytes(Vec<u8>),
// --- // ---
Param(Param), Param(Param),
Idiom(Idiom), Idiom(Idiom),
@ -1399,6 +1400,7 @@ impl fmt::Display for Value {
Value::Function(v) => write!(f, "{v}"), Value::Function(v) => write!(f, "{v}"),
Value::Subquery(v) => write!(f, "{v}"), Value::Subquery(v) => write!(f, "{v}"),
Value::Expression(v) => write!(f, "{v}"), Value::Expression(v) => write!(f, "{v}"),
Value::Bytes(_) => write!(f, "<bytes>"),
} }
} }
} }
@ -1466,20 +1468,21 @@ impl Serialize for Value {
Value::Array(v) => s.serialize_newtype_variant(TOKEN, 9, "Array", v), Value::Array(v) => s.serialize_newtype_variant(TOKEN, 9, "Array", v),
Value::Object(v) => s.serialize_newtype_variant(TOKEN, 10, "Object", v), Value::Object(v) => s.serialize_newtype_variant(TOKEN, 10, "Object", v),
Value::Geometry(v) => s.serialize_newtype_variant(TOKEN, 11, "Geometry", v), Value::Geometry(v) => s.serialize_newtype_variant(TOKEN, 11, "Geometry", v),
Value::Param(v) => s.serialize_newtype_variant(TOKEN, 12, "Param", v), Value::Bytes(v) => s.serialize_newtype_variant(TOKEN, 12, "Bytes", v),
Value::Idiom(v) => s.serialize_newtype_variant(TOKEN, 13, "Idiom", v), Value::Param(v) => s.serialize_newtype_variant(TOKEN, 13, "Param", v),
Value::Table(v) => s.serialize_newtype_variant(TOKEN, 14, "Table", v), Value::Idiom(v) => s.serialize_newtype_variant(TOKEN, 14, "Idiom", v),
Value::Thing(v) => s.serialize_newtype_variant(TOKEN, 15, "Thing", v), Value::Table(v) => s.serialize_newtype_variant(TOKEN, 15, "Table", v),
Value::Model(v) => s.serialize_newtype_variant(TOKEN, 16, "Model", v), Value::Thing(v) => s.serialize_newtype_variant(TOKEN, 16, "Thing", v),
Value::Regex(v) => s.serialize_newtype_variant(TOKEN, 17, "Regex", v), Value::Model(v) => s.serialize_newtype_variant(TOKEN, 17, "Model", v),
Value::Block(v) => s.serialize_newtype_variant(TOKEN, 18, "Block", v), Value::Regex(v) => s.serialize_newtype_variant(TOKEN, 18, "Regex", v),
Value::Range(v) => s.serialize_newtype_variant(TOKEN, 19, "Range", v), Value::Block(v) => s.serialize_newtype_variant(TOKEN, 19, "Block", v),
Value::Edges(v) => s.serialize_newtype_variant(TOKEN, 20, "Edges", v), Value::Range(v) => s.serialize_newtype_variant(TOKEN, 20, "Range", v),
Value::Future(v) => s.serialize_newtype_variant(TOKEN, 21, "Future", v), Value::Edges(v) => s.serialize_newtype_variant(TOKEN, 21, "Edges", v),
Value::Constant(v) => s.serialize_newtype_variant(TOKEN, 22, "Constant", v), Value::Future(v) => s.serialize_newtype_variant(TOKEN, 22, "Future", v),
Value::Function(v) => s.serialize_newtype_variant(TOKEN, 23, "Function", v), Value::Constant(v) => s.serialize_newtype_variant(TOKEN, 23, "Constant", v),
Value::Subquery(v) => s.serialize_newtype_variant(TOKEN, 24, "Subquery", v), Value::Function(v) => s.serialize_newtype_variant(TOKEN, 24, "Function", v),
Value::Expression(v) => s.serialize_newtype_variant(TOKEN, 25, "Expression", v), Value::Subquery(v) => s.serialize_newtype_variant(TOKEN, 25, "Subquery", v),
Value::Expression(v) => s.serialize_newtype_variant(TOKEN, 26, "Expression", v),
} }
} else { } else {
match self { match self {