Пример #1
0
        public static ReadOnlySpan <byte> UnpackBytes(DcPackerInterface pi, ReadOnlySpan <byte> buffer)
        {
            if (pi.HasFixedByteSize && pi.HasFixedStructure)
            {
                return(buffer.Slice(0, pi.FixedByteSize));
            }

            if (pi.PackType == DcPackType.Array || pi.PackType == DcPackType.Blob || pi.PackType == DcPackType.String)
            {
                var length = pi.NumLengthBytes switch {
                    2 => BinaryPrimitives.ReadUInt16LittleEndian(buffer),
                    4 => BinaryPrimitives.ReadUInt32LittleEndian(buffer),
                    _ => throw new Exception()
                };
                return(buffer.Slice(0, (int)(pi.NumLengthBytes + length)));
            }

            var offset = 0;

            if (pi.HasNestedFields)
            {
                for (var i = 0; i < pi.NumNestedFields; i++)
                {
                    var f = pi.GetNestedField(i);
                    var d = UnpackBytes(f, buffer.Slice(offset));
                    offset += d.Length;
                }
            }
            return(buffer.Slice(0, offset));
        }
Пример #2
0
        public static object ReadObject(this MemoryBufferReader reader, DcPackerInterface pi)
        {
            var spanReader = new SpanBufferReader(reader.RemainingData.Span);
            var value      = spanReader.ReadObject(pi);

            reader.SkipBytes(spanReader.Offset);
            return(value);
        }
Пример #3
0
        public static ReadOnlyMemory <byte> UnpackBytes(DcPackerInterface pi, ReadOnlyMemory <byte> buffer)
        {
            var s = UnpackBytes(pi, buffer.Span);

            return(buffer.Slice(0, s.Length));
        }