From dca832adb5eb0ad336b0baaebf8d826c9b5ed125 Mon Sep 17 00:00:00 2001 From: ng0 Date: Tue, 5 Sep 2017 12:08:13 +0000 Subject: [PATCH] doc: gnunet-c-tutorial: include example 4 and 5. --- doc/gnunet-c-tutorial.texi | 22 ++++------------------ doc/tutorial-examples/004.c | 5 +++++ doc/tutorial-examples/005.c | 8 ++++++++ 3 files changed, 17 insertions(+), 18 deletions(-) create mode 100644 doc/tutorial-examples/004.c create mode 100644 doc/tutorial-examples/005.c diff --git a/doc/gnunet-c-tutorial.texi b/doc/gnunet-c-tutorial.texi index 2973dd779..a08888845 100644 --- a/doc/gnunet-c-tutorial.texi +++ b/doc/gnunet-c-tutorial.texi @@ -657,28 +657,14 @@ there are errors communicating with the service. In GNUnet, messages are always sent beginning with a {\tt struct GNUNET\_MessageHeader} in big endian format. This header defines the size and the type of the message, the payload follows after this header. - -\lstset{language=C} -\begin{lstlisting} -struct GNUNET_MessageHeader -{ - uint16_t size GNUNET_PACKED; - uint16_t type GNUNET_PACKED; -}; +@example +@verbatiminclude tutorial-examples/004.c @end example Existing message types are defined in @file{gnunet\_protocols.h}\\ A common way to create a message is with an envelope: - -\lstset{language=C} -\begin{lstlisting} -struct GNUNET_MQ_Envelope *env; -struct GNUNET_MessageHeader *msg; - -env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE); -memcpy (&msg[1], &payload, payload_size); -// Send message via message queue 'mq' -GNUNET_mq_send (mq, env); +@example +@verbatiminclude tutorial-examples/005.c @end example Exercise: Define a message struct that includes a 32-bit diff --git a/doc/tutorial-examples/004.c b/doc/tutorial-examples/004.c new file mode 100644 index 000000000..0ef007907 --- /dev/null +++ b/doc/tutorial-examples/004.c @@ -0,0 +1,5 @@ +struct GNUNET_MessageHeader +{ + uint16_t size GNUNET_PACKED; + uint16_t type GNUNET_PACKED; +}; diff --git a/doc/tutorial-examples/005.c b/doc/tutorial-examples/005.c new file mode 100644 index 000000000..0c459f509 --- /dev/null +++ b/doc/tutorial-examples/005.c @@ -0,0 +1,8 @@ +struct GNUNET_MQ_Envelope *env; +struct GNUNET_MessageHeader *msg; + +env = GNUNET_MQ_msg_extra (msg, payload_size, GNUNET_MY_MESSAGE_TYPE); +memcpy (&msg[1], &payload, payload_size); +// Send message via message queue 'mq' +GNUNET_mq_send (mq, env); + -- 2.25.1