示例#1
0
        public void Rewind_ByOne()
        {
            ReadOnlySequence <byte> bytes = SequenceFactory.Create(new byte[][] {
                new byte[] { 0 },
                new byte[] { 1, 2 },
                new byte[] { 3, 4 },
                new byte[] { 5, 6, 7, 8 }
            });

            ByteBufferReader reader = new ByteBufferReader(bytes);

            reader.Advance(1);
            ByteBufferReader copy = reader;

            for (int i = 1; i < bytes.Length; i++)
            {
                reader.Advance(i);
                Assert.Equal(i + 1, reader.Consumed);

                for (int j = 0; j < i; j++)
                {
                    reader.Rewind(1);
                    Assert.Equal(i - j, reader.Consumed);
                    Assert.False(reader.End);
                }

                Assert.Equal(copy.Position, reader.Position);
                Assert.Equal(copy.Consumed, reader.Consumed);
                Assert.Equal(copy.CurrentSpanIndex, reader.CurrentSpanIndex);
                Assert.Equal(copy.End, reader.End);
                Assert.True(copy.CurrentSpan.SequenceEqual(reader.CurrentSpan));
            }
        }
示例#2
0
文件: ReadTo.cs 项目: dora-BYR/Fenix
        public void TryReadToSpan_Sequence(bool advancePastDelimiter)
        {
            ReadOnlySequence <byte> bytes = SequenceFactory.Create(new byte[][] {
                new byte[] { 0, 0 },
                new byte[] { 1, 1, 2, 2 },
                new byte[] { },
                new byte[] { 3, 3, 4, 4, 5, 5, 6, 6 }
            });

            ByteBufferReader reader = new ByteBufferReader(bytes);

            for (byte i = 0; i < bytes.Length / 2 - 1; i++)
            {
                byte[] expected = new byte[i * 2 + 1];
                for (int j = 0; j < expected.Length - 1; j++)
                {
                    expected[j] = (byte)(j / 2);
                }
                expected[i * 2] = i;
                ReadOnlySpan <byte> searchFor = new byte[] { i, (byte)(i + 1) };
                ByteBufferReader    copy      = reader;
                Assert.True(copy.TryReadTo(out ReadOnlySequence <byte> seq, searchFor, advancePastDelimiter));
                Assert.True(seq.ToArray().AsSpan().SequenceEqual(expected));
            }

            bytes = SequenceFactory.Create(new byte[][] {
                new byte[] { 47, 42, 66, 32, 42, 32, 66, 42, 47 }   // /*b * b*/
            });

            reader = new ByteBufferReader(bytes);
            Assert.True(reader.TryReadTo(out ReadOnlySequence <byte> sequence, new byte[] { 42, 47 }, advancePastDelimiter));    //  */
            Assert.True(sequence.ToArray().AsSpan().SequenceEqual(new byte[] { 47, 42, 66, 32, 42, 32, 66 }));
        }
