mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-27 13:31:02 +08:00
git-svn-id: https://protobuf-c.googlecode.com/svn/trunk@167 00440858-1255-0410-a3e6-75ea37f81c3a
This commit is contained in:
parent
b826c3c569
commit
6a95f7b765
@ -47,7 +47,8 @@ called libprotobuf-c rather than generated code.</para>
|
|||||||
would generate a C type <type>Foo__Bar__BazBah</type>.</para>
|
would generate a C type <type>Foo__Bar__BazBah</type>.</para>
|
||||||
</listitem><listitem>
|
</listitem><listitem>
|
||||||
<para>Functions and globals are all lowercase, with camel-case
|
<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:
|
For example:
|
||||||
<programlisting><![CDATA[
|
<programlisting><![CDATA[
|
||||||
Foo__Bar__BazBah *foo__bar__baz_bah__unpack
|
Foo__Bar__BazBah *foo__bar__baz_bah__unpack
|
||||||
@ -78,8 +79,8 @@ called libprotobuf-c rather than generated code.</para>
|
|||||||
</section>
|
</section>
|
||||||
<section><title>Message Methods</title>
|
<section><title>Message Methods</title>
|
||||||
<para>
|
<para>
|
||||||
The message structures all begin with <type>ProtobufCMessageDescriptor*</type>
|
The message structures all begin with <type>ProtobufCMessage</type>,
|
||||||
which is sufficient to allow them to be cast to <type>ProtobufCMessage</type>.
|
so they may be cast to that type.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
We generate some functions for each message:
|
We generate some functions for each message:
|
||||||
@ -174,6 +175,7 @@ called libprotobuf-c rather than generated code.</para>
|
|||||||
We will get generated code:
|
We will get generated code:
|
||||||
<programlisting><![CDATA[
|
<programlisting><![CDATA[
|
||||||
struct _Convert_Service {
|
struct _Convert_Service {
|
||||||
|
ProtobufCService base;
|
||||||
void (*itoa) (Convert_Service *service,
|
void (*itoa) (Convert_Service *service,
|
||||||
const A *input,
|
const A *input,
|
||||||
B__Closure closure,
|
B__Closure closure,
|
||||||
@ -184,10 +186,7 @@ called libprotobuf-c rather than generated code.</para>
|
|||||||
void *closure_data);
|
void *closure_data);
|
||||||
void (*destroy) (Convert_Service *service);
|
void (*destroy) (Convert_Service *service);
|
||||||
};
|
};
|
||||||
ProtobufCService *convert__create_service (Foo__DirLookup_Service *service);
|
|
||||||
]]></programlisting>
|
]]></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[
|
<programlisting><![CDATA[
|
||||||
/* structure derived from Convert_Service. */
|
/* structure derived from Convert_Service. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -228,15 +227,16 @@ called libprotobuf-c rather than generated code.</para>
|
|||||||
create_convert_service_from_radix (unsigned radix)
|
create_convert_service_from_radix (unsigned radix)
|
||||||
{
|
{
|
||||||
Convert_WithRadix *wr = malloc (sizeof (Convert_WithRadix));
|
Convert_WithRadix *wr = malloc (sizeof (Convert_WithRadix));
|
||||||
|
convert__init (wr, (Convert__ServiceDestroy) free);
|
||||||
wr->base.itoa = radix_itoa;
|
wr->base.itoa = radix_itoa;
|
||||||
wr->base.atoi = radix_atoi;
|
wr->base.atoi = radix_atoi;
|
||||||
wr->base.destroy = (void(*)(Convert_Service *)) free;
|
|
||||||
wr->radix = radix;
|
wr->radix = radix;
|
||||||
return convert__create_service (&wr->base);
|
return (ProtobufCService *) wr;
|
||||||
}
|
}
|
||||||
]]></programlisting>
|
]]></programlisting>
|
||||||
Note that, unlike with messages, you must NOT cast
|
Just like with messages, you may cast
|
||||||
from <type>Convert_Service</type> to <type>ProtobufCService</type>.
|
from <type>Convert_Service</type> to <type>ProtobufCService</type>,
|
||||||
|
at least as long as you have run the __init function.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Conversely, we generate functions to help you invoke service
|
Conversely, we generate functions to help you invoke service
|
||||||
|
Loading…
x
Reference in New Issue
Block a user