Merge various proto utils together in core-util-jvm.

This commit is contained in:
Greyson Parrelli
2024-09-20 23:29:08 -04:00
parent 5b69d98579
commit ec49352635
17 changed files with 122 additions and 136 deletions

View File

@@ -1,20 +0,0 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.util
import com.google.protobuf.InvalidProtocolBufferException
import com.squareup.wire.ProtoAdapter
/**
* Performs the common pattern of attempting to decode a serialized proto and returning null if it fails to decode.
*/
fun <E> ProtoAdapter<E>.decodeOrNull(serialized: ByteArray): E? {
return try {
this.decode(serialized)
} catch (e: InvalidProtocolBufferException) {
null
}
}