Commit 8ae9f561 by xiongziliang

添加to_string接口

parent 8da9aee1
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "Util/util.h" #include "Util/util.h"
#include "Util/logger.h" #include "Util/logger.h"
#include "Network/sockutil.h" #include "Network/sockutil.h"
#include "Util/util.h"
using namespace toolkit; using namespace toolkit;
/////////////////////AMFValue///////////////////////////// /////////////////////AMFValue/////////////////////////////
...@@ -225,6 +226,32 @@ bool AMFValue::as_boolean() const { ...@@ -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 { const AMFValue& AMFValue::operator[](const char *str) const {
if (_type != AMF_OBJECT && _type != AMF_ECMA_ARRAY) { if (_type != AMF_OBJECT && _type != AMF_ECMA_ARRAY) {
throw std::runtime_error("AMF not a object"); throw std::runtime_error("AMF not a object");
......
...@@ -73,6 +73,7 @@ public: ...@@ -73,6 +73,7 @@ public:
double as_number() const; double as_number() const;
int as_integer() const; int as_integer() const;
bool as_boolean() const; bool as_boolean() const;
string to_string() const;
const AMFValue &operator[](const char *str) const; const AMFValue &operator[](const char *str) const;
void object_for_each(const function<void(const string &key, const AMFValue &val)> &fun) const ; void object_for_each(const function<void(const string &key, const AMFValue &val)> &fun) const ;
operator bool() const; operator bool() const;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论