Class BaseMessage

java.lang.Object
org.bitcoinj.core.BaseMessage
All Implemented Interfaces:
Message
Direct Known Subclasses:
AddressMessage, Block, BloomFilter, EmptyMessage, FeeFilterMessage, FilteredBlock, GetBlocksMessage, HeadersMessage, ListMessage, Ping, Pong, RejectMessage, Transaction, VersionMessage

public abstract class BaseMessage extends Object implements Message
A Message is a data structure that can be serialized/deserialized using the Bitcoin serialization format. Specific types of messages that are used both in the blockchain, and on the wire, are derived from this class.

Instances of this class are not safe for use by multiple threads.

  • Constructor Details

    • BaseMessage

      public BaseMessage()
  • Method Details

    • serialize

      public final byte[] serialize()

      Serialize this message to a byte array that conforms to the bitcoin wire protocol.

      Specified by:
      serialize in interface Message
      Returns:
      serialized data in Bitcoin protocol format
    • bitcoinSerializeToStream

      protected abstract void bitcoinSerializeToStream(OutputStream stream) throws IOException
      Serializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize().
      Throws:
      IOException
    • messageSize

      public int messageSize()
      Return the size of the serialized message. Note that if the message was deserialized from a payload, this size can differ from the size of the original payload.
      Specified by:
      messageSize in interface Message
      Returns:
      size of this object when serialized (in bytes)