MCPcopy Create free account
hub / github.com/ceramicnetwork/rust-ceramic / decode

Method decode

car/src/header.rs:18–33  ·  view source on GitHub ↗
(buffer: &[u8])

Source from the content-addressed store, hash-verified

16 }
17
18 pub fn decode(buffer: &[u8]) -> Result<Self, Error> {
19 let header: CarHeaderV1 =
20 serde_ipld_dagcbor::from_slice(buffer).map_err(|e| Error::Parsing(e.to_string()))?;
21
22 if header.roots.is_empty() {
23 return Err(Error::Parsing("empty CAR file".to_owned()));
24 }
25
26 if header.version != 1 {
27 return Err(Error::InvalidFile(
28 "Only CAR file version 1 is supported".to_string(),
29 ));
30 }
31
32 Ok(CarHeader::V1(header))
33 }
34
35 pub fn encode(&self) -> Result<Vec<u8>, Error> {
36 match self {

Callers 15

to_vecMethod · 0.45
test_siwx_messagesFunction · 0.45
verify_signatureMethod · 0.45
verify_webauth_nMethod · 0.45
commit-id.test.tsFile · 0.45
stream-id.test.tsFile · 0.45
readVarintFunction · 0.45
fromStringFunction · 0.45
carFromStringFunction · 0.45

Calls 2

to_stringMethod · 0.45
is_emptyMethod · 0.45

Tested by 1

test_siwx_messagesFunction · 0.36