public void testDict() { TestRoundtrip(new Hashtable()); var ht = new Hashtable() { { 0.1, 7.7 }, { 8.7, 9 }, // { 2, 3 }, TODO: integral keys don't work well across bert because (int)7 becomes (byte)7 { -2, 3 }, { 666, 3 }, { "foo", ETFCodec.ToBytes("bar") }, { "", ETFCodec.ToBytes("empty") }, { "x", null }, { "a", new ETFTuple() }, { "b", new ETFTuple() { 7 } }, { "c", new Hashtable() }, { "d", new Hashtable() { { "P", ETFCodec.ToBytes("Q") } } }, }; var encoded = BertCodec.Encode(ht); var reencoded = (Hashtable)BertCodec.Decode(encoded); Assert.That(reencoded.Keys, Is.EquivalentTo(ht.Keys)); foreach (DictionaryEntry e in ht) { Assert.That(reencoded[e.Key], Is.EqualTo(e.Value)); } }
public void testBinary() { var bytes = new byte[] { 7, 8, 9, 0, 255 }; TestRoundtrip(new byte[0]); TestRoundtrip(new byte[] { 7, 8, 9, 0, 255 }); TestRoundtrip(new ETFTuple() { bytes }); TestRoundtrip(new ArrayList() { null, ETFCodec.ToBytes("foo"), new byte[] { 9, 0, 255 } }); }
public void TestString([Values("", "nonempty", "unicode: ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ")] string s) { Assert.That(Roundtrip(s), Is.EqualTo(ETFCodec.ToBytes(s))); }
public static byte[] Encode(object obj) { return(ETFCodec.Encode(bertEncode(obj)));; }
public static object Decode(byte[] bytes) { return(bertDecode(ETFCodec.Decode(bytes))); }