public class BitcoinSerializer extends MessageSerializer
Methods to serialize and de-serialize messages to the Bitcoin network format as defined in the protocol specification.
To be able to serialize and deserialize new Message subclasses the following criteria needs to be met.
| Modifier and Type | Class and Description |
|---|---|
static class |
BitcoinSerializer.BitcoinPacketHeader |
| Constructor and Description |
|---|
BitcoinSerializer(NetworkParameters params,
boolean parseRetain)
Constructs a BitcoinSerializer with the given behavior.
|
BitcoinSerializer(NetworkParameters params,
int protocolVersion,
boolean parseRetain)
Constructs a BitcoinSerializer with the given behavior.
|
| Modifier and Type | Method and Description |
|---|---|
Message |
deserialize(java.nio.ByteBuffer in)
Reads a message from the given ByteBuffer and returns it.
|
BitcoinSerializer.BitcoinPacketHeader |
deserializeHeader(java.nio.ByteBuffer in)
Deserializes only the header in case packet meta data is needed before decoding
the payload.
|
Message |
deserializePayload(BitcoinSerializer.BitcoinPacketHeader header,
java.nio.ByteBuffer in)
Deserialize payload only.
|
boolean |
equals(java.lang.Object o) |
NetworkParameters |
getParameters()
Get the network parameters for this serializer.
|
int |
getProtocolVersion()
Get the protocol version of this serializer.
|
int |
hashCode() |
boolean |
isParseRetainMode()
Whether the serializer will produce cached mode Messages
|
AddressMessage |
makeAddressMessage(byte[] payloadBytes,
int length)
Make an address message from the payload.
|
Message |
makeAlertMessage(byte[] payloadBytes)
Make an alert message from the payload.
|
Block |
makeBlock(byte[] payloadBytes,
int offset,
int length)
Make a block from the payload.
|
Message |
makeBloomFilter(byte[] payloadBytes)
Make an filter message from the payload.
|
FilteredBlock |
makeFilteredBlock(byte[] payloadBytes)
Make a filtered block from the payload.
|
InventoryMessage |
makeInventoryMessage(byte[] payloadBytes,
int length)
Make an inventory message from the payload.
|
Transaction |
makeTransaction(byte[] payloadBytes,
int offset,
int length,
byte[] hashFromHeader)
Make a transaction from the payload.
|
void |
seekPastMagicBytes(java.nio.ByteBuffer in) |
void |
serialize(Message message,
java.io.OutputStream out)
Writes message to to the output stream.
|
void |
serialize(java.lang.String name,
byte[] message,
java.io.OutputStream out)
Writes message to to the output stream.
|
BitcoinSerializer |
withProtocolVersion(int protocolVersion)
Create a new serializer with a specific protocol version.
|
makeBlock, makeBlock, makeTransaction, makeTransactionpublic BitcoinSerializer(NetworkParameters params, boolean parseRetain)
params - networkParams used to create Messages instances and determining packetMagicparseRetain - retain the backing byte array of a message for fast reserialization.public BitcoinSerializer(NetworkParameters params, int protocolVersion, boolean parseRetain)
params - networkParams used to create Messages instances and determining packetMagicprotocolVersion - the protocol version to useparseRetain - retain the backing byte array of a message for fast reserialization.public BitcoinSerializer withProtocolVersion(int protocolVersion)
MessageSerializerwithProtocolVersion in class MessageSerializerpublic int getProtocolVersion()
MessageSerializergetProtocolVersion in class MessageSerializerpublic void serialize(java.lang.String name,
byte[] message,
java.io.OutputStream out)
throws java.io.IOException
serialize in class MessageSerializerjava.io.IOExceptionpublic void serialize(Message message, java.io.OutputStream out) throws java.io.IOException
serialize in class MessageSerializerjava.io.IOExceptionpublic Message deserialize(java.nio.ByteBuffer in) throws ProtocolException, java.io.IOException
deserialize in class MessageSerializerProtocolExceptionjava.io.IOExceptionpublic BitcoinSerializer.BitcoinPacketHeader deserializeHeader(java.nio.ByteBuffer in) throws ProtocolException, java.io.IOException
deserializeHeader in class MessageSerializerProtocolExceptionjava.io.IOExceptionpublic Message deserializePayload(BitcoinSerializer.BitcoinPacketHeader header, java.nio.ByteBuffer in) throws ProtocolException, java.nio.BufferUnderflowException
deserializeHeader(java.nio.ByteBuffer).deserializePayload in class MessageSerializerProtocolExceptionjava.nio.BufferUnderflowExceptionpublic NetworkParameters getParameters()
public AddressMessage makeAddressMessage(byte[] payloadBytes, int length) throws ProtocolException
makeAddressMessage in class MessageSerializerProtocolExceptionpublic Message makeAlertMessage(byte[] payloadBytes) throws ProtocolException
makeAlertMessage in class MessageSerializerProtocolExceptionpublic Block makeBlock(byte[] payloadBytes, int offset, int length) throws ProtocolException
makeBlock in class MessageSerializerProtocolExceptionpublic Message makeBloomFilter(byte[] payloadBytes) throws ProtocolException
makeBloomFilter in class MessageSerializerProtocolExceptionpublic FilteredBlock makeFilteredBlock(byte[] payloadBytes) throws ProtocolException
makeFilteredBlock in class MessageSerializerProtocolExceptionpublic InventoryMessage makeInventoryMessage(byte[] payloadBytes, int length) throws ProtocolException
makeInventoryMessage in class MessageSerializerProtocolExceptionpublic Transaction makeTransaction(byte[] payloadBytes, int offset, int length, byte[] hashFromHeader) throws ProtocolException
makeTransaction in class MessageSerializerProtocolExceptionpublic void seekPastMagicBytes(java.nio.ByteBuffer in)
throws java.nio.BufferUnderflowException
seekPastMagicBytes in class MessageSerializerjava.nio.BufferUnderflowExceptionpublic boolean isParseRetainMode()
isParseRetainMode in class MessageSerializerpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object