添加to_string接口

This commit is contained in:
xiongziliang 2019-09-21 19:27:55 +08:00
parent 8da9aee11a
commit 8ae9f56110
2 changed files with 28 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include "Util/util.h"
#include "Util/logger.h"
#include "Network/sockutil.h"
#include "Util/util.h"
using namespace toolkit;
/////////////////////AMFValue/////////////////////////////
@ -225,6 +226,32 @@ bool AMFValue::as_boolean() const {
}
}
string AMFValue::to_string() const{
switch (_type) {
case AMF_NUMBER:
return StrPrinter << _value.number;
case AMF_INTEGER:
return StrPrinter << _value.integer;
case AMF_BOOLEAN:
return _value.boolean ? "true" : "false";
case AMF_STRING:
return *(_value.string);
case AMF_OBJECT:
return "object";
case AMF_NULL:
return "null";
case AMF_UNDEFINED:
return "undefined";
case AMF_ECMA_ARRAY:
return "ecma_array";
case AMF_STRICT_ARRAY:
return "strict_array";
default:
throw std::runtime_error("can not convert to string ");
}
}
const AMFValue& AMFValue::operator[](const char *str) const {
if (_type != AMF_OBJECT && _type != AMF_ECMA_ARRAY) {
throw std::runtime_error("AMF not a object");

View File

@ -73,6 +73,7 @@ public:
double as_number() const;
int as_integer() const;
bool as_boolean() const;
string to_string() const;
const AMFValue &operator[](const char *str) const;
void object_for_each(const function<void(const string &key, const AMFValue &val)> &fun) const ;
operator bool() const;