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(ByteBuffer in)
Reads a message from the given ByteBuffer and returns it.
|
BitcoinSerializer.BitcoinPacketHeader |
deserializeHeader(ByteBuffer in)
Deserializes only the header in case packet meta data is needed before decoding
the payload.
|
Message |
deserializePayload(BitcoinSerializer.BitcoinPacketHeader header,
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[] hash)
Make a transaction from the payload.
|
void |
seekPastMagicBytes(ByteBuffer in) |
void |
serialize(Message message,
OutputStream out)
Writes message to to the output stream.
|
void |
serialize(String name,
byte[] message,
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 termining packetMagicparseRetain
- retain the backing byte array of a message for fast reserialization.public void serialize(String name, byte[] message, OutputStream out) throws IOException
serialize
in class MessageSerializer
IOException
public void serialize(Message message, OutputStream out) throws IOException
serialize
in class MessageSerializer
IOException
public Message deserialize(ByteBuffer in) throws ProtocolException, IOException
deserialize
in class MessageSerializer
ProtocolException
IOException
public BitcoinSerializer.BitcoinPacketHeader deserializeHeader(ByteBuffer in) throws ProtocolException, IOException
deserializeHeader
in class MessageSerializer
ProtocolException
IOException
public Message deserializePayload(BitcoinSerializer.BitcoinPacketHeader header, ByteBuffer in) throws ProtocolException, BufferUnderflowException
deserializeHeader(java.nio.ByteBuffer)
.deserializePayload
in class MessageSerializer
ProtocolException
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[] hash) throws ProtocolException
makeTransaction
in class MessageSerializer
ProtocolException
public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException
seekPastMagicBytes
in class MessageSerializer
BufferUnderflowException
public boolean isParseRetainMode()
isParseRetainMode
in class MessageSerializer
Copyright © 2016. All rights reserved.