_has_bits_ and field bit definitions generated by protoc

2009-02-23 Thread timblack0

In my application, I have a need to track characteristics of message
fields on a field-by-field basis, e.g. has this field changed. This is
very much like what is already done in libprotobuf code for tracking
whether a field has been set yet. Looking under the hood, I found the
_has_bits_, a simple bitfield tracking mechanism, and thought I could
reuse this for tracking other characteristics my app is interested in.
So far, though, it looks like the bit numbers are hard-coded in the
_set_bit/_clear_bit/has_bit method calls. Is there any plan to modify
the compiler to define these field bits as constants or at least
#defines in the generated c++ header file?

Aside from this general question, is there another simple way you can
think of to track what fields have changed? I couldn't find anything
in the API that allowed diff'ing two instances of the same message
class. (I also couldn't find any equality operators, so had to define
that myself; please advise if this was unnecessary.)

Thanks,
Tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---



Re: _has_bits_ and field bit definitions generated by protoc

2009-02-23 Thread Kenton Varda
You could query the message's Descriptor to find out the field number and
index of each field, and then use one of those (probably the index).
  const Descriptor* descriptor = message.GetDescriptor()
  int foo_index = descriptor-FindFieldByName(foo)-index();

On Mon, Feb 23, 2009 at 7:42 PM, Tim timbla...@gmail.com wrote:


 OK, thanks. Just to clarify, I don't want access to _has_bits_, but
 just to the definition of which bit position corresponds to which
 field in the message. I.e., I want the compiler to do this:

 #define ATTR1_BIT 1
 ...
 _has_bit(ATTR1_BIT);

 instead of this:

 _has_bit(1);

 Then my application can use the ATTR1_BIT definitions to implement it
 own tracking of message field characteristics.

 Does that change anything?
 Tim

 On Feb 23, 7:18 pm, Kenton Varda ken...@google.com wrote:
  Hi Tim,
 
  On Mon, Feb 23, 2009 at 7:01 PM, timbla...@gmail.com wrote:
 
   In my application, I have a need to track characteristics of message
   fields on a field-by-field basis, e.g. has this field changed. This is
   very much like what is already done in libprotobuf code for tracking
   whether a field has been set yet. Looking under the hood, I found the
   _has_bits_, a simple bitfield tracking mechanism, and thought I could
   reuse this for tracking other characteristics my app is interested in.
   So far, though, it looks like the bit numbers are hard-coded in the
   _set_bit/_clear_bit/has_bit method calls. Is there any plan to modify
   the compiler to define these field bits as constants or at least
   #defines in the generated c++ header file?
 
  _has_bits_ is an internal (private) implementation detail.  We don't plan
 to
  make it publicly-accessible.
 
  Aside from this general question, is there another simple way you can
 
   think of to track what fields have changed? I couldn't find anything
   in the API that allowed diff'ing two instances of the same message
   class. (I also couldn't find any equality operators, so had to define
   that myself; please advise if this was unnecessary.)
 
  It's not included in the base library, but you could write code to do
 this
  based on reflection.
 
 
 
   Thanks,
   Tim
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~--~~~~--~~--~--~---