BitcoinSerializer: Simplify if ladder in makeMessage().
@@ -215,29 +215,28 @@ public class BitcoinSerializer extends MessageSerializer {
private Message makeMessage(String command, int length, byte[] payloadBytes, byte[] hash, byte[] checksum) throws ProtocolException {
// We use an if ladder rather than reflection because reflection is very slow on Android.
- Message message;
if (command.equals("version")) {
return new VersionMessage(params, payloadBytes);
} else if (command.equals("inv")) {
- message = makeInventoryMessage(payloadBytes, length);
+ return makeInventoryMessage(payloadBytes, length);
} else if (command.equals("block")) {
- message = makeBlock(payloadBytes, length);
+ return makeBlock(payloadBytes, length);
} else if (command.equals("merkleblock")) {
- message = makeFilteredBlock(payloadBytes);
+ return makeFilteredBlock(payloadBytes);
} else if (command.equals("getdata")) {
- message = new GetDataMessage(params, payloadBytes, this, length);
+ return new GetDataMessage(params, payloadBytes, this, length);
} else if (command.equals("getblocks")) {
- message = new GetBlocksMessage(params, payloadBytes);
+ return new GetBlocksMessage(params, payloadBytes);
} else if (command.equals("getheaders")) {
- message = new GetHeadersMessage(params, payloadBytes);
+ return new GetHeadersMessage(params, payloadBytes);
} else if (command.equals("tx")) {
- message = makeTransaction(payloadBytes, 0, length, hash);
+ return makeTransaction(payloadBytes, 0, length, hash);
} else if (command.equals("addr")) {
- message = makeAddressMessage(payloadBytes, length);
+ return makeAddressMessage(payloadBytes, length);
} else if (command.equals("ping")) {
- message = new Ping(params, payloadBytes);
+ return new Ping(params, payloadBytes);
} else if (command.equals("pong")) {
- message = new Pong(params, payloadBytes);
+ return new Pong(params, payloadBytes);
} else if (command.equals("verack")) {
return new VersionAck(params, payloadBytes);
} else if (command.equals("headers")) {
@@ -262,7 +261,6 @@ public class BitcoinSerializer extends MessageSerializer {
log.warn("No support for deserializing message with name {}", command);
return new UnknownMessage(params, command, payloadBytes);
}
- return message;
}
/**
