Class Serializer
- java.lang.Object
-
- net.morimekta.providence.serializer.Serializer
-
- Direct Known Subclasses:
BinarySerializer
,FastBinarySerializer
,JsonSerializer
,PrettySerializer
,UrlEncodedSerializer
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>>
Messagedeserialize(java.io.InputStream input, PMessageDescriptor<Message> descriptor)
Deserialize a message.abstract <Message extends PMessage<Message>>
PServiceCall<Message>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>>
intserialize(java.io.OutputStream output, PMessageOrBuilder<Message> message)
Serialize a message.abstract <Message extends PMessage<Message>>
intserialize(java.io.OutputStream output, PServiceCall<Message> call)
Serialize a service call.java.lang.String
toString()
abstract void
verifyEndOfContent(java.io.InputStream input)
Verify that the input stream does not contain any more readable content and close the stream.
-
-
-
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>> int serialize(@Nonnull java.io.OutputStream output, @Nonnull PMessageOrBuilder<Message> message) throws java.io.IOException
Serialize a message.- Type Parameters:
Message
- The message 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>> int serialize(@Nonnull java.io.OutputStream output, @Nonnull PServiceCall<Message> call) throws java.io.IOException
Serialize a service call.- Type Parameters:
Message
- The message type contained in the service call.- 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>> Message deserialize(@Nonnull java.io.InputStream input, @Nonnull PMessageDescriptor<Message> descriptor) throws java.io.IOException
Deserialize a message.- 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 abstract <Message extends PMessage<Message>> PServiceCall<Message> 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.- 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.
-
verifyEndOfContent
public abstract void verifyEndOfContent(@Nonnull java.io.InputStream input) throws java.io.IOException
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.- 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 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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-