#include "core.h" #include "cbor.h" #include "packet.h" #include #define CIRCE_CORE_ASSERT(x, err) \ do \ { \ if (!(x)) \ { \ return err; \ } \ } \ while (false) enum circe_result circe_handle_packet (struct circe_ctx *ctx, const uint8_t *in, uint32_t len, uint64_t now_ms, uint8_t *out, uint32_t *out_len, struct circe_event *events, uint32_t *n_events) { struct circe_cbor_decoder cd = { .buf_start = in, .buf_len = len, .cursor = in, }; enum circe_cbor_major_type major_type; CIRCE_CORE_ASSERT (circe_cbor_get_major_type (&cd, &major_type), CIRCE_RESULT_INVALID_PACKET); CIRCE_CORE_ASSERT (major_type == CIRCE_CBOR_MAJOR_MAPPING, CIRCE_RESULT_INVALID_PACKET); uint64_t num_fields; CIRCE_CORE_ASSERT (circe_cbor_extract_unsigned (&cd, &num_fields), CIRCE_RESULT_INVALID_PACKET); CIRCE_CORE_ASSERT (num_fields > 0, CIRCE_RESULT_INVALID_PACKET); CIRCE_CORE_ASSERT (circe_cbor_get_major_type (&cd, &major_type), CIRCE_RESULT_INVALID_PACKET); CIRCE_CORE_ASSERT (major_type == CIRCE_CBOR_MAJOR_UNSIGNED, CIRCE_RESULT_INVALID_PACKET); uint64_t field; CIRCE_CORE_ASSERT (circe_cbor_extract_unsigned (&cd, &field), CIRCE_RESULT_INVALID_PACKET); CIRCE_CORE_ASSERT (field < CIRCE_PACKET_FIELD_OVERMAX, CIRCE_RESULT_INVALID_PACKET); return CIRCE_RESULT_SUCCESS; }