Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…255-0410-a3e6-75ea37f81c3a
  • Loading branch information
lahiker42 committed Feb 10, 2009
1 parent 3b88a65 commit 101cc37
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions doc/c-code-generator.xml
Expand Up @@ -47,7 +47,8 @@ called libprotobuf-c rather than generated code.</para>
would generate a C type <type>Foo__Bar__BazBah</type>.</para>
</listitem><listitem>
<para>Functions and globals are all lowercase, with camel-case
words separated by single underscores.
words separated by single underscores; namespaces are separated with
double-underscores.
For example:
<programlisting><![CDATA[
Foo__Bar__BazBah *foo__bar__baz_bah__unpack
Expand Down Expand Up @@ -78,8 +79,8 @@ called libprotobuf-c rather than generated code.</para>
</section>
<section><title>Message Methods</title>
<para>
The message structures all begin with <type>ProtobufCMessageDescriptor*</type>
which is sufficient to allow them to be cast to <type>ProtobufCMessage</type>.
The message structures all begin with <type>ProtobufCMessage</type>,
so they may be cast to that type.
</para>
<para>
We generate some functions for each message:
Expand Down Expand Up @@ -174,6 +175,7 @@ called libprotobuf-c rather than generated code.</para>
We will get generated code:
<programlisting><![CDATA[
struct _Convert_Service {
ProtobufCService base;
void (*itoa) (Convert_Service *service,
const A *input,
B__Closure closure,
Expand All @@ -184,10 +186,7 @@ called libprotobuf-c rather than generated code.</para>
void *closure_data);
void (*destroy) (Convert_Service *service);
};
ProtobufCService *convert__create_service (Foo__DirLookup_Service *service);
]]></programlisting>
Note that <function>create_service</function> takes ownership of <parameter>service</parameter>.
For example, here's how to implement a convert service that takes the default radix to use:
<programlisting><![CDATA[
/* structure derived from Convert_Service. */
typedef struct {
Expand Down Expand Up @@ -228,15 +227,16 @@ called libprotobuf-c rather than generated code.</para>
create_convert_service_from_radix (unsigned radix)
{
Convert_WithRadix *wr = malloc (sizeof (Convert_WithRadix));
convert__init (wr, (Convert__ServiceDestroy) free);
wr->base.itoa = radix_itoa;
wr->base.atoi = radix_atoi;
wr->base.destroy = (void(*)(Convert_Service *)) free;
wr->radix = radix;
return convert__create_service (&wr->base);
return (ProtobufCService *) wr;
}
]]></programlisting>
Note that, unlike with messages, you must NOT cast
from <type>Convert_Service</type> to <type>ProtobufCService</type>.
Just like with messages, you may cast
from <type>Convert_Service</type> to <type>ProtobufCService</type>,
at least as long as you have run the __init function.
</para>
<para>
Conversely, we generate functions to help you invoke service
Expand Down

0 comments on commit 101cc37

Please sign in to comment.