Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Round trip (msgpack) on patches/changes works
- Loading branch information
Showing
16 changed files
with
371 additions
and
59 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
automerge-c-v2/examples/example-data/multi_element_insert.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"action": "multi-insert", | ||
"index": 0, | ||
"elemId": "9@8c8a54b01ce24c3a8dd9e05af04c862a", | ||
"datatype": "int", | ||
"values": [1, 2, 3] | ||
} | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// See comment in map_type.rs | ||
use serde::{de::Error, Deserialize, Deserializer, Serialize}; | ||
|
||
use crate::DataType; | ||
|
||
impl Serialize for DataType { | ||
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
match self { | ||
DataType::Counter => s.serialize_str("counter"), | ||
DataType::Timestamp => s.serialize_str("timestamp"), | ||
DataType::Bytes => s.serialize_str("bytes"), | ||
DataType::Cursor => s.serialize_str("cursor"), | ||
DataType::Uint => s.serialize_str("uint"), | ||
DataType::Int => s.serialize_str("int"), | ||
DataType::F64 => s.serialize_str("float64"), | ||
DataType::Undefined => s.serialize_str("undefined"), | ||
} | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for DataType { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
const VARIANTS: &[&str] = &[ | ||
"counter", | ||
"timestamp", | ||
"bytes", | ||
"cursor", | ||
"uint", | ||
"int", | ||
"float64", | ||
"undefined", | ||
]; | ||
// TODO: Probably more efficient to deserialize to a `&str` | ||
let raw_type = String::deserialize(deserializer)?; | ||
match raw_type.as_str() { | ||
"counter" => Ok(DataType::Counter), | ||
"timestamp" => Ok(DataType::Timestamp), | ||
"bytes" => Ok(DataType::Bytes), | ||
"cursor" => Ok(DataType::Cursor), | ||
"uint" => Ok(DataType::Uint), | ||
"int" => Ok(DataType::Int), | ||
"float64" => Ok(DataType::F64), | ||
"undefined" => Ok(DataType::Undefined), | ||
other => Err(Error::unknown_variant(other, VARIANTS)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// By default, msgpack-rust serializes enums | ||
// as maps with a single K/V pair. This is unnecessary, | ||
// so we override that decision and manually serialize | ||
// to a string | ||
|
||
// The downside of this is that we cannot deserialize data structures | ||
// that use this enum b/c the msgpack deserializer will expect | ||
// enums to be encoded as a map with a single K/V pair | ||
// Luckily, we don't need to deserialize data structures | ||
// that use this enum | ||
use serde::{de::Error, Deserialize, Deserializer, Serialize}; | ||
|
||
use crate::MapType; | ||
|
||
impl Serialize for MapType { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
match self { | ||
MapType::Map => serializer.serialize_str("map"), | ||
MapType::Table => serializer.serialize_str("table"), | ||
} | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for MapType { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
const VARIANTS: &[&str] = &["map", "table"]; | ||
// TODO: Probably more efficient to deserialize to a `&str` | ||
let raw_type = String::deserialize(deserializer)?; | ||
match raw_type.as_str() { | ||
"map" => Ok(MapType::Map), | ||
"table" => Ok(MapType::Table), | ||
other => Err(Error::unknown_variant(other, VARIANTS)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// See type in map_type.rs | ||
use serde::{de::Error, Deserialize, Deserializer, Serialize}; | ||
|
||
use crate::ObjType; | ||
|
||
impl Serialize for ObjType { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
match self { | ||
ObjType::Map => serializer.serialize_str("map"), | ||
ObjType::Table => serializer.serialize_str("table"), | ||
ObjType::List => serializer.serialize_str("list"), | ||
ObjType::Text => serializer.serialize_str("text"), | ||
} | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for ObjType { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
const VARIANTS: &[&str] = &["map", "table", "list", "text"]; | ||
// TODO: Probably more efficient to deserialize to a `&str` | ||
let raw_type = String::deserialize(deserializer)?; | ||
match raw_type.as_str() { | ||
"map" => Ok(ObjType::Map), | ||
"table" => Ok(ObjType::Table), | ||
"list" => Ok(ObjType::List), | ||
"text" => Ok(ObjType::Text), | ||
other => Err(Error::unknown_variant(other, VARIANTS)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// See type in map_type.rs | ||
use serde::{de::Error, Deserialize, Deserializer, Serialize}; | ||
|
||
use crate::SequenceType; | ||
|
||
impl Serialize for SequenceType { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
match self { | ||
SequenceType::List => serializer.serialize_str("list"), | ||
SequenceType::Text => serializer.serialize_str("text"), | ||
} | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for SequenceType { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
const VARIANTS: &[&str] = &["list", "text"]; | ||
// TODO: Probably more efficient to deserialize to a `&str` | ||
let raw_type = String::deserialize(deserializer)?; | ||
match raw_type.as_str() { | ||
"list" => Ok(SequenceType::List), | ||
"text" => Ok(SequenceType::Text), | ||
other => Err(Error::unknown_variant(other, VARIANTS)), | ||
} | ||
} | ||
} |
Oops, something went wrong.