public void ShouldThrowOnVeryLongString() { Assert.Throws <OverflowException>(() => { const int size = MsgSerializer.MaxStringLength; MsgSerializer.WriteString(new string('A', size + 1), new byte[size + 2], 0); }); }
public void ShouldSerializeAndDeserializeString(string value) { var buf = new byte[MsgSerializer.SizeOf(value)]; MsgSerializer.WriteString(value, buf, 0); var offset = 0; var deserialized = MsgSerializer.ReadString(buf, ref offset); Assert.True(value == deserialized, $"'{value}' != '{deserialized}'"); }
public int WriteTo(byte[] buffer, int offset) { var dataOffset = offset + MsgSerializer.HeaderLength; var written = 0; written += MsgSerializer.WriteString(Game, buffer, dataOffset); written += MsgSerializer.WriteUInt16(Version, buffer, dataOffset + written); written += MsgSerializer.WriteString(PlayerName, buffer, dataOffset + written); written += MsgSerializer.WriteHeader(written, MsgId, buffer, offset); return(written); }
public void ShouldThrowOnNullStringSerialization() { Assert.Throws <NullReferenceException>(() => { MsgSerializer.WriteString(null, Array.Empty <byte>(), 0); }); }