Package org.bitcoinj.core
Class Message
- java.lang.Object
-
- org.bitcoinj.core.Message
-
- Direct Known Subclasses:
AddressMessage,Block,BloomFilter,ChildMessage,EmptyMessage,FeeFilterMessage,FilteredBlock,GetBlocksMessage,HeadersMessage,ListMessage,MemoryPoolMessage,PartialMerkleTree,Ping,Pong,RejectMessage,VersionMessage
public abstract class Message extends java.lang.ObjectA 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 block chain, and on the wire, are derived from this class.
Instances of this class are not safe for use by multiple threads.
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_SIZEprotected NetworkParametersparamsprotected java.nio.ByteBufferpayloadprotected MessageSerializerserializer
-
Constructor Summary
Constructors Modifier Constructor Description protectedMessage()protectedMessage(NetworkParameters params)protectedMessage(NetworkParameters params, java.nio.ByteBuffer payload)protectedMessage(NetworkParameters params, java.nio.ByteBuffer payload, MessageSerializer serializer)protectedMessage(NetworkParameters params, MessageSerializer serializer)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description byte[]bitcoinSerialize()Serialize this message to a byte array that conforms to the bitcoin wire protocol.protected voidbitcoinSerializeToStream(java.io.OutputStream stream)Serializes this message to the provided stream.Sha256HashgetHash()Deprecated.intgetMessageSize()Return the size of the serialized message.NetworkParametersgetParams()Network parameters this message was created with.protected abstract voidparse()protected bytereadByte()protected byte[]readByteArray()protected byte[]readBytes(int length)protected Sha256HashreadHash()protected intreadInt32()protected longreadInt64()protected java.lang.StringreadStr()protected longreadUint32()protected java.math.BigIntegerreadUint64()protected VarIntreadVarInt()protected voidskipBytes(int numBytes)protected voidunCache()To be called before any change of internal values including any setters.byte[]unsafeBitcoinSerialize()Deprecated.
-
-
-
Field Detail
-
MAX_SIZE
public static final int MAX_SIZE
- See Also:
- Constant Field Values
-
payload
protected java.nio.ByteBuffer payload
-
serializer
protected final MessageSerializer serializer
-
params
@Nullable protected final NetworkParameters params
-
-
Constructor Detail
-
Message
protected Message()
-
Message
protected Message(NetworkParameters params)
-
Message
protected Message(NetworkParameters params, MessageSerializer serializer)
-
Message
protected Message(NetworkParameters params, java.nio.ByteBuffer payload, MessageSerializer serializer) throws ProtocolException
- Parameters:
params- NetworkParameters object.payload- Bitcoin protocol formatted byte array containing message content.serializer- the serializer to use for this message.- Throws:
ProtocolException
-
Message
protected Message(NetworkParameters params, java.nio.ByteBuffer payload) throws ProtocolException
- Throws:
ProtocolException
-
-
Method Detail
-
parse
protected abstract void parse() throws java.nio.BufferUnderflowException, ProtocolException- Throws:
java.nio.BufferUnderflowExceptionProtocolException
-
unCache
protected void unCache()
To be called before any change of internal values including any setters. This ensures any cached byte array is removed.
Child messages of this object(e.g. Transactions belonging to a Block) will not have their internal byte caches invalidated unless they are also modified internally.
-
bitcoinSerialize
public final byte[] bitcoinSerialize()
Serialize this message to a byte array that conforms to the bitcoin wire protocol.
- Returns:
- a byte array
-
unsafeBitcoinSerialize
@Deprecated public byte[] unsafeBitcoinSerialize()
Deprecated.
-
bitcoinSerializeToStream
protected void bitcoinSerializeToStream(java.io.OutputStream stream) throws java.io.IOExceptionSerializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize().- Throws:
java.io.IOException
-
getHash
@Deprecated public Sha256Hash getHash()
Deprecated.
-
getMessageSize
public int getMessageSize()
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.- Returns:
- size of the serialized message in bytes
-
readInt32
protected int readInt32() throws java.nio.BufferUnderflowException- Throws:
java.nio.BufferUnderflowException
-
readUint32
protected long readUint32() throws java.nio.BufferUnderflowException- Throws:
java.nio.BufferUnderflowException
-
readInt64
protected long readInt64() throws java.nio.BufferUnderflowException- Throws:
java.nio.BufferUnderflowException
-
readUint64
protected java.math.BigInteger readUint64() throws java.nio.BufferUnderflowException- Throws:
java.nio.BufferUnderflowException
-
readVarInt
protected VarInt readVarInt() throws java.nio.BufferUnderflowException
- Throws:
java.nio.BufferUnderflowException
-
readBytes
protected byte[] readBytes(int length) throws java.nio.BufferUnderflowException- Throws:
java.nio.BufferUnderflowException
-
readByte
protected byte readByte() throws java.nio.BufferUnderflowException- Throws:
java.nio.BufferUnderflowException
-
readByteArray
protected byte[] readByteArray() throws java.nio.BufferUnderflowException- Throws:
java.nio.BufferUnderflowException
-
readStr
protected java.lang.String readStr() throws java.nio.BufferUnderflowException- Throws:
java.nio.BufferUnderflowException
-
readHash
protected Sha256Hash readHash() throws java.nio.BufferUnderflowException
- Throws:
java.nio.BufferUnderflowException
-
skipBytes
protected void skipBytes(int numBytes) throws java.nio.BufferUnderflowException- Throws:
java.nio.BufferUnderflowException
-
getParams
public NetworkParameters getParams()
Network parameters this message was created with.
-
-