11#ifndef ASRT_STREAM_PROTO_H
12#define ASRT_STREAM_PROTO_H
23enum asrt_strm_message_id_e
25 ASRT_STRM_MSG_DEFINE = 0x01,
26 ASRT_STRM_MSG_DATA = 0x02,
27 ASRT_STRM_MSG_ERROR = 0x03,
29typedef uint8_t asrt_strm_message_id;
32enum asrt_strm_field_type_e
34 ASRT_STRM_FIELD_U8 = 0x01,
35 ASRT_STRM_FIELD_U16 = 0x02,
36 ASRT_STRM_FIELD_U32 = 0x03,
37 ASRT_STRM_FIELD_I8 = 0x04,
38 ASRT_STRM_FIELD_I16 = 0x05,
39 ASRT_STRM_FIELD_I32 = 0x06,
40 ASRT_STRM_FIELD_FLOAT = 0x07,
41 ASRT_STRM_FIELD_BOOL = 0x08,
42 ASRT_STRM_FIELD_LBRACKET = 0x09,
43 ASRT_STRM_FIELD_RBRACKET = 0x0A,
45typedef uint8_t asrt_strm_field_type;
48#define ASRT_STRM_FIELD_TAG_MAX 0x0A
53 ASRT_STRM_ERR_SUCCESS = 0x00,
54 ASRT_STRM_ERR_UNKNOWN_SCHEMA = 0x01,
55 ASRT_STRM_ERR_SIZE_MISMATCH = 0x02,
56 ASRT_STRM_ERR_ALLOC_FAILURE = 0x03,
57 ASRT_STRM_ERR_DUPLICATE_SCHEMA = 0x04,
58 ASRT_STRM_ERR_INVALID_DEFINE = 0x05,
62static inline uint8_t asrt_strm_field_valid( uint8_t type_tag )
64 return type_tag >= 0x01 && type_tag <= ASRT_STRM_FIELD_TAG_MAX;
69static inline uint8_t asrt_strm_field_size( asrt_strm_field_type type_tag )
72 case ASRT_STRM_FIELD_U8:
73 case ASRT_STRM_FIELD_I8:
74 case ASRT_STRM_FIELD_BOOL:
76 case ASRT_STRM_FIELD_U16:
77 case ASRT_STRM_FIELD_I16:
79 case ASRT_STRM_FIELD_U32:
80 case ASRT_STRM_FIELD_I32:
81 case ASRT_STRM_FIELD_FLOAT:
83 case ASRT_STRM_FIELD_LBRACKET:
84 case ASRT_STRM_FIELD_RBRACKET:
91static inline char const* asrt_strm_field_type_to_str(
enum asrt_strm_field_type_e ft )
94 case ASRT_STRM_FIELD_U8:
96 case ASRT_STRM_FIELD_U16:
98 case ASRT_STRM_FIELD_U32:
100 case ASRT_STRM_FIELD_I8:
102 case ASRT_STRM_FIELD_I16:
104 case ASRT_STRM_FIELD_I32:
106 case ASRT_STRM_FIELD_FLOAT:
108 case ASRT_STRM_FIELD_BOOL:
110 case ASRT_STRM_FIELD_LBRACKET:
112 case ASRT_STRM_FIELD_RBRACKET:
129static inline struct asrt_send_req* asrt_msg_rtoc_strm_define(
132 enum asrt_strm_field_type_e
const* fields,
133 uint16_t field_count )
135 ASRT_ASSERT( field_count <= 255 );
136 msg->hdr[0] = ASRT_STRM_MSG_DEFINE;
137 msg->hdr[1] = schema_id;
138 msg->hdr[2] = (uint8_t) field_count;
139 for ( uint16_t i = 0; i < field_count; i++ )
140 msg->fields[i] = (uint8_t) fields[i];
141 msg->field_span = (
struct asrt_span ){ .
b = msg->fields, .e = msg->fields + field_count };
144 .e = msg->hdr +
sizeof msg->hdr,
145 .rest = &msg->field_span,
166 msg->hdr[0] = ASRT_STRM_MSG_DATA;
167 msg->hdr[1] = schema_id;
169 (
struct asrt_span ){ .
b = (uint8_t*) data, .
e = (uint8_t*) data + data_size };
172 .e = msg->hdr +
sizeof msg->hdr,
173 .rest = &msg->data_span,
182 enum asrt_strm_err_e error_code )
184 msg->buff[0] = ASRT_STRM_MSG_ERROR;
185 msg->buff[1] = error_code;
An outgoing message request placed in a module's send queue.
Definition: chann.h:64
struct asrt_span_span buff
Message payload (scatter-gather).
Definition: chann.h:65
Scatter-gather buffer: a primary byte range [b, e) followed by rest_count additional spans.
Definition: span.h:37
uint8_t * b
Primary buffer start.
Definition: span.h:38
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee ...
Definition: span.h:23
uint8_t * b
Pointer to the first byte.
Definition: span.h:24
uint8_t * e
One-past-the-end pointer.
Definition: span.h:25
Send DATA message from reactor to controller.
Definition: stream_proto.h:154
Send DEFINE message from reactor to controller.
Definition: stream_proto.h:122