/// <summary> /// Put binary types to Grid. /// </summary> /// <param name="types">Binary types.</param> internal void PutBinaryTypes(ICollection <BinaryType> types) { DoOutOp(OpMeta, stream => { BinaryWriter metaWriter = _marsh.StartMarshal(stream); metaWriter.WriteInt(types.Count); foreach (var meta in types) { BinaryType meta0 = meta; metaWriter.WriteInt(meta0.TypeId); metaWriter.WriteString(meta0.TypeName); metaWriter.WriteString(meta0.AffinityKeyFieldName); IDictionary <string, int> fields = meta0.GetFieldsMap(); metaWriter.WriteInt(fields.Count); foreach (var field in fields) { metaWriter.WriteString(field.Key); metaWriter.WriteInt(field.Value); } metaWriter.WriteBoolean(meta.IsEnum); } _marsh.FinishMarshal(metaWriter); }); _marsh.OnBinaryTypesSent(types); }
/// <summary> /// Writes the binary type. /// </summary> public static void WriteBinaryType(BinaryWriter w, BinaryType meta) { Debug.Assert(w != null); Debug.Assert(meta != null); w.WriteInt(meta.TypeId); w.WriteString(meta.TypeName); w.WriteString(meta.AffinityKeyFieldName); var fields = meta.GetFieldsMap(); w.WriteInt(fields.Count); foreach (var field in fields) { w.WriteString(field.Key); w.WriteInt(field.Value.TypeId); w.WriteInt(field.Value.FieldId); } // Enum data w.WriteBoolean(meta.IsEnum); if (meta.IsEnum) { if (meta.EnumValuesMap != null) { w.WriteInt(meta.EnumValuesMap.Count); foreach (var pair in meta.EnumValuesMap) { w.WriteString(pair.Key); w.WriteInt(pair.Value); } } else { w.WriteInt(0); } } // Send schemas var desc = meta.Descriptor; Debug.Assert(desc != null); var count = 0; var countPos = w.Stream.Position; w.WriteInt(0); // Reserve for count foreach (var schema in desc.Schema.GetAll()) { w.WriteInt(schema.Key); var ids = schema.Value; w.WriteInt(ids.Length); foreach (var id in ids) { w.WriteInt(id); } count++; } w.Stream.WriteInt(countPos, count); }