示例#1
0
        public void Memory_stream_sequence(int positionAfter, int length)
        {
            MemoryStream stream = new MemoryStream();

            Rlp.StartSequence(stream, length);
            Assert.AreEqual(positionAfter, stream.Position);
        }
示例#2
0
 public void Encode(MemoryStream stream, PendingValidators item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
 {
     (int contentLength, int addressesLength) = GetContentLength(item, rlpBehaviors);
     Rlp.StartSequence(stream, contentLength);
     Rlp.Encode(stream, item.BlockNumber);
     Rlp.Encode(stream, item.BlockHash);
     Rlp.StartSequence(stream, addressesLength);
     for (int i = 0; i < item.Addresses.Length; i++)
     {
         Rlp.Encode(stream, item.Addresses[i]);
     }
     Rlp.Encode(stream, item.AreFinalized);
 }
示例#3
0
        public byte[] Serialize(BlockHeadersMessage message)
        {
            int contentLength = 0;

            for (int i = 0; i < message.BlockHeaders.Length; i++)
            {
                contentLength += _headerDecoder.GetLength(message.BlockHeaders[i], RlpBehaviors.None);
            }

            using (MemoryStream stream = Rlp.BorrowStream())
            {
                Rlp.StartSequence(stream, contentLength);
                for (int i = 0; i < message.BlockHeaders.Length; i++)
                {
                    _headerDecoder.Encode(stream, message.BlockHeaders[i]);
                }

                return(stream.ToArray());
            }
        }