Class Any

    • Method Detail

      • hasType

        public boolean hasType()
      • getType

        @Nonnull
        public java.lang.String getType()
        The thrift / providence program + message type name. This should refer to a message type. Enums will need to be wrapped in a message to be contained.
        Returns:
        The type value
      • hasMediaType

        public boolean hasMediaType()
      • getMediaType

        public java.lang.String getMediaType()
        The media type used for encoding. There will need to exist a serializer registered for this. If the media type is not set, it is assumed to be 'application/vnd.apache.thrift.binary', the default thrift serialization.
        Returns:
        The media_type value
      • optionalMediaType

        @Nonnull
        public java.util.Optional<java.lang.String> optionalMediaType()
        The media type used for encoding. There will need to exist a serializer registered for this. If the media type is not set, it is assumed to be 'application/vnd.apache.thrift.binary', the default thrift serialization.
        Returns:
        Optional of the media_type field value.
      • hasData

        public boolean hasData()
      • getData

        public net.morimekta.util.Binary getData()
        The actual content binary data.
        Returns:
        The data value
      • optionalData

        @Nonnull
        public java.util.Optional<net.morimekta.util.Binary> optionalData()
        The actual content binary data.
        Returns:
        Optional of the data field value.
      • hasText

        public boolean hasText()
      • getText

        public java.lang.String getText()
        Optional string encoded content for non-binary media types. If this is filled in, then the 'bin' field is not needed.
        Returns:
        The text value
      • optionalText

        @Nonnull
        public java.util.Optional<java.lang.String> optionalText()
        Optional string encoded content for non-binary media types. If this is filled in, then the 'bin' field is not needed.
        Returns:
        Optional of the text field value.
      • has

        public boolean has​(int key)
        Specified by:
        has in interface PMessage<Any,​Any._Field>
        Parameters:
        key - The key of the field.
        Returns:
        Whether the field is present.
      • get

        public <T> T get​(int key)
        Specified by:
        get in interface PMessage<Any,​Any._Field>
        Type Parameters:
        T - The return type.
        Parameters:
        key - The key of the field.
        Returns:
        The value of the field.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • asString

        @Nonnull
        public java.lang.String asString()
        Description copied from interface: PMessage
        Pure string representation of content. Does not contain type info.
        Specified by:
        asString in interface PMessage<Any,​Any._Field>
        Specified by:
        asString in interface net.morimekta.util.Stringable
        Returns:
        String representation.
      • compareTo

        public int compareTo​(Any other)
        Specified by:
        compareTo in interface java.lang.Comparable<Any>
      • wrappedTypeIs

        public <M extends PMessage<M,​F>,​F extends PField> boolean wrappedTypeIs​(@Nonnull
                                                                                            PMessageDescriptor<M,​F> descriptor)
        Check the wrapped message type against the provided message type descriptor.
        Type Parameters:
        M - The message type
        F - The message field type
        Parameters:
        descriptor - The message type to check.
        Returns:
        True if the wrapped message type matches the provided.
      • unwrapMessage

        public <M extends PMessage<M,​F>,​F extends PField> M unwrapMessage​(@Nonnull
                                                                                      PMessageDescriptor<M,​F> descriptor)
        Unwrap a message from this wrapper message. This will use the default serializer provider to find a suitable serializer to use to deserialize the wrapped message. If no serializer is available, or the message cannot be deserialized an unchecked IO exception is thrown.
        Type Parameters:
        M - The message type
        F - The message field type
        Parameters:
        descriptor - The message type to unpack from the content.
        Returns:
        The unwrapped message.
      • unwrapMessage

        public <M extends PMessage<M,​F>,​F extends PField> M unwrapMessage​(@Nonnull
                                                                                      PMessageDescriptor<M,​F> descriptor,
                                                                                      @Nonnull
                                                                                      SerializerProvider provider)
        Unwrap a message from this wrapper message. This will use the provided serializer provider to find a suitable serializer to use to deserialize the wrapped message. If no serializer is available, or the message cannot be deserialized an unchecked IO exception is thrown.
        Type Parameters:
        M - The message type
        F - The message field type
        Parameters:
        descriptor - The message type to unpack from the content.
        provider - Serializer provider to get serializer from.
        Returns:
        The unwrapped message.
      • writeBinary

        public int writeBinary​(net.morimekta.util.io.BigEndianBinaryWriter writer)
                        throws java.io.IOException
        Description copied from interface: BinaryWriter
        Write the current message to the binary writer. NOTE: This method is not intended to be used directly. Instead use the BinarySerializer.serialize(OutputStream, PMessage) call.
        Specified by:
        writeBinary in interface BinaryWriter
        Parameters:
        writer - The binary writer to write to.
        Returns:
        The number of bytes written.
        Throws:
        java.io.IOException - If it failed to write the message for any reason.
      • mutate

        @Nonnull
        public Any._Builder mutate()
        Description copied from interface: PMessage
        Get a builder that extends the current object.
        Specified by:
        mutate in interface PMessage<Any,​Any._Field>
        Returns:
        The builder instance.
      • wrapMessage

        public static <M extends PMessage<M,​F>,​F extends PFieldAny wrapMessage​(@Nonnull
                                                                                             M message)
        Wrap a message into an Any wrapper message. This will serialize the message using the default binary serializer.
        Type Parameters:
        M - The message type
        F - The message field type
        Parameters:
        message - Wrap this message.
        Returns:
        The wrapped message.
      • wrapMessage

        public static <M extends PMessage<M,​F>,​F extends PFieldAny wrapMessage​(@Nonnull
                                                                                             M message,
                                                                                             @Nonnull
                                                                                             Serializer serializer)
        Wrap a message into an Any wrapper message. This will serialize the message using the provided serializer.
        Type Parameters:
        M - The message type
        F - The message field type
        Parameters:
        message - Wrap this message.
        serializer - Use this serializer.
        Returns:
        The wrapped message.
      • builder

        public static Any._Builder builder()
        Make a putil.Any builder.
        Returns:
        The builder instance.