Package org.bitcoinj.core
Class MessageSerializer
java.lang.Object
org.bitcoinj.core.MessageSerializer
- Direct Known Subclasses:
BitcoinSerializer
Generic interface for classes which serialize/deserialize messages. Implementing
classes should be immutable.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract Message
Reads a message from the given ByteBuffer and returns it.Deserializes only the header in case packet meta data is needed before decoding the payload.abstract Message
Deserialize payload only.abstract int
Get the protocol version of this serializer.abstract AddressV1Message
makeAddressV1Message
(ByteBuffer payload) Make an address message from the payload.abstract AddressV2Message
makeAddressV2Message
(ByteBuffer payload) Make an address message from the payload.abstract Block
makeBlock
(ByteBuffer payload) Make a block from the payload.abstract Message
makeBloomFilter
(ByteBuffer payload) Make an filter message from the payload.abstract FilteredBlock
makeFilteredBlock
(ByteBuffer payload) Make a filtered block from the payload.abstract InventoryMessage
makeInventoryMessage
(ByteBuffer payload) Make an inventory message from the payload.abstract Transaction
makeTransaction
(ByteBuffer payload) Make a transaction from the payload.abstract void
abstract void
serialize
(String name, byte[] message, OutputStream out) Writes message to the output stream.abstract void
serialize
(Message message, OutputStream out) Writes message to the output stream.abstract MessageSerializer
withProtocolVersion
(int protocolVersion) Create a new serializer with a specific protocol version.
-
Constructor Details
-
MessageSerializer
public MessageSerializer()
-
-
Method Details
-
withProtocolVersion
Create a new serializer with a specific protocol version. Mainly used to disable segwit when parsing transactions. -
getProtocolVersion
public abstract int getProtocolVersion()Get the protocol version of this serializer. -
deserialize
public abstract Message deserialize(ByteBuffer in) throws ProtocolException, IOException, UnsupportedOperationException Reads a message from the given ByteBuffer and returns it. -
deserializeHeader
public abstract BitcoinSerializer.BitcoinPacketHeader deserializeHeader(ByteBuffer in) throws ProtocolException, IOException, UnsupportedOperationException Deserializes only the header in case packet meta data is needed before decoding the payload. This method assumes you have already called seekPastMagicBytes() -
deserializePayload
public abstract Message deserializePayload(BitcoinSerializer.BitcoinPacketHeader header, ByteBuffer in) throws ProtocolException, BufferUnderflowException, UnsupportedOperationException Deserialize payload only. You must provide a header, typically obtained by callingBitcoinSerializer.deserializeHeader(java.nio.ByteBuffer)
. -
makeAddressV1Message
public abstract AddressV1Message makeAddressV1Message(ByteBuffer payload) throws ProtocolException, UnsupportedOperationException Make an address message from the payload. Extension point for alternative serialization format support. -
makeAddressV2Message
public abstract AddressV2Message makeAddressV2Message(ByteBuffer payload) throws ProtocolException, UnsupportedOperationException Make an address message from the payload. Extension point for alternative serialization format support. -
makeBlock
public abstract Block makeBlock(ByteBuffer payload) throws ProtocolException, UnsupportedOperationException Make a block from the payload. Extension point for alternative serialization format support. -
makeBloomFilter
public abstract Message makeBloomFilter(ByteBuffer payload) throws ProtocolException, UnsupportedOperationException Make an filter message from the payload. Extension point for alternative serialization format support. -
makeFilteredBlock
public abstract FilteredBlock makeFilteredBlock(ByteBuffer payload) throws ProtocolException, UnsupportedOperationException Make a filtered block from the payload. Extension point for alternative serialization format support. -
makeInventoryMessage
public abstract InventoryMessage makeInventoryMessage(ByteBuffer payload) throws ProtocolException, UnsupportedOperationException Make an inventory message from the payload. Extension point for alternative serialization format support. -
makeTransaction
public abstract Transaction makeTransaction(ByteBuffer payload) throws ProtocolException, UnsupportedOperationException Make a transaction from the payload. Extension point for alternative serialization format support.- Throws:
UnsupportedOperationException
- if this serializer/deserializer does not support deserialization. This can occur either because it's a dummy serializer (i.e. for messages with no network parameters), or because it does not support deserializing transactions.ProtocolException
-
seekPastMagicBytes
- Throws:
BufferUnderflowException
-
serialize
public abstract void serialize(String name, byte[] message, OutputStream out) throws IOException, UnsupportedOperationException Writes message to the output stream.- Throws:
UnsupportedOperationException
- if this serializer/deserializer does not support serialization. This can occur either because it's a dummy serializer (i.e. for messages with no network parameters), or because it does not support serializing the given message.IOException
-
serialize
public abstract void serialize(Message message, OutputStream out) throws IOException, UnsupportedOperationException Writes message to the output stream.- Throws:
UnsupportedOperationException
- if this serializer/deserializer does not support serialization. This can occur either because it's a dummy serializer (i.e. for messages with no network parameters), or because it does not support serializing the given message.IOException
-