Re: The way to set value to extension in Protocol buffers

2009-01-09 Thread Alek Storm

On Jan 9, 1:32 am, chongyc chongy...@gmail.com wrote:
 I defined proto by following .

 message Ch {
   required int32        offset = 1;

 }

 message Foo {
   required string cmd = 1;

   extensions 1000 to max;

 }

 message Bar {
   extend Foo {
     required Ch ck = 1000;
   }

 }

 Then I generated c++ code from it.
 It's OK

 I am going to set value to extension ck()
 I compiled c++ source following below.

         term2relay::Foo f;
         term2relay::Bar b;
         term2relay::Ch c;

         c.set_offset (100);

        f.SetExtension(Bar::ck, c);

 But compiling failed in source code line
       f.SetExtension(Bar::ck, c);

 How to do it ?

 Please help me.

You don't need to create a Ch instance yourself - it's done for you
when you create a new Foo instance, which is analogous to the same
situation without extensions, but in this case, you need to get a
mutable pointer to your Ch instance.  Try this:

term2relay::Foo f;
term2relay::Ch* c = f.MutableExtension(Bar::ck);
c-set_offset(100);

You also need to change ck's label to 'optional'; otherwise you get an
assertion error.  Kenton, do all composite fields in extensions have
to be optional?  If so, can we document this?
--~--~-~--~~~---~--~~
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: The way to set value to extension in Protocol buffers

2009-01-09 Thread Kenton Varda
To give the same answer as Alek with slightly different wording:

The accessors for extensions are analogous to the accessors for a normal
field.  For a normal message-type field, there is no set accessor.  There
is only mutable.  For example:

  // Proto
  message Foo {
optional Bar bar = 1;
  }
  message Bar {
optional int32 i = 1;
  }

  // C++
  Foo foo;
  foo.mutable_bar()-set_i(1);

So with extensions, you should not use SetExtension() for embedded
messages.  You should use MutableExtension():

  f.MutableExtension(Bar::ck)-set_offset(100);

On Thu, Jan 8, 2009 at 11:32 PM, chongyc chongy...@gmail.com wrote:


 I defined proto by following .

 message Ch {
  required int32offset = 1;
 }

 message Foo {
  required string cmd = 1;

  extensions 1000 to max;
 }

 message Bar {
  extend Foo {
required Ch ck = 1000;
  }
 }

 Then I generated c++ code from it.
 It's OK

 I am going to set value to extension ck()
 I compiled c++ source following below.

term2relay::Foo f;
term2relay::Bar b;
term2relay::Ch c;

c.set_offset (100);

   f.SetExtension(Bar::ck, c);

 But compiling failed in source code line
  f.SetExtension(Bar::ck, c);

 How to do it ?

 Please help me.






 


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



Announcing Haskell protocol-buffers 1.4.0 (the smashing recursive edition)

2009-01-09 Thread Chris

Hello,

  What is Haskell protocol-buffers?
This provides a program 'hprotoc' which compiles a .proto file 
defining messages to Haskell modules, and the protocol-buffers API to 
access them and convert back and forth to the binary wire protocol, and 
protocol-buffers-descriptors which are messages which describe .proto 
files and allow for runtime reflection of annotated message definitions.

  The big addition to this version (which is 1.4.0) over the previous 
version (which was 1.2.0) is for when modules are in a dependency loop.  
The most common reason this happens is whenever a message is extended in 
the same proto file but outside of the message itself (e.g. at the top 
level).  This was salved in previous versions by telling the user to 
create boilerplate header files (a .hs-boot file) and add a few {-# 
SOURCE #-} pragmas.  This was primitive, and could not cover all the 
corner cases.

  Those days are gone.

  The new version of hprotoc uses the cutting edge version of 
haskell-src-exts (4.8.0) to generate not only the Haskell modules but 
also the hs-boot files and {-# SOURCE #-} pragmas!  This is truly a 
glorious way to start the New Year.

  But wait, there is more!  If a more than two messages define 
extensions of each other in a strongly connected dependency graph then 
the hs-boot files are not enough.  For these strange cases hprotoc will 
now generate modules ending with 'Key.hs that separately define the 
extensions.  You do not need to lift a finger, you never need to import 
these modules yourself, this all exists behind the scenes.  Also, 
hprotoc goes way out its way to reduce the number of .hs-boot and 
'Key.hs files, and it uses only a minimal set of {-# SOURCE #-} 
pragmas.  It is so painless that if I did not put this into this 
announcement you might not even know.

  Now all generated should compile with no changes or additions.
  Of course, hprotoc still generates nothing for services and methods.

Where to get the new shiny packages? hackage:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/protocol-buffers

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/protocol-buffers-descriptor

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hprotoc

And you will need haskell-src-exts, version 0.4.8, by Niklas Broberg:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/haskell-src-exts-0.4.8

(past version do not work and future versions will probably change 
enough to break compilation of hprotoc)

Happy New Year,
  Chris Kuklewicz


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