Ejemplo n.º 1
0
 public void ShouldThrowOnVeryLongStringArray()
 {
     Assert.Throws <OverflowException>(() => {
         var longArray = Enumerable.Repeat("0", MsgSerializer.MaxArrayLength + 1).ToArray();
         MsgSerializer.WriteStringArray(longArray, Array.Empty <byte>(), 0);
     });
 }
Ejemplo n.º 2
0
        public int WriteTo(byte[] buffer, int offset)
        {
            var dataOffset = offset + MsgSerializer.HeaderLength;
            var written    = 0;

            written += MsgSerializer.WriteInt32(Seed, buffer, dataOffset);
            written += MsgSerializer.WriteStringArray(Players, buffer, dataOffset + written);
            written += MsgSerializer.WriteByte(YourIndex, buffer, dataOffset + written);
            written += MsgSerializer.WriteByte(TicksPerSecond, buffer, dataOffset + written);
            written += MsgSerializer.WriteHeader(written, MsgId, buffer, offset);

            return(written);
        }
Ejemplo n.º 3
0
        public void ShouldSerializeAndDeserializeStringArray(string item, int count)
        {
            var value = Enumerable.Repeat(item, count).ToArray();
            var buf   = new byte[MsgSerializer.SizeOf(value)];

            MsgSerializer.WriteStringArray(value, buf, 0);

            var offset       = 0;
            var deserialized = MsgSerializer.ReadStringArray(buf, ref offset);

            Assert.True(value.Length == deserialized.Length, "Length mismatch");

            for (var i = 0; i < value.Length; i++)
            {
                Assert.True(value[i] == deserialized[i], $"Values mismatch at {i}");
            }
        }