public void TestNonFixedArrayTryRead() { var tests = new[] { 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, }; Span <byte> bytes = new byte[] { 0xdc, 0x00, 0x14, 0x01, 0x02, 0x03, 0x04, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05, }; MsgPackSpec.TryReadArrayHeader(bytes, out var length, out var readSize).ShouldBeTrue(); length.ShouldBe(tests.Length); var actual = new int[length]; for (var i = 0; i < length; i++) { actual[i] = MsgPackSpec.ReadInt32(bytes.Slice(readSize), out var temp); readSize += temp; } actual.ShouldBe(tests); }
private static void ReadDictionary(Dictionary <int, string> test, int length, ReadOnlySequence <byte> span, int readSize) { length.ShouldBe(test.Count); var dictionary = new Dictionary <int, string>(length); for (var i = 0; i < length; i++) { span = span.Slice(readSize); var key = MsgPackSpec.ReadInt32(span, out readSize); span = span.Slice(readSize); dictionary[key] = MsgPackSpec.ReadString(span, out readSize); } dictionary.ShouldBe(test, true); }
public void TestSignedInt(int number, byte[] data) { MsgPackSpec.ReadInt32(data, out var readSize).ShouldBe(number); readSize.ShouldBe(data.Length); }
public void ReadSignedInt(int number, byte[] data) { MsgPackSpec.ReadInt32(data.ToSingleSegment(), out var readSize).ShouldBe(number); readSize.ShouldBe(data.Length); }