| 1 |
// Copyright (c) Microsoft. All rights reserved. |
| 2 |
// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 |
|
| 4 |
#ifndef FRAME_CODEC_H |
| 5 |
#define FRAME_CODEC_H |
| 6 |
|
| 7 |
#include "azure_uamqp_c/amqpvalue.h" |
| 8 |
|
| 9 |
#ifdef __cplusplus |
| 10 |
extern "C" { |
| 11 |
#include <cstdint> |
| 12 |
#include <cstddef> |
| 13 |
#else |
| 14 |
#include <stdint.h> |
| 15 |
#include <stddef.h> |
| 16 |
#include <stdbool.h> |
| 17 |
#endif /* __cplusplus */ |
| 18 |
|
| 19 |
#include "umock_c/umock_c_prod.h" |
| 20 |
|
| 21 |
typedef struct PAYLOAD_TAG |
| 22 |
{ |
| 23 |
const unsigned char* bytes; |
| 24 |
size_t length; |
| 25 |
} PAYLOAD; |
| 26 |
|
| 27 |
/* Codes_SRS_FRAME_CODEC_01_016: [The type code indicates the format and purpose of the frame.] */ |
| 28 |
/* Codes_SRS_FRAME_CODEC_01_017: [The subsequent bytes in the frame header MAY be interpreted differently depending on the type of the frame.] */ |
| 29 |
/* Codes_SRS_FRAME_CODEC_01_070: [The type code indicates the format and purpose of the frame.] */ |
| 30 |
/* Codes_SRS_FRAME_CODEC_01_071: [The subsequent bytes in the frame header MAY be interpreted differently depending on the type of the frame.] */ |
| 31 |
/* Codes_SRS_FRAME_CODEC_01_018: [A type code of 0x00 indicates that the frame is an AMQP frame.] */ |
| 32 |
/* Codes_SRS_FRAME_CODEC_01_072: [A type code of 0x00 indicates that the frame is an AMQP frame.] */ |
| 33 |
#define FRAME_TYPE_AMQP (uint8_t)0x00 |
| 34 |
|
| 35 |
/* Codes_SRS_FRAME_CODEC_01_073: [A type code of 0x01 indicates that the frame is a SASL frame] */ |
| 36 |
/* Codes_SRS_FRAME_CODEC_01_019: [A type code of 0x01 indicates that the frame is a SASL frame] */ |
| 37 |
#define FRAME_TYPE_SASL (uint8_t)0x01 |
| 38 |
|
| 39 |
typedef struct FRAME_CODEC_INSTANCE_TAG* FRAME_CODEC_HANDLE; |
| 40 |
typedef void(*ON_FRAME_RECEIVED)(void* context, const unsigned char* type_specific, uint32_t type_specific_size, const unsigned char* frame_body, uint32_t frame_body_size); |
| 41 |
typedef void(*ON_FRAME_CODEC_ERROR)(void* context); |
| 42 |
typedef void(*ON_BYTES_ENCODED)(void* context, const unsigned char* bytes, size_t length, bool encode_complete); |
| 43 |
|
| 44 |
MOCKABLE_FUNCTION(, FRAME_CODEC_HANDLE, frame_codec_create, ON_FRAME_CODEC_ERROR, on_frame_codec_error, void*, callback_context); |
| 45 |
MOCKABLE_FUNCTION(, void, frame_codec_destroy, FRAME_CODEC_HANDLE, frame_codec); |
| 46 |
MOCKABLE_FUNCTION(, int, frame_codec_set_max_frame_size, FRAME_CODEC_HANDLE, frame_codec, uint32_t, max_frame_size); |
| 47 |
MOCKABLE_FUNCTION(, int, frame_codec_subscribe, FRAME_CODEC_HANDLE, frame_codec, uint8_t, type, ON_FRAME_RECEIVED, on_frame_received, void*, callback_context); |
| 48 |
MOCKABLE_FUNCTION(, int, frame_codec_unsubscribe, FRAME_CODEC_HANDLE, frame_codec, uint8_t, type); |
| 49 |
MOCKABLE_FUNCTION(, int, frame_codec_receive_bytes, FRAME_CODEC_HANDLE, frame_codec, const unsigned char*, buffer, size_t, size); |
| 50 |
MOCKABLE_FUNCTION(, int, frame_codec_encode_frame, FRAME_CODEC_HANDLE, frame_codec, uint8_t, type, const PAYLOAD*, payloads, size_t, payload_count, const unsigned char*, type_specific_bytes, uint32_t, type_specific_size, ON_BYTES_ENCODED, on_bytes_encoded, void*, callback_context); |
| 51 |
|
| 52 |
#ifdef __cplusplus |
| 53 |
} |
| 54 |
#endif /* __cplusplus */ |
| 55 |
|
| 56 |
#endif /* FRAME_CODEC_H */ |