示例#3
0
        public void TryReadReturnsValueAndAdvances()
        {
            ByteBufferReader reader = new ByteBufferReader(Factory.CreateWithContent(GetInputData(2)));

            Assert.Equal(2, reader.Length);
            Assert.Equal(2, reader.Remaining);
            Assert.Equal(0, reader.Consumed);
            Assert.Equal(0, reader.CurrentSpanIndex);
            Assert.Equal(InputData[0], reader.CurrentSpan[reader.CurrentSpanIndex]);

            // Read 1st value
            Assert.True(reader.TryRead(out byte value));
            Assert.Equal(InputData[0], value);
            Assert.Equal(1, reader.Remaining);
            Assert.Equal(1, reader.Consumed);
            Assert.Equal(1, reader.CurrentSpanIndex);
            Assert.Equal(InputData[1], reader.CurrentSpan[reader.CurrentSpanIndex]);

            // Read 2nd value
            Assert.True(reader.TryRead(out value));
            Assert.Equal(InputData[1], value);
            Assert.Equal(0, reader.Remaining);
            Assert.Equal(2, reader.Consumed);
            Assert.Equal(2, reader.CurrentSpanIndex);

            // Read at end
            Assert.False(reader.TryRead(out value));
            Assert.Equal(default, value);
示例#4
0
        public int Read(ByteBufferReader reader)
        {
            BlockHeader header = new BlockHeader(reader);

            vertexCount = reader.ReadInt();
            reader.ReadInt(); //normal count
            reader.ReadInt(); //offset
            vertexData   = new VertexData[vertexCount];
            normalCounts = new int[vertexCount];
            normals      = new List <Vector3>();

            for (int i = 0; i < normalCounts.Length; i++)
            {
                normalCounts[i] = reader.ReadByte();
            }

            for (int i = 0; i < vertexCount; i++)
            {
                int normalCountForVertex = normalCounts[i];
                vertexData[i].vertex  = reader.ReadVector3();
                vertexData[i].normals = new Vector3[normalCountForVertex];

                for (int j = 0; j < normalCountForVertex; j++)
                {
                    Vector3 normal = reader.ReadVector3();
                    vertexData[i].normals[j] = normal;
                    normals.Add(normal);
                }
            }

            return(header.size);
        }
示例#5
0
        public void AdvanceSingleBufferSkipsValues()
        {
            ByteBufferReader reader = new ByteBufferReader(SequenceFactory.Create(GetInputData(5)));

            Assert.Equal(5, reader.Length);
            Assert.Equal(5, reader.Remaining);
            Assert.Equal(0, reader.Consumed);
            Assert.Equal(0, reader.CurrentSpanIndex);

            // Advance 2 positions
            reader.Advance(2);
            Assert.Equal(5, reader.Length);
            Assert.Equal(3, reader.Remaining);
            Assert.Equal(2, reader.Consumed);
            Assert.Equal(2, reader.CurrentSpanIndex);
            Assert.Equal(InputData[2], reader.CurrentSpan[reader.CurrentSpanIndex]);
            Assert.True(reader.TryPeek(out byte value));
            Assert.Equal(InputData[2], value);

            // Advance 2 positions
            reader.Advance(2);
            Assert.Equal(1, reader.Remaining);
            Assert.Equal(4, reader.Consumed);
            Assert.Equal(4, reader.CurrentSpanIndex);
            Assert.Equal(InputData[4], reader.CurrentSpan[reader.CurrentSpanIndex]);
            Assert.True(reader.TryPeek(out value));
            Assert.Equal(InputData[4], value);
        }
示例#6
0
        public static string DumpConditionalIntExpression(ByteBufferReader reader)
        {
            var op = reader[1].ReadByte();

            switch (op)
            {
            case 0:
            {
                var count = reader[2].ReadUInt16();
                var sb    = new StringBuilder();

                for (int i = 0, j = 0; i < count; i++, j += 2)
                {
                    if (i > 0)
                    {
                        sb.Append(" + ");
                    }

                    var subReader = reader[reader[j + 4].ReadUInt16() + 4];
                    sb.Append(DumpConditionalInt(subReader));
                }

                return(sb.ToString());
            }

            default:
            {
                throw new NotImplementedException();
            }
            }
        }
示例#7
0
 public GeometryParser(byte[] bspBytes)
 {
     reader        = new ByteBufferReader(bspBytes);
     points        = new PointDefinitions();
     polygonGroups = new List <PolygonGroup>();
     ParseBSPTree();
 }
示例#8
0
        public void IsNext_Span()
        {
            ReadOnlySequence <byte> bytes = BufferFactory.Create(new byte[][] {
                new byte[] { 0 },
                new byte[] { 1, 2 },
                new byte[] { 3, 4 },
                new byte[] { 5, 6, 7, 8 }
            });

            ByteBufferReader reader = new ByteBufferReader(bytes);

            Assert.True(reader.IsNext(ReadOnlySpan <byte> .Empty, advancePast: false));
            Assert.True(reader.IsNext(ReadOnlySpan <byte> .Empty, advancePast: true));
            Assert.True(reader.IsNext(new byte[] { 0 }, advancePast: false));
            Assert.False(reader.IsNext(new byte[] { 0, 2 }, advancePast: false));
            Assert.False(reader.IsNext(new byte[] { 0, 2 }, advancePast: true));
            Assert.True(reader.IsNext(new byte[] { 0, 1 }, advancePast: false));
            Assert.False(reader.IsNext(new byte[] { 0, 1, 3 }, advancePast: false));
            Assert.True(reader.IsNext(new byte[] { 0, 1, 2 }, advancePast: false));
            Assert.False(reader.IsNext(new byte[] { 0, 1, 2, 4 }, advancePast: false));
            Assert.True(reader.IsNext(new byte[] { 0, 1, 2, 3 }, advancePast: false));
            Assert.True(reader.IsNext(new byte[] { 0, 1, 2, 3, 4 }, advancePast: false));
            Assert.True(reader.IsNext(new byte[] { 0, 1, 2, 3, 4, 5 }, advancePast: false));
            Assert.True(reader.IsNext(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, advancePast: false));
            Assert.False(reader.IsNext(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, advancePast: false));
            Assert.False(reader.IsNext(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, advancePast: true));
            Assert.Equal(0, reader.Consumed);

            Assert.True(reader.IsNext(new byte[] { 0, 1, 2, 3 }, advancePast: true));
            Assert.True(reader.IsNext(new byte[] { 4, 5, 6 }, advancePast: true));
            Assert.True(reader.TryPeek(out byte value));
            Assert.Equal(7, value);
        }
示例#9
0
        public void SkipTests(bool singleSegment)
        {
            byte[] buffer = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var    bytes  = singleSegment
                ? new ReadOnlySequence <byte>(buffer)
                : BufferUtilities.CreateSplitBuffer(buffer, 2, 4);

            var skipReader = new ByteBufferReader(bytes);

            Assert.False(skipReader.TryAdvanceTo(10));
            Assert.True(skipReader.TryAdvanceTo(4, advancePastDelimiter: false));
            Assert.True(skipReader.TryRead(out byte value));
            Assert.Equal(4, value);

            Assert.True(skipReader.TryAdvanceToAny(new byte[] { 3, 12, 7 }, advancePastDelimiter: false));
            Assert.True(skipReader.TryRead(out value));
            Assert.Equal(7, value);
            Assert.Equal(1, skipReader.AdvancePast(8));
            Assert.True(skipReader.TryRead(out value));
            Assert.Equal(9, value);

            skipReader = new ByteBufferReader(bytes);
            Assert.Equal(0, skipReader.AdvancePast(2));
            Assert.Equal(3, skipReader.AdvancePastAny(new byte[] { 2, 3, 1 }));
            Assert.True(skipReader.TryRead(out value));
            Assert.Equal(4, value);
        }
示例#10
0
        public void EmptyBytesReader()
        {
            var bytes  = ReadOnlySequence <byte> .Empty;
            var reader = new ByteBufferReader(bytes);

            Assert.False(reader.TryReadTo(out ReadOnlySequence <byte> range, (byte)' '));
        }
示例#11
0
        public void MultiSegmentBytesReaderNumbers()
        {
            ReadOnlySequence <byte> bytes = SequenceFactory.Create(new byte[][] {
                new byte[] { 0 },
                new byte[] { 1, 2 },
                new byte[] { 3, 4 },
                new byte[] { 5, 6, 7, 8 },
                new byte[] { 8, 0 },
                new byte[] { 1, },
                new byte[] { 0, 2, },
                new byte[] { 1, 2, 3, 4 },
                new byte[] { 5, 6 },
                new byte[] { 7, 8, 9, },
                new byte[] { 0, 1, 2, 3 },
                new byte[] { 4, 5 },
                new byte[] { 6, 7, 8, 9 },
                new byte[] { 0, 1, 2, 3 },
                new byte[] { 4 },
            });

            ByteBufferReader reader = new ByteBufferReader(bytes);

            Assert.True(reader.TryReadTo(out ReadOnlySequence <byte> bytesValue, 2));
            Span <byte> span = bytesValue.ToArray();

            Assert.Equal(0, span[0]);
            Assert.Equal(1, span[1]);

            Assert.True(reader.TryReadTo(out bytesValue, 5));
            span = bytesValue.ToArray();
            Assert.Equal(3, span[0]);
            Assert.Equal(4, span[1]);

            Assert.True(reader.TryReadTo(out bytesValue, new byte[] { 8, 8 }));
            span = bytesValue.ToArray();
            Assert.Equal(6, span[0]);
            Assert.Equal(7, span[1]);

            //Assert.True(SequenceMarshal.TryRead(ref reader, out int intValue));
            Assert.True(reader.TryReadIntLE(out int intValue));
            Assert.Equal(BitConverter.ToInt32(new byte[] { 0, 1, 0, 2 }), intValue);

            Assert.True(reader.TryReadInt(out intValue));
            Assert.Equal(BitConverter.ToInt32(new byte[] { 4, 3, 2, 1 }), intValue);

            Assert.True(reader.TryReadLongLE(out long longValue));
            Assert.Equal(BitConverter.ToInt64(new byte[] { 5, 6, 7, 8, 9, 0, 1, 2 }), longValue);

            Assert.True(reader.TryReadLong(out longValue));
            Assert.Equal(BitConverter.ToInt64(new byte[] { 0, 9, 8, 7, 6, 5, 4, 3 }), longValue);

            Assert.True(reader.TryReadShortLE(out short shortValue));
            Assert.Equal(BitConverter.ToInt16(new byte[] { 1, 2 }), shortValue);

            Assert.True(reader.TryReadShort(out shortValue));
            Assert.Equal(BitConverter.ToInt16(new byte[] { 4, 3 }), shortValue);
        }
示例#12
0
        public static string DumpConditionalInt(ByteBufferReader reader)
        {
            var flags    = reader[0].ReadByte();
            var flagType = (FlagType)((flags & 0x0F) >> 0);
            var opType   = (OpType)((flags & 0xF0) >> 4);

            switch (flagType)
            {
            case FlagType.Int:
            {
                switch (opType)
                {
                case OpType.StaticInt:
                {
                    return(reader[1].ReadInt32().ToString(CultureInfo.InvariantCulture));
                }

                case OpType.Argument:
                {
                    var value = reader[1].ReadInt32();
                    if (value == -1)
                    {
                        return("arg");
                    }

                    throw new NotImplementedException();
                }

                case OpType.Expression:
                {
                    return("(" + DumpConditionalIntExpression(reader) + ")");
                }

                case OpType.Table:
                {
                    return("plot.ints[" + reader[1].ReadInt32().ToString(CultureInfo.InvariantCulture) + "]");
                }

                default:
                {
                    throw new NotImplementedException();
                }
                }
            }

            case FlagType.Float:
            {
                return(DumpConditionalFloat(reader));
            }

            default:
            {
                throw new NotImplementedException();
            }
            }
        }
示例#13
0
        public void TryCopyTo_Empty()
        {
            var reader = new ByteBufferReader(ReadOnlySequence <byte> .Empty);

            // Nothing to nothing is always possible
            Assert.True(reader.TryCopyTo(Span <byte> .Empty));

            // Nothing to something doesn't work
            Assert.False(reader.TryCopyTo(new byte[1]));
        }
示例#14
0
        bool Process(BlockType blockType, ByteBuffer block, IEventStoreObserver observer)
        {
            if ((blockType & BlockType.Compressed) != 0)
            {
                CompressionStrategy.Decompress(ref block);
            }
            var reader = new ByteBufferReader(block);

            if ((blockType & BlockType.HasTypeDeclaration) != 0)
            {
                Mapping.LoadTypeDescriptors(reader);
            }
            var  metadata = (blockType & BlockType.HasMetadata) != 0 ? Mapping.LoadObject(reader) : null;
            uint eventCount;

            if ((blockType & BlockType.HasOneEvent) != 0)
            {
                eventCount = 1;
            }
            else if ((blockType & BlockType.HasMoreEvents) != 0)
            {
                eventCount = reader.ReadVUInt32();
            }
            else
            {
                eventCount = 0;
            }
            var readEvents = observer.ObservedMetadata(metadata, eventCount);

            if (!readEvents)
            {
                return(observer.ShouldStopReadingNextEvents());
            }
            var events = new object[eventCount];
            var successfulEventCount = 0;

            for (var i = 0; i < eventCount; i++)
            {
                var ev = Mapping.LoadObject(reader);
                if (ev == null)
                {
                    continue;
                }
                events[successfulEventCount] = ev;
                successfulEventCount++;
            }

            if (eventCount != successfulEventCount)
            {
                Array.Resize(ref events, successfulEventCount);
            }

            observer.ObservedEvents(events);
            return(observer.ShouldStopReadingNextEvents());
        }
示例#15
0
        TValue ByteArrayToValue(ByteBuffer data)
        {
            var        reader = new ByteBufferReader(data);
            IReaderCtx ctx    = null;

            if (_valueHandler.NeedsCtx())
            {
                ctx = new DBReaderCtx(_tr, reader);
            }
            return(_valueReader(reader, ctx));
        }
示例#16
0
        TKey ByteArrayToKey(ByteBuffer data)
        {
            var        reader = new ByteBufferReader(data);
            IReaderCtx ctx    = null;

            if (_keyHandler.NeedsCtx())
            {
                ctx = new DBReaderCtx(_tr, reader);
            }
            return(_keyReader(reader, ctx));
        }
示例#17
0
文件: ReadTo.cs 项目: dora-BYR/Fenix
        public void TryReadTo_Span_At_Segments_Boundary()
        {
            Span <byte>          delimiter = new byte[] { 13, 10 }; // \r\n
            BufferSegment <byte> segment   = new BufferSegment <byte>(Text.Encoding.ASCII.GetBytes("Hello\r"));

            segment.Append(Text.Encoding.ASCII.GetBytes("\nWorld"));                                // add next segment
            ReadOnlySequence <byte> inputSeq = new ReadOnlySequence <byte>(segment, 0, segment, 6); // span only the first segment!
            ByteBufferReader        sr       = new ByteBufferReader(inputSeq);
            bool r = sr.TryReadTo(out _, delimiter);

            Assert.False(r);
        }
示例#18
0
文件: ReadTo.cs 项目: dora-BYR/Fenix
        public void TryReadTo_NotFound_Sequence(bool advancePastDelimiter)
        {
            ReadOnlySequence <byte> bytes = SequenceFactory.Create(new byte[][] {
                new byte[] { 1 },
                new byte[] { 2, 3, 255 }
            });

            ByteBufferReader reader = new ByteBufferReader(bytes);

            reader.Advance(4);
            Assert.False(reader.TryReadTo(out ReadOnlySequence <byte> span, 255, 0, advancePastDelimiter));
        }
示例#19
0
        void CanSerializeSimpleValue(object value)
        {
            var writer = new ByteBufferWriter();
            var storedDescriptorCtx = _mapping.StoreNewDescriptors(writer, value);

            storedDescriptorCtx.FinishNewDescriptors(writer);
            storedDescriptorCtx.StoreObject(writer, value);
            storedDescriptorCtx.CommitNewDescriptors();
            var reader = new ByteBufferReader(writer.Data);
            var obj    = _mapping.LoadObject(reader);

            Assert.Equal(value, obj);
        }
示例#20
0
        public void CanSerializeInt()
        {
            var writer = new ByteBufferWriter();
            var storedDescriptorCtx = _mapping.StoreNewDescriptors(writer, 12345);

            storedDescriptorCtx.FinishNewDescriptors(writer);
            storedDescriptorCtx.StoreObject(writer, 12345);
            storedDescriptorCtx.CommitNewDescriptors();
            var reader = new ByteBufferReader(writer.Data);
            var obj    = _mapping.LoadObject(reader);

            Assert.Equal(12345, obj);
        }
示例#21
0
        public void Basics()
        {
            var buffer = Unpooled.Buffer(1024);
            var writer = new ByteBufferWriter(buffer);

            writer.WriteByte(1);
            writer.WriteShort(12);
            writer.WriteShortLE(21);

            writer.WriteMedium(13);
            writer.WriteMediumLE(31);

            writer.WriteInt(14);
            writer.WriteIntLE(41);
            writer.WriteLong(15);
            writer.WriteLongLE(51);

            writer.WriteDecimal(168.86m);
            writer.WriteDecimalLE(188.88m);

            writer.Flush();

            var reader = new ByteBufferReader(buffer);

            reader.TryRead(out byte b);
            Assert.Equal(1, b);
            reader.TryReadShort(out var sV);
            Assert.Equal(12, sV);
            reader.TryReadShortLE(out sV);
            Assert.Equal(21, sV);

            reader.TryReadMedium(out var iV);
            Assert.Equal(13, iV);
            reader.TryReadMediumLE(out iV);
            Assert.Equal(31, iV);

            reader.TryReadInt(out iV);
            Assert.Equal(14, iV);
            reader.TryReadIntLE(out iV);
            Assert.Equal(41, iV);
            reader.TryReadLong(out var lV);
            Assert.Equal(15, lV);
            reader.TryReadLongLE(out lV);
            Assert.Equal(51, lV);

            reader.TryReadDecimal(out var mV);
            Assert.Equal(168.86m, mV);
            reader.TryReadDecimalLE(out mV);
            Assert.Equal(188.88m, mV);
        }
        public void TakeReturnsByteAndMoves()
        {
            var reader = new ByteBufferReader(Factory.CreateWithContent(GetInputData(2)));

            Assert.Equal(0, reader.CurrentSpanIndex);
            Assert.Equal(InputData[0], reader.CurrentSpan[reader.CurrentSpanIndex]);
            Assert.True(reader.TryRead(out byte value));
            Assert.Equal(InputData[0], value);
            Assert.Equal(1, reader.CurrentSpanIndex);
            Assert.Equal(InputData[1], reader.CurrentSpan[reader.CurrentSpanIndex]);
            Assert.True(reader.TryRead(out value));
            Assert.Equal(InputData[1], value);
            Assert.False(reader.TryRead(out value));
            Assert.Equal(default, value);
示例#23
0
文件: ReadTo.cs 项目: dora-BYR/Fenix
        public void TryReadTo_Sequence(bool advancePastDelimiter, bool useEscapeOverload)
        {
            ReadOnlySequence <byte> bytes = SequenceFactory.Create(new byte[][] {
                new byte[] { 0 },
                new byte[] { 1, 2 },
                new byte[] { },
                new byte[] { 3, 4, 5, 6 }
            });

            ByteBufferReader reader = new ByteBufferReader(bytes);

            // Read to 0-5
            for (byte i = 0; i < bytes.Length - 1; i++)
            {
                ByteBufferReader copy = reader;

                // Can read to the first integer (0-5)
                Assert.True(
                    useEscapeOverload
                        ? copy.TryReadTo(out ReadOnlySequence <byte> sequence, i, 255, advancePastDelimiter)
                        : copy.TryReadTo(out sequence, i, advancePastDelimiter));

                // Should never have a null Position object
                Assert.NotNull(copy.Position.GetObject());
                ReadOnlySequence <byte> .Enumerator enumerator = sequence.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ;
                }

                // Should be able to read to final 6
                Assert.True(
                    useEscapeOverload
                        ? copy.TryReadTo(out sequence, 6, 255, advancePastDelimiter)
                        : copy.TryReadTo(out sequence, 6, advancePastDelimiter));

                Assert.NotNull(copy.Position.GetObject());
                enumerator = sequence.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ;
                }

                // If we didn't advance, we should still be able to read to 6
                Assert.Equal(!advancePastDelimiter,
                             useEscapeOverload
                        ? copy.TryReadTo(out sequence, 6, 255, advancePastDelimiter)
                        : copy.TryReadTo(out sequence, 6, advancePastDelimiter));
            }
        }
        public void AdvanceSingleBufferSkipsBytes()
        {
            var reader = new ByteBufferReader(BufferUtilities.CreateBuffer(GetInputData(5)));

            reader.Advance(2);
            Assert.Equal(2, reader.CurrentSpanIndex);
            Assert.Equal(InputData[2], reader.CurrentSpan[reader.CurrentSpanIndex]);
            Assert.True(reader.TryPeek(out byte value));
            Assert.Equal(InputData[2], value);
            reader.Advance(2);
            Assert.True(reader.TryPeek(out value));
            Assert.Equal(InputData[4], value);
            Assert.Equal(4, reader.CurrentSpanIndex);
            Assert.Equal(InputData[4], reader.CurrentSpan[reader.CurrentSpanIndex]);
        }
