Package net.morimekta.providence.util
Class Any
- java.lang.Object
-
- net.morimekta.providence.util.Any
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<Any>
,PMessage<Any,Any._Field>
,PValue<Any>
,BinaryWriter
,net.morimekta.util.Stringable
@Generated("providence-maven-plugin") @Immutable public class Any extends java.lang.Object implements PMessage<Any,Any._Field>, java.lang.Comparable<Any>, java.io.Serializable, BinaryWriter
A message containing anything.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Any._Builder
A message containing anything.static class
Any._Field
-
Field Summary
Fields Modifier and Type Field Description static PStructDescriptor<Any,Any._Field>
kDescriptor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
asString()
Pure string representation of content.static Any._Builder
builder()
Make aputil.Any
builder.int
compareTo(Any other)
PStructDescriptor<Any,Any._Field>
descriptor()
boolean
equals(java.lang.Object o)
<T> T
get(int key)
net.morimekta.util.Binary
getData()
The actual content binary data.java.lang.String
getMediaType()
The media type used for encoding.java.lang.String
getText()
Optional string encoded content for non-binary media types.java.lang.String
getType()
The thrift / providence program + message type name.boolean
has(int key)
boolean
hasData()
int
hashCode()
boolean
hasMediaType()
boolean
hasText()
boolean
hasType()
Any._Builder
mutate()
Get a builder that extends the current object.java.util.Optional<net.morimekta.util.Binary>
optionalData()
The actual content binary data.java.util.Optional<java.lang.String>
optionalMediaType()
The media type used for encoding.java.util.Optional<java.lang.String>
optionalText()
Optional string encoded content for non-binary media types.static PStructDescriptorProvider<Any,Any._Field>
provider()
java.lang.String
toString()
<M extends PMessage<M,F>,F extends PField>
MunwrapMessage(PMessageDescriptor<M,F> descriptor)
Unwrap a message from this wrapper message.<M extends PMessage<M,F>,F extends PField>
MunwrapMessage(PMessageDescriptor<M,F> descriptor, SerializerProvider provider)
Unwrap a message from this wrapper message.static <M extends PMessage<M,F>,F extends PField>
AnywrapMessage(M message)
Wrap a message into anAny
wrapper message.static <M extends PMessage<M,F>,F extends PField>
AnywrapMessage(M message, Serializer serializer)
Wrap a message into anAny
wrapper message.<M extends PMessage<M,F>,F extends PField>
booleanwrappedTypeIs(PMessageDescriptor<M,F> descriptor)
Check the wrapped message type against the provided message type descriptor.int
writeBinary(net.morimekta.util.io.BigEndianBinaryWriter writer)
Write the current message to the binary writer.
-
-
-
Field Detail
-
kDescriptor
public static final PStructDescriptor<Any,Any._Field> kDescriptor
-
-
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 interfacePMessage<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 interfacePMessage<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 classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.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 interfacePMessage<Any,Any._Field>
- Specified by:
asString
in interfacenet.morimekta.util.Stringable
- Returns:
- String representation.
-
compareTo
public int compareTo(Any other)
- Specified by:
compareTo
in interfacejava.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 typeF
- 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 typeF
- 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 typeF
- 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 theBinarySerializer.serialize(OutputStream, PMessage)
call.- Specified by:
writeBinary
in interfaceBinaryWriter
- 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 interfacePMessage<Any,Any._Field>
- Returns:
- The builder instance.
-
provider
@Nonnull public static PStructDescriptorProvider<Any,Any._Field> provider()
-
descriptor
@Nonnull public PStructDescriptor<Any,Any._Field> descriptor()
- Specified by:
descriptor
in interfacePMessage<Any,Any._Field>
- Specified by:
descriptor
in interfacePValue<Any>
-
wrapMessage
public static <M extends PMessage<M,F>,F extends PField> Any wrapMessage(@Nonnull M message)
Wrap a message into anAny
wrapper message. This will serialize the message using the default binary serializer.- Type Parameters:
M
- The message typeF
- The message field type- Parameters:
message
- Wrap this message.- Returns:
- The wrapped message.
-
wrapMessage
public static <M extends PMessage<M,F>,F extends PField> Any wrapMessage(@Nonnull M message, @Nonnull Serializer serializer)
Wrap a message into anAny
wrapper message. This will serialize the message using the provided serializer.- Type Parameters:
M
- The message typeF
- The message field type- Parameters:
message
- Wrap this message.serializer
- Use this serializer.- Returns:
- The wrapped message.
-
builder
public static Any._Builder builder()
Make aputil.Any
builder.- Returns:
- The builder instance.
-
-