Coverage Summary for Class: P2pMessageFactory (org.ethereum.net.p2p)

Class Method, % Line, %
P2pMessageFactory 0% (0/2) 0% (0/10)
P2pMessageFactory$1 0% (0/1) 0% (0/1)
Total 0% (0/3) 0% (0/11)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package org.ethereum.net.p2p; 21  22 import org.ethereum.net.message.Message; 23 import org.ethereum.net.message.StaticMessages; 24  25 /** 26  * P2P message factory 27  * 28  * @author Mikhail Kalinin 29  * @since 20.08.2015 30  */ 31 public class P2pMessageFactory { 32  33  public Message create(byte code, byte[] encoded) { 34  35  P2pMessageCodes receivedCommand = P2pMessageCodes.fromByte(code); 36  switch (receivedCommand) { 37  case HELLO: 38  return new HelloMessage(encoded); 39  case DISCONNECT: 40  return new DisconnectMessage(encoded); 41  case PING: 42  return StaticMessages.PING_MESSAGE; 43  case PONG: 44  return StaticMessages.PONG_MESSAGE; 45  case GET_PEERS: 46  return StaticMessages.GET_PEERS_MESSAGE; 47  case PEERS: 48  return new PeersMessage(encoded); 49  default: 50  throw new IllegalArgumentException("No such message"); 51  } 52  } 53 }