Package io.protostuff
Class ProtostuffIOUtil
- java.lang.Object
-
- io.protostuff.ProtostuffIOUtil
-
public final class ProtostuffIOUtil extends java.lang.Object
Protostuff ser/deser util for messages/objects.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ProtostuffIOUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> int
mergeDelimitedFrom(java.io.DataInput in, T message, Schema<T> schema)
Used by the code generated messages that implementExternalizable
.static <T> int
mergeDelimitedFrom(java.io.InputStream in, T message, Schema<T> schema)
Merges themessage
(delimited) from theInputStream
using the givenschema
.static <T> int
mergeDelimitedFrom(java.io.InputStream in, T message, Schema<T> schema, LinkedBuffer buffer)
Merges themessage
(delimited) from theInputStream
using the givenschema
.static <T> void
mergeFrom(byte[] data, int offset, int length, T message, Schema<T> schema)
Merges themessage
with the byte array using the givenschema
.static <T> void
mergeFrom(byte[] data, T message, Schema<T> schema)
Merges themessage
with the byte array using the givenschema
.static <T> void
mergeFrom(java.io.InputStream in, T message, Schema<T> schema)
Merges themessage
from theInputStream
using the givenschema
.static <T> void
mergeFrom(java.io.InputStream in, T message, Schema<T> schema, LinkedBuffer buffer)
Merges themessage
from theInputStream
using the givenschema
.static Pipe
newPipe(byte[] data)
Creates a protostuff pipe from a byte array.static Pipe
newPipe(byte[] data, int offset, int len)
Creates a protostuff pipe from a byte array.static Pipe
newPipe(java.io.InputStream in)
Creates a protostuff pipe from anInputStream
.static <T> boolean
optMergeDelimitedFrom(java.io.InputStream in, T message, Schema<T> schema, boolean drainRemainingBytesIfTooLarge, LinkedBuffer buffer)
Optimal/Optional mergeDelimitedFrom - If the message does not fit the buffer, no merge is done and this method will return false.static <T> boolean
optMergeDelimitedFrom(java.io.InputStream in, T message, Schema<T> schema, LinkedBuffer buffer)
Optimal/Optional mergeDelimitedFrom - If the message does not fit the buffer, no merge is done and this method will return false.static <T> int
optWriteDelimitedTo(java.io.OutputStream out, T message, Schema<T> schema, LinkedBuffer buffer)
Optimal writeDelimitedTo - The varint32 prefix is written to the buffer instead of directly writing to outputstream.static <T> java.util.List<T>
parseListFrom(java.io.InputStream in, Schema<T> schema)
Parses themessages
(delimited) from theInputStream
using the givenschema
.static <T> byte[]
toByteArray(T message, Schema<T> schema, LinkedBuffer buffer)
Serializes themessage
into a byte array using the given schema.static <T> int
writeDelimitedTo(java.io.DataOutput out, T message, Schema<T> schema)
Used by the code generated messages that implementExternalizable
.static <T> int
writeDelimitedTo(java.io.OutputStream out, T message, Schema<T> schema, LinkedBuffer buffer)
Serializes themessage
, prefixed with its length, into anOutputStream
.static <T> int
writeListTo(java.io.OutputStream out, java.util.List<T> messages, Schema<T> schema, LinkedBuffer buffer)
Serializes themessages
(delimited) into anOutputStream
using the given schema.static <T> int
writeTo(LinkedBuffer buffer, T message, Schema<T> schema)
Writes themessage
into theLinkedBuffer
using the given schema.static <T> int
writeTo(java.io.OutputStream out, T message, Schema<T> schema, LinkedBuffer buffer)
Serializes themessage
into anOutputStream
using the given schema.
-
-
-
Method Detail
-
newPipe
public static Pipe newPipe(byte[] data)
Creates a protostuff pipe from a byte array.
-
newPipe
public static Pipe newPipe(byte[] data, int offset, int len)
Creates a protostuff pipe from a byte array.
-
newPipe
public static Pipe newPipe(java.io.InputStream in)
Creates a protostuff pipe from anInputStream
.
-
mergeFrom
public static <T> void mergeFrom(byte[] data, T message, Schema<T> schema)
Merges themessage
with the byte array using the givenschema
.
-
mergeFrom
public static <T> void mergeFrom(byte[] data, int offset, int length, T message, Schema<T> schema)
Merges themessage
with the byte array using the givenschema
.
-
mergeFrom
public static <T> void mergeFrom(java.io.InputStream in, T message, Schema<T> schema) throws java.io.IOException
Merges themessage
from theInputStream
using the givenschema
.- Throws:
java.io.IOException
-
mergeFrom
public static <T> void mergeFrom(java.io.InputStream in, T message, Schema<T> schema, LinkedBuffer buffer) throws java.io.IOException
Merges themessage
from theInputStream
using the givenschema
.The
buffer
's internal byte array will be used for reading the message.- Throws:
java.io.IOException
-
mergeDelimitedFrom
public static <T> int mergeDelimitedFrom(java.io.InputStream in, T message, Schema<T> schema) throws java.io.IOException
Merges themessage
(delimited) from theInputStream
using the givenschema
.- Returns:
- the size of the message
- Throws:
java.io.IOException
-
mergeDelimitedFrom
public static <T> int mergeDelimitedFrom(java.io.InputStream in, T message, Schema<T> schema, LinkedBuffer buffer) throws java.io.IOException
Merges themessage
(delimited) from theInputStream
using the givenschema
.The delimited message size must not be larger than the
buffer
's size/capacity.ProtobufException
"size limit exceeded" is thrown otherwise.- Returns:
- the size of the message
- Throws:
java.io.IOException
-
mergeDelimitedFrom
public static <T> int mergeDelimitedFrom(java.io.DataInput in, T message, Schema<T> schema) throws java.io.IOException
Used by the code generated messages that implementExternalizable
. Merges from theDataInput
.- Returns:
- the size of the message
- Throws:
java.io.IOException
-
toByteArray
public static <T> byte[] toByteArray(T message, Schema<T> schema, LinkedBuffer buffer)
Serializes themessage
into a byte array using the given schema.- Returns:
- the byte array containing the data.
-
writeTo
public static <T> int writeTo(LinkedBuffer buffer, T message, Schema<T> schema)
Writes themessage
into theLinkedBuffer
using the given schema.- Returns:
- the size of the message
-
writeTo
public static <T> int writeTo(java.io.OutputStream out, T message, Schema<T> schema, LinkedBuffer buffer) throws java.io.IOException
Serializes themessage
into anOutputStream
using the given schema.- Returns:
- the size of the message
- Throws:
java.io.IOException
-
writeDelimitedTo
public static <T> int writeDelimitedTo(java.io.OutputStream out, T message, Schema<T> schema, LinkedBuffer buffer) throws java.io.IOException
Serializes themessage
, prefixed with its length, into anOutputStream
.- Returns:
- the size of the message
- Throws:
java.io.IOException
-
writeDelimitedTo
public static <T> int writeDelimitedTo(java.io.DataOutput out, T message, Schema<T> schema) throws java.io.IOException
Used by the code generated messages that implementExternalizable
. Writes to theDataOutput
.- Returns:
- the size of the message.
- Throws:
java.io.IOException
-
writeListTo
public static <T> int writeListTo(java.io.OutputStream out, java.util.List<T> messages, Schema<T> schema, LinkedBuffer buffer) throws java.io.IOException
Serializes themessages
(delimited) into anOutputStream
using the given schema.- Returns:
- the bytes written
- Throws:
java.io.IOException
-
parseListFrom
public static <T> java.util.List<T> parseListFrom(java.io.InputStream in, Schema<T> schema) throws java.io.IOException
Parses themessages
(delimited) from theInputStream
using the givenschema
.- Returns:
- the list containing the messages.
- Throws:
java.io.IOException
-
optMergeDelimitedFrom
public static <T> boolean optMergeDelimitedFrom(java.io.InputStream in, T message, Schema<T> schema, LinkedBuffer buffer) throws java.io.IOException
Optimal/Optional mergeDelimitedFrom - If the message does not fit the buffer, no merge is done and this method will return false.This is strictly for reading a single message from the stream because the buffer is aggressively filled when reading the delimited size (which could result into reading more bytes than it has to).
The remaining bytes will be drained (consumed and discared) when the message is too large.
- Throws:
java.io.IOException
-
optMergeDelimitedFrom
public static <T> boolean optMergeDelimitedFrom(java.io.InputStream in, T message, Schema<T> schema, boolean drainRemainingBytesIfTooLarge, LinkedBuffer buffer) throws java.io.IOException
Optimal/Optional mergeDelimitedFrom - If the message does not fit the buffer, no merge is done and this method will return false.This is strictly for reading a single message from the stream because the buffer is aggressively filled when reading the delimited size (which could result into reading more bytes than it has to).
- Throws:
java.io.IOException
-
optWriteDelimitedTo
public static <T> int optWriteDelimitedTo(java.io.OutputStream out, T message, Schema<T> schema, LinkedBuffer buffer) throws java.io.IOException
Optimal writeDelimitedTo - The varint32 prefix is written to the buffer instead of directly writing to outputstream.- Returns:
- the size of the message
- Throws:
java.io.IOException
-
-