104 lines
2.4 KiB
C
104 lines
2.4 KiB
C
/*
|
|
* Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
|
* source code may only be used and distributed under the Widevine Master
|
|
* License Agreement.
|
|
*/
|
|
|
|
#ifndef ODKITEE_MESSAGE_H_
|
|
#define ODKITEE_MESSAGE_H_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
typedef struct _Message Message;
|
|
|
|
/*
|
|
* TODO: there is a dangerous duplication of the MessageStatus
|
|
* enum with odk/src/serialization_base.h. The two need to
|
|
* be converged. Removing the random enum values here, since
|
|
* a proper fix is outside the scope of the current CL. Opened
|
|
* b/158603784.
|
|
*/
|
|
typedef enum {
|
|
MESSAGE_STATUS_OK,
|
|
MESSAGE_STATUS_UNKNOWN_ERROR,
|
|
MESSAGE_STATUS_OVERFLOW_ERROR,
|
|
MESSAGE_STATUS_UNDERFLOW_ERROR,
|
|
MESSAGE_STATUS_PARSE_ERROR,
|
|
MESSAGE_STATUS_NULL_POINTER_ERROR,
|
|
MESSAGE_STATUS_API_VALUE_ERROR,
|
|
MESSAGE_STATUS_INVALID_TAG_ERROR,
|
|
MESSAGE_STATUS_END_OF_MESSAGE_ERROR,
|
|
MESSAGE_STATUS_INVALID_ENUM_VALUE
|
|
} MessageStatus;
|
|
|
|
/*
|
|
* Create a message from a buffer. The message structure consumes the first
|
|
* sizeof(Message) bytes of the buffer. The caller is responsible for ensuring
|
|
* that the buffer remains allocated for the lifetime of the message.
|
|
*/
|
|
Message* CreateMessage(uint8_t* buffer, size_t buffer_size);
|
|
|
|
/*
|
|
* Initialize a message structure to reference a separate buffer. The caller
|
|
* is responsible for ensuring that the buffer remains allocated for the
|
|
* lifetime of the message.
|
|
*/
|
|
void InitMessage(Message* message, uint8_t* buffer, size_t capacity);
|
|
|
|
/*
|
|
* Erase the contents of the message, set it
|
|
* to an empty state.
|
|
*/
|
|
void ClearMessage(Message* message);
|
|
|
|
/*
|
|
* Reset read pointer to the beginning of the
|
|
* message and clear status
|
|
*/
|
|
void ResetMessage(Message* message);
|
|
|
|
/*
|
|
* The message base is the start of the payload
|
|
*/
|
|
uint8_t* GetBase(Message* message);
|
|
|
|
/*
|
|
* Get the maximum number of bytes the message
|
|
* can hold.
|
|
*/
|
|
size_t GetCapacity(Message* message);
|
|
|
|
/*
|
|
* Get the number of bytes currently in the
|
|
* message
|
|
*/
|
|
size_t GetSize(Message* message);
|
|
|
|
/*
|
|
* Return the status of the message
|
|
*/
|
|
MessageStatus GetStatus(Message* message);
|
|
|
|
/*
|
|
* Set the message status to a specific value
|
|
*/
|
|
void SetStatus(Message* message, MessageStatus status);
|
|
|
|
/*
|
|
* Set the size of the message to a value. This
|
|
* may be needed after writing data into the payload.
|
|
*/
|
|
void SetSize(Message*message, size_t size);
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
#endif
|
|
|
|
#endif // ODKITEE_MESSAGE_H_
|
|
|