This is an automated email from the ASF dual-hosted git repository.

jorgebg pushed a commit to branch TINKERPOP-1942
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit f51616199f38bb28ab2a7485f30ca6baf0380ecf
Author: Jorge Bay Gondra <[email protected]>
AuthorDate: Tue Nov 27 12:12:14 2018 +0100

    Start sample composite type implementation
---
 .../gremlin/driver/ser/binary/DataType.java        |  3 +-
 .../driver/ser/binary/GraphBinaryWriter.java       |  4 +-
 .../driver/ser/binary/types/sample/SamplePair.java | 47 +++++++++++++++
 .../binary/types/sample/SamplePairSerializer.java  | 66 ++++++++++++++++++++++
 .../ser/binary/types/sample/SamplePairTests.java   | 29 ++++++++++
 5 files changed, 147 insertions(+), 2 deletions(-)

diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/DataType.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/DataType.java
index d06a2ef..a49c86b 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/DataType.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/DataType.java
@@ -61,7 +61,8 @@ public enum DataType {
     BYTEBUFFER(0X25),
     SHORT(0X26),
     BOOLEAN(0x27),
-    UNSPECIFIED_NULL(-1);
+    UNSPECIFIED_NULL(-1),
+    CUSTOM(0);
 
     private final int code;
     private static final Map<Integer, DataType> typeByCode = new HashMap<>();
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryWriter.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryWriter.java
index 50af406..29b9549 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryWriter.java
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/GraphBinaryWriter.java
@@ -73,9 +73,11 @@ public class GraphBinaryWriter {
     /**
      * Represents a null value of a specific type, useful when the parent type 
contains a type parameter that must be
      * specified.
+     * <p>Note that for simple types, the provided information will be 
<code>null</code>.</p>
      */
-    public <T> ByteBuf writeFullyQualifiedNull(Class<T> objectClass, 
ByteBufAllocator allocator) throws SerializationException {
+    public <T> ByteBuf writeFullyQualifiedNull(Class<T> objectClass, 
ByteBufAllocator allocator, Object information) throws SerializationException {
         TypeSerializer<T> serializer = registry.getSerializer(objectClass);
+        //TODO: Change to writeNull()
         return serializer.write(null, allocator, this);
     }
 
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePair.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePair.java
new file mode 100644
index 0000000..5a729cd
--- /dev/null
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePair.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.driver.ser.binary.types.sample;
+
+/**
+ * A sample custom data type, trying to demonstrate the possibility to have 
arbitrary complex types and null
+ * values without loosing type information.
+ */
+class SamplePair<K, V> {
+    private final K key;
+    private final V value;
+    private final Info info;
+
+    class Info {
+
+    }
+
+    SamplePair(K key, V value, SamplePair.Info info) {
+        this.key = key;
+        this.value = value;
+        this.info = info;
+    }
+
+    public K getKey() {
+        return key;
+    }
+
+    public V getValue() {
+        return value;
+    }
+}
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePairSerializer.java
 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePairSerializer.java
new file mode 100644
index 0000000..36db02c
--- /dev/null
+++ 
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePairSerializer.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.driver.ser.binary.types.sample;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.buffer.Unpooled;
+import org.apache.tinkerpop.gremlin.driver.ser.SerializationException;
+import org.apache.tinkerpop.gremlin.driver.ser.binary.DataType;
+import org.apache.tinkerpop.gremlin.driver.ser.binary.GraphBinaryReader;
+import org.apache.tinkerpop.gremlin.driver.ser.binary.GraphBinaryWriter;
+import org.apache.tinkerpop.gremlin.driver.ser.binary.TypeSerializer;
+
+import java.nio.charset.StandardCharsets;
+
+class SamplePairSerializer implements TypeSerializer<SamplePair> {
+    private final static byte[] dataTypeBuffer = new byte[] { 
DataType.CUSTOM.getCodeByte() };
+    private final byte[] dataTypeNameBuffer = 
"SAMPLE_PAIR".getBytes(StandardCharsets.UTF_8);
+
+    @Override
+    public SamplePair read(ByteBuf buffer, GraphBinaryReader context) throws 
SerializationException {
+        return null;
+    }
+
+    @Override
+    public SamplePair readValue(ByteBuf buffer, GraphBinaryReader context, 
boolean nullable) throws SerializationException {
+        throw new SerializationException("SamplePairSerializer can't read the 
value without type information");
+    }
+
+    @Override
+    public ByteBuf write(SamplePair value, ByteBufAllocator allocator, 
GraphBinaryWriter context) throws SerializationException {
+
+        ByteBuf valueBuffer = null;
+
+        return allocator.compositeBuffer(3).addComponents(true,
+                // Type code
+                Unpooled.wrappedBuffer(dataTypeBuffer),
+                // Custom type name
+                Unpooled.wrappedBuffer(dataTypeNameBuffer),
+                // No custom type info in this case
+                // Value flag
+                valueBuffer
+        );
+    }
+
+    @Override
+    public ByteBuf writeValue(SamplePair value, ByteBufAllocator allocator, 
GraphBinaryWriter context, boolean nullable) throws SerializationException {
+        throw new SerializationException("SamplePairSerializer can't write the 
value without type information");
+    }
+}
diff --git 
a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePairTests.java
 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePairTests.java
new file mode 100644
index 0000000..71c9789
--- /dev/null
+++ 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePairTests.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.driver.ser.binary.types.sample;
+
+import org.junit.Test;
+
+public class SamplePairTests {
+
+    @Test
+    public void tempTest() {
+
+    }
+}

Reply via email to