Ping: move parse() to static constructor read()

This commit is contained in:
Andreas Schildbach 2023-03-30 14:39:55 +02:00
parent 7d31021663
commit 1f8ed23e24
2 changed files with 11 additions and 4 deletions

View File

@ -240,7 +240,7 @@ public class BitcoinSerializer extends MessageSerializer {
} else if (command.equals("addrv2")) {
return makeAddressV2Message(payload);
} else if (command.equals("ping")) {
return new Ping(payload);
return Ping.read(payload);
} else if (command.equals("pong")) {
return new Pong(payload);
} else if (command.equals("verack")) {

View File

@ -33,8 +33,15 @@ import java.util.Random;
public class Ping extends BaseMessage {
private long nonce;
public Ping(ByteBuffer payload) throws ProtocolException {
super(payload);
/**
* Deserialize this message from a given payload.
*
* @param payload payload to deserialize from
* @return read message
* @throws BufferUnderflowException if the read message extends beyond the remaining bytes of the payload
*/
public static Ping read(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
return new Ping(ByteUtils.readInt64(payload));
}
/**
@ -58,7 +65,7 @@ public class Ping extends BaseMessage {
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
nonce = ByteUtils.readInt64(payload);
throw new UnsupportedOperationException();
}
/** @deprecated returns true */