diff --git a/include/neuron/utils/log.h b/include/neuron/utils/log.h index 47df04fb..c14e795f 100644 --- a/include/neuron/utils/log.h +++ b/include/neuron/utils/log.h @@ -86,4 +86,15 @@ extern zlog_category_t *neuron; } \ plog_debug(plugin, "%s", protocol_buf); +#define zlog_recv_protocol(log, bytes, n_byte) \ + char protocol_buf[2048] = { 0 }; \ + int offset = 0; \ + offset = snprintf(protocol_buf, sizeof(protocol_buf), "<<"); \ + for (int i = 0; i < n_byte; i++) { \ + offset += \ + snprintf(protocol_buf + offset, sizeof(protocol_buf) - offset, \ + " 0x%02hhX", bytes[i]); \ + } \ + zlog_debug(log, "%s", protocol_buf); + #endif \ No newline at end of file diff --git a/src/connection/connection.c b/src/connection/connection.c index 51e6c912..cf786a82 100644 --- a/src/connection/connection.c +++ b/src/connection/connection.c @@ -769,6 +769,7 @@ void neu_conn_stream_consume(neu_conn_t *conn, void *context, ssize_t ret = neu_conn_recv(conn, recv_buf + offset, sizeof(recv_buf) - offset); if (ret > 0) { + zlog_recv_protocol(conn->param.log, recv_buf + offset, ret); offset += ret; neu_protocol_unpack_buf_t protocol_buf = { 0 }; neu_protocol_unpack_buf_init(&protocol_buf, recv_buf, offset);