Simplify frame header to message_type + payload_length (6 bytes)
Removes channel_id from the header. All message-specific identifiers (stream_id, request_id, etc.) now live at the start of the payload, interpreted by each message type handler. A relay seeing an unknown type can skip or forward it using only payload_length, with no knowledge of the payload structure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,8 +13,8 @@ static void server_on_frame(struct Transport_Conn *conn,
|
||||
{
|
||||
(void)userdata;
|
||||
|
||||
printf("recv type=0x%04x channel=%u length=%u",
|
||||
frame->message_type, frame->channel_id, frame->payload_length);
|
||||
printf("recv type=0x%04x length=%u",
|
||||
frame->message_type, frame->payload_length);
|
||||
|
||||
if (frame->payload_length > 0) {
|
||||
uint32_t show = frame->payload_length < 8 ? frame->payload_length : 8;
|
||||
@@ -28,7 +28,7 @@ static void server_on_frame(struct Transport_Conn *conn,
|
||||
printf("\n");
|
||||
|
||||
struct App_Error err = transport_send_frame(conn,
|
||||
frame->message_type, frame->channel_id,
|
||||
frame->message_type,
|
||||
frame->payload, frame->payload_length);
|
||||
|
||||
if (!APP_IS_OK(err)) {
|
||||
@@ -90,8 +90,8 @@ static void client_on_frame(struct Transport_Conn *conn,
|
||||
struct Transport_Frame *frame, void *userdata)
|
||||
{
|
||||
(void)conn; (void)userdata;
|
||||
printf("echo type=0x%04x channel=%u length=%u\n",
|
||||
frame->message_type, frame->channel_id, frame->payload_length);
|
||||
printf("echo type=0x%04x length=%u\n",
|
||||
frame->message_type, frame->payload_length);
|
||||
free(frame->payload);
|
||||
}
|
||||
|
||||
@@ -123,15 +123,15 @@ static void cmd_client(int argc, char **argv) {
|
||||
|
||||
printf("connected to %s:%u\n", host, port);
|
||||
|
||||
for (uint16_t i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
uint8_t payload[] = { 0xde, 0xad, 0xbe, 0xef, (uint8_t)i };
|
||||
err = transport_send_frame(conn, 0x0001, i, payload, sizeof(payload));
|
||||
err = transport_send_frame(conn, 0x0001, payload, sizeof(payload));
|
||||
if (!APP_IS_OK(err)) {
|
||||
fprintf(stderr, "send failed on frame %u (errno %d)\n",
|
||||
fprintf(stderr, "send failed on frame %d (errno %d)\n",
|
||||
i, err.detail.syscall.err_no);
|
||||
break;
|
||||
}
|
||||
printf("sent type=0x0001 channel=%u length=5\n", i);
|
||||
printf("sent type=0x0001 length=5\n");
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
|
||||
Reference in New Issue
Block a user