Пример #1
0
        public static TransferPartial Decode(G2Header root)
        {
            TransferPartial partial = new TransferPartial();

            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                switch (child.Name)
                {
                case Packet_Created:
                    partial.Created = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                    break;

                case Packet_Details:
                    partial.Details = FileDetails.Decode(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize));
                    break;

                case Packet_Target:
                    partial.Target = BitConverter.ToUInt64(child.Data, child.PayloadPos);
                    break;

                case Packet_BitCount:
                    partial.BitCount = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_Bitfield:
                    partial.Bitfield = Utilities.ToBitArray(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize), partial.BitCount);
                    break;

                case Packet_InternalSize:
                    partial.InternalSize = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize);
                    break;

                case Packet_ChunkSize:
                    partial.ChunkSize = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize);
                    break;
                }
            }

            return(partial);
        }
Пример #2
0
        public static TransferPartial Decode(G2Header root)
        {
            TransferPartial partial = new TransferPartial();

            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                    continue;

                switch (child.Name)
                {
                    case Packet_Created:
                        partial.Created = DateTime.FromBinary(BitConverter.ToInt64(child.Data, child.PayloadPos));
                        break;

                    case Packet_Details:
                        partial.Details = FileDetails.Decode(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize));
                        break;

                    case Packet_Target:
                        partial.Target = BitConverter.ToUInt64(child.Data, child.PayloadPos);
                        break;

                    case Packet_BitCount:
                        partial.BitCount = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Bitfield:
                        partial.Bitfield = Utilities.ToBitArray(Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize), partial.BitCount);
                        break;

                    case Packet_InternalSize:
                        partial.InternalSize = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_ChunkSize:
                        partial.ChunkSize = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize);
                        break;
                }
            }

            return partial;
        }