mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-11 17:58:01 +01:00
BitcoinSerializer: Simplify if ladder in makeMessage().
This commit is contained in:
parent
9336f1db1b
commit
4fcfedd704
1 changed files with 10 additions and 12 deletions
|
@ -215,29 +215,28 @@ public class BitcoinSerializer extends MessageSerializer {
|
||||||
|
|
||||||
private Message makeMessage(String command, int length, byte[] payloadBytes, byte[] hash, byte[] checksum) throws ProtocolException {
|
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.
|
// We use an if ladder rather than reflection because reflection is very slow on Android.
|
||||||
Message message;
|
|
||||||
if (command.equals("version")) {
|
if (command.equals("version")) {
|
||||||
return new VersionMessage(params, payloadBytes);
|
return new VersionMessage(params, payloadBytes);
|
||||||
} else if (command.equals("inv")) {
|
} else if (command.equals("inv")) {
|
||||||
message = makeInventoryMessage(payloadBytes, length);
|
return makeInventoryMessage(payloadBytes, length);
|
||||||
} else if (command.equals("block")) {
|
} else if (command.equals("block")) {
|
||||||
message = makeBlock(payloadBytes, length);
|
return makeBlock(payloadBytes, length);
|
||||||
} else if (command.equals("merkleblock")) {
|
} else if (command.equals("merkleblock")) {
|
||||||
message = makeFilteredBlock(payloadBytes);
|
return makeFilteredBlock(payloadBytes);
|
||||||
} else if (command.equals("getdata")) {
|
} else if (command.equals("getdata")) {
|
||||||
message = new GetDataMessage(params, payloadBytes, this, length);
|
return new GetDataMessage(params, payloadBytes, this, length);
|
||||||
} else if (command.equals("getblocks")) {
|
} else if (command.equals("getblocks")) {
|
||||||
message = new GetBlocksMessage(params, payloadBytes);
|
return new GetBlocksMessage(params, payloadBytes);
|
||||||
} else if (command.equals("getheaders")) {
|
} else if (command.equals("getheaders")) {
|
||||||
message = new GetHeadersMessage(params, payloadBytes);
|
return new GetHeadersMessage(params, payloadBytes);
|
||||||
} else if (command.equals("tx")) {
|
} else if (command.equals("tx")) {
|
||||||
message = makeTransaction(payloadBytes, 0, length, hash);
|
return makeTransaction(payloadBytes, 0, length, hash);
|
||||||
} else if (command.equals("addr")) {
|
} else if (command.equals("addr")) {
|
||||||
message = makeAddressMessage(payloadBytes, length);
|
return makeAddressMessage(payloadBytes, length);
|
||||||
} else if (command.equals("ping")) {
|
} else if (command.equals("ping")) {
|
||||||
message = new Ping(params, payloadBytes);
|
return new Ping(params, payloadBytes);
|
||||||
} else if (command.equals("pong")) {
|
} else if (command.equals("pong")) {
|
||||||
message = new Pong(params, payloadBytes);
|
return new Pong(params, payloadBytes);
|
||||||
} else if (command.equals("verack")) {
|
} else if (command.equals("verack")) {
|
||||||
return new VersionAck(params, payloadBytes);
|
return new VersionAck(params, payloadBytes);
|
||||||
} else if (command.equals("headers")) {
|
} else if (command.equals("headers")) {
|
||||||
|
@ -262,7 +261,6 @@ public class BitcoinSerializer extends MessageSerializer {
|
||||||
log.warn("No support for deserializing message with name {}", command);
|
log.warn("No support for deserializing message with name {}", command);
|
||||||
return new UnknownMessage(params, command, payloadBytes);
|
return new UnknownMessage(params, command, payloadBytes);
|
||||||
}
|
}
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue