Add examples/pack.c
This commit is contained in:
parent
b1e81b4a16
commit
95f110cb18
2 changed files with 34 additions and 1 deletions
|
@ -7,7 +7,7 @@ INCLUDE_PATH = ../include
|
|||
CFLAGS += -I$(INCLUDE_PATH)
|
||||
LDFLAGS = -L../src -lskipstone
|
||||
|
||||
EXAMPLES = read map test queue
|
||||
EXAMPLES = read map test queue pack
|
||||
|
||||
RM = /bin/rm
|
||||
|
||||
|
|
33
examples/pack.c
Normal file
33
examples/pack.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <skipstone/message.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
uint8_t buf[SKIPSTONE_MESSAGE_MAX_PAYLOAD];
|
||||
|
||||
ssize_t len;
|
||||
|
||||
if ((len = skipstone_message_pack(buf,
|
||||
SKIPSTONE_MESSAGE_MAX_PAYLOAD,
|
||||
"CCCC",
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4)) < 0) {
|
||||
fprintf(stderr, "%s: %s: %s\n", argv[0],
|
||||
"skipstone_message_pack()", strerror(errno));
|
||||
|
||||
goto error_message_pack;
|
||||
}
|
||||
|
||||
write(1, buf, len);
|
||||
|
||||
return 0;
|
||||
|
||||
error_message_pack:
|
||||
return 1;
|
||||
}
|
Loading…
Add table
Reference in a new issue