Class Serializer
- java.lang.Object
-
- net.morimekta.providence.serializer.Serializer
-
- Direct Known Subclasses:
BinarySerializer
,FastBinarySerializer
,JsonSerializer
,PrettySerializer
public abstract class Serializer extends java.lang.Object
Thrift serializers are stateless injectable implementation classes that transforms messages to binary stream (serializes), or binary stream to messages (deserializes). Since the serializer is state-less it should also be inherently thread safe (including not needing any synchronized methods.
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_STRICT
Default value for the "strict" serializer settings.
-
Constructor Summary
Constructors Constructor Description Serializer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
binaryProtocol()
abstract <Message extends PMessage<Message,Field>,Field extends PField>
Messagedeserialize(java.io.InputStream input, PMessageDescriptor<Message,Field> descriptor)
Deserialize a message.abstract <Message extends PMessage<Message,Field>,Field extends PField>
PServiceCall<Message,Field>deserialize(java.io.InputStream input, PService service)
Deserialize a service call.protected boolean
isRequestCallType(PServiceCallType type)
Utility method to check if a service call is a request type.abstract java.lang.String
mediaType()
abstract <Message extends PMessage<Message,Field>,Field extends PField>
intserialize(java.io.OutputStream output, Message message)
Serialize a message.abstract <Message extends PMessage<Message,Field>,Field extends PField>
intserialize(java.io.OutputStream output, PServiceCall<Message,Field> call)
Serialize a service call.
-
-
-
Field Detail
-
DEFAULT_STRICT
public static final boolean DEFAULT_STRICT
Default value for the "strict" serializer settings.- See Also:
- Constant Field Values
-
-
Method Detail
-
serialize
public abstract <Message extends PMessage<Message,Field>,Field extends PField> int serialize(@Nonnull java.io.OutputStream output, @Nonnull Message message) throws java.io.IOException
Serialize a message.- Type Parameters:
Message
- The message type.Field
- The message field type.- Parameters:
output
- 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 abstract <Message extends PMessage<Message,Field>,Field extends PField> int serialize(@Nonnull java.io.OutputStream output, @Nonnull PServiceCall<Message,Field> call) throws java.io.IOException
Serialize a service call.- Type Parameters:
Message
- The message type contained in the service call.Field
- The message field type.- Parameters:
output
- 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 abstract <Message extends PMessage<Message,Field>,Field extends PField> Message deserialize(@Nonnull java.io.InputStream input, @Nonnull PMessageDescriptor<Message,Field> descriptor) throws java.io.IOException
Deserialize a message.- 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 abstract <Message extends PMessage<Message,Field>,Field extends PField> PServiceCall<Message,Field> deserialize(@Nonnull java.io.InputStream input, @Nonnull PService service) throws java.io.IOException
Deserialize a service call.- Type Parameters:
Message
- The message type contained in the returned service call.Field
- The message field type.- Parameters:
input
- 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.
-
binaryProtocol
public abstract boolean binaryProtocol()
- Returns:
- True if the protocol of the serializer is "binary" a.k.a. unreadable to most humans.
-
mediaType
@Nonnull public abstract java.lang.String mediaType()
- Returns:
- Media type of the content generated by the serializer. Can be used for Content-Type and Accept HTTP headers, MIME type etc.
-
isRequestCallType
protected boolean isRequestCallType(PServiceCallType type)
Utility method to check if a service call is a request type.- Parameters:
type
- The service call type.- Returns:
- If the service call is a request, and not a response.
-
-