Re: [protobuf] Compile protobuf to use Java primitive classes instead of well-known types

2018-01-05 Thread Renatas M
Hi Josh, 

thank you a lot for informative answer.

2018 m. sausis 4 d., ketvirtadienis 15:34:37 UTC, Josh Humphries rašė:
>
> What you're asking for is not currently do-able. There is an existing 
> request to add this functionality though: 
> https://github.com/google/protobuf/issues/2055
>
> In the meantime, you can accomplish this using a custom plugin that is run 
> in addition to the normal java code-gen. Plugins can generate extra code 
> into existing Java source files using insertion points 
> .
>  
> So you could generate overloaded forms of the setter methods into the 
> relevant builder classes (via "builder_scope" insertion points).
>
> 
> *Josh Humphries*
> jh...@bluegosling.com 
>
> On Thu, Jan 4, 2018 at 7:13 AM, Renatas M  > wrote:
>
>> Lets say I have test.proto file:
>>
>> syntax = "proto3";
>> 
>> option java_package = "testing";
>> option java_outer_classname = "Test_v1";
>> 
>> import "google/protobuf/wrappers.proto";
>> 
>> message TestMessage {
>> .google.protobuf.Int32Value integerField = 1;
>> }
>>
>>
>> If I compile (using protoc v3.5.0) it to c# code I will get nullable type 
>> properties:
>>
>> public int? IntegerField {
>>get { return integerField_; }
>>set { integerField_ = value; }
>>  }
>>
>>
>> But if I compile it to Java code, fields will be of well-known type:
>>
>> public Builder setIntegerField(com.google.protobuf.Int32Value value) 
>> {
>>   if (integerFieldBuilder_ == null) {
>> if (value == null) {
>>   throw new NullPointerException();
>> }
>> integerField_ = value;
>> onChanged();
>>   } else {
>> integerFieldBuilder_.setMessage(value);
>>  }
>>
>>
>> I am moving project from proto2 to proto3 so I would like to avoid using 
>> well-known types, because it will require a lot of work to change related 
>> code. With c# projects I will not require to modify anything but in Java I 
>> will need to do as in the following example: 
>>
>> TestMessage.Builder builder = TestMessage.newBuilder();
>> builder.setIntegerField(5); //<-- instead of this (with proto2)
>> builder.setIntegerField(Int32Value.newBuilder().setValue(5)); //<-- 
>> I will need to change to something like this (with proto3)
>>
>>
>> Is there a way to compile proto file to Java so setters would accept 
>> primitive classes/wrappers (String, Integer, etc.) as parameters?
>>
>> -- 
>> 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+u...@googlegroups.com .
>> To post to this group, send email to prot...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/protobuf.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] Compile protobuf to use Java primitive classes instead of well-known types

2018-01-04 Thread Josh Humphries
What you're asking for is not currently do-able. There is an existing
request to add this functionality though:
https://github.com/google/protobuf/issues/2055

In the meantime, you can accomplish this using a custom plugin that is run
in addition to the normal java code-gen. Plugins can generate extra code
into existing Java source files using insertion points
.
So you could generate overloaded forms of the setter methods into the
relevant builder classes (via "builder_scope" insertion points).


*Josh Humphries*
jh...@bluegosling.com

On Thu, Jan 4, 2018 at 7:13 AM, Renatas M  wrote:

> Lets say I have test.proto file:
>
> syntax = "proto3";
>
> option java_package = "testing";
> option java_outer_classname = "Test_v1";
>
> import "google/protobuf/wrappers.proto";
>
> message TestMessage {
> .google.protobuf.Int32Value integerField = 1;
> }
>
>
> If I compile (using protoc v3.5.0) it to c# code I will get nullable type
> properties:
>
> public int? IntegerField {
>get { return integerField_; }
>set { integerField_ = value; }
>  }
>
>
> But if I compile it to Java code, fields will be of well-known type:
>
> public Builder setIntegerField(com.google.protobuf.Int32Value value) {
>   if (integerFieldBuilder_ == null) {
> if (value == null) {
>   throw new NullPointerException();
> }
> integerField_ = value;
> onChanged();
>   } else {
> integerFieldBuilder_.setMessage(value);
>  }
>
>
> I am moving project from proto2 to proto3 so I would like to avoid using
> well-known types, because it will require a lot of work to change related
> code. With c# projects I will not require to modify anything but in Java I
> will need to do as in the following example:
>
> TestMessage.Builder builder = TestMessage.newBuilder();
> builder.setIntegerField(5); //<-- instead of this (with proto2)
> builder.setIntegerField(Int32Value.newBuilder().setValue(5)); //<-- I
> will need to change to something like this (with proto3)
>
>
> Is there a way to compile proto file to Java so setters would accept
> primitive classes/wrappers (String, Integer, etc.) as parameters?
>
> --
> 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 post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] Compile protobuf to use Java primitive classes instead of well-known types

2018-01-04 Thread Renatas M
Lets say I have test.proto file:

syntax = "proto3";

option java_package = "testing";
option java_outer_classname = "Test_v1";

import "google/protobuf/wrappers.proto";

message TestMessage {
.google.protobuf.Int32Value integerField = 1;
}


If I compile (using protoc v3.5.0) it to c# code I will get nullable type 
properties:

public int? IntegerField {
   get { return integerField_; }
   set { integerField_ = value; }
 }


But if I compile it to Java code, fields will be of well-known type:

public Builder setIntegerField(com.google.protobuf.Int32Value value) {
  if (integerFieldBuilder_ == null) {
if (value == null) {
  throw new NullPointerException();
}
integerField_ = value;
onChanged();
  } else {
integerFieldBuilder_.setMessage(value);
 }


I am moving project from proto2 to proto3 so I would like to avoid using 
well-known types, because it will require a lot of work to change related 
code. With c# projects I will not require to modify anything but in Java I 
will need to do as in the following example: 

TestMessage.Builder builder = TestMessage.newBuilder();
builder.setIntegerField(5); //<-- instead of this (with proto2)
builder.setIntegerField(Int32Value.newBuilder().setValue(5)); //<-- I 
will need to change to something like this (with proto3)


Is there a way to compile proto file to Java so setters would accept 
primitive classes/wrappers (String, Integer, etc.) as parameters?

-- 
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 post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.