/// <summary> /// Merges schemas from two binary types. /// </summary> private static BinaryObjectSchema MergeSchemas(BinaryType a, BinaryType b) { if (a == null || a.Schema == null) { return(b.Schema); } if (b == null || b.Schema == null) { return(a.Schema); } var res = new BinaryObjectSchema(); foreach (var schema in a.Schema.GetAll()) { res.Add(schema.Key, schema.Value); } foreach (var schema in b.Schema.GetAll()) { res.Add(schema.Key, schema.Value); } return(res); }
/// <summary> /// Initializes a new instance of the <see cref="BinaryType" /> class. /// </summary> /// <param name="reader">The reader.</param> /// <param name="readSchemas">Whether to read schemas.</param> public BinaryType(BinaryReader reader, bool readSchemas = false) { _typeId = reader.ReadInt(); _typeName = reader.ReadString(); _affinityKeyFieldName = reader.ReadString(); int fieldsNum = reader.ReadInt(); _fields = new Dictionary <string, BinaryField>(fieldsNum); for (int i = 0; i < fieldsNum; ++i) { string name = reader.ReadString(); BinaryField field = new BinaryField(reader); _fields[name] = field; } _isEnum = reader.ReadBoolean(); if (_isEnum) { var count = reader.ReadInt(); _enumNameToValue = new Dictionary <string, int>(count); for (var i = 0; i < count; i++) { _enumNameToValue[reader.ReadString()] = reader.ReadInt(); } _enumValueToName = _enumNameToValue.ToDictionary(x => x.Value, x => x.Key); } if (readSchemas) { var cnt = reader.ReadInt(); for (var i = 0; i < cnt; i++) { var schemaId = reader.ReadInt(); var ids = new int[reader.ReadInt()]; for (var j = 0; j < ids.Length; j++) { ids[j] = reader.ReadInt(); } _schema.Add(schemaId, ids); } } _marshaller = reader.Marshaller; }