本文整理了Java中com.google.protobuf.Any.getTypeUrl()
方法的一些代码示例,展示了Any.getTypeUrl()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Any.getTypeUrl()
方法的具体详情如下:
包路径:com.google.protobuf.Any
类名称:Any
方法名:getTypeUrl
[英]```
A URL/resource name whose content describes the type of the
serialized protocol buffer message.
For URLs which use the scheme http
, https
, or no scheme, the
following restrictions and interpretations apply:
https
is assumed.path/google.protobuf.Duration
).http
, https
(or the empty scheme) might be`optional string type_url = 1;`
[中]```
A URL/resource name whose content describes the type of the
serialized protocol buffer message.
For URLs which use the scheme `http`, `https`, or no scheme, the
following restrictions and interpretations apply:
* If no scheme is provided, `https` is assumed.
* The last segment of the URL's path must represent the fully
qualified name of the type (as in `path/google.protobuf.Duration`).
The name should be in a canonical form (e.g., leading "." is
not accepted).
* An HTTP GET on the URL must yield a [google.protobuf.Type][]
value in binary format, or produce an error.
* Applications are allowed to cache lookup results based on the
URL, or have them precompiled into a binary to avoid any
lookup. Therefore, binary compatibility needs to be preserved
on changes to types. (Use versioned type names to manage
breaking changes.)
Schemes other than `http`, `https` (or the empty scheme) might be
used with implementation specific semantics.
optional string type_url = 1;
代码示例来源:origin: com.google.protobuf/protobuf-java
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.google.protobuf.Any)) {
return super.equals(obj);
}
com.google.protobuf.Any other = (com.google.protobuf.Any) obj;
boolean result = true;
result = result && getTypeUrl()
.equals(other.getTypeUrl());
result = result && getValue()
.equals(other.getValue());
result = result && unknownFields.equals(other.unknownFields);
return result;
}
代码示例来源:origin: Netflix/conductor
@Override
public void serialize(Any value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
jgen.writeStartObject();
jgen.writeStringField(JSON_TYPE, value.getTypeUrl());
jgen.writeBinaryField(JSON_VALUE, value.getValue().toByteArray());
jgen.writeEndObject();
}
}
代码示例来源:origin: com.google.protobuf/protobuf-java
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + TYPE_URL_FIELD_NUMBER;
hash = (53 * hash) + getTypeUrl().hashCode();
hash = (37 * hash) + VALUE_FIELD_NUMBER;
hash = (53 * hash) + getValue().hashCode();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
代码示例来源:origin: com.google.protobuf/protobuf-java
public <T extends com.google.protobuf.Message> boolean is(
java.lang.Class<T> clazz) {
T defaultInstance =
com.google.protobuf.Internal.getDefaultInstance(clazz);
return getTypeNameFromTypeUrl(getTypeUrl()).equals(
defaultInstance.getDescriptorForType().getFullName());
}
代码示例来源:origin: com.google.protobuf/protobuf-java
typeUrl_ = getDefaultInstance().getTypeUrl();
onChanged();
return this;
代码示例来源:origin: com.google.protobuf/protobuf-java
public Builder mergeFrom(com.google.protobuf.Any other) {
if (other == com.google.protobuf.Any.getDefaultInstance()) return this;
if (!other.getTypeUrl().isEmpty()) {
typeUrl_ = other.typeUrl_;
onChanged();
}
if (other.getValue() != com.google.protobuf.ByteString.EMPTY) {
setValue(other.getValue());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
代码示例来源:origin: com.google.protobuf/protobuf-java
public static <T extends com.google.protobuf.Message> Any pack(
T message) {
return Any.newBuilder()
.setTypeUrl(getTypeUrl("type.googleapis.com",
message.getDescriptorForType()))
.setValue(message.toByteString())
.build();
}
代码示例来源:origin: com.google.protobuf/protobuf-java
/**
* Packs a message using the given type URL prefix. The type URL will
* be constructed by concatenating the message type's full name to the
* prefix with an optional "/" separator if the prefix doesn't end
* with "/" already.
*/
public static <T extends com.google.protobuf.Message> Any pack(
T message, java.lang.String typeUrlPrefix) {
return Any.newBuilder()
.setTypeUrl(getTypeUrl(typeUrlPrefix,
message.getDescriptorForType()))
.setValue(message.toByteString())
.build();
}
代码示例来源:origin: Netflix/conductor
@Test
public void testSimpleMapping() throws JsonGenerationException, JsonMappingException, IOException {
ObjectMapper m = new JsonMapperProvider().get();
assertTrue(m.canSerialize(Any.class));
Struct struct1 = Struct.newBuilder().putFields(
"some-key", Value.newBuilder().setStringValue("some-value").build()
).build();
Any source = Any.pack(struct1);
StringWriter buf = new StringWriter();
m.writer().writeValue(buf, source);
Any dest = m.reader().forType(Any.class).readValue(buf.toString());
assertEquals(source.getTypeUrl(), dest.getTypeUrl());
Struct struct2 = dest.unpack(Struct.class);
assertTrue(struct2.containsFields("some-key"));
assertEquals(
struct1.getFieldsOrThrow("some-key").getStringValue(),
struct2.getFieldsOrThrow("some-key").getStringValue()
);
}
}
代码示例来源:origin: yeriomin/play-store-api
/**
* <pre>
* A URL/resource name whose content describes the type of the
* serialized protocol buffer message.
* For URLs which use the scheme `http`, `https`, or no scheme, the
* following restrictions and interpretations apply:
* * If no scheme is provided, `https` is assumed.
* * The last segment of the URL's path must represent the fully
* qualified name of the type (as in `path/google.protobuf.Duration`).
* The name should be in a canonical form (e.g., leading "." is
* not accepted).
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
* value in binary format, or produce an error.
* * Applications are allowed to cache lookup results based on the
* URL, or have them precompiled into a binary to avoid any
* lookup. Therefore, binary compatibility needs to be preserved
* on changes to types. (Use versioned type names to manage
* breaking changes.)
* Schemes other than `http`, `https` (or the empty scheme) might be
* used with implementation specific semantics.
* </pre>
*
* <code>optional string type_url = 1;</code>
*/
public java.lang.String getTypeUrl() {
return instance.getTypeUrl();
}
/**
代码示例来源:origin: yeriomin/play-store-api
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (!typeUrl_.isEmpty()) {
output.writeString(1, getTypeUrl());
}
if (!value_.isEmpty()) {
output.writeBytes(2, value_);
}
}
代码示例来源:origin: com.google.api/gax-grpc
@Override
public PackedT apply(Any input) {
try {
return input == null || packedClass == null ? null : input.unpack(packedClass);
} catch (InvalidProtocolBufferException | ClassCastException e) {
throw new IllegalStateException(
"Failed to unpack object from 'any' field. Expected "
+ packedClass.getName()
+ ", found "
+ input.getTypeUrl());
}
}
}
代码示例来源:origin: googleapis/gax-java
@Override
public PackedT apply(Any input) {
try {
return input == null || packedClass == null ? null : input.unpack(packedClass);
} catch (InvalidProtocolBufferException | ClassCastException e) {
throw new IllegalStateException(
"Failed to unpack object from 'any' field. Expected "
+ packedClass.getName()
+ ", found "
+ input.getTypeUrl());
}
}
}
代码示例来源:origin: yeriomin/play-store-api
public int getSerializedSize() {
int size = memoizedSerializedSize;
if (size != -1) return size;
size = 0;
if (!typeUrl_.isEmpty()) {
size += com.google.protobuf.CodedOutputStream
.computeStringSize(1, getTypeUrl());
}
if (!value_.isEmpty()) {
size += com.google.protobuf.CodedOutputStream
.computeBytesSize(2, value_);
}
memoizedSerializedSize = size;
return size;
}
代码示例来源:origin: com.netflix.conductor/conductor-common
@Override
public void serialize(Any value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
jgen.writeStartObject();
jgen.writeStringField(JSON_TYPE, value.getTypeUrl());
jgen.writeBinaryField(JSON_VALUE, value.getValue().toByteArray());
jgen.writeEndObject();
}
}
代码示例来源:origin: envoyproxy/java-control-plane
/**
* Returns the name of the given resource message.
*
* @param anyResource the resource message
* @throws RuntimeException if the passed Any doesn't correspond to an xDS resource
*/
public static String getResourceName(Any anyResource) {
Class<? extends Message> clazz = RESOURCE_TYPE_BY_URL.get(anyResource.getTypeUrl());
Preconditions.checkNotNull(clazz, "cannot unpack non-xDS message type");
try {
return getResourceName(anyResource.unpack(clazz));
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: yeriomin/play-store-api
/**
* <pre>
* A URL/resource name whose content describes the type of the
* serialized protocol buffer message.
* For URLs which use the scheme `http`, `https`, or no scheme, the
* following restrictions and interpretations apply:
* * If no scheme is provided, `https` is assumed.
* * The last segment of the URL's path must represent the fully
* qualified name of the type (as in `path/google.protobuf.Duration`).
* The name should be in a canonical form (e.g., leading "." is
* not accepted).
* * An HTTP GET on the URL must yield a [google.protobuf.Type][]
* value in binary format, or produce an error.
* * Applications are allowed to cache lookup results based on the
* URL, or have them precompiled into a binary to avoid any
* lookup. Therefore, binary compatibility needs to be preserved
* on changes to types. (Use versioned type names to manage
* breaking changes.)
* Schemes other than `http`, `https` (or the empty scheme) might be
* used with implementation specific semantics.
* </pre>
*
* <code>optional string type_url = 1;</code>
*/
private void clearTypeUrl() {
typeUrl_ = getDefaultInstance().getTypeUrl();
}
/**
代码示例来源:origin: microbean/microbean-helm
final Yaml yaml = new Yaml();
for (final Any file : files) {
if (file != null && "requirements.yaml".equals(file.getTypeUrl())) {
final ByteString fileContents = file.getValue();
if (fileContents != null) {
代码示例来源:origin: org.microbean/microbean-helm
final Yaml yaml = new Yaml();
for (final Any file : files) {
if (file != null && "requirements.yaml".equals(file.getTypeUrl())) {
final ByteString fileContents = file.getValue();
if (fileContents != null) {
代码示例来源:origin: googleapis/api-compiler
/**
* Attempt to unpack if its an any instance. Returns null if not unpacked.
*/
@Nullable private Message maybeUnpackAnyType(FieldDescriptor field, Object value) {
if (field.getType() == FieldDescriptor.Type.MESSAGE
&& field.getMessageType().getFullName().equals(Any.getDescriptor().getFullName())) {
Any any = (Any) value;
Message defaultInstance = anyConverterRegistry.get(any.getTypeUrl());
if (defaultInstance != null) {
try {
return defaultInstance.toBuilder().mergeFrom(any.getValue()).build();
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
}
}
return null;
}
内容来源于网络,如有侵权,请联系作者删除!