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.mdfor format spec.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringALT_MEDIA_TYPEstatic java.lang.StringMEDIA_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 Instance Methods Concrete Methods Modifier and Type Method Description booleanbinaryProtocol()<Message extends PMessage<Message,Field>,Field extends PField>
Messagedeserialize(java.io.InputStream input, PMessageDescriptor<Message,Field> descriptor)Deserialize a message.<Message extends PMessage<Message,Field>,Field extends PField>
PServiceCall<Message,Field>deserialize(java.io.InputStream is, PService service)Deserialize a service call.java.lang.StringmediaType()<Message extends PMessage<Message,Field>,Field extends PField>
intserialize(java.io.OutputStream os, Message message)Serialize a message.<Message extends PMessage<Message,Field>,Field extends PField>
intserialize(java.io.OutputStream os, PServiceCall<Message,Field> call)Serialize a service call.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from class net.morimekta.providence.serializer.Serializer
isRequestCallType
-
-
-
-
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
-
-
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
-
binaryProtocol
public boolean binaryProtocol()
- Specified by:
binaryProtocolin classSerializer- Returns:
- True if the protocol of the serializer is "binary" a.k.a. unreadable to most humans.
-
mediaType
@Nonnull public java.lang.String mediaType()
- Specified by:
mediaTypein 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,Field>,Field extends PField> int serialize(@Nonnull java.io.OutputStream os, @Nonnull Message message) throws java.io.IOException
Description copied from class:SerializerSerialize a message.- Specified by:
serializein classSerializer- Type Parameters:
Message- The message type.Field- The message field 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,Field>,Field extends PField> int serialize(@Nonnull java.io.OutputStream os, @Nonnull PServiceCall<Message,Field> call) throws java.io.IOException
Description copied from class:SerializerSerialize a service call.- Specified by:
serializein classSerializer- Type Parameters:
Message- The message type contained in the service call.Field- The message field type.- 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,Field>,Field extends PField> Message deserialize(@Nonnull java.io.InputStream input, @Nonnull PMessageDescriptor<Message,Field> descriptor) throws java.io.IOException
Description copied from class:SerializerDeserialize a message.- Specified by:
deserializein classSerializer- Type Parameters:
Message- The message type.Field- The message field 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,Field>,Field extends PField> PServiceCall<Message,Field> deserialize(@Nonnull java.io.InputStream is, @Nonnull PService service) throws java.io.IOException
Description copied from class:SerializerDeserialize a service call.- Specified by:
deserializein classSerializer- Type Parameters:
Message- The message type contained in the returned service call.Field- The message field type.- 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.
-
-