public final class Wire extends Object
| Constructor and Description |
|---|
Wire(Class<?>... extensionClasses)
Creates a new Wire that can encode and decode the extensions specified in
extensionClasses. |
Wire(List<Class<?>> extensionClasses)
Creates a new Wire that can encode and decode the extensions specified in
extensionClasses. |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
get(T value,
T defaultValue)
Returns
value if it is not null; defaultValue otherwise. |
<M extends Message> |
parseFrom(byte[] bytes,
Class<M> messageClass)
Reads a message of type
messageClass from bytes and returns
it. |
<M extends Message> |
parseFrom(byte[] bytes,
int offset,
int count,
Class<M> messageClass)
Reads a message of type
messageClass from the given range of bytes and returns it. |
<M extends Message> |
parseFrom(InputStream input,
Class<M> messageClass)
Reads a message of type
messageClass from the given InputStream and returns it. |
public Wire(Class<?>... extensionClasses)
extensionClasses. Typically the classes in this list are generated
and start with the "Ext_" prefix.public <M extends Message> M parseFrom(byte[] bytes, Class<M> messageClass) throws IOException
messageClass from bytes and returns
it.IOExceptionpublic <M extends Message> M parseFrom(byte[] bytes, int offset, int count, Class<M> messageClass) throws IOException
messageClass from the given range of bytes and returns it.IOExceptionpublic <M extends Message> M parseFrom(InputStream input, Class<M> messageClass) throws IOException
messageClass from the given InputStream and returns it.IOExceptionpublic static <T> T get(T value,
T defaultValue)
value if it is not null; defaultValue otherwise.
This is used to conveniently return a default value when a value is null.
For example,
MyProto myProto = ... MyField field = Wire.get(myProto.f, MyProto.f_default);will attempt to retrieve the value of the field 'f' defined by MyProto. If the field is null (i.e., unset),
get will return its
second argument, which in this case is the default value for the field
'f'.Copyright © 2013 Square, Inc.. All Rights Reserved.