Skip to content

Commit c828aa8

Browse files
authored
fix: address code review feedback
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
1 parent 72b4ddf commit c828aa8

6 files changed

Lines changed: 28 additions & 26 deletions

File tree

‎src/hyperlight_common/src/flatbuffer_wrappers/codec.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ pub trait ExternalValueSink<'a> {
1515
/// Receive one contiguous byte value.
1616
fn push_bytes(&mut self, value: &'a [u8]) -> Result<()>;
1717

18-
/// Receive one chunk-preserving byte value.
18+
/// Receive one logical byte sequence represented as chunks.
1919
fn push_chunks(&mut self, value: &'a [Bytes]) -> Result<()>;
2020
}
2121

2222
/// Supplies complete external byte values while a FlatBuffer is decoded.
23+
///
24+
/// Implementations must validate `length` against available input and the
25+
/// resource budget before allocating.
2326
pub trait ExternalValueSource {
2427
/// Take the next external value as contiguous bytes.
2528
fn take_bytes(&mut self, length: usize) -> Result<Vec<u8>>;

‎src/hyperlight_common/src/flatbuffer_wrappers/function_types.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ pub enum ParameterValue {
305305
Bool(bool),
306306
/// `Vec<u8>`
307307
VecBytes(Vec<u8>),
308-
/// One complete chunk-preserving byte value.
308+
/// One logical byte sequence represented as chunks.
309309
///
310-
/// Chunk boundaries are not framing and are not guaranteed to survive
311-
/// transport.
310+
/// Chunk boundaries are a storage detail and may change during transport.
311+
/// They do not delimit messages or values.
312312
ByteChunks(
313313
#[cfg_attr(feature = "fuzzing", arbitrary(with = arbitrary_byte_chunks))] Vec<Bytes>,
314314
),
@@ -336,7 +336,7 @@ pub enum ParameterType {
336336
Bool,
337337
/// `Vec<u8>`
338338
VecBytes,
339-
/// One complete chunk-preserving byte value.
339+
/// One logical byte sequence represented as chunks.
340340
ByteChunks,
341341
}
342342

@@ -363,10 +363,10 @@ pub enum ReturnValue {
363363
Void(()),
364364
/// `Vec<u8>`
365365
VecBytes(Vec<u8>),
366-
/// One complete chunk-preserving byte value.
366+
/// One logical byte sequence represented as chunks.
367367
///
368-
/// Chunk boundaries are not framing and are not guaranteed to survive
369-
/// transport.
368+
/// Chunk boundaries are a storage detail and may change during transport.
369+
/// They do not delimit messages or values.
370370
ByteChunks(Vec<Bytes>),
371371
}
372372

@@ -396,7 +396,7 @@ pub enum ReturnType {
396396
Void,
397397
/// `Vec<u8>`
398398
VecBytes,
399-
/// One complete chunk-preserving byte value.
399+
/// One logical byte sequence represented as chunks.
400400
ByteChunks,
401401
}
402402

‎src/hyperlight_common/src/func/ret_type.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ use crate::flatbuffer_wrappers::function_types::{ReturnType, ReturnValue};
99

1010
/// This is a marker trait that is used to indicate that a type is a valid Hyperlight return type.
1111
///
12-
/// `Vec<u8>` and `Vec<Bytes>` are distinct logical return types. `Vec<u8>`
13-
/// carries contiguous bytes, while `Vec<Bytes>` preserves local chunk
14-
/// ownership. Chunk boundaries are not application framing.
12+
/// `Vec<u8>` and `Vec<Bytes>` both represent one logical byte sequence.
13+
/// `Vec<u8>` stores it contiguously. `Vec<Bytes>` represents it as chunks and
14+
/// may avoid flattening them into one allocation. Chunk boundaries are a
15+
/// storage detail and may change during transport. They do not delimit messages
16+
/// or values.
1517
pub trait SupportedReturnType: Sized + Clone + Send + Sync + 'static {
1618
/// The return type of the supported return value
1719
const TYPE: ReturnType;

‎src/hyperlight_guest_capi/src/types/parameter.rs‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,12 @@ impl OwnedFfiParameter {
9797
FfiParameterOwner::String { _value: value },
9898
)
9999
}
100-
ParameterValue::VecBytes(v) => {
101-
ParameterValue::VecBytes(mut v) => {
102-
let view = FfiVec::from_mut_slice(&mut v);
103-
(
104-
ParameterType::VecBytes,
105-
FfiParameterValue { VecBytes: view },
106-
FfiParameterOwner::VecBytes { _value: v },
107-
)
108-
}
109-
let view = FfiVec::from_mut_slice(&mut value);
100+
ParameterValue::VecBytes(mut v) => {
101+
let view = FfiVec::from_mut_slice(&mut v);
110102
(
111103
ParameterType::VecBytes,
112104
FfiParameterValue { VecBytes: view },
113-
FfiParameterOwner::VecBytes { _value: value },
105+
FfiParameterOwner::VecBytes { _value: v },
114106
)
115107
}
116108
ParameterValue::ByteChunks(v) => {

‎src/hyperlight_guest_capi/src/types/vec.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ pub struct FfiVec {
1616
}
1717

1818
impl FfiVec {
19+
/// Creates a non-owning FFI view over `value` without copying.
20+
///
21+
/// The caller must keep `value` alive and at a stable address while the
22+
/// view is used. The view must not be passed to [`Self::into_vec`].
1923
pub(crate) fn from_mut_slice(value: &mut [u8]) -> Self {
2024
Self {
2125
data: value.as_mut_ptr(),

‎src/schema/function_types.fbs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,16 @@ table hlvecbytes {
5757
value:[ubyte];
5858
}
5959

60-
// hlbytechunks is the embedded compatibility representation of a chunked byte
61-
// value. Embedded transport does not preserve chunk boundaries.
60+
// hlbytechunks is the embedded compatibility representation of one logical
61+
// byte sequence. It stores the bytes contiguously, so original chunk boundaries
62+
// are not preserved.
6263

6364
table hlbytechunks {
6465
value:[ubyte];
6566
}
6667

6768
// hlexternalbytes declares a logical byte value stored outside the FlatBuffer.
68-
// chunked distinguishes ByteChunks from the default VecBytes logical type.
69+
// chunked requests the ByteChunks representation rather than VecBytes.
6970

7071
table hlexternalbytes {
7172
length:ulong;

0 commit comments

Comments
 (0)