public void Memory_stream_sequence(int positionAfter, int length) { MemoryStream stream = new MemoryStream(); Rlp.StartSequence(stream, length); Assert.AreEqual(positionAfter, stream.Position); }
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); }
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()); } }