本文整理汇总了Java中com.google.protobuf.BytesValue类的典型用法代码示例。如果您正苦于以下问题:Java BytesValue类的具体用法?Java BytesValue怎么用?Java BytesValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BytesValue类属于com.google.protobuf包,在下文中一共展示了BytesValue类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: shouldParseCompatibleTypes
import com.google.protobuf.BytesValue; //导入依赖的package包/类
@Test
public void shouldParseCompatibleTypes() throws IOException {
// Given:
final StringValue val = StringValue.newBuilder().setValue("test").build();
// When:
final byte[] buf;
try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
provider.writeTo(val, val.getClass(), null, EMPTY_ANNOTATIONS, ProtobufMediaType.MEDIA_TYPE, null, os);
buf = os.toByteArray();
}
// Then:
assertTrue(provider.isReadable(BytesValue.class, null, EMPTY_ANNOTATIONS, ProtobufMediaType.MEDIA_TYPE));
assertTrue(provider.isWriteable(BytesValue.class, null, EMPTY_ANNOTATIONS, ProtobufMediaType.MEDIA_TYPE));
try (final ByteArrayInputStream is = new ByteArrayInputStream(buf)) {
@SuppressWarnings("unchecked") final Class<Object> clazz = (Class) val.getClass();
final Object actual = provider.readFrom(clazz, null, EMPTY_ANNOTATIONS, ProtobufMediaType.MEDIA_TYPE, null, is);
assertEquals(val, actual);
}
}
开发者ID:truward,项目名称:protobuf-jaxrs,代码行数:23,代码来源:ProtobufProviderTest.java
示例2: BytesValueMarshaller
import com.google.protobuf.BytesValue; //导入依赖的package包/类
BytesValueMarshaller() {
super(BytesValue.getDefaultInstance());
}
开发者ID:curioswitch,项目名称:curiostack,代码行数:4,代码来源:WellKnownTypeMarshaller.java
示例3: doMerge
import com.google.protobuf.BytesValue; //导入依赖的package包/类
@Override
protected final void doMerge(JsonParser parser, int unused, Message.Builder messageBuilder)
throws IOException {
BytesValue.Builder b = (BytesValue.Builder) messageBuilder;
b.setValue(ParseSupport.parseBytes(parser));
}
开发者ID:curioswitch,项目名称:curiostack,代码行数:7,代码来源:WellKnownTypeMarshaller.java
示例4: doWrite
import com.google.protobuf.BytesValue; //导入依赖的package包/类
@Override
protected final void doWrite(BytesValue message, JsonGenerator gen) throws IOException {
SerializeSupport.printBytes(message.getValue(), gen);
}
开发者ID:curioswitch,项目名称:curiostack,代码行数:5,代码来源:WellKnownTypeMarshaller.java
示例5: anyFields
import com.google.protobuf.BytesValue; //导入依赖的package包/类
@Test
public void anyFields() throws Exception {
TestAllTypes content = TestAllTypes.newBuilder().setOptionalInt32(1234).build();
TestAny message = TestAny.newBuilder().setAnyValue(Any.pack(content)).build();
assertMatchesUpstream(message, TestAllTypes.getDefaultInstance());
TestAny messageWithDefaultAnyValue =
TestAny.newBuilder().setAnyValue(Any.getDefaultInstance()).build();
assertMatchesUpstream(messageWithDefaultAnyValue);
// Well-known types have a special formatting when embedded in Any.
//
// 1. Any in Any.
Any anyMessage = Any.pack(Any.pack(content));
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 2. Wrappers in Any.
anyMessage = Any.pack(Int32Value.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(UInt32Value.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(Int64Value.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(UInt64Value.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(FloatValue.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(DoubleValue.newBuilder().setValue(12345).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(BoolValue.newBuilder().setValue(true).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage = Any.pack(StringValue.newBuilder().setValue("Hello").build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
anyMessage =
Any.pack(BytesValue.newBuilder().setValue(ByteString.copyFrom(new byte[] {1, 2})).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 3. Timestamp in Any.
anyMessage = Any.pack(Timestamps.parse("1969-12-31T23:59:59Z"));
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 4. Duration in Any
anyMessage = Any.pack(Durations.parse("12345.10s"));
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 5. FieldMask in Any
anyMessage = Any.pack(FieldMaskUtil.fromString("foo.bar,baz"));
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 6. Struct in Any
Struct.Builder structBuilder = Struct.newBuilder();
structBuilder.putFields("number", Value.newBuilder().setNumberValue(1.125).build());
anyMessage = Any.pack(structBuilder.build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 7. Value (number type) in Any
Value.Builder valueBuilder = Value.newBuilder();
valueBuilder.setNumberValue(1);
anyMessage = Any.pack(valueBuilder.build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
// 8. Value (null type) in Any
anyMessage = Any.pack(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build());
assertMatchesUpstream(anyMessage, TestAllTypes.getDefaultInstance());
}
开发者ID:curioswitch,项目名称:curiostack,代码行数:66,代码来源:MessageMarshallerTest.java
示例6: shouldNotReadIncompatibleMessages
import com.google.protobuf.BytesValue; //导入依赖的package包/类
@Test
public void shouldNotReadIncompatibleMessages() {
assertFalse(provider.isReadable(String.class, null, EMPTY_ANNOTATIONS, MediaType.TEXT_PLAIN_TYPE));
assertFalse(provider.isReadable(String.class, null, EMPTY_ANNOTATIONS, MediaType.APPLICATION_JSON_TYPE));
assertFalse(provider.isReadable(BytesValue.class, null, EMPTY_ANNOTATIONS, MediaType.TEXT_PLAIN_TYPE));
}
开发者ID:truward,项目名称:protobuf-jaxrs,代码行数:7,代码来源:ProtobufJacksonProviderTest.java
示例7: shouldNotWriteIncompatibleMessages
import com.google.protobuf.BytesValue; //导入依赖的package包/类
@Test
public void shouldNotWriteIncompatibleMessages() {
assertFalse(provider.isWriteable(String.class, null, EMPTY_ANNOTATIONS, MediaType.TEXT_PLAIN_TYPE));
assertFalse(provider.isWriteable(String.class, null, EMPTY_ANNOTATIONS, MediaType.APPLICATION_JSON_TYPE));
assertFalse(provider.isWriteable(BytesValue.class, null, EMPTY_ANNOTATIONS, MediaType.TEXT_PLAIN_TYPE));
}
开发者ID:truward,项目名称:protobuf-jaxrs,代码行数:7,代码来源:ProtobufJacksonProviderTest.java
示例8: shouldNotReadIncompatibleMessages
import com.google.protobuf.BytesValue; //导入依赖的package包/类
@Test
public void shouldNotReadIncompatibleMessages() {
assertFalse(provider.isReadable(String.class, null, EMPTY_ANNOTATIONS, MediaType.TEXT_PLAIN_TYPE));
assertFalse(provider.isReadable(String.class, null, EMPTY_ANNOTATIONS, ProtobufMediaType.MEDIA_TYPE));
assertFalse(provider.isReadable(BytesValue.class, null, EMPTY_ANNOTATIONS, MediaType.TEXT_PLAIN_TYPE));
}
开发者ID:truward,项目名称:protobuf-jaxrs,代码行数:7,代码来源:ProtobufProviderTest.java
示例9: shouldNotWriteIncompatibleMessages
import com.google.protobuf.BytesValue; //导入依赖的package包/类
@Test
public void shouldNotWriteIncompatibleMessages() {
assertFalse(provider.isWriteable(String.class, null, EMPTY_ANNOTATIONS, MediaType.TEXT_PLAIN_TYPE));
assertFalse(provider.isWriteable(String.class, null, EMPTY_ANNOTATIONS, ProtobufMediaType.MEDIA_TYPE));
assertFalse(provider.isWriteable(BytesValue.class, null, EMPTY_ANNOTATIONS, MediaType.TEXT_PLAIN_TYPE));
}
开发者ID:truward,项目名称:protobuf-jaxrs,代码行数:7,代码来源:ProtobufProviderTest.java
示例10: toAnyType
import com.google.protobuf.BytesValue; //导入依赖的package包/类
/**
* Convert a protocol buffer field value to {@link Any} with the below rule:
* <ul>
* <li> If the field is a primitive type and can be mapped to a wrapper message type
* defined in //tech/type/proto/wrappers.proto, its value is boxed into a wrapper
* and goes to Any.value, the type name of the wrapper goes to Any.type_url.
* <li> If the field is already a message, its type name goes to Any.type_url,
* its value directly goes to Any.value
* <li> If the field is an enum value, the name of the enum value is boxed into
* tech.type.String and put into Any.value, and tech.type.String goes to Any.type_url.
*/
private static Any toAnyType(FieldDescriptor.Type protobufType, Object value) {
Any.Builder builder = Any.newBuilder();
java.lang.String typeFullName;
Message wrapperMessage;
switch (protobufType) {
case MESSAGE:
wrapperMessage = (Message) value;
typeFullName = wrapperMessage.getDescriptorForType().getFullName();
break;
case ENUM:
// NOTE: Erasing the enum type to the String wrapper is currently intentional, to avoid
// the need to add an enum wrapper type. This may change in the future.
typeFullName = StringValue.getDescriptor().getFullName();
wrapperMessage =
StringValue.newBuilder().setValue(((EnumValueDescriptor) value).getName()).build();
break;
case BOOL:
typeFullName = BoolValue.getDescriptor().getFullName();
wrapperMessage = BoolValue.newBuilder().setValue((Boolean) value).build();
break;
case DOUBLE:
typeFullName = DoubleValue.getDescriptor().getFullName();
wrapperMessage = DoubleValue.newBuilder().setValue((java.lang.Double) value).build();
break;
case FLOAT:
typeFullName = FloatValue.getDescriptor().getFullName();
wrapperMessage = FloatValue.newBuilder().setValue((java.lang.Float) value).build();
break;
case STRING:
typeFullName = StringValue.getDescriptor().getFullName();
wrapperMessage = StringValue.newBuilder().setValue((java.lang.String) value).build();
break;
case SINT32:
case SFIXED32:
case INT32:
typeFullName = Int32Value.getDescriptor().getFullName();
wrapperMessage = Int32Value.newBuilder().setValue((Integer) value).build();
break;
case SINT64:
case SFIXED64:
case INT64:
typeFullName = Int64Value.getDescriptor().getFullName();
wrapperMessage = Int64Value.newBuilder().setValue((Long) value).build();
break;
case UINT32:
case FIXED32:
typeFullName = UInt32Value.getDescriptor().getFullName();
wrapperMessage = UInt32Value.newBuilder().setValue((Integer) value).build();
break;
case UINT64:
case FIXED64:
typeFullName = UInt64Value.getDescriptor().getFullName();
wrapperMessage = UInt64Value.newBuilder().setValue((Long) value).build();
break;
case BYTES:
typeFullName = BytesValue.getDescriptor().getFullName();
wrapperMessage = BytesValue.newBuilder().setValue(ByteString.copyFrom((byte[]) value))
.build();
break;
default:
throw new IllegalArgumentException("Type " + protobufType.name()
+ " cannot be converted to Any type.");
}
return builder.setTypeUrl(TYPE_SERVICE_BASE_URL + "/" + typeFullName)
.setValue(wrapperMessage.toByteString()).build();
}
开发者ID:googleapis,项目名称:api-compiler,代码行数:78,代码来源:DescriptorNormalization.java
示例11: return_byte_string_msg_field_class_by_descriptor
import com.google.protobuf.BytesValue; //导入依赖的package包/类
@Test
public void return_byte_string_msg_field_class_by_descriptor() {
assertReturnsFieldClass(ByteString.class, BytesValue.getDescriptor());
}
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:5,代码来源:FieldShould.java
注:本文中的com.google.protobuf.BytesValue类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论