com.google.bitcoin.core
Class BitcoinSerializer

java.lang.Object
  extended by com.google.bitcoin.core.BitcoinSerializer

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.


Nested Class Summary
static class BitcoinSerializer.BitcoinPacketHeader
           
 
Constructor Summary
BitcoinSerializer(NetworkParameters params)
          Constructs a BitcoinSerializer with the given behavior.
BitcoinSerializer(NetworkParameters params, boolean parseLazy, boolean parseRetain)
          Constructs a BitcoinSerializer with the given behavior.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitcoinSerializer

public BitcoinSerializer(NetworkParameters params)
Constructs a BitcoinSerializer with the given behavior.

Parameters:
params - networkParams used to create Messages instances and termining packetMagic

BitcoinSerializer

public BitcoinSerializer(NetworkParameters params,
                         boolean parseLazy,
                         boolean parseRetain)
Constructs a BitcoinSerializer with the given behavior.

Parameters:
params - networkParams used to create Messages instances and termining packetMagic
parseLazy - deserialize messages in lazy mode.
parseRetain - retain the backing byte array of a message for fast reserialization.
Method Detail

serialize

public void serialize(String name,
                      byte[] message,
                      OutputStream out)
               throws IOException
Writes message to to the output stream.

Throws:
IOException

serialize

public void serialize(Message message,
                      OutputStream out)
               throws IOException
Writes message to to the output stream.

Throws:
IOException

deserialize

public Message deserialize(ByteBuffer in)
                    throws ProtocolException,
                           IOException
Reads a message from the given ByteBuffer and returns it.

Throws:
ProtocolException
IOException

deserializeHeader

public BitcoinSerializer.BitcoinPacketHeader deserializeHeader(ByteBuffer in)
                                                        throws ProtocolException,
                                                               IOException
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
IOException

deserializePayload

public Message deserializePayload(BitcoinSerializer.BitcoinPacketHeader header,
                                  ByteBuffer in)
                           throws ProtocolException,
                                  BufferUnderflowException
Deserialize payload only. You must provide a header, typically obtained by calling deserializeHeader(java.nio.ByteBuffer).

Throws:
ProtocolException
BufferUnderflowException

seekPastMagicBytes

public void seekPastMagicBytes(ByteBuffer in)
                        throws BufferUnderflowException
Throws:
BufferUnderflowException

isParseLazyMode

public boolean isParseLazyMode()
Whether the serializer will produce lazy parse mode Messages


isParseRetainMode

public boolean isParseRetainMode()
Whether the serializer will produce cached mode Messages



Copyright © 2014. All rights reserved.