[protobuf] Does protobuf support : ParseFromArray without typeName ??

2018-01-04 Thread 陆林
auto proto_des = 
google::protobuf::DescriptorPool::generated_pool()->FindMessageTypeByName(typeName);
auto proto_type = 
google::protobuf::MessageFactory::generated_factory()->GetPrototype(descriptor);
auto protobuf_message = type->New();
protobuf_message->ParseFromArray(buf, len);

when we know "typeName", 
we can get protobuf_message from an knowned length buf.

if we dont know "typeName", but we know this length of buf is of couse a 
protobuf message!!!
can we unserialize this buf to an protobuf message instance??

just like c struct:
struct T
{
int v;
};
T a;
a.v = 5;
char buf[128] = {0};
memcpy(buf, , sizeof(T));

T b;
memcpy(, buf, sizeof(T));
/
we can get b.v = 5;

can protobuf just act like this??



-- 
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] protoc input dependency checking (--dependency_out)

2018-01-04 Thread Arpit Baldeva
Hi,

I tried using --dependency_out option and ran into a few issues.

   1. It does not work with multiple files input. Are there any plans to 
   add that support? 
   2. I noticed that the dependency file includes the whole dependency 
   chain from other proto files. I am not sure if it is necessary. So if there 
   is foo.proto that includes bar.proto and someone makes a change in 
   bar.proto, I don't think generating code for foo.proto is a necessity. Is 
   there something I am missing here?
   3. The option actually did not work for me. But I did not dig into it 
   too much because I wanted to figure out 1&2 first.


Thanks.

-- 
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] Re: How can i copy pointer to each message??

2018-01-04 Thread 기준
Update

I'm digging Arena document. 
(https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.arena)
But if any expert who know better way plz tell me.

I wonder whether it's available using arena or not.

Thanks!

2018년 1월 4일 목요일 오후 9시 14분 31초 UTC+9, 기준 님의 말:
>
> I'm testing protocol buffers, but encountered segment fault that i can't 
> understand.
>
> My protocol buffer is below
>
> ```
> message Sub {
>   string value = 1;
> }
>
> message Wrapping {
>   int32 key = 1;
>   repeated Sub sub = 2;
> }
> ```
>
> Testing code is below
>
> ```
> void Test()
> {
>   gbtest::Sub* sub = new gbtest::Sub();
>
>   for(int i = 0 ; i<4 ; ++i)
>   {
> gbtest::Wrapping wrapping; // Local variable
> wrapping.mutable_sub()->AddAllocated(sub);
> wrapping.set_key(i);
>
> std::cout << "Size -> " << wrapping->mutable_sub()->size() << 
> std::endl;
>   }
> }
> ```
>
>
>
>
> I want copy sub's pointer to each newed wrapping rather than copy it's 
> data.
>
>
> How can i achieve this?
> Plz tell me how.
>
> Thanks.
>
>
>
>
>
>
>
>
>
>
>
>

-- 
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] Re: How can i copy pointer to each message??

2018-01-04 Thread 기준
Update

I found this from document. ( 
https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.repeated_field#RepeatedPtrField.AddAllocated.details
 
)

Add an already-allocated object, passing ownership to the RepeatedPtrField 

.

It seems it's not possible to do what i want unfortunately.

Since Sub's value going to be a very large data like 100KB, 
so i want to avoid copying data for each Wrapping.

*How can i just toss pointer to Wrapping object without passing new 
instance's ownership?*
*I will clear up newed instance after all jobs done.*





2018년 1월 4일 목요일 오후 9시 14분 31초 UTC+9, 기준 님의 말:
>
> I'm testing protocol buffers, but encountered segment fault that i can't 
> understand.
>
> My protocol buffer is below
>
> ```
> message Sub {
>   string value = 1;
> }
>
> message Wrapping {
>   int32 key = 1;
>   repeated Sub sub = 2;
> }
> ```
>
> Testing code is below
>
> ```
> void Test()
> {
>   gbtest::Sub* sub = new gbtest::Sub();
>
>   for(int i = 0 ; i<4 ; ++i)
>   {
> gbtest::Wrapping wrapping; // Local variable
> wrapping.mutable_sub()->AddAllocated(sub);
> wrapping.set_key(i);
>
> std::cout << "Size -> " << wrapping->mutable_sub()->size() << 
> std::endl;
>   }
> }
> ```
>
>
>
>
> I want copy sub's pointer to each newed wrapping rather than copy it's 
> data.
>
>
> How can i achieve this?
> Plz tell me how.
>
> Thanks.
>
>
>
>
>
>
>
>
>
>
>
>

-- 
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] How can i copy pointer to each message??

2018-01-04 Thread 기준
I'm testing protocol buffers, but encountered segment fault that i can't 
understand.

My protocol buffer is below

```
message Sub {
  string value = 1;
}

message Wrapping {
  int32 key = 1;
  repeated Sub sub = 2;
}
```

Testing code is below

```
void Test()
{
  gbtest::Sub* sub = new gbtest::Sub();

  for(int i = 0 ; i<4 ; ++i)
  {
gbtest::Wrapping wrapping; // Local variable
wrapping.mutable_sub()->AddAllocated(sub);
wrapping.set_key(i);

std::cout << "Size -> " << wrapping->mutable_sub()->size() << std::endl;
  }
}
```




I want copy sub's pointer to each newed wrapping rather than copy it's data.


How can i achieve this?
Plz tell me how.

Thanks.











-- 
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.


[protobuf] Arranging protobuf files

2018-01-04 Thread oded . z
Hey!

So we use multiple languages for gRPC and thinking what's the best way to 
arrange our protobuf files. Should we place all in one repo with multiple 
folders (one per language, like they are arranged in 
https://github.com/google/protobuf), or multiple repo (each dedicated for a 
specific lang, like they are arranged in https://github.com/googleapis)

Thanks!!

-- 
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] setting fields in repeated messages rise exception

2018-01-04 Thread marcbegemot
Got it! the culprit is protobuf-lite 
If I switch to the standar protobuf everything goes smooth 


Is this a bug?? I'm not supposed to use protobuf little for androy 
development?
Thanks again

-- 
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] setting fields in repeated messages rise exception

2018-01-04 Thread marcbegemot
Thanks for help, my versions are : grpcVersion='0.8.3' protocVersion='3.5.1'

But if I only knew whether its feasible or not to modify the value of a 
repeated field it will be so grate!

I understand that once message it's build up it becomes immutable, but then 
you can resort to toBuilder() to make it again writeable, maybe I'm wrong. 

-- 
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.