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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract MessageReads 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 MessageDeserialize payload only.abstract intGet the protocol version of this serializer.abstract booleanWhether the serializer will produce cached mode Messagesabstract AddressV1MessagemakeAddressV1Message(byte[] payloadBytes, int length) Make an address message from the payload.abstract AddressV2MessagemakeAddressV2Message(byte[] payloadBytes, int length) Make an address message from the payload.final BlockmakeBlock(byte[] payloadBytes) Make a block from the payload, using an offset of zero and the payload length as block length.final BlockmakeBlock(byte[] payloadBytes, int length) Make a block from the payload, using an offset of zero and the provided length as block length.abstract BlockmakeBlock(byte[] payloadBytes, int offset, int length) Make a block from the payload, using an offset of zero and the provided length as block length.abstract MessagemakeBloomFilter(byte[] payloadBytes) Make an filter message from the payload.abstract FilteredBlockmakeFilteredBlock(byte[] payloadBytes) Make a filtered block from the payload.abstract InventoryMessagemakeInventoryMessage(byte[] payloadBytes, int length) Make an inventory message from the payload.final TransactionmakeTransaction(byte[] payloadBytes) Make a transaction from the payload.final TransactionmakeTransaction(byte[] payloadBytes, int offset) Make a transaction from the payload.abstract TransactionmakeTransaction(byte[] payloadBytes, int offset, int length, byte[] hash) Make a transaction from the payload.abstract voidabstract voidserialize(String name, byte[] message, OutputStream out) Writes message to to the output stream.abstract voidserialize(Message message, OutputStream out) Writes message to to the output stream.abstract MessageSerializerwithProtocolVersion(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). -
isParseRetainMode
public abstract boolean isParseRetainMode()Whether the serializer will produce cached mode Messages -
makeAddressV1Message
public abstract AddressV1Message makeAddressV1Message(byte[] payloadBytes, int length) throws ProtocolException, UnsupportedOperationException Make an address message from the payload. Extension point for alternative serialization format support. -
makeAddressV2Message
public abstract AddressV2Message makeAddressV2Message(byte[] payloadBytes, int length) throws ProtocolException, UnsupportedOperationException Make an address message from the payload. Extension point for alternative serialization format support. -
makeBlock
Make a block from the payload, using an offset of zero and the payload length as block length.- Throws:
ProtocolException
-
makeBlock
Make a block from the payload, using an offset of zero and the provided length as block length.- Throws:
ProtocolException
-
makeBlock
public abstract Block makeBlock(byte[] payloadBytes, int offset, int length) throws ProtocolException, UnsupportedOperationException Make a block from the payload, using an offset of zero and the provided length as block length. Extension point for alternative serialization format support. -
makeBloomFilter
public abstract Message makeBloomFilter(byte[] payloadBytes) throws ProtocolException, UnsupportedOperationException Make an filter message from the payload. Extension point for alternative serialization format support. -
makeFilteredBlock
public abstract FilteredBlock makeFilteredBlock(byte[] payloadBytes) throws ProtocolException, UnsupportedOperationException Make a filtered block from the payload. Extension point for alternative serialization format support. -
makeInventoryMessage
public abstract InventoryMessage makeInventoryMessage(byte[] payloadBytes, int length) throws ProtocolException, UnsupportedOperationException Make an inventory message from the payload. Extension point for alternative serialization format support. -
makeTransaction
public abstract Transaction makeTransaction(byte[] payloadBytes, int offset, int length, byte[] hash) 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
-
makeTransaction
public final Transaction makeTransaction(byte[] payloadBytes) 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
-
makeTransaction
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 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 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
-