Class BinarySerializer
- java.lang.Object
-
- net.morimekta.providence.serializer.Serializer
-
- net.morimekta.providence.serializer.BinarySerializer
-
public class BinarySerializer extends Serializer
Compact binary serializer. This usesd a format that is as close the the default thrift binary protocol as possible.See data definition file
docs/serializer-binary.md
for format spec.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ALT_MEDIA_TYPE
static BinarySerializer
INSTANCE
An instance of the binary serializer with lenient (non-strict) parsing ready to be used in serialization.static java.lang.String
MEDIA_TYPE
-
Fields inherited from class net.morimekta.providence.serializer.Serializer
DEFAULT_STRICT
-
-
Constructor Summary
Constructors Constructor Description BinarySerializer()
Construct a serializer instance.BinarySerializer(boolean readStrict)
Construct a serializer instance.BinarySerializer(boolean readStrict, boolean versioned)
Construct a serializer instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
binaryProtocol()
<Message extends PMessage<Message>>
Messagedeserialize(java.io.InputStream input, PMessageDescriptor<Message> descriptor)
Deserialize a message.<Message extends PMessage<Message>>
PServiceCall<Message>deserialize(java.io.InputStream is, PService service)
Deserialize a service call.java.lang.String
mediaType()
static <Message extends PMessage<Message>>
MessageparseBinary(net.morimekta.util.Binary binary, PMessageDescriptor<Message> descriptor)
<Message extends PMessage<Message>>
intserialize(java.io.OutputStream os, PMessageOrBuilder<Message> message)
Serialize a message.<Message extends PMessage<Message>>
intserialize(java.io.OutputStream os, PServiceCall<Message> call)
Serialize a service call.static <Message extends PMessage<Message>>
net.morimekta.util.BinarytoBinary(Message message)
void
verifyEndOfContent(java.io.InputStream input)
Verify that the input stream does not contain any more readable content and close the stream.-
Methods inherited from class net.morimekta.providence.serializer.Serializer
isRequestCallType, toString
-
-
-
-
Field Detail
-
MEDIA_TYPE
public static final java.lang.String MEDIA_TYPE
- See Also:
- Constant Field Values
-
ALT_MEDIA_TYPE
public static final java.lang.String ALT_MEDIA_TYPE
- See Also:
- Constant Field Values
-
INSTANCE
public static final BinarySerializer INSTANCE
An instance of the binary serializer with lenient (non-strict) parsing ready to be used in serialization. This is e.g. used inSerializable
reading and writing.
-
-
Constructor Detail
-
BinarySerializer
public BinarySerializer()
Construct a serializer instance.
-
BinarySerializer
public BinarySerializer(boolean readStrict)
Construct a serializer instance.- Parameters:
readStrict
- If the serializer should fail on bad reading.
-
BinarySerializer
public BinarySerializer(boolean readStrict, boolean versioned)
Construct a serializer instance. The 'versioned' param is equivalent to to the TBinaryProtocol strict flag.- Parameters:
readStrict
- If the serializer should fail on reading mismatched data.versioned
- If the serializer should use the versioned service call format.
-
-
Method Detail
-
toBinary
public static <Message extends PMessage<Message>> net.morimekta.util.Binary toBinary(@Nonnull Message message)
-
parseBinary
public static <Message extends PMessage<Message>> Message parseBinary(net.morimekta.util.Binary binary, PMessageDescriptor<Message> descriptor)
-
binaryProtocol
public boolean binaryProtocol()
- Specified by:
binaryProtocol
in classSerializer
- Returns:
- True if the protocol of the serializer is "binary" a.k.a. unreadable to most humans.
-
verifyEndOfContent
public void verifyEndOfContent(@Nonnull java.io.InputStream input) throws java.io.IOException
Description copied from class:Serializer
Verify that the input stream does not contain any more readable content and close the stream. Throws exception if unable to verify, or the streams contains any meaningful content.- Specified by:
verifyEndOfContent
in classSerializer
- Parameters:
input
- The input stream to check.- Throws:
java.io.IOException
- If unable to read from stream or stream contains meaningful content.
-
mediaType
@Nonnull public java.lang.String mediaType()
- Specified by:
mediaType
in classSerializer
- Returns:
- Media type of the content generated by the serializer. Can be used for Content-Type and Accept HTTP headers, MIME type etc.
-
serialize
public <Message extends PMessage<Message>> int serialize(@Nonnull java.io.OutputStream os, @Nonnull PMessageOrBuilder<Message> message) throws java.io.IOException
Description copied from class:Serializer
Serialize a message.- Specified by:
serialize
in classSerializer
- Type Parameters:
Message
- The message type.- Parameters:
os
- The output stream to write to.message
- The message to write.- Returns:
- The number of bytes written to the output stream.
- Throws:
java.io.IOException
- If writing or serialization failed.
-
serialize
public <Message extends PMessage<Message>> int serialize(@Nonnull java.io.OutputStream os, @Nonnull PServiceCall<Message> call) throws java.io.IOException
Description copied from class:Serializer
Serialize a service call.- Specified by:
serialize
in classSerializer
- Type Parameters:
Message
- The message type contained in the service call.- Parameters:
os
- The output stream to write to.call
- The service call to write.- Returns:
- The number of bytes written to the output stream.
- Throws:
java.io.IOException
- If writing or serialization failed.
-
deserialize
@Nonnull public <Message extends PMessage<Message>> Message deserialize(@Nonnull java.io.InputStream input, @Nonnull PMessageDescriptor<Message> descriptor) throws java.io.IOException
Description copied from class:Serializer
Deserialize a message.- Specified by:
deserialize
in classSerializer
- Type Parameters:
Message
- The message type.- Parameters:
input
- The input stream to read from.descriptor
- The descriptor of the message to read.- Returns:
- The message read.
- Throws:
java.io.IOException
- If reading or deserialization failed.
-
deserialize
@Nonnull public <Message extends PMessage<Message>> PServiceCall<Message> deserialize(@Nonnull java.io.InputStream is, @Nonnull PService service) throws java.io.IOException
Description copied from class:Serializer
Deserialize a service call.- Specified by:
deserialize
in classSerializer
- Type Parameters:
Message
- The message type contained in the returned service call.- Parameters:
is
- The input stream to read from.service
- The service definition to read for.- Returns:
- The service call read.
- Throws:
java.io.IOException
- If reading or deserialization failed.
-
-