aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/google/common/io/protocol/ProtoBufUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/google/common/io/protocol/ProtoBufUtil.java')
-rw-r--r--src/com/google/common/io/protocol/ProtoBufUtil.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/com/google/common/io/protocol/ProtoBufUtil.java b/src/com/google/common/io/protocol/ProtoBufUtil.java
index 72e1bca..b47e79c 100644
--- a/src/com/google/common/io/protocol/ProtoBufUtil.java
+++ b/src/com/google/common/io/protocol/ProtoBufUtil.java
@@ -22,6 +22,25 @@ public final class ProtoBufUtil {
}
}
+ /** Convenience method to return a string value from of a proto or null. */
+ public static String getProtoValueOrNull(ProtoBuf proto, int tag) {
+ try {
+ return (proto != null && proto.has(tag)) ? proto.getString(tag) : null;
+ } catch (ClassCastException e) {
+ return null;
+ }
+ }
+
+ /** Convenience method to return a string value from of a proto or null. */
+ public static String getProtoValueOrNull(ProtoBuf proto, int tag, int index) {
+ try {
+ return (proto != null && proto.has(tag) && proto.getCount(tag) > index) ?
+ proto.getString(tag, index) : null;
+ } catch (ClassCastException e) {
+ return null;
+ }
+ }
+
/** Convenience method to return a string value from of a sub-proto or "". */
public static String getSubProtoValueOrEmpty(
ProtoBuf proto, int sub, int tag) {