MCPcopy Create free account
hub / github.com/apache/qpid-proton / encode_message

Function encode_message

c/examples/send-abort.c:77–110  ·  view source on GitHub ↗

Create a message with a map { "sequence" : number } encode it and return the encoded buffer. */

Source from the content-addressed store, hash-verified

75
76/* Create a message with a map { "sequence" : number } encode it and return the encoded buffer. */
77static pn_bytes_t encode_message(app_data_t* app) {
78 /* Construct a message with the map { "sequence": app.sent } */
79 pn_message_t* message = pn_message();
80 char data[MSG_SIZE + 11] = {0};
81 pn_data_t* body;
82 pn_message_set_id(message, (pn_atom_t){.type=PN_ULONG, .u.as_ulong=app->sent});
83 body = pn_message_body(message);
84 pn_data_enter(body);
85 pn_data_put_string(body, pn_bytes(MSG_SIZE, data));
86 pn_data_exit(body);
87
88 /* encode the message, expanding the encode buffer as needed */
89 if (app->message_buffer.start == NULL) {
90 static const size_t initial_size = MSG_SIZE + 1000;
91 app->message_buffer = pn_rwbytes(initial_size, (char*)malloc(initial_size));
92 }
93 /* app->message_buffer is the total buffer space available. */
94 /* mbuf wil point at just the portion used by the encoded message */
95 {
96 pn_rwbytes_t mbuf = pn_rwbytes(app->message_buffer.size, app->message_buffer.start);
97 int status = 0;
98 while ((status = pn_message_encode(message, mbuf.start, &mbuf.size)) == PN_OVERFLOW) {
99 app->message_buffer.size *= 2;
100 app->message_buffer.start = (char*)realloc(app->message_buffer.start, app->message_buffer.size);
101 mbuf.size = app->message_buffer.size;
102 }
103 if (status != 0) {
104 fprintf(stderr, "error encoding message: %s\n", pn_error_text(pn_message_error(message)));
105 exit(1);
106 }
107 pn_message_free(message);
108 return pn_bytes(mbuf.size, mbuf.start);
109 }
110}
111
112/* Returns true to continue, false if finished */
113static bool handle(app_data_t* app, pn_event_t* event) {

Callers 1

handleFunction · 0.70

Calls 12

pn_messageFunction · 0.85
pn_message_bodyFunction · 0.85
pn_data_enterFunction · 0.85
pn_data_exitFunction · 0.85
pn_message_errorFunction · 0.85
exitFunction · 0.85
pn_message_freeFunction · 0.85
pn_message_set_idFunction · 0.50
pn_data_put_stringFunction · 0.50
pn_bytesFunction · 0.50
pn_message_encodeFunction · 0.50
pn_error_textFunction · 0.50

Tested by

no test coverage detected