Re: [protobuf] How to erase particular field with MergeFrom()

2016-05-18 Thread Benjamin Krämer
And instead of encapsulating the field mask into a new message, you should 
be alright to just use google.protobuf.FieldMask as it is already a message 
by itself (in case that you don't add other data to RepAndOptMask of 
course).

Am Dienstag, 17. Mai 2016 10:51:04 UTC+2 schrieb Denis Bakhvalov:
>
>
> message RepAndOptMask
> {
> google.protobuf.FieldMask field_mask = 1;
> }
>
> I think there is nothing wrong if I will send them separately, right?
>

-- 
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] How to erase particular field with MergeFrom()

2016-05-17 Thread 'Feng Xiao' via Protocol Buffers
On Tue, May 17, 2016 at 1:49 AM, Denis Bakhvalov 
wrote:

> Hi Feng Xiao,
>
> Thanks for your reply!
>
> Unfortunately I couldn't find good examples how to use it, so let me ask
> one more question:
>
> Should I put mask as a part of original message:
>
> message RepAndOpt
> {
> repeated string name = 1;
> string surname = 2;
>
> google.protobuf.FieldMask field_mask = 3;
> }
>
> or put it as standalone message?
>
> message RepAndOptMask
> {
> google.protobuf.FieldMask field_mask = 1;
> }
>
> I think there is nothing wrong if I will send them separately, right?
>
It's probably more clear to put it separately from the original message
it's applied to, but either one works.


>
> понедельник, 16 мая 2016 г., 22:14:33 UTC+2 пользователь Feng Xiao написал:
>>
>>
>>
>> On Wed, May 11, 2016 at 5:09 AM, Denis Bakhvalov 
>> wrote:
>>
>>> Hi,
>>>
>>> Suppose I have such message structure:
>>>
>>>
>>> package msg_RepAndOpt;
>>>
>>> message RepAndOpt{
>>> repeated string name = 1;
>>> optional string surname = 2;
>>> ...
>>> // there are lots of others.}
>>>
>>>
>>> And I have two components that have copies of this message:
>>>
>>>
>>> // component1:RepAndOpt A;
>>> A.add_name("Name");
>>> A.set_surname("Surname");
>>> // component2:RepAndOpt B;
>>>
>>>
>>> In my case components modify those messages via transaction mechanism.
>>> It means that if one component changes some field it also sends it to
>>> another component to propagate those changes. Component-receiver is doing
>>> merge:
>>>
>>>
>>> // Component2 modifies B and sends it to component1.// Component1 perfoms 
>>> merge:
>>> A.MergeFrom(B);
>>>
>>>
>>> Now, say, component2 wants to erase field "name". If it will send clear
>>> B message (default construction) than:
>>>
>>>- - MergeFrom() will not modify A;
>>>- - CopyFrom() will erase also other fields.
>>>
>>> Another way will be to fill B with the contents of A, clear name field
>>> and component1 will use CopyFrom(). But this is not acceptable because
>>> system is really high-loaded and there could be lots of other fields. So,
>>> desired solution to clean name field is:
>>>
>>>1. 1. Component2 create B message.
>>>2. 2. Explicitly stores information that it want to erase only name
>>>field.
>>>3. 3. Component1 perform A.MergeFrom(B).
>>>4. 4. Result: A::name is cleared but other fields are left untouched.
>>>
>>> As far as I tested this applies to repeated and optional fields. Is
>>> there any ready-to-use solution or I should modify protobuf implementation?
>>>
>> I think you can do this using FieldMaskUtil:
>>
>> https://github.com/google/protobuf/blob/beta-3/src/google/protobuf/util/field_mask_util.h#L111
>>
>> You create an empty B message along with a FieldMask containing only the
>> field you want to clear, and use FieldMaskUtil::MergeMessageTo(A,
>> field_mask, )  to replace the field in A with the value from B.
>>
>>
>>
>>> --
>>> 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.
>

-- 
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] How to erase particular field with MergeFrom()

2016-05-17 Thread Denis Bakhvalov
Hi Feng Xiao,

Thanks for your reply!

Unfortunately I couldn't find good examples how to use it, so let me ask 
one more question:

Should I put mask as a part of original message:

message RepAndOpt
{
repeated string name = 1;
string surname = 2;

google.protobuf.FieldMask field_mask = 3;
}

or put it as standalone message?

message RepAndOptMask
{
google.protobuf.FieldMask field_mask = 1;
}

I think there is nothing wrong if I will send them separately, right?

-- 
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] How to erase particular field with MergeFrom()

2016-05-17 Thread Denis Bakhvalov
Hi Feng Xiao,

Thanks for your reply!

Unfortunately I couldn't find good examples how to use it, so let me ask 
one more question:

Should I put mask as a part of original message:

message RepAndOpt
{
repeated string name = 1;
string surname = 2;

google.protobuf.FieldMask field_mask = 3;
}

or put it as standalone message?

message RepAndOptMask
{
google.protobuf.FieldMask field_mask = 1;
}

I think there is nothing wrong if I will send them separately, right?

