public abstract class Message extends Object implements Serializable
A Message is a data structure that can be serialized/deserialized using both the Bitcoin proprietary serialization format and built-in Java object serialization. Specific types of messages that are used both in the block chain, and on the wire, are derived from this class.
Modifier and Type | Class and Description |
---|---|
static class |
Message.LazyParseException |
Modifier and Type | Field and Description |
---|---|
protected byte[] |
checksum |
protected int |
cursor |
protected int |
length |
static int |
MAX_SIZE |
protected int |
offset |
protected NetworkParameters |
params |
protected boolean |
parsed |
protected boolean |
parseLazy |
protected boolean |
parseRetain |
protected byte[] |
payload |
protected int |
protocolVersion |
protected boolean |
recached |
static int |
UNKNOWN_LENGTH |
Modifier | Constructor and Description |
---|---|
protected |
Message()
This exists for the Java serialization framework to use only.
|
Modifier and Type | Method and Description |
---|---|
protected void |
adjustLength(int newArraySize,
int adjustment) |
byte[] |
bitcoinSerialize()
Returns a copy of the array returned by
unsafeBitcoinSerialize() , which is safe to mutate. |
void |
bitcoinSerialize(OutputStream stream)
Serialize this message to the provided OutputStream using the bitcoin wire format.
|
void |
ensureParsed()
In lazy parsing mode access to getters and setters may throw an unchecked LazyParseException.
|
Sha256Hash |
getHash()
This method is a NOP for all classes except Block and Transaction.
|
int |
getMessageSize()
This should be overridden to extract correct message size in the case of lazy parsing.
|
NetworkParameters |
getParams()
Network parameters this message was created with.
|
boolean |
isCached()
used for unit testing
|
boolean |
isParsed()
used for unit testing
|
boolean |
isRecached() |
protected void |
maybeParse()
Ensure the object is parsed if needed.
|
protected abstract void |
parseLite()
Perform the most minimal parse possible to calculate the length of the message payload.
|
protected void |
unCache()
To be called before any change of internal values including any setters.
|
byte[] |
unsafeBitcoinSerialize()
Serialize this message to a byte array that conforms to the bitcoin wire protocol.
|
public static final int MAX_SIZE
public static final int UNKNOWN_LENGTH
protected transient int offset
protected transient int cursor
protected transient int length
protected transient byte[] payload
protected transient boolean parsed
protected transient boolean recached
protected final transient boolean parseLazy
protected final transient boolean parseRetain
protected transient int protocolVersion
protected transient byte[] checksum
protected NetworkParameters params
protected Message()
protected abstract void parseLite() throws ProtocolException
ProtocolException
protected void maybeParse()
public void ensureParsed() throws ProtocolException
ProtocolException
protected void unCache()
protected void adjustLength(int newArraySize, int adjustment)
public boolean isParsed()
public boolean isCached()
public boolean isRecached()
public byte[] bitcoinSerialize()
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.public byte[] unsafeBitcoinSerialize()
public final void bitcoinSerialize(OutputStream stream) throws IOException
stream
- IOException
public Sha256Hash getHash()
public int getMessageSize()
public NetworkParameters getParams()
Copyright © 2014. All rights reserved.