com.google.protobuf.FloatValue Java Examples
The following examples show how to use
com.google.protobuf.FloatValue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WrappedPrimitiveTest.java From jackson-datatype-protobuf with Apache License 2.0 | 6 votes |
@Test public void itSetsFieldsWhenZeroInJson() throws IOException { String json = camelCase().writeValueAsString(defaultPopulatedJsonNode(camelCase())); HasWrappedPrimitives message = camelCase().readValue(json, HasWrappedPrimitives.class); assertThat(message.hasDoubleWrapper()).isTrue(); assertThat(message.getDoubleWrapper()).isEqualTo(DoubleValue.getDefaultInstance()); assertThat(message.hasFloatWrapper()).isTrue(); assertThat(message.getFloatWrapper()).isEqualTo(FloatValue.getDefaultInstance()); assertThat(message.hasInt64Wrapper()).isTrue(); assertThat(message.getInt64Wrapper()).isEqualTo(Int64Value.getDefaultInstance()); assertThat(message.hasUint64Wrapper()).isTrue(); assertThat(message.getUint64Wrapper()).isEqualTo(UInt64Value.getDefaultInstance()); assertThat(message.hasInt32Wrapper()).isTrue(); assertThat(message.getInt32Wrapper()).isEqualTo(Int32Value.getDefaultInstance()); assertThat(message.hasUint32Wrapper()).isTrue(); assertThat(message.getUint32Wrapper()).isEqualTo(UInt32Value.getDefaultInstance()); assertThat(message.hasBoolWrapper()).isTrue(); assertThat(message.getBoolWrapper()).isEqualTo(BoolValue.getDefaultInstance()); assertThat(message.hasStringWrapper()).isTrue(); assertThat(message.getStringWrapper()).isEqualTo(StringValue.getDefaultInstance()); assertThat(message.hasBytesWrapper()).isTrue(); assertThat(message.getBytesWrapper()).isEqualTo(BytesValue.getDefaultInstance()); }
Example #2
Source File: SetupRemarketing.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Updates the bid modifier on a campaign criterion. * * @param googleAdsClient the Google Ads API client. * @param customerId the client customer ID. * @param campaignCriterionResourceName the campaign criterion to update. * @param bidModifier the bid modifier. */ private void modifyCampaignBids( GoogleAdsClient googleAdsClient, long customerId, String campaignCriterionResourceName, double bidModifier) { // Creates the campaign criterion to update. CampaignCriterion campaignCriterion = CampaignCriterion.newBuilder() .setResourceName(campaignCriterionResourceName) .setBidModifier(FloatValue.of((float) bidModifier)) .build(); // Creates the update operation. CampaignCriterionOperation operation = CampaignCriterionOperation.newBuilder() .setUpdate(campaignCriterion) .setUpdateMask(FieldMasks.allSetFieldsOf(campaignCriterion)) .build(); // Creates the campaign criterion service client. try (CampaignCriterionServiceClient campaignCriterionServiceClient = googleAdsClient.getLatestVersion().createCampaignCriterionServiceClient()) { // Updates the campaign criterion. MutateCampaignCriteriaResponse response = campaignCriterionServiceClient.mutateCampaignCriteria( Long.toString(customerId), ImmutableList.of(operation)); System.out.printf( "Successfully updated the bid for campaign criterion with resource name '%s'.%n", response.getResults(0).getResourceName()); } }
Example #3
Source File: WrappedPrimitiveTest.java From jackson-datatype-protobuf with Apache License 2.0 | 5 votes |
private static HasWrappedPrimitives defaultPopulatedMessage() { return HasWrappedPrimitives .newBuilder() .setDoubleWrapper(DoubleValue.getDefaultInstance()) .setFloatWrapper(FloatValue.getDefaultInstance()) .setInt64Wrapper(Int64Value.getDefaultInstance()) .setUint64Wrapper(UInt64Value.getDefaultInstance()) .setInt32Wrapper(Int32Value.getDefaultInstance()) .setUint32Wrapper(UInt32Value.getDefaultInstance()) .setBoolWrapper(BoolValue.getDefaultInstance()) .setStringWrapper(StringValue.getDefaultInstance()) .setBytesWrapper(BytesValue.getDefaultInstance()) .build(); }
Example #4
Source File: WellKnownTypeMarshaller.java From curiostack with MIT License | 4 votes |
FloatValueMarshaller() { super(FloatValue.getDefaultInstance()); }
Example #5
Source File: WellKnownTypeMarshaller.java From curiostack with MIT License | 4 votes |
@Override protected final void doMerge(JsonParser parser, int unused, Message.Builder messageBuilder) throws IOException { FloatValue.Builder builder = (FloatValue.Builder) messageBuilder; builder.setValue(ParseSupport.parseFloat(parser)); }
Example #6
Source File: WellKnownTypeMarshaller.java From curiostack with MIT License | 4 votes |
@Override protected final void doWrite(FloatValue message, JsonGenerator gen) throws IOException { SerializeSupport.printFloat(message.getValue(), gen); }
Example #7
Source File: MessageMarshallerTest.java From curiostack with MIT License | 4 votes |
@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()); }
Example #8
Source File: ProtobufModule.java From jackson-datatype-protobuf with Apache License 2.0 | 4 votes |
@Override public void setupModule(SetupContext context) { SimpleSerializers serializers = new SimpleSerializers(); serializers.addSerializer(new MessageSerializer(config)); serializers.addSerializer(new DurationSerializer()); serializers.addSerializer(new FieldMaskSerializer()); serializers.addSerializer(new ListValueSerializer()); serializers.addSerializer(new NullValueSerializer()); serializers.addSerializer(new StructSerializer()); serializers.addSerializer(new TimestampSerializer()); serializers.addSerializer(new ValueSerializer()); serializers.addSerializer(new WrappedPrimitiveSerializer<>(DoubleValue.class)); serializers.addSerializer(new WrappedPrimitiveSerializer<>(FloatValue.class)); serializers.addSerializer(new WrappedPrimitiveSerializer<>(Int64Value.class)); serializers.addSerializer(new WrappedPrimitiveSerializer<>(UInt64Value.class)); serializers.addSerializer(new WrappedPrimitiveSerializer<>(Int32Value.class)); serializers.addSerializer(new WrappedPrimitiveSerializer<>(UInt32Value.class)); serializers.addSerializer(new WrappedPrimitiveSerializer<>(BoolValue.class)); serializers.addSerializer(new WrappedPrimitiveSerializer<>(StringValue.class)); serializers.addSerializer(new WrappedPrimitiveSerializer<>(BytesValue.class)); context.addSerializers(serializers); context.addDeserializers(new MessageDeserializerFactory(config)); SimpleDeserializers deserializers = new SimpleDeserializers(); deserializers.addDeserializer(Duration.class, new DurationDeserializer()); deserializers.addDeserializer(FieldMask.class, new FieldMaskDeserializer()); deserializers.addDeserializer(ListValue.class, new ListValueDeserializer().buildAtEnd()); deserializers.addDeserializer(NullValue.class, new NullValueDeserializer()); deserializers.addDeserializer(Struct.class, new StructDeserializer().buildAtEnd()); deserializers.addDeserializer(Timestamp.class, new TimestampDeserializer()); deserializers.addDeserializer(Value.class, new ValueDeserializer().buildAtEnd()); deserializers.addDeserializer(DoubleValue.class, wrappedPrimitiveDeserializer(DoubleValue.class)); deserializers.addDeserializer(FloatValue.class, wrappedPrimitiveDeserializer(FloatValue.class)); deserializers.addDeserializer(Int64Value.class, wrappedPrimitiveDeserializer(Int64Value.class)); deserializers.addDeserializer(UInt64Value.class, wrappedPrimitiveDeserializer(UInt64Value.class)); deserializers.addDeserializer(Int32Value.class, wrappedPrimitiveDeserializer(Int32Value.class)); deserializers.addDeserializer(UInt32Value.class, wrappedPrimitiveDeserializer(UInt32Value.class)); deserializers.addDeserializer(BoolValue.class, wrappedPrimitiveDeserializer(BoolValue.class)); deserializers.addDeserializer(StringValue.class, wrappedPrimitiveDeserializer(StringValue.class)); deserializers.addDeserializer(BytesValue.class, wrappedPrimitiveDeserializer(BytesValue.class)); context.addDeserializers(deserializers); context.setMixInAnnotations(MessageOrBuilder.class, MessageOrBuilderMixin.class); }
Example #9
Source File: AllMapValuesTest.java From jackson-datatype-protobuf with Apache License 2.0 | 4 votes |
private static HasAllMapValues hasAllMapValues() { Value value = Value.newBuilder().setStringValue("test").build(); ByteString byteString = ByteString.copyFromUtf8("test"); Any any = Any .newBuilder() .setTypeUrl("type.googleapis.com/google.protobuf.Value") .setValue(value.toByteString()) .build(); return HasAllMapValues .newBuilder() .putDoubleMap("double", 1.5d) .putFloatMap("float", 2.5f) .putInt32Map("int32", 1) .putInt64Map("int64", 2) .putUint32Map("uint32", 3) .putUint64Map("uint64", 4) .putSint32Map("sint32", 5) .putSint64Map("sint64", 6) .putFixed32Map("fixed32", 7) .putFixed64Map("fixed64", 8) .putSfixed32Map("sfixed32", 9) .putSfixed64Map("sfixed64", 10) .putBoolMap("bool", true) .putStringMap("string", "test") .putBytesMap("bytes", byteString) .putAnyMap("any", any) .putDurationMap("duration", Duration.newBuilder().setSeconds(30).build()) .putFieldMaskMap("field_mask", FieldMask.newBuilder().addPaths("path_one").addPaths("path_two").build()) .putListValueMap("list_value", ListValue.newBuilder().addValues(value).build()) .putNullValueMap("null_value", NullValue.NULL_VALUE) .putStructMap("struct", Struct.newBuilder().putFields("field", value).build()) .putTimestampMap("timestamp", Timestamp.newBuilder().setSeconds(946684800).build()) .putValueMap("value", value) .putDoubleWrapperMap("double_wrapper", DoubleValue.newBuilder().setValue(3.5d).build()) .putFloatWrapperMap("float_wrapper", FloatValue.newBuilder().setValue(4.5f).build()) .putInt32WrapperMap("int32_wrapper", Int32Value.newBuilder().setValue(11).build()) .putInt64WrapperMap("int64_wrapper", Int64Value.newBuilder().setValue(12).build()) .putUint32WrapperMap("uint32_wrapper", UInt32Value.newBuilder().setValue(13).build()) .putUint64WrapperMap("uint64_wrapper", UInt64Value.newBuilder().setValue(14).build()) .putBoolWrapperMap("bool_wrapper", BoolValue.newBuilder().setValue(true).build()) .putStringWrapperMap("string_wrapper", StringValue.newBuilder().setValue("test").build()) .putBytesWrapperMap("bytes_wrapper", BytesValue.newBuilder().setValue(byteString).build()) .putEnumMap("enum", EnumProto3.FIRST) .putProto2MessageMap("proto2", AllFields.newBuilder().setString("proto2").build()) .putProto3MessageMap("proto3", AllFieldsProto3.newBuilder().setString("proto3").build()) .build(); }