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.
|
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.
|
NetworkParameters |
getParameters()
Get the network parameters for this serializer.
|
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.
|
makeBlock, makeBlock, makeTransaction, makeTransaction
public 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 void serialize(java.lang.String name, byte[] message, java.io.OutputStream out) throws java.io.IOException
serialize
in class MessageSerializer
java.io.IOException
public void serialize(Message message, java.io.OutputStream out) throws java.io.IOException
serialize
in class MessageSerializer
java.io.IOException
public Message deserialize(java.nio.ByteBuffer in) throws ProtocolException, java.io.IOException
deserialize
in class MessageSerializer
ProtocolException
java.io.IOException
public BitcoinSerializer.BitcoinPacketHeader deserializeHeader(java.nio.ByteBuffer in) throws ProtocolException, java.io.IOException
deserializeHeader
in class MessageSerializer
ProtocolException
java.io.IOException
public Message deserializePayload(BitcoinSerializer.BitcoinPacketHeader header, java.nio.ByteBuffer in) throws ProtocolException, java.nio.BufferUnderflowException
deserializeHeader(java.nio.ByteBuffer)
.deserializePayload
in class MessageSerializer
ProtocolException
java.nio.BufferUnderflowException
public NetworkParameters getParameters()
public AddressMessage makeAddressMessage(byte[] payloadBytes, int length) throws ProtocolException
makeAddressMessage
in class MessageSerializer
ProtocolException
public Message makeAlertMessage(byte[] payloadBytes) throws ProtocolException
makeAlertMessage
in class MessageSerializer
ProtocolException
public Block makeBlock(byte[] payloadBytes, int offset, int length) throws ProtocolException
makeBlock
in class MessageSerializer
ProtocolException
public Message makeBloomFilter(byte[] payloadBytes) throws ProtocolException
makeBloomFilter
in class MessageSerializer
ProtocolException
public FilteredBlock makeFilteredBlock(byte[] payloadBytes) throws ProtocolException
makeFilteredBlock
in class MessageSerializer
ProtocolException
public InventoryMessage makeInventoryMessage(byte[] payloadBytes, int length) throws ProtocolException
makeInventoryMessage
in class MessageSerializer
ProtocolException
public Transaction makeTransaction(byte[] payloadBytes, int offset, int length, byte[] hashFromHeader) throws ProtocolException
makeTransaction
in class MessageSerializer
ProtocolException
public void seekPastMagicBytes(java.nio.ByteBuffer in) throws java.nio.BufferUnderflowException
seekPastMagicBytes
in class MessageSerializer
java.nio.BufferUnderflowException
public boolean isParseRetainMode()
isParseRetainMode
in class MessageSerializer