Example #1
0
        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));
            }
        }
Example #2
0
        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 }
            });
        }
Example #3
0
 public void TestString([Values("", "nonempty", "unicode: ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ")] string s)
 {
     Assert.That(Roundtrip(s), Is.EqualTo(ETFCodec.ToBytes(s)));
 }
Example #4
0
 public static byte[] Encode(object obj)
 {
     return(ETFCodec.Encode(bertEncode(obj)));;
 }
Example #5
0
 public static object Decode(byte[] bytes)
 {
     return(bertDecode(ETFCodec.Decode(bytes)));
 }