public class BitcoinSerializer extends Object
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)
Constructs a BitcoinSerializer with the given behavior.
|
BitcoinSerializer(NetworkParameters params,
boolean parseLazy,
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.
|
boolean |
isParseLazyMode()
Whether the serializer will produce lazy parse mode Messages
|
boolean |
isParseRetainMode()
Whether the serializer will produce cached mode Messages
|
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.
|
public BitcoinSerializer(NetworkParameters params)
params
- networkParams used to create Messages instances and termining packetMagicpublic BitcoinSerializer(NetworkParameters params, boolean parseLazy, boolean parseRetain)
params
- networkParams used to create Messages instances and termining packetMagicparseLazy
- deserialize messages in lazy mode.parseRetain
- retain the backing byte array of a message for fast reserialization.public void serialize(String name, byte[] message, OutputStream out) throws IOException
IOException
public void serialize(Message message, OutputStream out) throws IOException
IOException
public Message deserialize(ByteBuffer in) throws ProtocolException, IOException
ProtocolException
IOException
public BitcoinSerializer.BitcoinPacketHeader deserializeHeader(ByteBuffer in) throws ProtocolException, IOException
ProtocolException
IOException
public Message deserializePayload(BitcoinSerializer.BitcoinPacketHeader header, ByteBuffer in) throws ProtocolException, BufferUnderflowException
deserializeHeader(java.nio.ByteBuffer)
.public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException
BufferUnderflowException
public boolean isParseLazyMode()
public boolean isParseRetainMode()
Copyright © 2014. All rights reserved.