Beispiel #1
0
        /// <inheritdoc/>
        public bool TryDeserialize(FastStreamReader stream, out string error)
        {
            if (!CompactInt.TryRead(stream, out CompactInt count, out error))
            {
                return(false);
            }

            // A quick check to avoid data loss during cast below
            if (count > int.MaxValue)
            {
                error = "Item count is too big.";
                return(false);
            }
            Items = new PushDataOp[(int)count];
            for (int i = 0; i < Items.Length; i++)
            {
                PushDataOp temp = new PushDataOp();
                if (!temp.TryReadWitness(stream, out error))
                {
                    return(false);
                }
                Items[i] = temp;
            }

            error = null;
            return(true);
        }
Beispiel #2
0
        public void TryRead_Fail_NullStreamTest()
        {
            bool b = CompactInt.TryRead(null, out CompactInt actual, out string error);

            Assert.False(b);
            Assert.Equal("Stream can not be null.", error);
            Helper.ComparePrivateField(actual, "value", 0UL);
        }
Beispiel #3
0
        public void TryReadTest(byte[] data, int finalPos, ulong expected)
        {
            FastStreamReader stream = new FastStreamReader(data);
            bool             b      = CompactInt.TryRead(stream, out CompactInt actual, out string error);

            Assert.True(b);
            Assert.Null(error);
            Helper.ComparePrivateField(stream, "position", finalPos);
            Helper.ComparePrivateField(actual, "value", expected);
        }
Beispiel #4
0
        public void TryRead_FailTest(byte[] data, int finalPos, string expError)
        {
            FastStreamReader stream = new FastStreamReader(data);
            bool             b      = CompactInt.TryRead(stream, out CompactInt actual, out string error);

            Assert.False(b);
            Assert.Equal(expError, error);
            Helper.ComparePrivateField(stream, "position", finalPos);
            Helper.ComparePrivateField(actual, "value", 0UL);
        }
Beispiel #5
0
        /// <inheritdoc/>
        public override bool TryDeserialize(FastStreamReader stream, out string error)
        {
            if (stream is null)
            {
                error = "Stream can not be null.";
                return(false);
            }

            if (!CompactInt.TryRead(stream, out CompactInt count, out error))
            {
                return(false);
            }

            Headers = new Block[count];
            for (int i = 0; i < (int)count; i++)
            {
                Block temp = new Block();
                if (!temp.TryDeserializeHeader(stream, out error))
                {
                    return(false);
                }
                Headers[i] = temp;

                if (!stream.TryReadByte(out byte zero))
                {
                    error = Err.EndOfStream;
                    return(false);
                }
                if (zero != 0)
                {
                    error = "Transaction count in a headers message must be zero.";
                    return(false);
                }
            }

            error = null;
            return(true);
        }