DarkflameServer/dCommon/AMFFormat.cpp

172 lines
4.2 KiB
C++
Raw Normal View History

#include "AMFFormat.h"
// AMFInteger
void AMFIntegerValue::SetIntegerValue(uint32_t value) {
2022-07-28 13:39:57 +00:00
this->value = value;
}
uint32_t AMFIntegerValue::GetIntegerValue() {
2022-07-28 13:39:57 +00:00
return this->value;
}
// AMFDouble
void AMFDoubleValue::SetDoubleValue(double value) {
2022-07-28 13:39:57 +00:00
this->value = value;
}
double AMFDoubleValue::GetDoubleValue() {
2022-07-28 13:39:57 +00:00
return this->value;
}
// AMFString
void AMFStringValue::SetStringValue(const std::string& value) {
2022-07-28 13:39:57 +00:00
this->value = value;
}
std::string AMFStringValue::GetStringValue() {
2022-07-28 13:39:57 +00:00
return this->value;
}
// AMFXMLDoc
void AMFXMLDocValue::SetXMLDocValue(const std::string& value) {
2022-07-28 13:39:57 +00:00
this->xmlData = value;
}
std::string AMFXMLDocValue::GetXMLDocValue() {
2022-07-28 13:39:57 +00:00
return this->xmlData;
}
// AMFDate
void AMFDateValue::SetDateValue(uint64_t value) {
2022-07-28 13:39:57 +00:00
this->millisecondTimestamp = value;
}
uint64_t AMFDateValue::GetDateValue() {
2022-07-28 13:39:57 +00:00
return this->millisecondTimestamp;
}
// AMFArray Insert Value
void AMFArrayValue::InsertValue(const std::string& key, AMFValue* value) {
2022-07-28 13:39:57 +00:00
this->associative.insert(std::make_pair(key, value));
}
// AMFArray Remove Value
void AMFArrayValue::RemoveValue(const std::string& key) {
2022-07-28 13:39:57 +00:00
_AMFArrayMap_::iterator it = this->associative.find(key);
if (it != this->associative.end()) {
this->associative.erase(it);
}
}
// AMFArray Find Value
AMFValue* AMFArrayValue::FindValue(const std::string& key) {
2022-07-28 13:39:57 +00:00
_AMFArrayMap_::iterator it = this->associative.find(key);
if (it != this->associative.end()) {
return it->second;
}
return nullptr;
}
// AMFArray Get Associative Iterator Begin
_AMFArrayMap_::iterator AMFArrayValue::GetAssociativeIteratorValueBegin() {
2022-07-28 13:39:57 +00:00
return this->associative.begin();
}
// AMFArray Get Associative Iterator End
_AMFArrayMap_::iterator AMFArrayValue::GetAssociativeIteratorValueEnd() {
2022-07-28 13:39:57 +00:00
return this->associative.end();
}
// AMFArray Push Back Value
void AMFArrayValue::PushBackValue(AMFValue* value) {
2022-07-28 13:39:57 +00:00
this->dense.push_back(value);
}
// AMFArray Pop Back Value
void AMFArrayValue::PopBackValue() {
2022-07-28 13:39:57 +00:00
this->dense.pop_back();
}
// AMFArray Get Dense List Size
uint32_t AMFArrayValue::GetDenseValueSize() {
2022-07-28 13:39:57 +00:00
return (uint32_t)this->dense.size();
}
// AMFArray Get value at index in Dense List
AMFValue* AMFArrayValue::GetValueAt(uint32_t index) {
2022-07-28 13:39:57 +00:00
return this->dense.at(index);
}
// AMFArray Get Dense Iterator Begin
_AMFArrayList_::iterator AMFArrayValue::GetDenseIteratorBegin() {
2022-07-28 13:39:57 +00:00
return this->dense.begin();
}
// AMFArray Get Dense Iterator End
_AMFArrayList_::iterator AMFArrayValue::GetDenseIteratorEnd() {
2022-07-28 13:39:57 +00:00
return this->dense.end();
}
AMFArrayValue::~AMFArrayValue() {
2022-07-28 13:39:57 +00:00
for (auto valueToDelete : GetDenseArray()) {
if (valueToDelete) delete valueToDelete;
}
for (auto valueToDelete : GetAssociativeMap()) {
if (valueToDelete.second) delete valueToDelete.second;
}
}
// AMFObject Constructor
AMFObjectValue::AMFObjectValue(std::vector<std::pair<std::string, AMFValueType>> traits) {
2022-07-28 13:39:57 +00:00
this->traits.reserve(traits.size());
std::vector<std::pair<std::string, AMFValueType>>::iterator it = traits.begin();
while (it != traits.end()) {
this->traits.insert(std::make_pair(it->first, std::make_pair(it->second, new AMFNullValue())));
it++;
}
}
// AMFObject Set Value
void AMFObjectValue::SetTraitValue(const std::string& trait, AMFValue* value) {
2022-07-28 13:39:57 +00:00
if (value) {
_AMFObjectTraits_::iterator it = this->traits.find(trait);
if (it != this->traits.end()) {
if (it->second.first == value->GetValueType()) {
it->second.second = value;
}
}
}
}
// AMFObject Get Value
AMFValue* AMFObjectValue::GetTraitValue(const std::string& trait) {
2022-07-28 13:39:57 +00:00
_AMFObjectTraits_::iterator it = this->traits.find(trait);
if (it != this->traits.end()) {
return it->second.second;
}
return nullptr;
}
// AMFObject Get Trait Iterator Begin
_AMFObjectTraits_::iterator AMFObjectValue::GetTraitsIteratorBegin() {
2022-07-28 13:39:57 +00:00
return this->traits.begin();
}
// AMFObject Get Trait Iterator End
_AMFObjectTraits_::iterator AMFObjectValue::GetTraitsIteratorEnd() {
2022-07-28 13:39:57 +00:00
return this->traits.end();
}
// AMFObject Get Trait Size
uint32_t AMFObjectValue::GetTraitArrayCount() {
2022-07-28 13:39:57 +00:00
return (uint32_t)this->traits.size();
}
AMFObjectValue::~AMFObjectValue() {
2022-07-28 13:39:57 +00:00
for (auto valueToDelete = GetTraitsIteratorBegin(); valueToDelete != GetTraitsIteratorEnd(); valueToDelete++) {
if (valueToDelete->second.second) delete valueToDelete->second.second;
}
}