isWithinSizeLimit
fun <T : ERROR CLASS: Symbol not found for Message<T, *>> ERROR CLASS: Symbol not found for ProtoAdapter<T>.isWithinSizeLimit(message: T, maxBytes: Int): Boolean(source)
Check if an encoded message would fit within a size limit.
More accurate than checking ByteArray.size() as it uses Wire's actual encoding size calculation, which accounts for variable-length encoding.
Useful for:
Validating packet sizes before transmission
Enforcing payload limits
Better error messages with actual vs expected sizes
Example:
val data = Data(portnum = PortNum.TEXT_MESSAGE_APP, payload = bytes)
if (!Data.ADAPTER.isWithinSizeLimit(data, MAX_PAYLOAD)) {
throw RemoteException("Payload too large")
}Content copied to clipboard
Return
true if encodedSize(message) <= maxBytes
Parameters
message
The message to check
maxBytes
Maximum allowed bytes