diff --git a/gremlin-client/src/io/graph_binary_v1.rs b/gremlin-client/src/io/graph_binary_v1.rs index d555779..3a81861 100644 --- a/gremlin-client/src/io/graph_binary_v1.rs +++ b/gremlin-client/src/io/graph_binary_v1.rs @@ -10,7 +10,7 @@ use crate::{ message::{ReponseStatus, Response, ResponseResult}, process::traversal::Instruction, structure::{Traverser, T}, - GKey, GValue, GremlinError, GremlinResult, Vertex, GID, + GKey, GValue, GremlinError, GremlinResult, ToGValue, Vertex, VertexProperty, GID, }; use super::IoProtocol; @@ -284,6 +284,10 @@ impl GraphBinaryV1Ser for &GValue { buf.push(VALUE_FLAG); value.to_be_bytes(buf)?; } + GValue::Vertex(value) => { + buf.push(VERTEX); + buf.push(VALUE_FLAG); + } GValue::Bytecode(code) => { //Type code of 0x15: Bytecode buf.push(BYTECODE); @@ -688,6 +692,53 @@ impl GraphBinaryV1Ser for &Uuid { } } +impl GraphBinaryV1Ser for &Vertex { + fn to_be_bytes(self, buf: &mut Vec) -> GremlinResult<()> { + //Format: {id}{label}{properties} + + //{id} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value}. + self.id().to_be_bytes(buf)?; + + //{label} is a String value + self.label().to_be_bytes(buf)?; + + //{properties} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value} which contains properties. + self.properties.len(); + todo!() + } +} + +impl GraphBinaryV1Ser for &VertexProperty { + fn to_be_bytes(self, buf: &mut Vec) -> GremlinResult<()> { + //Format: {id}{label}{value}{parent}{properties} + + //{id} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value}. + self.id().to_be_bytes(buf)?; + + //{label} is a String value. + self.label().to_be_bytes(buf)?; + + //{value} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value}. + //??????? + + //{parent} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value} which contains the parent Vertex. Note that as TinkerPop currently send "references" only, this value will always be null.} + + //{properties} is a fully qualified typed value composed of {type_code}{type_info}{value_flag}{value} which contains properties. + + todo!() + } +} + +impl GraphBinaryV1Ser for &GID { + fn to_be_bytes(self, buf: &mut Vec) -> GremlinResult<()> { + match self { + GID::String(s) => s.to_gvalue().to_be_bytes(buf), + GID::Int32(i) => i.to_gvalue().to_be_bytes(buf), + GID::Int64(i) => i.to_gvalue().to_be_bytes(buf), + } + } +} + impl GraphBinaryV1Deser for Uuid { fn from_be_bytes<'a, S: Iterator>(bytes: &mut S) -> GremlinResult { bytes diff --git a/gremlin-client/src/structure/vertex.rs b/gremlin-client/src/structure/vertex.rs index fdd2a4d..b000157 100644 --- a/gremlin-client/src/structure/vertex.rs +++ b/gremlin-client/src/structure/vertex.rs @@ -8,7 +8,7 @@ use std::hash::Hasher; pub struct Vertex { id: GID, label: String, - properties: HashMap>, + pub(crate) properties: HashMap>, } impl Vertex { diff --git a/gremlin-client/tests/integration_traversal_omni.rs b/gremlin-client/tests/integration_traversal_omni.rs index 9b3eaca..fd6cdd0 100644 --- a/gremlin-client/tests/integration_traversal_omni.rs +++ b/gremlin-client/tests/integration_traversal_omni.rs @@ -1168,7 +1168,10 @@ fn test_value_map(client: GremlinClient) { let value = &results[0]; - assert_eq!("test", get_map::(value, "name").unwrap().unwrap()); + assert_eq!( + "test", + get_map::(value, "name").unwrap().unwrap() + ); let results = g.v(vertex.id()).value_map("name").to_list().unwrap(); @@ -1176,7 +1179,10 @@ fn test_value_map(client: GremlinClient) { let value = &results[0]; - assert_eq!("test", get_map::(value, "name").unwrap().unwrap()); + assert_eq!( + "test", + get_map::(value, "name").unwrap().unwrap() + ); let results = g.v(vertex.id()).value_map("fake").to_list().unwrap(); @@ -1186,9 +1192,15 @@ fn test_value_map(client: GremlinClient) { assert_eq!(1, results.len()); let value = &results[0]; - assert_eq!(Some(vertex.id().get().unwrap()), get_map_id(&value).unwrap()); + assert_eq!( + Some(vertex.id().get().unwrap()), + get_map_id(&value).unwrap() + ); assert_eq!(Some(vertex.label()), get_map_label(&value).unwrap()); - assert_eq!(Some("test".to_owned()).as_ref(), get_map(&value, "name").unwrap()); + assert_eq!( + Some("test".to_owned()).as_ref(), + get_map(&value, "name").unwrap() + ); } #[apply(serializers)] @@ -1248,15 +1260,24 @@ fn test_element_map(client: GremlinClient) { let value = &results[0]; assert_eq!(2, value.len()); - assert_eq!(Some(vertex.id().get().unwrap()), get_map_id(&value).unwrap()); + assert_eq!( + Some(vertex.id().get().unwrap()), + get_map_id(&value).unwrap() + ); assert_eq!(Some(vertex.label()), get_map_label(&value).unwrap()); let results = g.v(vertex.id()).element_map(()).to_list().unwrap(); let value = &results[0]; - assert_eq!(Some(vertex.id().get().unwrap()), get_map_id(&value).unwrap()); + assert_eq!( + Some(vertex.id().get().unwrap()), + get_map_id(&value).unwrap() + ); assert_eq!(Some(vertex.label()), get_map_label(&value).unwrap()); - assert_eq!(Some("test".to_owned()).as_ref(), get_map(&value, "name").unwrap()); + assert_eq!( + Some("test".to_owned()).as_ref(), + get_map(&value, "name").unwrap() + ); } #[apply(serializers)] @@ -2316,7 +2337,10 @@ fn test_anonymous_traversal_properties_drop(client: GremlinClient) { //Make sure the property was assigned assert_map_property(&element_map, pre_drop_prop_key, expected_prop_value); - let created_vertex_id = element_map.get("id").or(element_map.get(T::Id)).expect("Should have id property"); + let created_vertex_id = element_map + .get("id") + .or(element_map.get(T::Id)) + .expect("Should have id property"); let GValue::Int64(id) = created_vertex_id else { panic!("Not expected id type"); }; @@ -2619,21 +2643,21 @@ fn test_none_step(client: GremlinClient) { assert_eq!(1, vertex_count); } -fn get_map_id<'a>(map: &'a Map) -> Result, GremlinError>{ +fn get_map_id<'a>(map: &'a Map) -> Result, GremlinError> { let string_keyed = get_map(map, "id")?; if string_keyed.is_some() { Ok(string_keyed) } else { - get_map(map, T::Id) + get_map(map, T::Id) } } -fn get_map_label<'a>(map: &'a Map) -> Result, GremlinError>{ +fn get_map_label<'a>(map: &'a Map) -> Result, GremlinError> { let string_keyed = get_map(map, "label")?; if string_keyed.is_some() { Ok(string_keyed) } else { - get_map(map, T::Label) + get_map(map, T::Label) } }