public override void Write(BinaryWriter writer, PropertyList list) { writer.Write((ushort)list.Count); foreach (var property in list) { BinaryDeSerializerRegistry.WriteProperty(writer, property); } }
public override void Write(BinaryWriter writer, PropertyMap dictionary) { writer.Write((ushort)dictionary.Count); foreach (var entry in dictionary) { writer.Write(entry.Key); BinaryDeSerializerRegistry.WriteProperty(writer, entry.Value); } }
public override PropertyList Read(BinaryReader reader) { var count = reader.ReadUInt16(); if (count > PropertyList.MAX_SIZE) { throw new Exception( $"{ nameof(PropertyList) } count is larger than " + $"MAX_SIZE ({ count } > { PropertyList.MAX_SIZE })"); } var list = new List <IProperty>(count); for (var i = 0; i < count; i++) { list.Add(BinaryDeSerializerRegistry.ReadProperty(reader)); } return(new PropertyList(list)); }
public void BasicTest() { var map = new PropertyMap { { "bool", true }, { "byte", (byte)128 }, { "short", (short)32000 }, { "int", 1337 }, { "long", 0xD34DB33FC4FE }, { "float", 3.14F }, { "double", 0.000002 }, { "string", "gosh" }, { "primitive list", new PropertyList { "a", "b", "c" } }, { "byte array", Property.Of(new byte[] { 1, 2, 3 }) }, { "float array", Property.Of(new [] { 1.0F, 2.0F, 3.0F }) }, { "map list", new PropertyList { new PropertyMap { { "type", "zombie" }, { "health", 20 } }, new PropertyMap { { "type", "skeleton" }, { "health", 15 } }, new PropertyMap { { "type", "creeper" }, { "health", 10 } }, } }, }; var stream = new MemoryStream(); var writer = new BinaryWriter(stream, Encoding.UTF8); BinaryDeSerializerRegistry.WriteProperty(writer, map); stream.Position = 0; var reader = new BinaryReader(stream, Encoding.UTF8); var readMap = BinaryDeSerializerRegistry.ReadProperty(reader); Assert.Equal(map, readMap); }
public override PropertyMap Read(BinaryReader reader) { var dictionary = new PropertyMap(); var count = reader.ReadUInt16(); if (count > PropertyMap.MAX_SIZE) { throw new Exception( $"{ nameof(PropertyMap) } count is larger than " + $"MAX_SIZE ({ count } > { PropertyMap.MAX_SIZE })"); } for (var i = 0; i < count; i++) { var name = reader.ReadString(); var property = BinaryDeSerializerRegistry.ReadProperty(reader); dictionary.Add(name, property); } return(dictionary); }