@@ -85,11 +85,10 @@ fn read_segment_table(slice: &[u8], options: ReaderOptions) -> Result<ReadSegmen
85
85
pub type NoAllocSliceSegments < ' b > = NoAllocBufferSegments < & ' b [ u8 ] > ;
86
86
87
87
enum NoAllocBufferSegmentType {
88
- /// The buffer contains a single segment, with bounds given by the two
89
- /// `usize` parameters. The first parameter gives the byte offset of the
90
- /// start of the segment, and the second parameter gives the byte offset
91
- /// of its end.
92
- SingleSegment ( usize , usize ) ,
88
+ /// The buffer contains a single segment, with length in bytes given by
89
+ /// the value of the `usize` parameter. The segment starts at byte index
90
+ /// 8 of the buffer.
91
+ SingleSegment ( usize ) ,
93
92
94
93
/// The buffer contains multiple segments. In this case, the segment table
95
94
/// needs to be re-parsed on each call to `get_segment()`.
@@ -114,12 +113,10 @@ pub struct NoAllocBufferSegments<T> {
114
113
impl < T > NoAllocBufferSegments < T > {
115
114
pub ( crate ) fn from_segment_table ( buffer : T , info : ReadSegmentTableResult ) -> Self {
116
115
if info. segments_count == 1 {
117
- let message_length = info. segment_table_length_bytes + info. total_segments_length_bytes ;
118
116
Self {
119
117
buffer,
120
118
segment_type : NoAllocBufferSegmentType :: SingleSegment (
121
- info. segment_table_length_bytes ,
122
- message_length,
119
+ info. total_segments_length_bytes ,
123
120
) ,
124
121
}
125
122
} else {
@@ -172,9 +169,9 @@ impl<T: AsRef<[u8]>> ReaderSegments for NoAllocBufferSegments<T> {
172
169
let idx: usize = idx. try_into ( ) . unwrap ( ) ;
173
170
174
171
match self . segment_type {
175
- NoAllocBufferSegmentType :: SingleSegment ( start , end ) => {
172
+ NoAllocBufferSegmentType :: SingleSegment ( length_bytes ) => {
176
173
if idx == 0 {
177
- Some ( & self . buffer . as_ref ( ) [ start..end ] )
174
+ Some ( & self . buffer . as_ref ( ) [ 8 .. 8 + length_bytes ] )
178
175
} else {
179
176
None
180
177
}
0 commit comments