decodeAs
Decode this packet's decoded.payload using the supplied Wire adapter.
Returns null when:
decodedis null (payload was never set, or the packet isencryptedonly),decoded.payloadis empty, orthe wire bytes fail to parse against adapter (any Throwable is swallowed and surfaced as
nullso callers can branch without atry/catch).
No portnum check — callers asserting a payload type are responsible for verifying decoded.portnum first if mismatch matters. The convenience overloads on this file (e.g. decodeAsPosition) bake in the matching portnum guard.
Why not reified? Wire's Kotlin runtime exposes one ADAPTER per generated message class, but does not expose a generic way to recover that adapter from a reified type parameter at the common-Kotlin level (no kotlin.reflect for proto types in commonMain, and Message.Companion.ADAPTER is per-class, not on a shared base companion). Passing the adapter explicitly is therefore the portable form; convenience overloads below cover the common payload types.
Example:
val pos = packet.decodeAs(Position.ADAPTER)Since
0.1.0