public void SimpleArrayRead() { var tests = new[] { "a", "b", "c", "d", "e" }; Span <byte> bytes = new byte[] { 149, 161, 97, 161, 98, 161, 99, 161, 100, 161, 101 }; var length = MsgPackSpec.ReadArrayHeader(bytes, out var readSize); length.ShouldBe(tests.Length); var actual = new string[length]; for (var i = 0; i < length; i++) { actual[i] = MsgPackSpec.ReadString(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 Read(string s, byte[] data) { MsgPackSpec.ReadString(data.ToSingleSegment(), out var readSize).ShouldBe(s); readSize.ShouldBe(data.Length); }