Class BinaryFormatUtils
- java.lang.Object
-
- net.morimekta.providence.serializer.binary.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 theBinarySerializer
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.
-
Constructor Summary
Constructors Constructor Description BinaryFormatUtils()
-
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 java.lang.Object
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>
MessagereadMessage(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>
intwriteMessage(net.morimekta.util.io.BigEndianBinaryWriter writer, Message message)
Write message to writer.
-
-
-
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 java.lang.Object readFieldValue(net.morimekta.util.io.BigEndianBinaryReader in, BinaryFormatUtils.FieldInfo fieldInfo, PDescriptor fieldType, boolean strict) throws java.io.IOException
Read a field value from stream.- 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.
-
-