static void ParseArrayToSegment() { // hex dump of [1, 2, 3] var arrayBytes = new byte[] { 0x02, 0x05, 0x31, 0x32, 0x33 }; // parsed segment var arraySegment = VPack.ToSegment(arrayBytes); PrintSegment(arraySegment); }
public void SegmentizeCompactArray() { // given var data = Converter.ToVPackBytes(Paths.JsonCompactArray, true, false); // when var segment = VPack.ToSegment <CompactArraySegment>(data); // then // array Assert.IsInstanceOf <CompactArraySegment>(segment); Assert.IsInstanceOf <ArraySegment>(segment); Assert.AreEqual(0, segment.StartIndex); Assert.AreEqual(6, segment.CursorIndex); Assert.AreEqual(data.Length, segment.ByteLength); Assert.AreEqual(SegmentType.CompactArray, segment.Type); Assert.AreEqual(ValueType.CompactNonIndexedArray, segment.ValueType); Assert.AreEqual(2, segment.ValueStartIndex); Assert.AreEqual(3, segment.ValueByteLength); Assert.AreEqual(3, segment.Items.Count); Assert.AreEqual(segment.ItemCount, segment.Items.Count); // first small integer segment item var item1 = segment.Items[0]; Assert.IsInstanceOf <SmallIntegerSegment>(item1); Assert.AreEqual(2, item1.StartIndex); Assert.AreEqual(3, item1.CursorIndex); Assert.AreEqual(SegmentType.SmallInteger, item1.Type); Assert.AreEqual(ValueType.PosOneInt, item1.ValueType); Assert.AreEqual(2, item1.ValueStartIndex); Assert.AreEqual(1, item1.ValueByteLength); // second small integer segment item var item2 = segment.Items[1]; Assert.IsInstanceOf <SmallIntegerSegment>(item2); Assert.AreEqual(3, item2.StartIndex); Assert.AreEqual(4, item2.CursorIndex); Assert.AreEqual(SegmentType.SmallInteger, item2.Type); Assert.AreEqual(ValueType.PosTwoInt, item2.ValueType); Assert.AreEqual(3, item2.ValueStartIndex); Assert.AreEqual(1, item2.ValueByteLength); // third small integer segment item var item3 = segment.Items[2]; Assert.IsInstanceOf <SmallIntegerSegment>(item3); Assert.AreEqual(4, item3.StartIndex); Assert.AreEqual(5, item3.CursorIndex); Assert.AreEqual(SegmentType.SmallInteger, item3.Type); Assert.AreEqual(ValueType.PosThreeInt, item3.ValueType); Assert.AreEqual(4, item3.ValueStartIndex); Assert.AreEqual(1, item3.ValueByteLength); }
public void SegmentizeNonIndexedArray() { // given var data = Hex.EightByteNonIndexedArray; // when var segment = VPack.ToSegment <NonIndexedArraySegment>(data); // then // array Assert.IsInstanceOf <NonIndexedArraySegment>(segment); Assert.IsInstanceOf <ArraySegment>(segment); Assert.AreEqual(0, segment.StartIndex); Assert.AreEqual(12, segment.CursorIndex); Assert.AreEqual(data.Length, segment.ByteLength); Assert.AreEqual(SegmentType.NonIndexedArray, segment.Type); Assert.AreEqual(ValueType.EightByteNonIndexedArray, segment.ValueType); Assert.AreEqual(9, segment.ValueStartIndex); Assert.AreEqual(3, segment.ValueByteLength); Assert.AreEqual(3, segment.Items.Count); // first item var item1 = segment.Items[0]; Assert.IsInstanceOf <SmallIntegerSegment>(item1); Assert.AreEqual(9, item1.StartIndex); Assert.AreEqual(10, item1.CursorIndex); Assert.AreEqual(SegmentType.SmallInteger, item1.Type); Assert.AreEqual(ValueType.PosOneInt, item1.ValueType); Assert.AreEqual(9, item1.ValueStartIndex); Assert.AreEqual(1, item1.ValueByteLength); // second item var item2 = segment.Items[1]; Assert.IsInstanceOf <SmallIntegerSegment>(item2); Assert.AreEqual(10, item2.StartIndex); Assert.AreEqual(11, item2.CursorIndex); Assert.AreEqual(SegmentType.SmallInteger, item2.Type); Assert.AreEqual(ValueType.PosTwoInt, item2.ValueType); Assert.AreEqual(10, item2.ValueStartIndex); Assert.AreEqual(1, item2.ValueByteLength); // third item var item3 = segment.Items[2]; Assert.IsInstanceOf <SmallIntegerSegment>(item3); Assert.AreEqual(11, item3.StartIndex); Assert.AreEqual(12, item3.CursorIndex); Assert.AreEqual(SegmentType.SmallInteger, item3.Type); Assert.AreEqual(ValueType.PosThreeInt, item3.ValueType); Assert.AreEqual(11, item3.ValueStartIndex); Assert.AreEqual(1, item3.ValueByteLength); }
public void SegmentizeIllegalValue() { // given var data = Hex.IllegalValue; // when var segment = VPack.ToSegment(data); // then Assert.IsInstanceOf <IllegalSegment>(segment); Assert.AreEqual(0, segment.StartIndex); Assert.AreEqual(1, segment.CursorIndex); Assert.AreEqual(data.Length, segment.ByteLength); Assert.AreEqual(SegmentType.Illegal, segment.Type); Assert.AreEqual(ValueType.Illegal, segment.ValueType); Assert.AreEqual(0, segment.ValueStartIndex); Assert.AreEqual(1, segment.ValueByteLength); }
public void SegmentizeNullValue() { // given var data = Converter.ToVPackBytes(Paths.JsonNullValue); // when var segment = VPack.ToSegment(data); // then Assert.IsInstanceOf <NullSegment>(segment); Assert.AreEqual(0, segment.StartIndex); Assert.AreEqual(1, segment.CursorIndex); Assert.AreEqual(data.Length, segment.ByteLength); Assert.AreEqual(SegmentType.Null, segment.Type); Assert.AreEqual(ValueType.Null, segment.ValueType); Assert.AreEqual(0, segment.ValueStartIndex); Assert.AreEqual(1, segment.ValueByteLength); }
public void SegmentizeNegOneByteFloatValue() { // given var data = Hex.NegOneByteLengthFloatValue; // when var segment = VPack.ToSegment(data); // then Assert.IsInstanceOf <FloatSegment>(segment); Assert.AreEqual(0, segment.StartIndex); Assert.AreEqual(9, segment.CursorIndex); Assert.AreEqual(data.Length, segment.ByteLength); Assert.AreEqual(SegmentType.Float, segment.Type); Assert.AreEqual(ValueType.NegOneByteFloat, segment.ValueType); Assert.AreEqual(6, segment.ValueStartIndex); Assert.AreEqual(3, segment.ValueByteLength); }
public void SegmentizeFiveByteUnsignedIntValue() { // given var data = Converter.ToVPackBytes(Paths.JsonFiveByteUnsignedInt); // when var segment = VPack.ToSegment(data); // then Assert.IsInstanceOf <UnsignedIntegerSegment>(segment); Assert.AreEqual(0, segment.StartIndex); Assert.AreEqual(6, segment.CursorIndex); Assert.AreEqual(data.Length, segment.ByteLength); Assert.AreEqual(SegmentType.UnsignedInteger, segment.Type); Assert.AreEqual(ValueType.FiveByteUInt, segment.ValueType); Assert.AreEqual(1, segment.ValueStartIndex); Assert.AreEqual(5, segment.ValueByteLength); }
public void SegmentizePosThreeIntValue() { // given var data = Converter.ToVPackBytes(Paths.JsonPosThreeInt); // when var segment = VPack.ToSegment(data); // then Assert.IsInstanceOf <SmallIntegerSegment>(segment); Assert.AreEqual(0, segment.StartIndex); Assert.AreEqual(1, segment.CursorIndex); Assert.AreEqual(data.Length, segment.ByteLength); Assert.AreEqual(SegmentType.SmallInteger, segment.Type); Assert.AreEqual(ValueType.PosThreeInt, segment.ValueType); Assert.AreEqual(0, segment.ValueStartIndex); Assert.AreEqual(1, segment.ValueByteLength); }
internal void ParseItems(byte[] data, ulong byteLength) { ValueStartIndex = CursorIndex; // cycle through array items until all of them are parsed // array needs to be parsed until it's BYTELENGTH value is reached while (byteLength != (ulong)(CursorIndex - StartIndex)) { // parse array item into segment var subSegment = VPack.ToSegment(data, CursorIndex); // array segment cursor index needs to be shifted to recently parse sub segment cursor index CursorIndex = subSegment.CursorIndex; Items.Add(subSegment); } ValueByteLength = CursorIndex - ValueStartIndex; }
public void SegmentizeEmptyArray() { // given var data = Converter.ToVPackBytes(Paths.JsonEmptyArray); // when var segment = VPack.ToSegment <EmptyArraySegment>(data); // then Assert.IsInstanceOf <EmptyArraySegment>(segment); Assert.IsInstanceOf <ArraySegment>(segment); Assert.AreEqual(0, segment.StartIndex); Assert.AreEqual(1, segment.CursorIndex); Assert.AreEqual(data.Length, segment.ByteLength); Assert.AreEqual(SegmentType.EmptyArray, segment.Type); Assert.AreEqual(ValueType.EmptyArray, segment.ValueType); Assert.AreEqual(0, segment.ValueStartIndex); Assert.AreEqual(1, segment.ValueByteLength); Assert.AreEqual(0, segment.Items.Count); }
public void SegmentizeNonIndexedArray_With_SixZeroByteByteLengthSize() { // given var data = Hex.TwoByteNonIndexedArrayWithSixZeroBytes; // when var segment = VPack.ToSegment <NonIndexedArraySegment>(data); // then // array Assert.IsInstanceOf <NonIndexedArraySegment>(segment); Assert.IsInstanceOf <ArraySegment>(segment); Assert.AreEqual(0, segment.StartIndex); Assert.AreEqual(data.Length, segment.CursorIndex); Assert.AreEqual(data.Length, segment.ByteLength); Assert.AreEqual(SegmentType.NonIndexedArray, segment.Type); Assert.AreEqual(ValueType.TwoByteNonIndexedArray, segment.ValueType); Assert.AreEqual(9, segment.ValueStartIndex); Assert.AreEqual(3, segment.ValueByteLength); Assert.AreEqual(3, segment.Items.Count); TestSmallIntegerItems(segment); }