示例#25
0
        ByteBuffer WriteSecondaryKeyKey(uint secondaryKeyIndex, ByteBuffer keyBytes, ByteBuffer valueBytes)
        {
            var keyWriter = new ByteBufferWriter();

            keyWriter.WriteVUInt32(_relationInfo.Id);
            keyWriter.WriteVUInt32(secondaryKeyIndex);

            var valueReader = new ByteBufferReader(valueBytes);
            var version     = valueReader.ReadVUInt32();

            var keySaver = _relationInfo.GetPKValToSKMerger(version, secondaryKeyIndex);

            keySaver(_transaction, keyWriter, new ByteBufferReader(keyBytes), new ByteBufferReader(valueBytes), _relationInfo.DefaultClientObject);
            return(keyWriter.Data);
        }
示例#26
0
        public void SingleSegmentBytesReader()
        {
            byte[] buffer = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var    bytes  = new ReadOnlySequence <byte>(buffer);
            var    reader = new ByteBufferReader(bytes);

            Assert.True(reader.TryReadTo(out ReadOnlySequence <byte> ab, 3));
            Assert.True(ab.First.Span.SequenceEqual(new byte[] { 1, 2 }));

            Assert.True(reader.TryReadTo(out ReadOnlySequence <byte> cd, 6));
            Assert.True(cd.First.Span.SequenceEqual(new byte[] { 4, 5 }));

            Assert.True(reader.TryReadTo(out ReadOnlySequence <byte> ef, new byte[] { 8, 9 }));
            Assert.True(ef.First.Span.SequenceEqual(new byte[] { 7 }));
        }
