@@ -51,7 +51,7 @@ internal readonly struct SubEntryChunk
5151 private SubEntryChunk ( byte compress ,
5252 ushort numRecordsInBatch ,
5353 uint unCompressedDataSize , uint dataLen ,
54- ReadOnlySequence < byte > data )
54+ Memory < byte > data )
5555 {
5656 compressValue = compress ;
5757 NumRecordsInBatch = numRecordsInBatch ;
@@ -67,7 +67,18 @@ private SubEntryChunk(byte compress,
6767 public uint UnCompressedDataSize { get ; }
6868
6969 public uint DataLen { get ; }
70- public ReadOnlySequence < byte > Data { get ; }
70+ public Memory < byte > Data { get ; }
71+
72+ // This wrapper was added to be used in async methods
73+ // where the SequenceReader is not available
74+ // see RawConsumer:ParseChunk for more details
75+ // at some point we could remove this wrapper
76+ // and use system.io.pipeline instead of SequenceReader
77+ internal static int Read ( ref ReadOnlySequence < byte > seq , byte entryType , out SubEntryChunk subEntryChunk )
78+ {
79+ var reader = new SequenceReader < byte > ( seq ) ;
80+ return Read ( ref reader , entryType , out subEntryChunk ) ;
81+ }
7182
7283 internal static int Read ( ref SequenceReader < byte > reader , byte entryType , out SubEntryChunk subEntryChunk )
7384 {
@@ -77,14 +88,18 @@ internal static int Read(ref SequenceReader<byte> reader, byte entryType, out Su
7788 // Determinate what kind of the compression it is using
7889 // See Compress:CompressMode
7990 var compress = ( byte ) ( ( byte ) ( entryType & 0x70 ) >> 4 ) ;
80- offset ++ ;
8191
8292 // Data contains the subEntryChunk information
8393 // We need to pass it to the subEntryChunk that will decode the information
94+ var memory =
95+ ArrayPool < byte > . Shared . Rent ( ( int ) dataLen ) . AsMemory ( 0 , ( int ) dataLen ) ;
8496 var data = reader . Sequence . Slice ( reader . Consumed , dataLen ) ;
97+ data . CopyTo ( memory . Span ) ;
98+
8599 subEntryChunk =
86- new SubEntryChunk ( compress , numRecordsInBatch , unCompressedDataSize , dataLen , data ) ;
87- offset += ( int ) dataLen ;
100+ new SubEntryChunk ( compress , numRecordsInBatch , unCompressedDataSize , dataLen , memory ) ;
101+ offset += memory . Length ;
102+
88103 // Here we need to advance the reader to the datalen
89104 // Since Data is passed to the subEntryChunk.
90105 reader . Advance ( dataLen ) ;
@@ -101,7 +116,7 @@ private Chunk(byte magicVersion,
101116 ulong epoch ,
102117 ulong chunkId ,
103118 int crc ,
104- ReadOnlySequence < byte > data )
119+ Memory < byte > data )
105120 {
106121 MagicVersion = magicVersion ;
107122 NumEntries = numEntries ;
@@ -121,7 +136,7 @@ private Chunk(byte magicVersion,
121136 public ulong Epoch { get ; }
122137 public ulong ChunkId { get ; }
123138 public int Crc { get ; }
124- public ReadOnlySequence < byte > Data { get ; }
139+ public Memory < byte > Data { get ; }
125140
126141 internal static int Read ( ReadOnlySequence < byte > frame , out Chunk chunk )
127142 {
@@ -138,9 +153,11 @@ internal static int Read(ReadOnlySequence<byte> frame, out Chunk chunk)
138153 offset += WireFormatting . ReadUInt32 ( ref reader , out _ ) ;
139154 // offset += 4; // reserved
140155 offset += WireFormatting . ReadUInt32 ( ref reader , out _ ) ; // reserved
156+ var memory =
157+ ArrayPool < byte > . Shared . Rent ( ( int ) dataLen ) . AsMemory ( 0 , ( int ) dataLen ) ;
141158 var data = reader . Sequence . Slice ( reader . Consumed , dataLen ) ;
142- offset += ( int ) dataLen ;
143- chunk = new Chunk ( magicVersion , numEntries , numRecords , timestamp , epoch , chunkId , crc , data ) ;
159+ data . CopyTo ( memory . Span ) ;
160+ chunk = new Chunk ( magicVersion , numEntries , numRecords , timestamp , epoch , chunkId , crc , memory ) ;
144161 return offset ;
145162 }
146163 }
0 commit comments