Class PrettySerializer


  • public class PrettySerializer
    extends Serializer
    Pretty printer that can print message content for easily reading and debugging. This is a write only format used in stringifying messages.
    • Constructor Detail

      • PrettySerializer

        public PrettySerializer()
      • PrettySerializer

        public PrettySerializer​(boolean strict)
    • Method Detail

      • compact

        public PrettySerializer compact()
        Make a PrettySerializer that generates content similar to the PMessage asString methods. The output of this has very little whitespace, so can be pretty difficult to read. It's similar to the string() variant, but without the qualified name prefix.
        Returns:
        Compact pretty serializer.
      • string

        public PrettySerializer string()
        Make a PrettySerializer that generates content similar to the PMessage toString methods. The output of this has very little whitespace, so can be pretty difficult to read. It prefixes the message with the root message qualified name, as any PMessage.toString() would expect.
        Returns:
        String pretty serializer.
      • config

        public PrettySerializer config()
        Make a PrettySerializer that generates content similar to what the ProvidenceConfig reads. It will not make use of references or anything fancy though.
        Returns:
        Config-like pretty serializer.
      • serialize

        public <Message extends PMessage<Message,Field>,Field extends PField> int serialize​(@Nonnull
                                                                                            java.io.OutputStream out,
                                                                                            @Nonnull
                                                                                            Message message)
        Description copied from class: Serializer
        Serialize a message.
        Specified by:
        serialize in class Serializer
        Type Parameters:
        Message - The message type.
        Field - The message field type.
        Parameters:
        out - The output stream to write to.
        message - The message to write.
        Returns:
        The number of bytes written to the output stream.
      • serialize

        public <Message extends PMessage<Message,Field>,Field extends PField> int serialize​(@Nonnull
                                                                                            java.io.OutputStream out,
                                                                                            @Nonnull
                                                                                            PServiceCall<Message,Field> call)
                                                                                     throws java.io.IOException
        Description copied from class: Serializer
        Serialize a service call.
        Specified by:
        serialize in class Serializer
        Type Parameters:
        Message - The message type contained in the service call.
        Field - The message field type.
        Parameters:
        out - 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 PFieldPServiceCall<Message,Field> deserialize​(@Nonnull
                                                                                                                      java.io.InputStream input,
                                                                                                                      @Nonnull
                                                                                                                      PService service)
                                                                                                               throws java.io.IOException
        Description copied from class: Serializer
        Deserialize a service call.
        Specified by:
        deserialize in class Serializer
        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.
      • 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: Serializer
        Deserialize a message.
        Specified by:
        deserialize in class Serializer
        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.
      • binaryProtocol

        public boolean binaryProtocol()
        Specified by:
        binaryProtocol in class Serializer
        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:
        mediaType in class Serializer
        Returns:
        Media type of the content generated by the serializer. Can be used for Content-Type and Accept HTTP headers, MIME type etc.