From e1582f20468560728811a765b7d3b67a6ca7975f Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Thu, 28 Mar 2024 16:27:43 -0400 Subject: [PATCH] give NoAllocSegmentTableInfo public visibility --- capnp/src/serialize.rs | 4 ++-- .../src/serialize/no_alloc_buffer_segments.rs | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/capnp/src/serialize.rs b/capnp/src/serialize.rs index 3128a4339..681991ef8 100644 --- a/capnp/src/serialize.rs +++ b/capnp/src/serialize.rs @@ -393,13 +393,13 @@ where } read.read_exact(&mut buffer[start..end])?; - let info = no_alloc_buffer_segments::ReadSegmentTableResult { + let info = no_alloc_buffer_segments::NoAllocSegmentTableInfo { segments_count: segment_count, segment_table_length_bytes: (num_segment_counts_read + 1) * 4, total_segments_length_bytes: total_body_words * 8, }; - let segments = NoAllocSliceSegments::from_segment_table(buffer, info); + let segments = NoAllocSliceSegments::from_segment_table_info(buffer, info); Ok(Some(crate::message::Reader::new(segments, options))) } diff --git a/capnp/src/serialize/no_alloc_buffer_segments.rs b/capnp/src/serialize/no_alloc_buffer_segments.rs index 9ab8c33e3..47c9ff608 100644 --- a/capnp/src/serialize/no_alloc_buffer_segments.rs +++ b/capnp/src/serialize/no_alloc_buffer_segments.rs @@ -7,13 +7,19 @@ use super::SEGMENTS_COUNT_LIMIT; const U32_LEN_IN_BYTES: usize = core::mem::size_of::(); -pub(crate) struct ReadSegmentTableResult { +/// Information about a message read from its segment table. +pub struct NoAllocSegmentTableInfo { + /// The number of segments in the message. pub segments_count: usize, + + /// The number of bytes in the segment table. pub segment_table_length_bytes: usize, + + /// The total number of bytes in all segments of the message. pub total_segments_length_bytes: usize, } -fn read_segment_table(slice: &[u8], options: ReaderOptions) -> Result { +fn read_segment_table(slice: &[u8], options: ReaderOptions) -> Result { let mut remaining = slice; verify_alignment(remaining.as_ptr())?; @@ -74,7 +80,7 @@ fn read_segment_table(slice: &[u8], options: ReaderOptions) -> Result { } impl NoAllocBufferSegments { - pub(crate) fn from_segment_table(buffer: T, info: ReadSegmentTableResult) -> Self { + /// Constructs a NoAllocBufferSegments from a buffer and a `NoAllocSegmentTableInfo`. + pub fn from_segment_table_info(buffer: T, info: NoAllocSegmentTableInfo) -> Self { if info.segments_count == 1 { Self { buffer, @@ -144,7 +151,7 @@ impl<'b> NoAllocBufferSegments<&'b [u8]> { let message = &slice[..message_length]; *slice = &slice[message_length..]; - Ok(Self::from_segment_table(message, segment_table_info)) + Ok(Self::from_segment_table_info(message, segment_table_info)) } } @@ -156,7 +163,7 @@ impl> NoAllocBufferSegments { /// Otherwise, `buffer` must be 8-byte aligned (attempts to read the message will trigger errors). pub fn from_buffer(buffer: T, options: ReaderOptions) -> Result { let segment_table_info = read_segment_table(buffer.as_ref(), options)?; - Ok(Self::from_segment_table(buffer, segment_table_info)) + Ok(Self::from_segment_table_info(buffer, segment_table_info)) } }