-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathMessage.h
More file actions
73 lines (58 loc) · 2.14 KB
/
Message.h
File metadata and controls
73 lines (58 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (C) Microsoft Corporation.
// Copyright (C) 2025 IAMAI CONSULTING CORP
//
// MIT License. All rights reserved.
#pragma once
#include <cstdint>
#include <string>
#include "ASCDecl.h"
#include "IRefCounted.h"
namespace microsoft {
namespace projectairsim {
namespace client {
// Forward declarations
class IMessageBuffer;
// Message class for passing a received message back to the callers or
// callback functions. This class handles the details of buffer
// memory management across the DLL boundary. The Message object is
// created by whoever wishes to receive the message and the object is
// eventually deleted by them on the same side of the boundary. The
// Message buffer is allocated by the side returning the message and
// when the message object is deleted, the buffer is deleted by the
// side that allocated it even when the message object was deleted on
// the other side of the boundary.
class Message : protected RefCountedContainer {
public:
ASC_DECL Message(void) noexcept;
ASC_DECL Message(const Message& message_other) noexcept;
ASC_DECL Message(Message&& message_other) noexcept;
ASC_DECL virtual ~Message();
// Delete the attached buffer
ASC_DECL void Clear(void);
// Return the message data
ASC_DECL const std::uint8_t* Data(void) const;
// Return the number of bytes returned by Data()
ASC_DECL size_t Cb(void) const;
// Set the message buffer
ASC_DECL void SetMessageBuffer(IMessageBuffer* pimessage_buffer);
// Convert to a string
// Make this inline so we don't have allocated objects crossing the DLL
// boundary
inline operator std::string(void) const {
std::string strRet;
if (piref_counted_ != nullptr)
strRet.assign(reinterpret_cast<const char*>(Data()), Cb());
return (strRet);
}
inline Message& operator=(const Message& message_other) noexcept {
RefCountedContainer::operator=(message_other);
return (*this);
}
inline Message& operator=(Message&& message_other) noexcept {
RefCountedContainer::operator=(std::move(message_other));
return (*this);
}
}; // struct Message
} // namespace client
} // namespace projectairsim
} // namespace microsoft