понедельник, 16 мая 2016 г., 22:14:33 UTC+2 пользователь Feng Xiao написал:
>
>
>
> On Wed, May 11, 2016 at 5:09 AM, Denis Bakhvalov  > wrote:
>
>> Hi,
>>
>> Suppose I have such message structure:
>>
>>
>> package msg_RepAndOpt;
>>
>> message RepAndOpt{
>> repeated string name = 1;
>> optional string surname = 2;
>> ...
>> // there are lots of others.}
>>
>>
>> And I have two components that have copies of this message:
>>
>>
>> // component1:RepAndOpt A;
>> A.add_name("Name");
>> A.set_surname("Surname");
>> // component2:RepAndOpt B;
>>
>>
>> In my case components modify those messages via transaction mechanism. It 
>> means that if one component changes some field it also sends it to another 
>> component to propagate those changes. Component-receiver is doing merge:
>>
>>
>> // Component2 modifies B and sends it to component1.// Component1 perfoms 
>> merge:
>> A.MergeFrom(B);
>>
>>
>> Now, say, component2 wants to erase field "name". If it will send clear B 
>> message (default construction) than:
>>
>>- - MergeFrom() will not modify A;
>>- - CopyFrom() will erase also other fields.
>>
>> Another way will be to fill B with the contents of A, clear name field 
>> and component1 will use CopyFrom(). But this is not acceptable because 
>> system is really high-loaded and there could be lots of other fields. So, 
>> desired solution to clean name field is:
>>
>>1. 1. Component2 create B message.
>>2. 2. Explicitly stores information that it want to erase only name 
>>field.
>>3. 3. Component1 perform A.MergeFrom(B).
>>4. 4. Result: A::name is cleared but other fields are left untouched.
>>
>> As far as I tested this applies to repeated and optional fields. Is there 
>> any ready-to-use solution or I should modify protobuf implementation?
>>
> I think you can do this using FieldMaskUtil:
>
> https://github.com/google/protobuf/blob/beta-3/src/google/protobuf/util/field_mask_util.h#L111
>
> You create an empty B message along with a FieldMask containing only the 
> field you want to clear, and use FieldMaskUtil::MergeMessageTo(A, 
> field_mask, )  to replace the field in A with the value from B.
>
>  
>
>> -- 
>> 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] How to erase particular field with MergeFrom()

2016-05-16 Thread 'Feng Xiao' via Protocol Buffers
On Wed, May 11, 2016 at 5:09 AM, Denis Bakhvalov 
wrote:

> Hi,
>
> Suppose I have such message structure:
>
>
> package msg_RepAndOpt;
>
> message RepAndOpt{
> repeated string name = 1;
> optional string surname = 2;
> ...
> // there are lots of others.}
>
>
> And I have two components that have copies of this message:
>
>
> // component1:RepAndOpt A;
> A.add_name("Name");
> A.set_surname("Surname");
> // component2:RepAndOpt B;
>
>
> In my case components modify those messages via transaction mechanism. It
> means that if one component changes some field it also sends it to another
> component to propagate those changes. Component-receiver is doing merge:
>
>
> // Component2 modifies B and sends it to component1.// Component1 perfoms 
> merge:
> A.MergeFrom(B);
>
>
> Now, say, component2 wants to erase field "name". If it will send clear B
> message (default construction) than:
>
>- - MergeFrom() will not modify A;
>- - CopyFrom() will erase also other fields.
>
> Another way will be to fill B with the contents of A, clear name field and
> component1 will use CopyFrom(). But this is not acceptable because system
> is really high-loaded and there could be lots of other fields. So, desired
> solution to clean name field is:
>
>1. 1. Component2 create B message.
>2. 2. Explicitly stores information that it want to erase only name
>field.
>3. 3. Component1 perform A.MergeFrom(B).
>4. 4. Result: A::name is cleared but other fields are left untouched.
>
> As far as I tested this applies to repeated and optional fields. Is there
> any ready-to-use solution or I should modify protobuf implementation?
>
I think you can do this using FieldMaskUtil:
https://github.com/google/protobuf/blob/beta-3/src/google/protobuf/util/field_mask_util.h#L111

You create an empty B message along with a FieldMask containing only the
field you want to clear, and use FieldMaskUtil::MergeMessageTo(A,
field_mask, )  to replace the field in A with the value from B.



> --
> 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] How to erase particular field with MergeFrom()

2016-05-16 Thread Denis Bakhvalov
Hi,

Suppose I have such message structure:


package msg_RepAndOpt;

message RepAndOpt{
repeated string name = 1;
optional string surname = 2;
...
// there are lots of others.}


And I have two components that have copies of this message:


// component1:RepAndOpt A;
A.add_name("Name");
A.set_surname("Surname");
// component2:RepAndOpt B;


In my case components modify those messages via transaction mechanism. It 
means that if one component changes some field it also sends it to another 
component to propagate those changes. Component-receiver is doing merge:


// Component2 modifies B and sends it to component1.// Component1 perfoms merge:
A.MergeFrom(B);


Now, say, component2 wants to erase field "name". If it will send clear B 
message (default construction) than:

   - - MergeFrom() will not modify A;
   - - CopyFrom() will erase also other fields.

Another way will be to fill B with the contents of A, clear name field and 
component1 will use CopyFrom(). But this is not acceptable because system 
is really high-loaded and there could be lots of other fields. So, desired 
solution to clean name field is:

   1. 1. Component2 create B message.
   2. 2. Explicitly stores information that it want to erase only name 
   field.
   3. 3. Component1 perform A.MergeFrom(B).
   4. 4. Result: A::name is cleared but other fields are left untouched.

As far as I tested this applies to repeated and optional fields. Is there 
any ready-to-use solution or I should modify protobuf implementation?

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