コード例 #1
0
        public void TestStringRefs()
        {
            var        encodeOptions = new CBOREncodeOptions("resolvereferences=true");
            CBORObject cbor          = CBORObject.DecodeFromBytes(
                new byte[] {
                0xd9, 1, 0, 0x9f, 0x64, 0x61, 0x62, 0x63, 0x64, 0xd8,
                0x19, 0x00, 0xd8, 0x19, 0x00, 0x64, 0x62, 0x62, 0x63, 0x64, 0xd8, 0x19,
                0x01, 0xd8, 0x19, 0x00, 0xd8, 0x19, 0x01, 0xff,
            },
                encodeOptions);
            string expected =
                "[\"abcd\",\"abcd\",\"abcd\",\"bbcd\",\"bbcd\",\"abcd\",\"bbcd\"]";

            Assert.AreEqual(expected, cbor.ToJSONString());
            cbor = CBORObject.DecodeFromBytes(new byte[] {
                0xd9,
                1, 0, 0x9f, 0x64, 0x61, 0x62, 0x63, 0x64, 0x62, 0x61,
                0x61, 0xd8, 0x19, 0x00, 0xd8, 0x19, 0x00, 0x64, 0x62,
                0x62, 0x63, 0x64, 0xd8, 0x19, 0x01, 0xd8, 0x19, 0x00,
                0xd8, 0x19, 0x01, 0xff,
            },
                                              encodeOptions);
            expected =
                "[\"abcd\",\"aa\",\"abcd\",\"abcd\",\"bbcd\",\"bbcd\",\"abcd\",\"bbcd\"]";
            Assert.AreEqual(expected, cbor.ToJSONString());
        }
コード例 #2
0
        public void TestSharedRefs()
        {
            var encodeOptions = new CBOREncodeOptions("resolvereferences=true");

            byte[]     bytes;
            CBORObject cbor;
            string     expected;

            bytes = new byte[] {
                0x9f, 0xd8, 28, 1, 0xd8, 29, 0, 3, 3, 0xd8, 29,
                0, 0xff,
            };
            cbor     = CBORObject.DecodeFromBytes(bytes, encodeOptions);
            expected = "[1,1,3,3,1]";
            Assert.AreEqual(expected, cbor.ToJSONString());
            bytes = new byte[] {
                0x9f, 0xd8, 28, 0x81, 1, 0xd8, 29, 0, 3, 3, 0xd8,
                29, 0, 0xff,
            };
            cbor     = CBORObject.DecodeFromBytes(bytes, encodeOptions);
            expected = "[[1],[1],3,3,[1]]";
            Assert.AreEqual(expected, cbor.ToJSONString());
            // Checks if both objects are the same reference, not just equal
            Assert.IsTrue(cbor[0] == cbor[1], "cbor[0] not same as cbor[1]");
            Assert.IsTrue(cbor[0] == cbor[4], "cbor[0] not same as cbor[4]");
            bytes = new byte[] { 0xd8, 28, 0x82, 1, 0xd8, 29, 0 };
            cbor  = CBORObject.DecodeFromBytes(bytes, encodeOptions);
            Assert.AreEqual(2, cbor.Count);
            // Checks if both objects are the same reference, not just equal
            Assert.IsTrue(cbor == cbor[1], "objects not the same");
        }
コード例 #3
0
 private static CBORObject FromBytesB(byte[] b, CBOREncodeOptions options)
 {
     using (var ms = new System.IO.MemoryStream(b)) {
         CBORObject o = CBORObject.Read(ms, options);
         if (ms.Position != ms.Length)
         {
             throw new CBORException("not at EOF");
         }
         return(o);
     }
 }
コード例 #4
0
        // Tests the equivalence of the DecodeFromBytes and Read methods.
        public static CBORObject FromBytesTestAB(byte[] b, CBOREncodeOptions
                                                 options)
        {
            CBORObject oa = FromBytesA(b, options);
            CBORObject ob = FromBytesB(b, options);

            if (!oa.Equals(ob))
            {
                Assert.AreEqual(oa, ob);
            }
            return(oa);
        }
コード例 #5
0
 private static CBORObject FromBytesA(byte[] b, CBOREncodeOptions options)
 {
     return(CBORObject.DecodeFromBytes(b, options));
 }