mirror of https://github.com/llvm/circt.git
[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:
parent
5e2e73845c
commit
0a79297ac2
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue