add msg handling (#1737)

This commit is contained in:
David Markowitz
2025-01-19 22:42:15 -08:00
committed by GitHub
parent 1b3cdc6d9c
commit e4c2eecbc7
10 changed files with 163 additions and 13 deletions

View File

@@ -40,6 +40,7 @@ public:
// AMFValue template class instantiations
template <typename ValueType>
class AMFValue : public AMFBaseValue {
static_assert(!std::is_same_v<ValueType, std::string_view>, "AMFValue cannot be instantiated with std::string_view");
public:
AMFValue() = default;
AMFValue(const ValueType value) : m_Data{ value } {}
@@ -52,6 +53,15 @@ public:
void SetValue(const ValueType value) { m_Data = value; }
AMFValue<ValueType>& operator=(const AMFValue<ValueType>& other) {
return operator=(other.m_Data);
}
AMFValue<ValueType>& operator=(const ValueType& other) {
m_Data = other;
return *this;
}
protected:
ValueType m_Data;
};
@@ -211,13 +221,17 @@ public:
* @param key The key to associate with the value
* @param value The value to insert
*/
void Insert(const std::string_view key, std::unique_ptr<AMFBaseValue> value) {
template<typename AmfType>
AmfType& Insert(const std::string_view key, std::unique_ptr<AmfType> value) {
const auto element = m_Associative.find(key);
auto& toReturn = *value;
if (element != m_Associative.cend() && element->second) {
element->second = std::move(value);
} else {
m_Associative.emplace(key, std::move(value));
}
return toReturn;
}
/**
@@ -229,11 +243,15 @@ public:
* @param key The key to associate with the value
* @param value The value to insert
*/
void Insert(const size_t index, std::unique_ptr<AMFBaseValue> value) {
template<typename AmfType>
AmfType& Insert(const size_t index, std::unique_ptr<AmfType> value) {
auto& toReturn = *value;
if (index >= m_Dense.size()) {
m_Dense.resize(index + 1);
}
m_Dense.at(index) = std::move(value);
return toReturn;
}
/**
@@ -349,6 +367,13 @@ public:
m_Dense.clear();
}
template<typename AmfType = AMFArrayValue>
AmfType& PushDebug(const std::string_view name) {
auto* value = PushArray();
value->Insert("name", name.data());
return value->Insert<AmfType>("value", std::make_unique<AmfType>());
}
private:
/**
* The associative portion. These values are key'd with strings to an AMFValue.