Methods Summary |
---|
public static ProtoBuf | addProtoBuf(ProtoBuf proto, int tag)Creates a sub ProtoBuf of the given Protobuf and adds it.
ProtoBuf child = proto.createGroup(tag);
proto.addProtoBuf(tag, child);
return child;
|
public static ProtoBuf | createProtoBuf(ProtoBuf proto, int tag)Creates a sub ProtoBuf of the given Protobuf and sets it.
ProtoBuf child = proto.createGroup(tag);
proto.setProtoBuf(tag, child);
return child;
|
public static long | getProtoLongValueOrZero(ProtoBuf proto, int tag)Get an Long with "tag" from the proto buffer.
If the given field can't be retrieved, return 0.
try {
return (proto != null && proto.has(tag)) ? proto.getLong(tag) : 0L;
} catch (IllegalArgumentException e) {
return 0L;
} catch (ClassCastException e) {
return 0L;
}
|
public static int | getProtoValueOrDefault(ProtoBuf proto, int tag, int defaultValue)Get an int with "tag" from the proto buffer. If the given field can't be
retrieved, return the provided default value.
try {
return (proto != null && proto.has(tag))
? proto.getInt(tag) : defaultValue;
} catch (IllegalArgumentException e) {
return defaultValue;
} catch (ClassCastException e) {
return defaultValue;
}
|
public static java.lang.String | getProtoValueOrEmpty(ProtoBuf proto, int tag)Convenience method to return a string value from of a proto or "".
try {
return (proto != null && proto.has(tag)) ? proto.getString(tag) : "";
} catch (ClassCastException e) {
return "";
}
|
public static long | getProtoValueOrNegativeOne(ProtoBuf proto, int tag)Get an Int with "tag" from the proto buffer.
If the given field can't be retrieved, return -1.
try {
return (proto != null && proto.has(tag)) ? proto.getLong(tag) : -1;
} catch (IllegalArgumentException e) {
return -1;
} catch (ClassCastException e) {
return -1;
}
|
public static int | getProtoValueOrZero(ProtoBuf proto, int tag)Get an Int with "tag" from the proto buffer.
If the given field can't be retrieved, return 0.
return getProtoValueOrDefault(proto, tag, 0);
|
public static ProtoBuf | getSubProtoOrNull(ProtoBuf proto, int sub)Convenience method to get a subproto if the proto has it.
return (proto != null && proto.has(sub)) ? proto.getProtoBuf(sub) : null;
|
public static int | getSubProtoValueOrDefault(ProtoBuf proto, int sub, int tag, int defaultValue)A wrapper for {@link #getProtoValueOrDefault(ProtoBuf, int, int)} that
drills into a sub message returning the int value if it exists, returning
the given default if it does not.
try {
return getProtoValueOrDefault(getSubProtoOrNull(proto, sub), tag,
defaultValue);
} catch (IllegalArgumentException e) {
return defaultValue;
} catch (ClassCastException e) {
return defaultValue;
}
|
public static java.lang.String | getSubProtoValueOrEmpty(ProtoBuf proto, int sub, int tag)Convenience method to return a string value from of a sub-proto or "".
try {
return getProtoValueOrEmpty(getSubProtoOrNull(proto, sub), tag);
} catch (ClassCastException e) {
return "";
}
|
public static long | getSubProtoValueOrNegativeOne(ProtoBuf proto, int sub, int tag)A wrapper for getProtoValueOrNegativeOne that drills into
a sub message returning the long value if it exists, returning -1 if it
does not.
try {
return getProtoValueOrNegativeOne(getSubProtoOrNull(proto, sub), tag);
} catch (IllegalArgumentException e) {
return -1;
} catch (ClassCastException e) {
return -1;
}
|
public static int | readNextProtoBuf(ProtoBufType umbrellaType, java.io.InputStream is, ProtoBuf result)Reads a single protocol buffer from the given input stream. This method is
provided where the client needs incremental access to the contents of a
protocol buffer which contains a sequence of protocol buffers.
Please use {@link #getInputStreamForProtoBufResponse} to obtain an input
stream suitable for this method.
long tagAndType = ProtoBuf.readVarInt(is, true /* permits EOF */);
if (tagAndType == -1) {
return -1;
}
if ((tagAndType & 7) != ProtoBuf.WIRETYPE_LENGTH_DELIMITED) {
throw new IOException("Message expected");
}
int tag = (int) (tagAndType >>> 3);
result.setType((ProtoBufType) umbrellaType.getData(tag));
int length = (int) ProtoBuf.readVarInt(is, false);
result.parse(is, length);
return tag;
|
public static void | writeProtoBufToOutput(java.io.DataOutput output, ProtoBuf protoBuf)Writes the ProtoBuf to the given DataOutput. This is useful for unit
tests.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
protoBuf.outputTo(baos);
byte[] bytes = baos.toByteArray();
output.writeInt(bytes.length);
output.write(bytes);
|