From 8ae9f561108209e789ef239c4f443af8fefaf5bd Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 21 Sep 2019 19:27:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0to=5Fstring=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/amf.cpp | 27 +++++++++++++++++++++++++++ src/Rtmp/amf.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/Rtmp/amf.cpp b/src/Rtmp/amf.cpp index 89014856..2478cc10 100644 --- a/src/Rtmp/amf.cpp +++ b/src/Rtmp/amf.cpp @@ -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"); diff --git a/src/Rtmp/amf.h b/src/Rtmp/amf.h index ead844d8..da299b41 100644 --- a/src/Rtmp/amf.h +++ b/src/Rtmp/amf.h @@ -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 &fun) const ; operator bool() const;