package peer import ( "log" ) func unmarshalPacket(nonce Nonce, data []byte) Packet { var packet Packet switch nonce.PacketType { case PACKET_TYPE_PING: packet = &Ping{} case PACKET_TYPE_PONG: packet = &Pong{} case PACKET_TYPE_LIST_ADDR_REQ: packet = &AddrListReq{} case PACKET_TYPE_LIST_ADDR_RESP: packet = &AddrListResp{} default: // TODO: Log. return nil } if len(data) < packet.Size() { log.Printf("Short packet[%d]: %d", nonce.PacketType, len(data)) return nil } packet.Parse(data[:packet.Size()]) return packet }