diff --git a/gremlin-client/src/conversion.rs b/gremlin-client/src/conversion.rs index 538455a..7d2f3fd 100644 --- a/gremlin-client/src/conversion.rs +++ b/gremlin-client/src/conversion.rs @@ -157,6 +157,7 @@ impl FromGValue for GKey { GValue::Edge(s) => Ok(GKey::Edge(s)), GValue::Int64(v) => Ok(GKey::Int64(v)), GValue::Int32(v) => Ok(GKey::Int32(v)), + GValue::T(t) => Ok(GKey::T(t)), _ => Err(GremlinError::Cast(format!( "Cannot convert {:?} to {}", v, "GKey" diff --git a/gremlin-client/src/io/graph_binary_v1.rs b/gremlin-client/src/io/graph_binary_v1.rs index a7de09d..d555779 100644 --- a/gremlin-client/src/io/graph_binary_v1.rs +++ b/gremlin-client/src/io/graph_binary_v1.rs @@ -506,12 +506,12 @@ impl GraphBinaryV1Deser for GValue { impl GraphBinaryV1Deser for T { fn from_be_bytes<'a, S: Iterator>(bytes: &mut S) -> GremlinResult { - let literal = GValue::from_be_bytes_nullable(bytes)?; + let literal = GValue::from_be_bytes(bytes)?; match literal { - Some(GValue::String(literal)) if literal.eq_ignore_ascii_case("id") => Ok(T::Id), - Some(GValue::String(literal)) if literal.eq_ignore_ascii_case("key") => Ok(T::Id), - Some(GValue::String(literal)) if literal.eq_ignore_ascii_case("label") => Ok(T::Id), - Some(GValue::String(literal)) if literal.eq_ignore_ascii_case("value") => Ok(T::Id), + GValue::String(literal) if literal.eq_ignore_ascii_case("id") => Ok(T::Id), + GValue::String(literal) if literal.eq_ignore_ascii_case("key") => Ok(T::Key), + GValue::String(literal) if literal.eq_ignore_ascii_case("label") => Ok(T::Label), + GValue::String(literal) if literal.eq_ignore_ascii_case("value") => Ok(T::Value), other => Err(GremlinError::Cast(format!( "Unexpected T literal {other:?}" ))), diff --git a/gremlin-client/tests/integration_traversal_omni.rs b/gremlin-client/tests/integration_traversal_omni.rs index 8ef168d..d6fc98e 100644 --- a/gremlin-client/tests/integration_traversal_omni.rs +++ b/gremlin-client/tests/integration_traversal_omni.rs @@ -8,7 +8,9 @@ use gremlin_client::structure::{ Cardinality, Column, List, Map, Pop, TextP, Vertex, VertexProperty, P, T, }; -use gremlin_client::{utils, GKey, GValue, GremlinClient, IoProtocol}; +use gremlin_client::{ + utils, BorrowFromGValue, GKey, GValue, GremlinClient, GremlinError, IoProtocol, +}; mod common; @@ -1213,17 +1215,16 @@ fn test_unwrap_map(client: GremlinClient) { let results = g.v(vertex.id()).value_map(true).next().unwrap().unwrap(); let v_id = vertex.id().get::().unwrap(); - let id = utils::unwrap_map::(&results, "id", 0); - let property = utils::unwrap_map::(&results, "name", 0); - let label = utils::unwrap_map::(&results, "label", 0); - - assert_eq!(id.is_ok(), true); - assert_eq!(property.is_ok(), true); - assert_eq!(label.is_ok(), true); - - assert_eq!(id.unwrap(), v_id); + let id = get_map::(&results, "id") + .unwrap() + .or_else(|| get_map::(&results, T::Id).unwrap()); + let property = get_map::(&results, "name").unwrap(); + let label = get_map::(&results, "label") + .unwrap() + .or_else(|| get_map::(&results, T::Label).unwrap()); + assert_eq!(id, Some(v_id)); assert_eq!(property.unwrap(), "test"); - assert_eq!(label.unwrap(), "test_value_map"); + assert_eq!(label, Some(vertex.label())); } #[apply(serializers)] @@ -2628,6 +2629,19 @@ fn test_none_step(client: GremlinClient) { assert_eq!(1, vertex_count); } +fn get_map<'a, T, K>(map: &'a Map, key: K) -> Result, GremlinError> +where + T: BorrowFromGValue, + K: Into, +{ + map.get(key) + .map(|val| match val { + GValue::List(list) => list[0].get::(), + other => other.get::(), + }) + .transpose() +} + #[apply(serializers)] #[serial(test_traversal_vertex_mapping)] #[cfg(feature = "derive")]