I think I understand your example (there seem to be some things missing, or
maybe some typos?).

For enums, you should stick to the enumerator objects if you can, e.g.
(this is just a hypothetical example):
  builder.setStage(E.INTEGER)
In proto3, you can also use the int value if you need to:
  builder.setStage*Value*(1)
See also:

https://developers.google.com/protocol-buffers/docs/reference/java-generated#enum

For map fields, the generated code includes "put" functions, e.g.:
  String key = /* etc. */;
  builder.putDefinitions(key, Definition.newBuilder()./*...*/.build());
See also:

https://developers.google.com/protocol-buffers/docs/reference/java-generated#map-fields

On Tue, Jul 19, 2022 at 4:40 AM Jalaja Raj <jalajabhargav.r...@gmail.com>
wrote:

> Kindly share your thoughts/suggestions
>
> On Monday, July 18, 2022 at 9:47:24 PM UTC+5:30 Jalaja Raj wrote:
>
>> Hello,
>>
>> Below is a snippet of my proto file
>>
>> message UnitType {
>>     enum E {
>>         // Default - do not use
>>         UNDEFINED = 0;
>>         INTEGER = 1;
>>         DECIMAL = 2;
>>     }
>> }
>> message AdditionalKey {
>>     string name = 1;
>>     // If expected_values is empty, the value of the additional key can
>> be anything.
>>     // Otherwise, it should be one of the expected_values.
>>     repeated string expected_values = 2;
>> }
>>
>> // Definition of an accumulator for validation on writes
>> message Definition {
>>     UnitType.E unit_type = 1;
>>     // The stage in the adjudication pipeline that creates accumulators
>> of this definition.
>>     UnitType.E stage = 3;
>>     repeated AdditionalKey additional_keys = 2;
>> }
>>
>> message ReadAccumulatorDefinitionsResponse {
>>     // definitions is a map of accumulator name to corresponding
>> definition.
>>     // accumulator names that were not found in the database
>>     // will not be included in the definitions map.
>>     map<string, Definition> definitions = 1;
>> }
>>
>> I am trying to construct a test.java class for setting values to
>> instances of the above messages and the code snippet is as follows: -
>>
>> package accumulators;
>> import static org.testng.Assert.assertNotNull;
>>
>> import com.OscarHealth.accumulators.ReadAccumulatorNamesRequest;
>> import com.OscarHealth.accumulators.UnitType;
>> import com.OscarHealth.accumulators.UnitType.Builder;
>> import com.OscarHealth.accumulators.UnitType.E;
>> public class accumulatorsTest {
>>
>>     public static void main(String[] args) {
>>         // TODO Auto-generated method stub
>>
>>         /* ReadAccumulatorNamesRequest.Builder builder =
>> ReadAccumulatorNamesRequest.newBuilder();
>>         ReadAccumulatorNamesRequest req1 = builder
>>             .setStagesValue(2, 10)
>>             .build();
>>
>>         assertNotNull(req1); */
>>
>>         UnitType.Builder build = UnitType.newBuilder();
>>         UnitType req2 = ((Builder) build
>>                 .getDefaultInstanceForType()
>>                 .getField(null))
>>                 .build();
>>
>>
>>     }
>>
>> }
>>
>> However, I am not really sure on the correct values to be passed while
>> setting Enaums & Map data types.
>>
>> Kindly suggest and guide me here
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/905c8204-11a8-45e8-b94b-ea62fc9b525fn%40googlegroups.com
> <https://groups.google.com/d/msgid/protobuf/905c8204-11a8-45e8-b94b-ea62fc9b525fn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CAPOMCaFMhYQd7VJbdEMsWCv6AmVymPruZb4Hn2BZZmnFVxv3_A%40mail.gmail.com.

Reply via email to