Simple helpers that allows parsing out bytes and returning an error otherwise.
Details
Details
- Reviewers
Fabien - Group Reviewers
Restricted Project - Commits
- rABC03cac5b3187e: [Chronik] Add `read_bytes` and `read_array`
ninja check-crates
Diff Detail
Diff Detail
- Repository
- rABC Bitcoin ABC
- Branch
- chronik-read-bytes
- Lint
Lint Passed - Unit
No Test Coverage - Build Status
Buildable 23469 Build 46557: Build Diff build-chronik Build 46556: arc lint + arc unit
Event Timeline
chronik/bitcoinsuite-core/src/bytes.rs | ||
---|---|---|
35 | Even if well documented, this is rather unusual to have read function mutating the input to be read. Is there a real benefit in doing so vs returning a shorten copy of the input bytes ? |
chronik/bitcoinsuite-core/src/bytes.rs | ||
---|---|---|
35 | The benefit is that you can write really neat code parsing structured data: fn parse_slpv2(data: &mut Bytes) -> Result<...> { let lokad_id: [u8; 4] = read_array(data)?; let token_type = read_array::<1>(data)?[0]; let tx_type_len= read_array::<1>(data)?[0]; let tx_type = read_bytes(data, tx_type_len as usize)?; // ... } |