public override void SerializeMessage(PingMessage message, int protocolVersion, NetworkPeerContext peerContext,
                                       IBufferWriter <byte> output)
 {
     output.WriteUShort(message.NumPongBytes, true);
     output.WriteUShort(message.BytesLen, true);
     output.WriteBytes(message.Ignored);
 }
Beispiel #2
0
        public void Pack(IBufferWriter writer, AmpMessage message)
        {
            writer.WriteByte(message.Version);
            writer.WriteInt(message.Length);
            writer.WriteInt(message.Sequence);
            writer.WriteByte((byte)message.InvokeMessageType);

            if (message.Version == 0)
            {
                writer.WriteUShort((ushort)message.ServiceId);
            }
            else
            {
                writer.WriteInt(message.ServiceId);
            }


            writer.WriteUShort(message.MessageId);

            writer.WriteInt(message.Code);

            if (message.Version == 1)
            {
                writer.WriteByte(_serializer.CodecType);
            }

            if (message.Data != null)
            {
                writer.WriteBytes(message.Data);
            }
        }
        public override void SerializeMessage(InitMessage message, int protocolVersion, NetworkPeerContext peerContext, IBufferWriter <byte> output)
        {
            output.WriteUShort((ushort)message.GlobalFeatures.Length, true);
            output.Write(message.GlobalFeatures);

            output.WriteUShort((ushort)message.Features.Length, true);
            output.Write(message.Features);
        }
Beispiel #4
0
 public void Encode(AmpMessage message, IBufferWriter writer)
 {
     writer.WriteByte(message.Version);
     writer.WriteInt(message.Length);
     writer.WriteInt(message.Sequence);
     writer.WriteByte((byte)message.InvokeMessageType);
     writer.WriteUShort(message.ServiceId);
     writer.WriteUShort(message.MessageId);
     if (message.Data != null)
     {
         writer.WriteBytes(message.Data);
     }
 }
 public override void SerializeMessage(ErrorMessage message, int protocolVersion, NetworkPeerContext peerContext,
                                       IBufferWriter <byte> output)
 {
     output.WriteBytes(message.ChannelId);
     output.WriteUShort(message.Len, true);
     output.WriteBytes(message.Data);
 }
        public int Serialize(NetworkAddressNoTime typeInstance, int protocolVersion, IBufferWriter <byte> writer, ProtocolTypeSerializerOptions?options = null)
        {
            int size = 0;

            size += writer.WriteULong(typeInstance.Services);
            size += writer.WriteBytes(typeInstance.IP !);
            size += writer.WriteUShort(typeInstance.Port);

            return(size);
        }
        public int Serialize(NetworkAddress typeInstance, int protocolVersion, IBufferWriter <byte> writer, ProtocolTypeSerializerOptions?options = null)
        {
            int size = 0;

            // https://bitcoin.org/en/developer-reference#version
            size += writer.WriteUInt((uint)typeInstance.Time.ToUnixTimeSeconds());

            size += writer.WriteULong(typeInstance.Services);
            size += writer.WriteBytes(typeInstance.IP !);
            size += writer.WriteUShort(typeInstance.Port);

            return(size);
        }
 public static int WriteBigSize(this IBufferWriter <byte> writer, ulong value)
 {
     if (value < 0xFD)
     {
         return(writer.WriteByte((byte)value) + 1);
     }
     else if (value < 0x10000)
     {
         writer.WriteByte(0xFD);
         return(writer.WriteUShort((ushort)value, isBigEndian: true) + 1);
     }
     else if (value < 0x100000000)
     {
         writer.WriteByte(0xFE);
         return(writer.WriteUInt((uint)value, isBigEndian: true) + 1);
     }
     else // == 0xFF
     {
         writer.WriteByte(0xFF);
         return(writer.WriteULong(value, isBigEndian: true) + 1);
     }
 }