public void DeserializeAndSerialize() { var test = new FullNodeCapability() { StartHeight = uint.MaxValue }; var buffer = test.ToArray(); using var br = new BinaryReader(new MemoryStream(buffer)); var clone = (FullNodeCapability)NodeCapability.DeserializeFrom(br); Assert.AreEqual(test.StartHeight, clone.StartHeight); }
void ISerializable.Deserialize(BinaryReader reader) { Magic = reader.ReadUInt32(); Version = reader.ReadUInt32(); Timestamp = reader.ReadUInt32(); Nonce = reader.ReadUInt32(); UserAgent = reader.ReadVarString(1024); // Capabilities Capabilities = new NodeCapability[reader.ReadVarInt(MaxCapabilities)]; for (int x = 0, max = Capabilities.Length; x < max; x++) { Capabilities[x] = NodeCapability.DeserializeFrom(reader); } }
void ISerializable.Deserialize(BinaryReader reader) { Magic = reader.ReadUInt32(); Version = reader.ReadUInt32(); Timestamp = reader.ReadUInt32(); Nonce = reader.ReadUInt32(); UserAgent = reader.ReadVarString(1024); // Capabilities Capabilities = new NodeCapability[reader.ReadVarInt(MaxCapabilities)]; for (int x = 0, max = Capabilities.Length; x < max; x++) { Capabilities[x] = NodeCapability.DeserializeFrom(reader); } if (Capabilities.Select(p => p.Type).Distinct().Count() != Capabilities.Length) { throw new FormatException(); } }
void ISerializable.Deserialize(BinaryReader reader) { Timestamp = reader.ReadUInt32(); // Address byte[] data = reader.ReadBytes(16); if (data.Length != 16) { throw new FormatException(); } Address = new IPAddress(data).Unmap(); // Capabilities Capabilities = new NodeCapability[reader.ReadVarInt(VersionPayload.MaxCapabilities)]; for (int x = 0, max = Capabilities.Length; x < max; x++) { Capabilities[x] = NodeCapability.DeserializeFrom(reader); } }
void ISerializable.Deserialize(BinaryReader reader) { Timestamp = reader.ReadUInt32(); // Address byte[] data = reader.ReadFixedBytes(16); Address = new IPAddress(data).Unmap(); // Capabilities Capabilities = new NodeCapability[reader.ReadVarInt(VersionPayload.MaxCapabilities)]; for (int x = 0, max = Capabilities.Length; x < max; x++) { Capabilities[x] = NodeCapability.DeserializeFrom(reader); } if (Capabilities.Select(p => p.Type).Distinct().Count() != Capabilities.Length) { throw new FormatException(); } }
public void DeserializeAndSerialize() { var test = new ServerCapability(NodeCapabilityType.WsServer) { Port = 2 }; var buffer = test.ToArray(); var br = new MemoryReader(buffer); var clone = (ServerCapability)NodeCapability.DeserializeFrom(ref br); Assert.AreEqual(test.Port, clone.Port); Assert.AreEqual(test.Type, clone.Type); clone = new ServerCapability(NodeCapabilityType.WsServer, 123); br = new MemoryReader(buffer); ((ISerializable)clone).Deserialize(ref br); Assert.AreEqual(test.Port, clone.Port); Assert.AreEqual(test.Type, clone.Type); clone = new ServerCapability(NodeCapabilityType.TcpServer, 123); Assert.ThrowsException <FormatException>(() => { var br2 = new MemoryReader(buffer); ((ISerializable)clone).Deserialize(ref br2); }); Assert.ThrowsException <ArgumentException>(() => { _ = new ServerCapability(NodeCapabilityType.FullNode); }); // Wrog type buffer[0] = 0xFF; Assert.ThrowsException <FormatException>(() => { var br2 = new MemoryReader(buffer); NodeCapability.DeserializeFrom(ref br2); }); }