wire-runtime / com.squareup.wire / ProtoAdapter

ProtoAdapter

abstract class ProtoAdapter<E : Any>

Exceptions

EnumConstantNotFoundException

class EnumConstantNotFoundException : IllegalArgumentException

Constructors

<init>

ProtoAdapter(fieldEncoding: FieldEncoding, javaType: Class<*>?)

Properties

BOOL

static val BOOL: ProtoAdapter<Boolean>

BYTES

static val BYTES: ProtoAdapter<ByteString>

DOUBLE

static val DOUBLE: ProtoAdapter<Double>

FIXED32

static val FIXED32: ProtoAdapter<Int>

FIXED64

static val FIXED64: ProtoAdapter<Long>

FLOAT

static val FLOAT: ProtoAdapter<Float>

INT32

static val INT32: ProtoAdapter<Int>

INT64

static val INT64: ProtoAdapter<Long>

SFIXED32

static val SFIXED32: ProtoAdapter<Int>

SFIXED64

static val SFIXED64: ProtoAdapter<Long>

SINT32

static val SINT32: ProtoAdapter<Int>

SINT64

static val SINT64: ProtoAdapter<Long>

STRING

static val STRING: ProtoAdapter<String>

UINT32

static val UINT32: ProtoAdapter<Int>

UINT64

static val UINT64: ProtoAdapter<Long>

Like INT64, but negative longs are interpreted as large positive values, and encoded that way in JSON.

Functions

asPacked

fun asPacked(): ProtoAdapter<MutableList<E>>

Returns an adapter for E but as a packed, repeated value.

asRepeated

fun asRepeated(): ProtoAdapter<MutableList<E>>

Returns an adapter for 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.

decode

abstract fun decode(reader: ProtoReader): E

Read a non-null value from reader.

fun decode(bytes: ByteArray): E
fun decode(bytes: ByteString): E

Read an encoded message from bytes.

fun decode(stream: InputStream): E

Read an encoded message from stream.

fun decode(source: BufferedSource): E

Read an encoded message from source.

encode

abstract fun encode(writer: ProtoWriter, value: E): Unit

Write non-null value to writer.

fun encode(sink: BufferedSink, value: E): Unit
fun encode(stream: OutputStream, value: E): Unit

Encode value and write it to stream.

fun encode(value: E): ByteArray

Encode value as a byte[].

encodeWithTag

open fun encodeWithTag(writer: ProtoWriter, tag: Int, value: E?): Unit

Write tag and value to writer. If value is null this does nothing.

encodedSize

abstract fun encodedSize(value: E): Int

The size of the non-null data value. This does not include the size required for a length-delimited prefix (should the type require one).

encodedSizeWithTag

open fun encodedSizeWithTag(tag: Int, value: E?): Int

The size of tag and value in the wire format. This size includes the tag, type, length-delimited prefix (should the type require one), and value. Returns 0 if value is null.

get

open static fun <M : Message<Message<*, *>, Builder<*, *>>> get(message: M): ProtoAdapter<M>

Returns the adapter for the type of Message.

open static fun <M : Any> get(type: Class<M>): ProtoAdapter<M>

Returns the adapter for type.

open static fun get(adapterString: String): ProtoAdapter<*>

Returns the adapter for a given adapterString. adapterString is specified on a proto message field's WireField annotation in the form com.squareup.wire.protos.person.Person#ADAPTER.

newEnumAdapter

open static fun <E : WireEnum> newEnumAdapter(type: Class<E>): RuntimeEnumAdapter<E>

Creates a new proto adapter for type.

newMapAdapter

open static fun <K : Any, V : Any> newMapAdapter(keyAdapter: ProtoAdapter<K>, valueAdapter: ProtoAdapter<V>): ProtoAdapter<MutableMap<K, V>>

Creates a new proto adapter for a map using 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.

newMessageAdapter

open static fun <M : Message<M, B>, B : Builder<M, B>> newMessageAdapter(type: Class<M>): ProtoAdapter<M>

Creates a new proto adapter for type.

redact

open fun redact(value: E): E?

Returns the redacted form of value.

toString

open fun toString(value: E): String

Returns a human-readable version of the given value.

Inheritors

EnumAdapter

abstract class EnumAdapter<E : WireEnum> : ProtoAdapter<E>

An abstract ProtoAdapter that converts values of an enum to and from integers.