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, makeTransactionpublic 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 MessageSerializerIOExceptionpublic void serialize(Message message, OutputStream out) throws IOException
serialize in class MessageSerializerIOExceptionpublic Message deserialize(ByteBuffer in) throws ProtocolException, IOException
deserialize in class MessageSerializerProtocolExceptionIOExceptionpublic BitcoinSerializer.BitcoinPacketHeader deserializeHeader(ByteBuffer in) throws ProtocolException, IOException
deserializeHeader in class MessageSerializerProtocolExceptionIOExceptionpublic Message deserializePayload(BitcoinSerializer.BitcoinPacketHeader header, ByteBuffer in) throws ProtocolException, BufferUnderflowException
deserializeHeader(java.nio.ByteBuffer).deserializePayload in class MessageSerializerProtocolExceptionBufferUnderflowExceptionpublic 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[] hash) throws ProtocolException
makeTransaction in class MessageSerializerProtocolExceptionpublic void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException
seekPastMagicBytes in class MessageSerializerBufferUnderflowExceptionpublic boolean isParseRetainMode()
isParseRetainMode in class MessageSerializerCopyright © 2018. All rights reserved.