Exemplo n.º 1
0
        public override byte[] Encode(G2Protocol protocol)
        {
            byte[] details = Details.Encode(protocol); // prevent protocol conflict

            lock (protocol.WriteSection)
            {
                G2Frame ping = protocol.WritePacket(null, TransferPacket.Ping, null);

                protocol.WritePacket(ping, Packet_Target, BitConverter.GetBytes(Target));
                protocol.WritePacket(ping, Packet_Details, details);
                protocol.WritePacket(ping, Packet_Status, BitConverter.GetBytes((int)Status));

                if (MissingDepth >= 0)
                {
                    protocol.WritePacket(ping, Packet_MissingDepth, CompactNum.GetBytes(MissingDepth));
                }

                if (RequestInfo)
                {
                    protocol.WritePacket(ping, Packet_RequestInfo, null);
                }

                if (RequestAlts)
                {
                    protocol.WritePacket(ping, Packet_RequestAlts, null);
                }

                if (BitfieldUpdated)
                {
                    protocol.WritePacket(ping, Packet_BitfieldUpdated, null);
                }

                return(protocol.WriteFinish());
            }
        }
Exemplo n.º 2
0
        public override byte[] Encode(G2Protocol protocol)
        {
            byte[] details = Details.Encode(protocol); // prevent protocol conflict

            lock (protocol.WriteSection)
            {
                G2Frame partial = protocol.WritePacket(null, TransferPacket.Partial, null);

                protocol.WritePacket(partial, Packet_Created, BitConverter.GetBytes(Created.ToBinary()));
                protocol.WritePacket(partial, Packet_Details, details);
                protocol.WritePacket(partial, Packet_Target, BitConverter.GetBytes(Target));
                protocol.WritePacket(partial, Packet_BitCount, CompactNum.GetBytes(BitCount));
                protocol.WritePacket(partial, Packet_Bitfield, Bitfield.ToBytes());
                protocol.WritePacket(partial, Packet_InternalSize, CompactNum.GetBytes(InternalSize));
                protocol.WritePacket(partial, Packet_ChunkSize, CompactNum.GetBytes(ChunkSize));

                return(protocol.WriteFinish());
            }
        }