com.google.bitcoin.core
Class EmptyMessage

java.lang.Object
  extended by com.google.bitcoin.core.Message
      extended by com.google.bitcoin.core.EmptyMessage
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
GetAddrMessage, UnknownMessage, VersionAck

public abstract class EmptyMessage
extends Message

Parent class for header only messages that don't have a payload. Currently this includes getaddr, ping, verack as well as the special bitcoinj class UnknownMessage

Author:
git
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.bitcoin.core.Message
Message.LazyParseException
 
Field Summary
 
Fields inherited from class com.google.bitcoin.core.Message
bytes, checksum, cursor, length, MAX_SIZE, offset, params, parsed, parseLazy, parseRetain, protocolVersion, recached, UNKNOWN_LENGTH
 
Constructor Summary
EmptyMessage()
           
EmptyMessage(NetworkParameters params)
           
EmptyMessage(NetworkParameters params, byte[] msg, int offset)
           
 
Method Summary
 byte[] bitcoinSerialize()
          Returns a copy of the array returned by Message.unsafeBitcoinSerialize(), which is safe to mutate.
protected  void bitcoinSerializeToStream(OutputStream stream)
          Serializes this message to the provided stream.
 void ensureParsed()
          In lazy parsing mode access to getters and setters may throw an unchecked LazyParseException.
 int getMessageSize()
          This should be overridden to extract correct message size in the case of lazy parsing.
protected  void parseLite()
          Perform the most minimal parse possible to calculate the length of the message.
 
Methods inherited from class com.google.bitcoin.core.Message
adjustLength, bitcoinSerialize, getHash, getParams, isCached, isParsed, isRecached, maybeParse, unCache, unsafeBitcoinSerialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmptyMessage

public EmptyMessage()

EmptyMessage

public EmptyMessage(NetworkParameters params)

EmptyMessage

public EmptyMessage(NetworkParameters params,
                    byte[] msg,
                    int offset)
             throws ProtocolException
Throws:
ProtocolException
Method Detail

bitcoinSerializeToStream

protected final void bitcoinSerializeToStream(OutputStream stream)
                                       throws IOException
Description copied from class: Message
Serializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize().

Throws:
IOException

getMessageSize

public int getMessageSize()
Description copied from class: Message
This should be overridden to extract correct message size in the case of lazy parsing. Until this method is implemented in a subclass of ChildMessage lazy parsing may have no effect. This default implementation is a safe fall back that will ensure it returns a correct value by parsing the message.

Overrides:
getMessageSize in class Message

parseLite

protected void parseLite()
                  throws ProtocolException
Description copied from class: Message
Perform the most minimal parse possible to calculate the length of the message. This is only required for subclasses of ChildClass as root level messages will have their length passed into the constructor.

Implementations should adhere to the following contract: If parseLazy = true the 'length' field must be set before returning. If parseLazy = false the length field must be set either within the parseLite() method OR the parse() method. The overriding requirement is that length must be set to non UNKNOWN_MESSAGE value by the time the constructor exits.

Specified by:
parseLite in class Message
Throws:
ProtocolException

ensureParsed

public void ensureParsed()
                  throws ProtocolException
Description copied from class: Message
In lazy parsing mode access to getters and setters may throw an unchecked LazyParseException. If guaranteed safe access is required this method will force parsing to occur immediately thus ensuring LazyParseExeption will never be thrown from this Message. If the Message contains child messages (e.g. a Block containing Transaction messages) this will not force child messages to parse.

This could be overidden for Transaction and it's child classes to ensure the entire tree of Message objects is parsed.

Overrides:
ensureParsed in class Message
Throws:
ProtocolException

bitcoinSerialize

public byte[] bitcoinSerialize()
Description copied from class: Message
Returns a copy of the array returned by Message.unsafeBitcoinSerialize(), which is safe to mutate. If you need extra performance and can guarantee you won't write to the array, you can use the unsafe version.

Overrides:
bitcoinSerialize in class Message
Returns:
a freshly allocated serialized byte array


Copyright © 2014. All rights reserved.