-
-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Description
More information can be found in discussion #536
How to reproduce:
- Implement custom reader for custom format using
DekuReaderwithVec<u8>inside, but requiring limit - Add custom context value, such as
u8in front of other context values (as shown inVec<T>implementation. - From
TargetModelpass tripple to satisfy all 3 context parts - Check calls from
TargetModelto model implemented above usingcargo-expand.
it will show call from_reader_with_ctx if only Endian has been specified:
let __deku_value = <CustomModel as ::deku::DekuReader<
'_,
_,
>>::from_reader_with_ctx(
__deku_reader,
(
::deku::ctx::Endian::Little,
(1u8, Limit::from(10), Endian::Little),
),
)?;or Limit and Endian if both has been specified
let __deku_value = <CustomModel as ::deku::DekuReader<
'_,
_,
>>::from_reader_with_ctx(
__deku_reader,
(
::deku::ctx::Limit::new_count(
usize::try_from(*((10).borrow()))?,
),
(
::deku::ctx::Endian::Little,
(1u8, Limit::from(10), Endian::Little),
),
),
)?Thus only (Limit<u8, Predicate>, (Endian, u8)) quite strange tuple can be used instead of (Limit<u8, Predicate>, Endian, u8) or even (u8, Limit<u8, Predicate>, Endian, u8), which is an expected result.
I don't even remind that context for reading and writing may be different as we can see in reference implementations.
Taking in account information above, I have following recommendations to improve code generation:
- Change tuple
(Limit<u8, Predicate>, (Endian, CustomContext))to something more readable like(Limit<u8, Predicate>, Endian, u8)or(u8, Limit<u8, Predicate>, Endian) - Add
ctx_readandctx_writefor different custom contexts for reading and writing. e.g in example in the discussison, compression level is only used for writing. - Detect in macro (if possible) if reader and writer require endianess and limit. E.g. limit is useless for writing, but useful for reading, but field could be fixed length.
boozook
Metadata
Metadata
Assignees
Labels
No labels