Esempio n. 1
0
 public void ShouldThrowOnVeryLongString()
 {
     Assert.Throws <OverflowException>(() => {
         const int size = MsgSerializer.MaxStringLength;
         MsgSerializer.WriteString(new string('A', size + 1), new byte[size + 2], 0);
     });
 }
Esempio n. 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}'");
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 public void ShouldThrowOnNullStringSerialization()
 {
     Assert.Throws <NullReferenceException>(() => {
         MsgSerializer.WriteString(null, Array.Empty <byte>(), 0);
     });
 }