ptupitsyn commented on a change in pull request #577: URL: https://github.com/apache/ignite-3/pull/577#discussion_r790459748
########## 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: Same behavior as in Java API. I could not find any discussions on this topic, but it seems reasonable to me. -- 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]
