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
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
chronik/bitcoinsuite-core/src/bytes.rs | ||
---|---|---|
35 ↗ | (On Diff #39954) | 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 ↗ | (On Diff #39954) | 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)?; // ... } |