You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by GitBox <gi...@apache.org> on 2020/12/04 11:40:49 UTC

[GitHub] [tinkerpop] FlorianHockmann commented on a change in pull request #1369: TINKERPOP-2472 Decouple the driver from the IO format

FlorianHockmann commented on a change in pull request #1369:
URL: https://github.com/apache/tinkerpop/pull/1369#discussion_r536038574



##########
File path: gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/GraphSONMessageSerializer.cs
##########
@@ -0,0 +1,100 @@
+#region License
+
+/*
+ * 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.
+ */
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Text.Json;
+using Gremlin.Net.Driver;
+using Gremlin.Net.Driver.Messages;
+
+namespace Gremlin.Net.Structure.IO.GraphSON
+{
+    /// <summary>
+    ///     Serializes data to and from Gremlin Server in GraphSON format.
+    /// </summary>
+    public abstract class GraphSONMessageSerializer : IMessageSerializer
+    {
+        private static readonly JsonSerializerOptions JsonDeserializingOptions = new JsonSerializerOptions
+            {PropertyNamingPolicy = JsonNamingPolicy.CamelCase};
+        private readonly string _mimeType;
+        private readonly GraphSONReader _graphSONReader;
+        private readonly GraphSONWriter _graphSONWriter;
+
+        /// <summary>
+        ///     Initializes a new instance of the <see cref="GraphSONMessageSerializer" /> class.
+        /// </summary>
+        /// <param name="mimeType">The MIME type supported by this serializer.</param>
+        /// <param name="graphSONReader">The <see cref="GraphSONReader"/> used to deserialize from GraphSON.</param>
+        /// <param name="graphSonWriter">The <see cref="GraphSONWriter"/> used to serialize to GraphSON.</param>
+        protected GraphSONMessageSerializer(string mimeType, GraphSONReader graphSONReader,
+            GraphSONWriter graphSonWriter)
+        {
+            _mimeType = mimeType;
+            _graphSONReader = graphSONReader;
+            _graphSONWriter = graphSonWriter;
+        }
+
+        /// <inheritdoc />
+        public virtual byte[] SerializeMessage(RequestMessage requestMessage)
+        {
+            var graphSONMessage = _graphSONWriter.WriteObject(requestMessage);
+            return Encoding.UTF8.GetBytes(MessageWithHeader(graphSONMessage));
+        }
+
+        private string MessageWithHeader(string messageContent)
+        {
+            return $"{(char) _mimeType.Length}{_mimeType}{messageContent}";
+        }
+
+        /// <inheritdoc />
+        public virtual ResponseMessage<List<object>> DeserializeMessage(byte[] message)

Review comment:
       This is the method users need to override if they want to skip deserialization with our GraphSON reader to get the functionality from TINKERPOP-2067 back.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org