protected static void Write(Stream stream, short value)
        {
            ContractsCommon.CanWriteToStream(stream, BufferOperations.UINT16_SIZE);
            var bytes = BitConverter.GetBytes(value);

            stream.Write(bytes, 0, bytes.Length);
        }
 protected static void WriteBytes(Stream stream, byte[] buffer, int offset, int length)
 {
     ContractsCommon.CanWriteToStream(stream, BufferOperations.UINT8_SIZE * length);
     ContractsCommon.NotNull(buffer, "buffer");
     ContractsCommon.ValidOffsetLength(0, buffer.Length, offset, length);
     stream.Write(buffer, offset, length);
 }
        protected static void WriteCollection <T>(Stream stream, SCG.ICollection <T> objs) where T : BitcoinSerializable, new()
        {
            ContractsCommon.NotNull(objs, "objs");
            ContractsCommon.CanWriteToStream(stream, VarIntByteSize(objs.Count) + objs.Sum(o => o.SerializedByteSize));

            WriteVarInt(stream, objs.Count);
            foreach (var obj in objs)
            {
                obj.Serialize(stream);
            }
        }
        protected static void WriteVarArray <T>(Stream stream, T[] objs) where T : BitcoinSerializable, new()
        {
            ContractsCommon.NotNull(objs, "objs");
            ContractsCommon.CanWriteToStream(stream, VarIntByteSize(objs.Length) + objs.Sum(o => o.SerializedByteSize));

            WriteVarInt(stream, objs.Length);
            foreach (var obj in objs)
            {
                obj.Serialize(stream);
            }
        }
 protected static void WriteVarInt(Stream stream, ulong value)
 {
     ContractsCommon.CanWriteToStream(stream, VarIntByteSize(value));
     if (value < 253)
     {
         Write(stream, (byte)value);
     }
     else if (value < 65536)
     {
         Write(stream, (byte)253);
         Write(stream, (ushort)value);
     }
     else if (value < 4294967296L)
     {
         Write(stream, (byte)254);
         Write(stream, (uint)value);
     }
     else
     {
         Write(stream, (byte)255);
         Write(stream, value);
     }
 }
Exemple #6
0
 public void Serialize(Stream stream)
 {
     ContractsCommon.CanWriteToStream(stream, SerializedByteSize);
     //Contract.Requires<ArgumentOutOfRangeException>(stream.Position + SerializedByteSize <= stream.Length, "length");
 }
 protected static void WriteBytes(Stream stream, byte[] bytes)
 {
     ContractsCommon.NotNull(bytes, "bytes");
     ContractsCommon.CanWriteToStream(stream, BufferOperations.UINT8_SIZE * bytes.Length);
     stream.Write(bytes, 0, bytes.Length);
 }
 protected static void Write(Stream stream, sbyte value)
 {
     ContractsCommon.CanWriteToStream(stream, BufferOperations.UINT8_SIZE);
     stream.WriteByte((byte)value);
 }
 protected static void WriteVarInt(Stream stream, sbyte value)
 {
     ContractsCommon.CanWriteToStream(stream, VarIntByteSize(value));
     // Prevent sign extension when upconverting to long
     WriteVarInt(stream, (ulong)value);
 }
 protected static void WriteVarInt(Stream stream, long value)
 {
     ContractsCommon.CanWriteToStream(stream, VarIntByteSize(value));
     WriteVarInt(stream, (ulong)value);
 }