isapego commented on a change in pull request #577:
URL: https://github.com/apache/ignite-3/pull/577#discussion_r789679525



##########
File path: 
modules/platforms/dotnet/Apache.Ignite/Internal/Table/Serialization/RecordSerializer.cs
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Internal.Table.Serialization
+{
+    using System;
+    using System.Collections.Generic;
+    using Buffers;
+    using MessagePack;
+
+    /// <summary>
+    /// Generic record serializer.
+    /// Works for tuples and user objects, any differences are handled by the 
underlying <see cref="IRecordSerializerHandler{T}"/>.
+    /// </summary>
+    /// <typeparam name="T">Record type.</typeparam>
+    internal class RecordSerializer<T>
+        where T : class
+    {
+        /** Table. */
+        private readonly Table _table;
+
+        /** Serialization handler. */
+        private readonly IRecordSerializerHandler<T> _handler;
+
+        /// <summary>
+        /// Initializes a new instance of the <see 
cref="RecordSerializer{T}"/> class.
+        /// </summary>
+        /// <param name="table">Table.</param>
+        /// <param name="handler">Handler.</param>
+        public RecordSerializer(Table table, IRecordSerializerHandler<T> 
handler)
+        {
+            _table = table;
+            _handler = handler;
+        }
+
+        /// <summary>
+        /// Reads the value part.
+        /// </summary>
+        /// <param name="buf">Buffer.</param>
+        /// <param name="schema">Schema.</param>
+        /// <param name="key">Key part.</param>
+        /// <returns>Resulting record with key and value parts.</returns>
+        public T? ReadValue(PooledBuffer buf, Schema? schema, T key)
+        {
+            if (schema == null)
+            {
+                return null;
+            }

Review comment:
       Won't it be a little confusing for a user - silent return of a null in 
case of missing schema?

##########
File path: 
modules/platforms/dotnet/Apache.Ignite/Internal/Table/Serialization/ObjectSerializerHandler.cs
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Internal.Table.Serialization
+{
+    using System;
+    using System.Reflection;
+    using Buffers;
+    using MessagePack;
+    using Proto;
+
+    /// <summary>
+    /// Object serializer handler.
+    /// </summary>
+    /// <typeparam name="T">Object type.</typeparam>
+    internal class ObjectSerializerHandler<T> : IRecordSerializerHandler<T>
+        where T : class
+    {
+        /// <inheritdoc/>
+        public T Read(ref MessagePackReader reader, Schema schema, bool 
keyOnly = false)
+        {
+            // TODO: Emit code for efficient serialization (IGNITE-16341).
+            var columns = schema.Columns;
+            var count = keyOnly ? schema.KeyColumnCount : columns.Count;
+            var res = Activator.CreateInstance<T>();
+            var type = typeof(T);
+
+            for (var index = 0; index < count; index++)
+            {
+                if (reader.TryReadNoValue())
+                {
+                    continue;
+                }
+
+                var col = columns[index];
+                var prop = GetPropertyIgnoreCase(type, col.Name);
+
+                if (prop != null)
+                {
+                    var value = reader.ReadObject(col.Type);
+                    prop.SetValue(res, value);
+                }
+                else
+                {
+                    reader.Skip();
+                }
+            }
+
+            return (T)(object)res;
+        }
+
+        /// <inheritdoc/>
+        public T ReadValuePart(PooledBuffer buf, Schema schema, T key)
+        {
+            // TODO: Emit code for efficient serialization (IGNITE-16341).
+            // Skip schema version.
+            var r = buf.GetReader();
+            r.Skip();
+
+            var columns = schema.Columns;
+            var res = Activator.CreateInstance<T>();
+            var type = typeof(T);
+
+            for (var i = 0; i < columns.Count; i++)
+            {
+                var col = columns[i];
+                var prop = GetPropertyIgnoreCase(type, col.Name);
+
+                if (i < schema.KeyColumnCount)
+                {
+                    if (prop != null)
+                    {
+                        prop.SetValue(res, prop.GetValue(key));
+                    }

Review comment:
       Here we just silently ignore a case when user class does not have a 
column that present in schema. Is this behavior discussed somewhere?




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