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

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

View File

@ -242,7 +242,7 @@ public class BitcoinSerializer extends MessageSerializer {
} else if (command.equals("ping")) {
return Ping.read(payload);
} else if (command.equals("pong")) {
return new Pong(payload);
return Pong.read(payload);
} else if (command.equals("verack")) {
check(!payload.hasRemaining(), ProtocolException::new);
return new VersionAck();

View File

@ -32,8 +32,15 @@ import java.nio.ByteBuffer;
public class Pong extends BaseMessage {
private long nonce;
public Pong(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 Pong read(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
return new Pong(ByteUtils.readInt64(payload));
}
/**
@ -46,7 +53,7 @@ public class Pong extends BaseMessage {
@Override
protected void parse(ByteBuffer payload) throws BufferUnderflowException, ProtocolException {
nonce = ByteUtils.readInt64(payload);
throw new UnsupportedOperationException();
}
@Override