Class MessageSerializer

  • Direct Known Subclasses:
    BitcoinSerializer

    public abstract class MessageSerializer
    extends java.lang.Object
    Generic interface for classes which serialize/deserialize messages. Implementing classes should be immutable.
    • Constructor Detail

      • MessageSerializer

        public MessageSerializer()
    • Method Detail

      • withProtocolVersion

        public abstract MessageSerializer withProtocolVersion​(int protocolVersion)
        Create a new serializer with a specific protocol version. Mainly used to disable segwit when parsing transactions.
      • getProtocolVersion

        public abstract int getProtocolVersion()
        Get the protocol version of this serializer.
      • deserialize

        public abstract Message deserialize​(java.nio.ByteBuffer in)
                                     throws ProtocolException,
                                            java.io.IOException,
                                            java.lang.UnsupportedOperationException
        Reads a message from the given ByteBuffer and returns it.
        Throws:
        ProtocolException
        java.io.IOException
        java.lang.UnsupportedOperationException
      • deserializeHeader

        public abstract BitcoinSerializer.BitcoinPacketHeader deserializeHeader​(java.nio.ByteBuffer in)
                                                                         throws ProtocolException,
                                                                                java.io.IOException,
                                                                                java.lang.UnsupportedOperationException
        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
        java.io.IOException
        java.lang.UnsupportedOperationException
      • makeAddressV1Message

        public abstract AddressV1Message makeAddressV1Message​(java.nio.ByteBuffer payload)
                                                       throws ProtocolException,
                                                              java.lang.UnsupportedOperationException
        Make an address message from the payload. Extension point for alternative serialization format support.
        Throws:
        ProtocolException
        java.lang.UnsupportedOperationException
      • makeAddressV2Message

        public abstract AddressV2Message makeAddressV2Message​(java.nio.ByteBuffer payload)
                                                       throws ProtocolException,
                                                              java.lang.UnsupportedOperationException
        Make an address message from the payload. Extension point for alternative serialization format support.
        Throws:
        ProtocolException
        java.lang.UnsupportedOperationException
      • makeBlock

        public abstract Block makeBlock​(java.nio.ByteBuffer payload)
                                 throws ProtocolException,
                                        java.lang.UnsupportedOperationException
        Make a block from the payload. Extension point for alternative serialization format support.
        Throws:
        ProtocolException
        java.lang.UnsupportedOperationException
      • makeBloomFilter

        public abstract Message makeBloomFilter​(java.nio.ByteBuffer payload)
                                         throws ProtocolException,
                                                java.lang.UnsupportedOperationException
        Make an filter message from the payload. Extension point for alternative serialization format support.
        Throws:
        ProtocolException
        java.lang.UnsupportedOperationException
      • makeFilteredBlock

        public abstract FilteredBlock makeFilteredBlock​(java.nio.ByteBuffer payload)
                                                 throws ProtocolException,
                                                        java.lang.UnsupportedOperationException
        Make a filtered block from the payload. Extension point for alternative serialization format support.
        Throws:
        ProtocolException
        java.lang.UnsupportedOperationException
      • makeInventoryMessage

        public abstract InventoryMessage makeInventoryMessage​(java.nio.ByteBuffer payload)
                                                       throws ProtocolException,
                                                              java.lang.UnsupportedOperationException
        Make an inventory message from the payload. Extension point for alternative serialization format support.
        Throws:
        ProtocolException
        java.lang.UnsupportedOperationException
      • makeTransaction

        public abstract Transaction makeTransaction​(java.nio.ByteBuffer payload)
                                             throws ProtocolException,
                                                    java.lang.UnsupportedOperationException
        Make a transaction from the payload. Extension point for alternative serialization format support.
        Throws:
        java.lang.UnsupportedOperationException - if this serializer/deserializer does not support deserialization. This can occur either because it's a dummy serializer (i.e. for messages with no network parameters), or because it does not support deserializing transactions.
        ProtocolException
      • seekPastMagicBytes

        public abstract void seekPastMagicBytes​(java.nio.ByteBuffer in)
                                         throws java.nio.BufferUnderflowException
        Throws:
        java.nio.BufferUnderflowException
      • serialize

        public abstract void serialize​(java.lang.String name,
                                       byte[] message,
                                       java.io.OutputStream out)
                                throws java.io.IOException,
                                       java.lang.UnsupportedOperationException
        Writes message to the output stream.
        Throws:
        java.lang.UnsupportedOperationException - if this serializer/deserializer does not support serialization. This can occur either because it's a dummy serializer (i.e. for messages with no network parameters), or because it does not support serializing the given message.
        java.io.IOException
      • serialize

        public abstract void serialize​(Message message,
                                       java.io.OutputStream out)
                                throws java.io.IOException,
                                       java.lang.UnsupportedOperationException
        Writes message to the output stream.
        Throws:
        java.lang.UnsupportedOperationException - if this serializer/deserializer does not support serialization. This can occur either because it's a dummy serializer (i.e. for messages with no network parameters), or because it does not support serializing the given message.
        java.io.IOException