Esempio n. 1
0
        public void ByteArrays_V1()
        {
            Cid cid    = "zBunRGrmCGokA1oMESGGTfrtcMFsVA8aEtcNzM54akPWXF97uXCqTjF3GZ9v8YzxHrG66J8QhtPFWwZebRZ2zeUEELu67";
            var buffer = cid.ToArray();
            var clone  = Cid.Read(buffer);

            Assert.AreEqual(cid.Version, clone.Version);
            Assert.AreEqual(cid.ContentType, clone.ContentType);
            Assert.AreEqual(cid.Hash.Algorithm.Name, clone.Hash.Algorithm.Name);
            Assert.AreEqual(cid.Hash, clone.Hash);
        }
Esempio n. 2
0
        public void ByteArrays_V0()
        {
            var buffer = "1220a4edf38611d7d4a2d3ff2d97f88a7256eba31b57982f803b4de7bbeb0343c37b".ToHexBuffer();
            var cid    = Cid.Read(buffer);

            Assert.AreEqual(0, cid.Version);
            Assert.AreEqual("dag-pb", cid.ContentType);
            Assert.AreEqual("QmZSU1xNFsBtCnzK2Nk9N4bAxQiVNdmugU9DQDE3ntkTpe", cid.Hash.ToString());

            var clone = cid.ToArray();

            CollectionAssert.AreEqual(buffer, clone);
        }
Esempio n. 3
0
        public void Streaming_V1()
        {
            Cid cid    = "zBunRGrmCGokA1oMESGGTfrtcMFsVA8aEtcNzM54akPWXF97uXCqTjF3GZ9v8YzxHrG66J8QhtPFWwZebRZ2zeUEELu67";
            var stream = new MemoryStream();

            cid.Write(stream);
            stream.Position = 0;
            Cid clone = Cid.Read(stream);

            Assert.AreEqual(cid.Version, clone.Version);
            Assert.AreEqual(cid.ContentType, clone.ContentType);
            Assert.AreEqual(cid.Hash, clone.Hash);
        }
Esempio n. 4
0
        public void Streaming_V0()
        {
            Cid cid    = "QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4";
            var stream = new MemoryStream();

            cid.Write(stream);
            stream.Position = 0;
            Cid clone = Cid.Read(stream);

            Assert.AreEqual(cid.Version, clone.Version);
            Assert.AreEqual(cid.ContentType, clone.ContentType);
            Assert.AreEqual(cid.Hash, clone.Hash);
        }
Esempio n. 5
0
        public void Protobuf_V1()
        {
            Cid cid    = "zBunRGrmCGokA1oMESGGTfrtcMFsVA8aEtcNzM54akPWXF97uXCqTjF3GZ9v8YzxHrG66J8QhtPFWwZebRZ2zeUEELu67";
            var stream = new MemoryStream();
            var cos    = new CodedOutputStream(stream);

            cid.Write(cos);
            cos.Flush();
            stream.Position = 0;
            var cis   = new CodedInputStream(stream);
            Cid clone = Cid.Read(cis);

            Assert.AreEqual(cid.Version, clone.Version);
            Assert.AreEqual(cid.ContentType, clone.ContentType);
            Assert.AreEqual(cid.Hash, clone.Hash);
        }
Esempio n. 6
0
        public void Protobuf_V0()
        {
            Cid cid    = "QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4";
            var stream = new MemoryStream();
            var cos    = new CodedOutputStream(stream);

            cid.Write(cos);
            cos.Flush();
            stream.Position = 0;
            var cis   = new CodedInputStream(stream);
            Cid clone = Cid.Read(cis);

            Assert.AreEqual(cid.Version, clone.Version);
            Assert.AreEqual(cid.ContentType, clone.ContentType);
            Assert.AreEqual(cid.Hash, clone.Hash);
        }
        void Read(CodedInputStream stream)
        {
            while (!stream.IsAtEnd)
            {
                var tag = stream.ReadTag();
                switch (WireFormat.GetTagFieldNumber(tag))
                {
                case 1:
                    Id = Cid.Read(stream);
                    break;

                case 2:
                    Name = stream.ReadString();
                    break;

                case 3:
                    Size = stream.ReadInt64();
                    break;

                default:
                    throw new InvalidDataException("Unknown field number");
                }
            }
        }