public static TransferPong Decode(G2Header root) { TransferPong pong = new TransferPong(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if(child.Name == Packet_Error) pong.Error = true; if (!G2Protocol.ReadPayload(child)) continue; switch (child.Name) { case Packet_FileID: pong.FileID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_Timeout: pong.Timeout = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Status: pong.Status = (TransferStatus)CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_InternalSize: pong.InternalSize = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_ChunkSize: pong.ChunkSize = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_BitCount: pong.BitCount = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_AltClient: DhtClient client = DhtClient.FromBytes(child.Data, child.PayloadPos); pong.Alts[client] = new List<DhtAddress>(); G2Protocol.ResetPacket(child); G2Header sub = new G2Header(child.Data); while (G2Protocol.ReadNextChild(child, sub) == G2ReadResult.PACKET_GOOD) if (G2Protocol.ReadPayload(sub)) if (sub.Name == Packet_AltAddress) pong.Alts[client].Add(DhtAddress.ReadPacket(sub)); break; } } return pong; }
public static TransferPong Decode(G2Header root) { TransferPong pong = new TransferPong(); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (child.Name == Packet_Error) { pong.Error = true; } if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_FileID: pong.FileID = BitConverter.ToUInt64(child.Data, child.PayloadPos); break; case Packet_Timeout: pong.Timeout = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Status: pong.Status = (TransferStatus)CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_InternalSize: pong.InternalSize = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_ChunkSize: pong.ChunkSize = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_BitCount: pong.BitCount = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_AltClient: DhtClient client = DhtClient.FromBytes(child.Data, child.PayloadPos); pong.Alts[client] = new List <DhtAddress>(); G2Protocol.ResetPacket(child); G2Header sub = new G2Header(child.Data); while (G2Protocol.ReadNextChild(child, sub) == G2ReadResult.PACKET_GOOD) { if (G2Protocol.ReadPayload(sub)) { if (sub.Name == Packet_AltAddress) { pong.Alts[client].Add(DhtAddress.ReadPacket(sub)); } } } break; } } return(pong); }