[ESI] MessageData utility functions (#8777)

Just a few utility functions for `esi::MessageData` to make it play nicer with other things.

Co-authored-by: Morten Borup Petersen <mpetersen@microsoft.com>
This commit is contained in:
Morten Borup Petersen 2025-07-25 10:59:46 +02:00 committed by GitHub
parent 5e2e73845c
commit 0a79297ac2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 0 deletions

View File

@ -105,13 +105,24 @@ public:
/// Adopts the data vector buffer.
MessageData() = default;
MessageData(std::vector<uint8_t> &data) : data(std::move(data)) {}
MessageData(std::vector<uint8_t> &&data) : data(std::move(data)) {}
MessageData(const uint8_t *data, size_t size) : data(data, data + size) {}
~MessageData() = default;
const uint8_t *getBytes() const { return data.data(); }
/// Get the data as a vector of bytes.
const std::vector<uint8_t> &getData() const { return data; }
/// Move the data out of this object.
std::vector<uint8_t> takeData() { return std::move(data); }
/// Get the size of the data in bytes.
size_t getSize() const { return data.size(); }
/// Returns true if this message contains no data.
bool empty() const { return data.empty(); }
/// Cast to a type. Throws if the size of the data does not match the size of
/// the message. The lifetime of the resulting pointer is tied to the lifetime
/// of this object.