public class Any extends Object
* `Any` contains an arbitrary serialized protocol buffer message along with a
URL that describes the type of the serialized message.
Protobuf library provides support to pack/unpack Any values in the form
of utility functions or additional generated methods of the Any type.
Foo foo = ...;
Any any = Any.pack(foo);
...
if (any.is(Foo.class)) {
foo = any.unpack(Foo.class);
}
| 构造器和说明 |
|---|
Any() |
| 限定符和类型 | 方法和说明 |
|---|---|
protected Class<?> |
getAsClass()
Gets the as class.
|
byte[] |
getByteArray()
Gets the byte array.
|
String |
getCodecClass()
Gets the codec class.
|
<T> boolean |
is(Class<T> cls)
Checks if is.
|
static Any |
pack(Object o)
Pack the target object to
Any object |
static Any |
pack(Object o,
String mappingClsName)
Pack the target object to
Any object |
void |
setByteArray(byte[] byteArray)
Sets the byte array.
|
void |
setCodecClass(String codecClass)
Sets the codec class.
|
String |
toString() |
<T> T |
unpack(Class<T> cls)
Unpack.
|
public String getCodecClass()
public void setCodecClass(String codecClass)
codecClass - the new codec classprotected Class<?> getAsClass()
public byte[] getByteArray()
public void setByteArray(byte[] byteArray)
byteArray - the new byte arraypublic static Any pack(Object o, String mappingClsName) throws IOException
Any objecto - the omappingClsName - the mapping class name for origin protobufIOException - Signals that an I/O exception has occurred.public static Any pack(Object o) throws IOException
Any objecto - the oIOException - Signals that an I/O exception has occurred.public <T> boolean is(Class<T> cls)
T - the generic typecls - the clspublic <T> T unpack(Class<T> cls) throws IOException
T - the generic typecls - the clsIOException - Signals that an I/O exception has occurred.Copyright © 2022 Baidu, Inc.. All rights reserved.