public abstract class ProtoAdapter<E> extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ProtoAdapter.EnumConstantNotFoundException |
Modifier and Type | Field and Description |
---|---|
static ProtoAdapter<Boolean> |
BOOL |
static ProtoAdapter<okio.ByteString> |
BYTES |
static ProtoAdapter<Double> |
DOUBLE |
static ProtoAdapter<Integer> |
FIXED32 |
static ProtoAdapter<Long> |
FIXED64 |
static ProtoAdapter<Float> |
FLOAT |
static ProtoAdapter<Integer> |
INT32 |
static ProtoAdapter<Long> |
INT64 |
static ProtoAdapter<Integer> |
SFIXED32 |
static ProtoAdapter<Long> |
SFIXED64 |
static ProtoAdapter<Integer> |
SINT32 |
static ProtoAdapter<Long> |
SINT64 |
static ProtoAdapter<String> |
STRING |
static ProtoAdapter<Integer> |
UINT32 |
static ProtoAdapter<Long> |
UINT64
Like INT64, but negative longs are interpreted as large positive values, and encoded that way
in JSON.
|
Constructor and Description |
---|
ProtoAdapter(FieldEncoding fieldEncoding,
Class<?> javaType) |
Modifier and Type | Method and Description |
---|---|
ProtoAdapter<List<E>> |
asPacked()
Returns an adapter for
E but as a packed, repeated value. |
ProtoAdapter<List<E>> |
asRepeated()
Returns an adapter for
E but as a repeated value. |
E |
decode(okio.BufferedSource source)
Read an encoded message from
source . |
E |
decode(byte[] bytes)
Read an encoded message from
bytes . |
E |
decode(okio.ByteString bytes)
Read an encoded message from
bytes . |
E |
decode(InputStream stream)
Read an encoded message from
stream . |
abstract E |
decode(ProtoReader reader)
Read a non-null value from
reader . |
void |
encode(okio.BufferedSink sink,
E value)
Encode
value and write it to stream . |
byte[] |
encode(E value)
Encode
value as a byte[] . |
void |
encode(OutputStream stream,
E value)
Encode
value and write it to stream . |
abstract void |
encode(ProtoWriter writer,
E value)
Write non-null
value to writer . |
abstract int |
encodedSize(E value)
The size of the non-null data
value . |
int |
encodedSizeWithTag(int tag,
E value)
The size of
tag and non-null value in the wire format. |
void |
encodeWithTag(ProtoWriter writer,
int tag,
E value)
Write
tag and non-null value to writer . |
static <M> ProtoAdapter<M> |
get(Class<M> type)
Returns the adapter for
type . |
static <M extends Message> |
get(M message)
Returns the adapter for the type of
Message . |
static <E extends WireEnum> |
newEnumAdapter(Class<E> type)
Creates a new proto adapter for
type . |
static <K,V> ProtoAdapter<Map<K,V>> |
newMapAdapter(ProtoAdapter<K> keyAdapter,
ProtoAdapter<V> valueAdapter)
Creates a new proto adapter for a map using
keyAdapter and valueAdapter . |
static <M extends Message<M,B>,B extends Message.Builder<M,B>> |
newMessageAdapter(Class<M> type)
Creates a new proto adapter for
type . |
E |
redact(E value)
Returns the redacted form of
value . |
String |
toString(E value)
Returns a human-readable version of the given
value . |
public static final ProtoAdapter<Boolean> BOOL
public static final ProtoAdapter<Integer> INT32
public static final ProtoAdapter<Integer> UINT32
public static final ProtoAdapter<Integer> SINT32
public static final ProtoAdapter<Integer> FIXED32
public static final ProtoAdapter<Integer> SFIXED32
public static final ProtoAdapter<Long> INT64
public static final ProtoAdapter<Long> UINT64
public static final ProtoAdapter<Long> SINT64
public static final ProtoAdapter<Long> FIXED64
public static final ProtoAdapter<Long> SFIXED64
public static final ProtoAdapter<Float> FLOAT
public static final ProtoAdapter<Double> DOUBLE
public static final ProtoAdapter<String> STRING
public static final ProtoAdapter<okio.ByteString> BYTES
public ProtoAdapter(FieldEncoding fieldEncoding, Class<?> javaType)
public static <M extends Message<M,B>,B extends Message.Builder<M,B>> ProtoAdapter<M> newMessageAdapter(Class<M> type)
type
.public static <E extends WireEnum> com.squareup.wire.RuntimeEnumAdapter<E> newEnumAdapter(Class<E> type)
type
.public static <K,V> ProtoAdapter<Map<K,V>> newMapAdapter(ProtoAdapter<K> keyAdapter, ProtoAdapter<V> valueAdapter)
keyAdapter
and valueAdapter
.
Note: Map entries are not required to be encoded sequentially. Thus, when decoding using the returned adapter, only single-element maps will be returned and it is the caller's responsibility to merge them into the final map.
public static <M extends Message> ProtoAdapter<M> get(M message)
Message
.public static <M> ProtoAdapter<M> get(Class<M> type)
type
.public abstract int encodedSize(E value)
value
. This does not include the size required for
a length-delimited prefix (should the type require one).public int encodedSizeWithTag(int tag, E value)
tag
and non-null value
in the wire format. This size includes the
tag, type, length-delimited prefix (should the type require one), and value.public abstract void encode(ProtoWriter writer, E value) throws IOException
value
to writer
.IOException
public void encodeWithTag(ProtoWriter writer, int tag, E value) throws IOException
tag
and non-null value
to writer
.IOException
public final void encode(okio.BufferedSink sink, E value) throws IOException
value
and write it to stream
.IOException
public final byte[] encode(E value)
value
as a byte[]
.public final void encode(OutputStream stream, E value) throws IOException
value
and write it to stream
.IOException
public abstract E decode(ProtoReader reader) throws IOException
reader
.IOException
public final E decode(byte[] bytes) throws IOException
bytes
.IOException
public final E decode(okio.ByteString bytes) throws IOException
bytes
.IOException
public final E decode(InputStream stream) throws IOException
stream
.IOException
public final E decode(okio.BufferedSource source) throws IOException
source
.IOException
public final ProtoAdapter<List<E>> asPacked()
E
but as a packed, repeated value.public final ProtoAdapter<List<E>> asRepeated()
E
but as a repeated value.
Note: Repeated items are not required to be encoded sequentially. Thus, when decoding using the returned adapter, only single-element lists will be returned and it is the caller's responsibility to merge them into the final list.
Copyright © 2013–2016 Square, Inc.. All rights reserved.