mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-06-30 07:58:02 +02:00
Refined examples.
This commit is contained in:
parent
a2c8154960
commit
35483b95ae
@ -8,8 +8,6 @@ typedef struct receiver {
|
|||||||
size_t rest;
|
size_t rest;
|
||||||
} receiver;
|
} receiver;
|
||||||
|
|
||||||
receiver r;
|
|
||||||
|
|
||||||
void receiver_init(receiver *r) {
|
void receiver_init(receiver *r) {
|
||||||
msgpack_packer pk;
|
msgpack_packer pk;
|
||||||
|
|
||||||
@ -53,6 +51,7 @@ void unpack(receiver* r) {
|
|||||||
char* buf;
|
char* buf;
|
||||||
size_t recv_len;
|
size_t recv_len;
|
||||||
int recv_count = 0;
|
int recv_count = 0;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
msgpack_unpacked_init(&result);
|
msgpack_unpacked_init(&result);
|
||||||
if (msgpack_unpacker_buffer_capacity(unp) < EACH_RECV_SIZE) {
|
if (msgpack_unpacker_buffer_capacity(unp) < EACH_RECV_SIZE) {
|
||||||
@ -65,15 +64,14 @@ void unpack(receiver* r) {
|
|||||||
msgpack_unpacker_buffer_consumed(unp, recv_len);
|
msgpack_unpacker_buffer_consumed(unp, recv_len);
|
||||||
|
|
||||||
|
|
||||||
while (recv_len > 0) {
|
while (recv_len > 0) {
|
||||||
int i = 0;
|
printf("receive count: %d %zd bytes received.\n", recv_count++, recv_len);
|
||||||
printf("receive count: %d %zd bytes received.:\n", recv_count++, recv_len);
|
|
||||||
ret = msgpack_unpacker_next(unp, &result);
|
ret = msgpack_unpacker_next(unp, &result);
|
||||||
while (ret == MSGPACK_UNPACK_SUCCESS) {
|
while (ret == MSGPACK_UNPACK_SUCCESS) {
|
||||||
msgpack_object obj = result.data;
|
msgpack_object obj = result.data;
|
||||||
|
|
||||||
/* Use obj. */
|
/* Use obj. */
|
||||||
printf("Object no %d:\n", i++);
|
printf("Object no %d:\n", ++i);
|
||||||
msgpack_object_print(stdout, obj);
|
msgpack_object_print(stdout, obj);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
/* If you want to allocate something on the zone, you can use zone. */
|
/* If you want to allocate something on the zone, you can use zone. */
|
||||||
@ -110,10 +108,16 @@ int main(void) {
|
|||||||
/* Output */
|
/* Output */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
receive count: 0 4 bytes received.
|
||||||
|
receive count: 1 4 bytes received.
|
||||||
|
receive count: 2 4 bytes received.
|
||||||
Object no 1:
|
Object no 1:
|
||||||
[1, true, "example"]
|
[1, true, "example"]
|
||||||
|
receive count: 3 4 bytes received.
|
||||||
|
receive count: 4 4 bytes received.
|
||||||
Object no 2:
|
Object no 2:
|
||||||
"second"
|
"second"
|
||||||
|
receive count: 5 1 bytes received.
|
||||||
Object no 3:
|
Object no 3:
|
||||||
[42, false]
|
[42, false]
|
||||||
*/
|
*/
|
||||||
|
@ -33,7 +33,7 @@ void unpack(char const* buf, size_t len) {
|
|||||||
msgpack_object obj = result.data;
|
msgpack_object obj = result.data;
|
||||||
|
|
||||||
/* Use obj. */
|
/* Use obj. */
|
||||||
printf("Object no %d:\n", i++);
|
printf("Object no %d:\n", ++i);
|
||||||
msgpack_object_print(stdout, obj);
|
msgpack_object_print(stdout, obj);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
/* If you want to allocate something on the zone, you can use zone. */
|
/* If you want to allocate something on the zone, you can use zone. */
|
||||||
@ -72,4 +72,5 @@ Object no 2:
|
|||||||
"second"
|
"second"
|
||||||
Object no 3:
|
Object no 3:
|
||||||
[42, false]
|
[42, false]
|
||||||
|
All msgpack_object in the buffer is consumed.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user