Package org.bitcoinj.core
Class MessageSerializer
- java.lang.Object
-
- org.bitcoinj.core.MessageSerializer
-
- Direct Known Subclasses:
BitcoinSerializer
public abstract class MessageSerializer extends java.lang.Object
Generic interface for classes which serialize/deserialize messages. Implementing classes should be immutable.
-
-
Constructor Summary
Constructors Constructor Description MessageSerializer()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract Message
deserialize(java.nio.ByteBuffer in)
Reads a message from the given ByteBuffer and returns it.abstract BitcoinSerializer.BitcoinPacketHeader
deserializeHeader(java.nio.ByteBuffer in)
Deserializes only the header in case packet meta data is needed before decoding the payload.abstract Message
deserializePayload(BitcoinSerializer.BitcoinPacketHeader header, java.nio.ByteBuffer in)
Deserialize payload only.abstract int
getProtocolVersion()
Get the protocol version of this serializer.abstract AddressV1Message
makeAddressV1Message(java.nio.ByteBuffer payload)
Make an address message from the payload.abstract AddressV2Message
makeAddressV2Message(java.nio.ByteBuffer payload)
Make an address message from the payload.abstract Block
makeBlock(java.nio.ByteBuffer payload)
Make a block from the payload.abstract Message
makeBloomFilter(java.nio.ByteBuffer payload)
Make an filter message from the payload.abstract FilteredBlock
makeFilteredBlock(java.nio.ByteBuffer payload)
Make a filtered block from the payload.abstract InventoryMessage
makeInventoryMessage(java.nio.ByteBuffer payload)
Make an inventory message from the payload.abstract Transaction
makeTransaction(java.nio.ByteBuffer payload)
Make a transaction from the payload.abstract void
seekPastMagicBytes(java.nio.ByteBuffer in)
abstract void
serialize(java.lang.String name, byte[] message, java.io.OutputStream out)
Writes message to to the output stream.abstract void
serialize(Message message, java.io.OutputStream out)
Writes message to to the output stream.abstract MessageSerializer
withProtocolVersion(int protocolVersion)
Create a new serializer with a specific protocol version.
-
-
-
Method Detail
-
withProtocolVersion
public abstract MessageSerializer withProtocolVersion(int protocolVersion)
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(java.nio.ByteBuffer in) throws ProtocolException, java.io.IOException, java.lang.UnsupportedOperationException
Reads a message from the given ByteBuffer and returns it.- Throws:
ProtocolException
java.io.IOException
java.lang.UnsupportedOperationException
-
deserializeHeader
public abstract BitcoinSerializer.BitcoinPacketHeader deserializeHeader(java.nio.ByteBuffer in) throws ProtocolException, java.io.IOException, java.lang.UnsupportedOperationException
Deserializes only the header in case packet meta data is needed before decoding the payload. This method assumes you have already called seekPastMagicBytes()- Throws:
ProtocolException
java.io.IOException
java.lang.UnsupportedOperationException
-
deserializePayload
public abstract Message deserializePayload(BitcoinSerializer.BitcoinPacketHeader header, java.nio.ByteBuffer in) throws ProtocolException, java.nio.BufferUnderflowException, java.lang.UnsupportedOperationException
Deserialize payload only. You must provide a header, typically obtained by callingBitcoinSerializer.deserializeHeader(java.nio.ByteBuffer)
.- Throws:
ProtocolException
java.nio.BufferUnderflowException
java.lang.UnsupportedOperationException
-
makeAddressV1Message
public abstract AddressV1Message makeAddressV1Message(java.nio.ByteBuffer payload) throws ProtocolException, java.lang.UnsupportedOperationException
Make an address message from the payload. Extension point for alternative serialization format support.- Throws:
ProtocolException
java.lang.UnsupportedOperationException
-
makeAddressV2Message
public abstract AddressV2Message makeAddressV2Message(java.nio.ByteBuffer payload) throws ProtocolException, java.lang.UnsupportedOperationException
Make an address message from the payload. Extension point for alternative serialization format support.- Throws:
ProtocolException
java.lang.UnsupportedOperationException
-
makeBlock
public abstract Block makeBlock(java.nio.ByteBuffer payload) throws ProtocolException, java.lang.UnsupportedOperationException
Make a block from the payload. Extension point for alternative serialization format support.- Throws:
ProtocolException
java.lang.UnsupportedOperationException
-
makeBloomFilter
public abstract Message makeBloomFilter(java.nio.ByteBuffer payload) throws ProtocolException, java.lang.UnsupportedOperationException
Make an filter message from the payload. Extension point for alternative serialization format support.- Throws:
ProtocolException
java.lang.UnsupportedOperationException
-
makeFilteredBlock
public abstract FilteredBlock makeFilteredBlock(java.nio.ByteBuffer payload) throws ProtocolException, java.lang.UnsupportedOperationException
Make a filtered block from the payload. Extension point for alternative serialization format support.- Throws:
ProtocolException
java.lang.UnsupportedOperationException
-
makeInventoryMessage
public abstract InventoryMessage makeInventoryMessage(java.nio.ByteBuffer payload) throws ProtocolException, java.lang.UnsupportedOperationException
Make an inventory message from the payload. Extension point for alternative serialization format support.- Throws:
ProtocolException
java.lang.UnsupportedOperationException
-
makeTransaction
public abstract Transaction makeTransaction(java.nio.ByteBuffer payload) throws ProtocolException, java.lang.UnsupportedOperationException
Make a transaction from the payload. Extension point for alternative serialization format support.- Throws:
java.lang.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
public abstract void seekPastMagicBytes(java.nio.ByteBuffer in) throws java.nio.BufferUnderflowException
- Throws:
java.nio.BufferUnderflowException
-
serialize
public abstract void serialize(java.lang.String name, byte[] message, java.io.OutputStream out) throws java.io.IOException, java.lang.UnsupportedOperationException
Writes message to to the output stream.- Throws:
java.lang.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.java.io.IOException
-
serialize
public abstract void serialize(Message message, java.io.OutputStream out) throws java.io.IOException, java.lang.UnsupportedOperationException
Writes message to to the output stream.- Throws:
java.lang.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.java.io.IOException
-
-