示例#27
0
文件: IsNext.cs 项目: dora-BYR/Fenix
        public void IsNext_Empty(bool advancePast)
        {
            var reader = new ByteBufferReader(ReadOnlySequence <byte> .Empty);

            Assert.False(reader.IsNext((byte)'Z', advancePast));
            Assert.Equal(0, reader.Consumed);

            // Nothing is always next
            Assert.True(reader.IsNext(ReadOnlySpan <byte> .Empty, advancePast));
            Assert.Equal(0, reader.Consumed);

            // Something isn't
            Assert.False(reader.IsNext(new byte[] { (byte)'\0' }, advancePast));
            Assert.Equal(0, reader.Consumed);
        }
示例#28
0
 public SortNormalBlock(ByteBufferReader reader)
 {
     reader.FastForward(sizeof(int));
     size           = reader.ReadInt();
     planeNormal    = reader.ReadVector3();
     planePoint     = reader.ReadVector3();
     reserved       = reader.ReadInt();
     frontOffset    = reader.ReadInt();
     backOffset     = reader.ReadInt();
     preListOffset  = reader.ReadInt();
     postListOffset = reader.ReadInt();
     onlineOffset   = reader.ReadInt();
     boundingBoxMin = reader.ReadVector3();
     boundingBoxMax = reader.ReadVector3();
 }
示例#29
0
 void IterateFields(ByteBufferReader reader, IEnumerable <TableFieldInfo> fields, HashSet <int> knownInlineRefs)
 {
     foreach (var fi in fields)
     {
         if (_visitor == null || _visitor.StartField(fi.Name))
         {
             IterateHandler(reader, fi.Handler, false, knownInlineRefs);
             _visitor?.EndField();
         }
         else
         {
             IterateHandler(reader, fi.Handler, true, knownInlineRefs);
         }
     }
 }
示例#30
0
        public void RewindEmptyFirstSpan()
        {
            // This is to hit the "if (memory.Length == 0)" branch in ResetReader.
            ReadOnlySequence <byte> bytes = SequenceFactory.Create(new byte[][] {
                new byte[0],
                new byte[] { 1, 2 },
                new byte[] { 3, 4 }
            });

            var reader = new ByteBufferReader(bytes);

            reader.Advance(3);
            Assert.True(reader.IsNext(4));
            reader.Rewind(2);
            Assert.Equal(new byte[] { 1, 2 }, reader.CurrentSpan.ToArray());
        }