adamreeve commented on code in PR #100:
URL: https://github.com/apache/arrow-dotnet/pull/100#discussion_r2404804004


##########
src/Apache.Arrow.Flight/Internal/SchemaWriter.cs:
##########
@@ -13,53 +13,28 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using Apache.Arrow.Flatbuf;
-using Apache.Arrow.Flight.Internal;
-using Apache.Arrow.Ipc;
+using Apache.Arrow.Flight;
 using Google.Protobuf;
 
-namespace Apache.Arrow.Flight.Internal
+namespace Apache.Arrow.Flight
 {
-    /// <summary>
-    /// This class handles writing schemas
-    /// </summary>
-    internal class SchemaWriter : ArrowStreamWriter
+    internal static class SchemaWriter
     {
-        internal SchemaWriter(Stream baseStream, Schema schema) : 
base(baseStream, schema)
+        public static ByteString ToByteString(Schema schema)
         {
-        }
-
-        public void WriteSchema(Schema schema, CancellationToken 
cancellationToken)
-        {
-            var offset = base.SerializeSchema(schema);
-            WriteMessage(MessageHeader.Schema, offset, 0);
-        }
-
-        public static ByteString SerializeSchema(Schema schema, 
CancellationToken cancellationToken = default(CancellationToken))
-        {
-            using (var memoryStream = new MemoryStream())
-            {
-                var writer = new SchemaWriter(memoryStream, schema);
-                writer.WriteSchema(schema, cancellationToken);
-
-                memoryStream.Position = 0;
-                return ByteString.FromStream(memoryStream);
-            }
+            return schema == null ?
+                ByteString.Empty :
+                
UnsafeByteOperations.UnsafeWrap(ArrowSerializationHelpers.SerializeSchema(schema));
         }
     }
 }
 
 public static class SchemaExtension
 {
-    // Translate an Apache.Arrow.Schema to FlatBuffer Schema to ByteString
+    // This should never have been a public class without a namespace
+    // TODO: Mark as obsolete once sufficient time has passed

Review Comment:
   Should we just mark this as obsolete now? Otherwise there's no indication 
that users should switch to something else. Either way, it would be good to add 
a comment to direct users to use `ArrowSerializationHelpers.SerializeSchema` 
instead if we don't want people using this.



##########
src/Apache.Arrow/ArrowSerializationHelpers.cs:
##########
@@ -0,0 +1,88 @@
+// 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.
+
+using System;
+using System.IO;
+using Apache.Arrow.Flatbuf;
+using Apache.Arrow.Ipc;
+
+namespace Apache.Arrow
+{
+    /// <summary>
+    /// Helpers for serializing partial Arrow structures to and from buffers.
+    /// </summary>
+    public static class ArrowSerializationHelpers
+    {
+        public static Schema DeserializeSchema(ReadOnlyMemory<byte> 
serializedSchema)
+        {
+            ArrowMemoryReaderImplementation implementation = new 
ArrowMemoryReaderImplementation(serializedSchema, null);
+            return implementation.Schema;
+        }
+
+        public static RecordBatch DeserializeRecordBatch(Schema schema, 
ReadOnlyMemory<byte> serializedRecordBatch)
+        {
+            ArrowMemoryReaderImplementation implementation = new 
ArrowMemoryReaderImplementation(schema, serializedRecordBatch, null);
+            return implementation.ReadNextRecordBatch();
+        }
+
+        public static byte[] SerializeSchema(Schema schema)
+        {
+            using (var stream = new MemoryStream())
+            {
+                var writer = new SchemaWriter(stream, schema);
+                writer.WriteSchema(schema);
+                return stream.ToArray();
+            }
+        }
+
+        public static byte[] SerializeRecordBatch(RecordBatch recordBatch)
+        {
+            using (var stream = new MemoryStream())
+            {
+                var writer = new SchemaWriter(stream, recordBatch.Schema);
+                writer.WriteBatch(recordBatch);
+                return stream.ToArray();
+            }
+        }
+
+        /// <summary>
+        /// This class handles writing schemas

Review Comment:
   It also writes RecordBatches. I can't think of a better name for it though.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to