tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jorg...@apache.org
Subject [34/47] tinkerpop git commit: Vertex and Edge serialization
Date Wed, 17 Jan 2018 15:53:00 GMT
Vertex and Edge serialization


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/06677162
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/06677162
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/06677162

Branch: refs/heads/TINKERPOP-1489
Commit: 066771623a85716f63f4c711cbbc1edad2720966
Parents: 7e3d4be
Author: Jorge Bay Gondra <jorgebaygondra@gmail.com>
Authored: Tue Nov 28 12:50:37 2017 +0100
Committer: Jorge Bay Gondra <jorgebaygondra@gmail.com>
Committed: Wed Jan 17 16:16:21 2018 +0100

----------------------------------------------------------------------
 .../lib/structure/io/graph-serializer.js        | 42 ++++++++++++++++++--
 1 file changed, 39 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/06677162/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js
----------------------------------------------------------------------
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js
b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js
index 46d251e..ff3d72d 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/io/graph-serializer.js
@@ -65,7 +65,9 @@ var serializers = [
   TraverserSerializer,
   PSerializer,
   LambdaSerializer,
-  EnumSerializer
+  EnumSerializer,
+  VertexSerializer,
+  EdgeSerializer
 ];
 
 /**
@@ -237,7 +239,7 @@ BytecodeSerializer.prototype._serializeInstructions = function (instructions)
{
   }
   var result = new Array(instructions.length);
   result[0] = instructions[0];
-  for (var i = 1; i < instructions.length; i++) {
+  for (var i = 0; i < instructions.length; i++) {
     result[i] = this.writer.adaptObject(instructions[i]);
   }
   return result;
@@ -258,7 +260,7 @@ PSerializer.prototype.serialize = function (item) {
   var resultValue = result[valueKey] = {
     'predicate': item.operator
   };
-  if (item.other == undefined) {
+  if (item.other === undefined || item.other === null) {
     resultValue['value'] = this.writer.adaptObject(item.value);
   }
   else {
@@ -340,6 +342,21 @@ VertexSerializer.prototype.deserialize = function (obj) {
   return new g.Vertex(this.reader.read(value['id']), value['label'], this.reader.read(value['properties']));
 };
 
+/** @param {Vertex} item */
+VertexSerializer.prototype.serialize = function (item) {
+  var result = {};
+  result[typeKey] = 'g:Vertex';
+  result[valueKey] = {
+    'id': this.writer.adaptObject(item.id),
+    'label': item.label
+  };
+  return result;
+};
+
+VertexSerializer.prototype.canBeUsedFor = function (value) {
+  return (value instanceof g.Vertex);
+};
+
 function VertexPropertySerializer() {
 
 }
@@ -380,6 +397,25 @@ EdgeSerializer.prototype.deserialize = function (obj) {
   );
 };
 
+/** @param {Edge} item */
+EdgeSerializer.prototype.serialize = function (item) {
+  var result = {};
+  result[typeKey] = 'g:Edge';
+  result[valueKey] = {
+    'id': this.writer.adaptObject(item.id),
+    'label': item.label,
+    'outV': this.writer.adaptObject(item.outV.id),
+    'outVLabel': item.outV.label,
+    'inV': this.writer.adaptObject(item.inV.id),
+    'inVLabel': item.inV.label
+  };
+  return result;
+};
+
+EdgeSerializer.prototype.canBeUsedFor = function (value) {
+  return (value instanceof g.Edge);
+};
+
 function PathSerializer() {
 
 }


Mime
View raw message