-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cf1dee
commit 3eb90e8
Showing
17 changed files
with
91 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// https://github.com/ipld/libipld/blob/8478d6d66576636b9970cb3b00a232be7a88ea42/dag-cbor/src/encode.rs#L274-L288 | ||
|
||
use libipld::cbor::encode::write_null; | ||
use libipld::cbor::DagCborCodec; | ||
use libipld::codec::Encode; | ||
|
||
use crate::Any; | ||
|
||
impl Encode<DagCborCodec> for Any { | ||
fn encode<W: std::io::Write>(&self, c: DagCborCodec, w: &mut W) -> libipld::Result<()> { | ||
match self { | ||
Any::Null => write_null(w), | ||
Any::Bool(b) => b.encode(c, w), | ||
Any::Integer(i) => i.encode(c, w), | ||
Any::Bytes(b) => b.encode(c, w), | ||
Any::String(s) => s.encode(c, w), | ||
Any::List(l) => l.encode(c, w), | ||
Any::Map(m) => m.encode(c, w), | ||
Any::Link(l) => l.encode(c, w), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use libipld::{cbor::DagCborCodec, codec::assert_roundtrip, ipld, Ipld}; | ||
|
||
use crate::{Bytes, CidLink}; | ||
|
||
use super::*; | ||
|
||
fn cbor_roundtrip(unknown: Any, ipld: Ipld) { | ||
assert_roundtrip(DagCborCodec, &unknown, &ipld); | ||
} | ||
|
||
#[test] | ||
fn primitives_cbor() { | ||
cbor_roundtrip(Any::Integer(101), ipld!(101)); | ||
cbor_roundtrip(Any::Integer(-101), ipld!(-101)); | ||
cbor_roundtrip(Any::Integer(i64::MIN), ipld!(i64::MIN)); | ||
cbor_roundtrip(Any::Integer(i64::MAX), ipld!(i64::MAX)); | ||
|
||
cbor_roundtrip(Any::Bool(true), ipld!(true)); | ||
cbor_roundtrip(Any::Bool(false), ipld!(false)); | ||
|
||
cbor_roundtrip( | ||
Any::Bytes(Bytes::new(vec![1, 3, 3, 7])), | ||
Ipld::Bytes(vec![1, 3, 3, 7]), | ||
); | ||
cbor_roundtrip(Any::Bytes(Bytes::new(vec![])), Ipld::Bytes(vec![])); | ||
|
||
cbor_roundtrip(Any::String(String::new()), ipld!("")); | ||
cbor_roundtrip(Any::String("__test__".to_owned()), ipld!("__test__")); | ||
|
||
cbor_roundtrip(Any::List(vec![]), ipld!([])); | ||
cbor_roundtrip(Any::Null, ipld!(null)); | ||
|
||
let cid_link = | ||
CidLink::from_str("bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a").unwrap(); | ||
let cid = | ||
cid::Cid::try_from("bafyreidfayvfuwqa7qlnopdjiqrxzs6blmoeu4rujcjtnci5beludirz2a").unwrap(); | ||
cbor_roundtrip(Any::Link(cid_link), Ipld::Link(cid)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.