Class BinaryFormatUtils


  • public class BinaryFormatUtils
    extends java.lang.Object
    Utilities helping with reading and writing binary format (protocol) messages. NOTE: This class is not meant to be used directly, use the BinarySerializer serializer class instead. It is separated out and made public in order for pre-generated serialization code to be able to use the same utility methods.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  BinaryFormatUtils.FieldInfo
      Field info data holder with convenience methods.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void consumeMessage​(net.morimekta.util.io.BigEndianBinaryReader in)
      Consume a message from the stream without parsing the content into a message.
      static <T> T readFieldValue​(net.morimekta.util.io.BigEndianBinaryReader in, BinaryFormatUtils.FieldInfo fieldInfo, PDescriptor fieldType, boolean strict)
      Read a field value from stream.
      static <Message extends PMessage<Message,​Field>,​Field extends PField>
      Message
      readMessage​(net.morimekta.util.io.BigEndianBinaryReader input, PMessageDescriptor<Message,​Field> descriptor, boolean strict)
      Read message from reader.
      static <Message extends PMessage<Message,​Field>,​Field extends PField>
      int
      writeMessage​(net.morimekta.util.io.BigEndianBinaryWriter writer, Message message)
      Write message to writer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BinaryFormatUtils

        public BinaryFormatUtils()
    • Method Detail

      • readMessage

        public static <Message extends PMessage<Message,​Field>,​Field extends PField> Message readMessage​(net.morimekta.util.io.BigEndianBinaryReader input,
                                                                                                                     PMessageDescriptor<Message,​Field> descriptor,
                                                                                                                     boolean strict)
                                                                                                              throws java.io.IOException
        Read message from reader.
        Type Parameters:
        Message - The message type.
        Field - The field type.
        Parameters:
        input - The input reader.
        descriptor - The message descriptor.
        strict - If the message should be read in strict mode.
        Returns:
        The read and parsed message.
        Throws:
        java.io.IOException - If read failed.
      • consumeMessage

        public static void consumeMessage​(net.morimekta.util.io.BigEndianBinaryReader in)
                                   throws java.io.IOException
        Consume a message from the stream without parsing the content into a message.
        Parameters:
        in - Stream to read message from.
        Throws:
        java.io.IOException - On read failures.
      • readFieldValue

        public static <T> T readFieldValue​(net.morimekta.util.io.BigEndianBinaryReader in,
                                           BinaryFormatUtils.FieldInfo fieldInfo,
                                           PDescriptor fieldType,
                                           boolean strict)
                                    throws java.io.IOException
        Read a field value from stream.
        Type Parameters:
        T - Return type.
        Parameters:
        in - The stream to consume.
        fieldInfo - The field info about the content.
        fieldType - The type to generate content for.
        strict - If the field should be read strictly.
        Returns:
        The field value, or null if no type.
        Throws:
        java.io.IOException - If unable to read from stream or invalid field type.
      • writeMessage

        public static <Message extends PMessage<Message,​Field>,​Field extends PField> int writeMessage​(net.morimekta.util.io.BigEndianBinaryWriter writer,
                                                                                                                  Message message)
                                                                                                           throws java.io.IOException
        Write message to writer.
        Type Parameters:
        Message - The message type.
        Field - The field type.
        Parameters:
        writer - The binary writer.
        message - The message to write.
        Returns:
        The number of bytes written.
        Throws:
        java.io.IOException - If write failed.