amf0 utest: remove struct use class instead, move class together
正在显示
2 个修改的文件
包含
97 行增加
和
91 行删除
| @@ -625,6 +625,68 @@ SrsAmf0Any* SrsAmf0EcmaArray::ensure_property_string(std::string name) | @@ -625,6 +625,68 @@ SrsAmf0Any* SrsAmf0EcmaArray::ensure_property_string(std::string name) | ||
| 625 | return properties.ensure_property_string(name); | 625 | return properties.ensure_property_string(name); |
| 626 | } | 626 | } |
| 627 | 627 | ||
| 628 | +int SrsAmf0Size::utf8(string value) | ||
| 629 | +{ | ||
| 630 | + return 2 + value.length(); | ||
| 631 | +} | ||
| 632 | + | ||
| 633 | +int SrsAmf0Size::str(string value) | ||
| 634 | +{ | ||
| 635 | + return 1 + SrsAmf0Size::utf8(value); | ||
| 636 | +} | ||
| 637 | + | ||
| 638 | +int SrsAmf0Size::number() | ||
| 639 | +{ | ||
| 640 | + return 1 + 8; | ||
| 641 | +} | ||
| 642 | + | ||
| 643 | +int SrsAmf0Size::null() | ||
| 644 | +{ | ||
| 645 | + return 1; | ||
| 646 | +} | ||
| 647 | + | ||
| 648 | +int SrsAmf0Size::undefined() | ||
| 649 | +{ | ||
| 650 | + return 1; | ||
| 651 | +} | ||
| 652 | + | ||
| 653 | +int SrsAmf0Size::boolean() | ||
| 654 | +{ | ||
| 655 | + return 1 + 1; | ||
| 656 | +} | ||
| 657 | + | ||
| 658 | +int SrsAmf0Size::object(SrsAmf0Object* obj) | ||
| 659 | +{ | ||
| 660 | + if (!obj) { | ||
| 661 | + return 0; | ||
| 662 | + } | ||
| 663 | + | ||
| 664 | + return obj->size(); | ||
| 665 | +} | ||
| 666 | + | ||
| 667 | +int SrsAmf0Size::object_eof() | ||
| 668 | +{ | ||
| 669 | + return 2 + 1; | ||
| 670 | +} | ||
| 671 | + | ||
| 672 | +int SrsAmf0Size::array(SrsAmf0EcmaArray* arr) | ||
| 673 | +{ | ||
| 674 | + if (!arr) { | ||
| 675 | + return 0; | ||
| 676 | + } | ||
| 677 | + | ||
| 678 | + return arr->size(); | ||
| 679 | +} | ||
| 680 | + | ||
| 681 | +int SrsAmf0Size::any(SrsAmf0Any* o) | ||
| 682 | +{ | ||
| 683 | + if (!o) { | ||
| 684 | + return 0; | ||
| 685 | + } | ||
| 686 | + | ||
| 687 | + return o->size(); | ||
| 688 | +} | ||
| 689 | + | ||
| 628 | int srs_amf0_read_utf8(SrsStream* stream, std::string& value) | 690 | int srs_amf0_read_utf8(SrsStream* stream, std::string& value) |
| 629 | { | 691 | { |
| 630 | int ret = ERROR_SUCCESS; | 692 | int ret = ERROR_SUCCESS; |
| @@ -1194,65 +1256,3 @@ int srs_amf0_write_ecma_array(SrsStream* stream, SrsAmf0EcmaArray* value) | @@ -1194,65 +1256,3 @@ int srs_amf0_write_ecma_array(SrsStream* stream, SrsAmf0EcmaArray* value) | ||
| 1194 | { | 1256 | { |
| 1195 | return value->write(stream); | 1257 | return value->write(stream); |
| 1196 | } | 1258 | } |
| 1197 | - | ||
| 1198 | -int SrsAmf0Size::utf8(string value) | ||
| 1199 | -{ | ||
| 1200 | - return 2 + value.length(); | ||
| 1201 | -} | ||
| 1202 | - | ||
| 1203 | -int SrsAmf0Size::str(string value) | ||
| 1204 | -{ | ||
| 1205 | - return 1 + SrsAmf0Size::utf8(value); | ||
| 1206 | -} | ||
| 1207 | - | ||
| 1208 | -int SrsAmf0Size::number() | ||
| 1209 | -{ | ||
| 1210 | - return 1 + 8; | ||
| 1211 | -} | ||
| 1212 | - | ||
| 1213 | -int SrsAmf0Size::null() | ||
| 1214 | -{ | ||
| 1215 | - return 1; | ||
| 1216 | -} | ||
| 1217 | - | ||
| 1218 | -int SrsAmf0Size::undefined() | ||
| 1219 | -{ | ||
| 1220 | - return 1; | ||
| 1221 | -} | ||
| 1222 | - | ||
| 1223 | -int SrsAmf0Size::boolean() | ||
| 1224 | -{ | ||
| 1225 | - return 1 + 1; | ||
| 1226 | -} | ||
| 1227 | - | ||
| 1228 | -int SrsAmf0Size::object(SrsAmf0Object* obj) | ||
| 1229 | -{ | ||
| 1230 | - if (!obj) { | ||
| 1231 | - return 0; | ||
| 1232 | - } | ||
| 1233 | - | ||
| 1234 | - return obj->size(); | ||
| 1235 | -} | ||
| 1236 | - | ||
| 1237 | -int SrsAmf0Size::object_eof() | ||
| 1238 | -{ | ||
| 1239 | - return 2 + 1; | ||
| 1240 | -} | ||
| 1241 | - | ||
| 1242 | -int SrsAmf0Size::array(SrsAmf0EcmaArray* arr) | ||
| 1243 | -{ | ||
| 1244 | - if (!arr) { | ||
| 1245 | - return 0; | ||
| 1246 | - } | ||
| 1247 | - | ||
| 1248 | - return arr->size(); | ||
| 1249 | -} | ||
| 1250 | - | ||
| 1251 | -int SrsAmf0Size::any(SrsAmf0Any* o) | ||
| 1252 | -{ | ||
| 1253 | - if (!o) { | ||
| 1254 | - return 0; | ||
| 1255 | - } | ||
| 1256 | - | ||
| 1257 | - return o->size(); | ||
| 1258 | -} |
| @@ -34,7 +34,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -34,7 +34,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 34 | #include <vector> | 34 | #include <vector> |
| 35 | 35 | ||
| 36 | class SrsStream; | 36 | class SrsStream; |
| 37 | -class SrsAmf0Object; | ||
| 38 | 37 | ||
| 39 | /** | 38 | /** |
| 40 | * any amf0 value. | 39 | * any amf0 value. |
| @@ -44,8 +43,9 @@ class SrsAmf0Object; | @@ -44,8 +43,9 @@ class SrsAmf0Object; | ||
| 44 | * | strict-array-type | date-type | long-string-type | xml-document-type | 43 | * | strict-array-type | date-type | long-string-type | xml-document-type |
| 45 | * | typed-object-type | 44 | * | typed-object-type |
| 46 | */ | 45 | */ |
| 47 | -struct SrsAmf0Any | 46 | +class SrsAmf0Any |
| 48 | { | 47 | { |
| 48 | +public: | ||
| 49 | char marker; | 49 | char marker; |
| 50 | 50 | ||
| 51 | SrsAmf0Any(); | 51 | SrsAmf0Any(); |
| @@ -69,8 +69,9 @@ struct SrsAmf0Any | @@ -69,8 +69,9 @@ struct SrsAmf0Any | ||
| 69 | * string-type = string-marker UTF-8 | 69 | * string-type = string-marker UTF-8 |
| 70 | * @return default value is empty string. | 70 | * @return default value is empty string. |
| 71 | */ | 71 | */ |
| 72 | -struct SrsAmf0String : public SrsAmf0Any | 72 | +class SrsAmf0String : public SrsAmf0Any |
| 73 | { | 73 | { |
| 74 | +public: | ||
| 74 | std::string value; | 75 | std::string value; |
| 75 | 76 | ||
| 76 | SrsAmf0String(const char* _value = NULL); | 77 | SrsAmf0String(const char* _value = NULL); |
| @@ -86,8 +87,9 @@ struct SrsAmf0String : public SrsAmf0Any | @@ -86,8 +87,9 @@ struct SrsAmf0String : public SrsAmf0Any | ||
| 86 | * 0 is false, <> 0 is true | 87 | * 0 is false, <> 0 is true |
| 87 | * @return default value is false. | 88 | * @return default value is false. |
| 88 | */ | 89 | */ |
| 89 | -struct SrsAmf0Boolean : public SrsAmf0Any | 90 | +class SrsAmf0Boolean : public SrsAmf0Any |
| 90 | { | 91 | { |
| 92 | +public: | ||
| 91 | bool value; | 93 | bool value; |
| 92 | 94 | ||
| 93 | SrsAmf0Boolean(bool _value = false); | 95 | SrsAmf0Boolean(bool _value = false); |
| @@ -102,8 +104,9 @@ struct SrsAmf0Boolean : public SrsAmf0Any | @@ -102,8 +104,9 @@ struct SrsAmf0Boolean : public SrsAmf0Any | ||
| 102 | * number-type = number-marker DOUBLE | 104 | * number-type = number-marker DOUBLE |
| 103 | * @return default value is 0. | 105 | * @return default value is 0. |
| 104 | */ | 106 | */ |
| 105 | -struct SrsAmf0Number : public SrsAmf0Any | 107 | +class SrsAmf0Number : public SrsAmf0Any |
| 106 | { | 108 | { |
| 109 | +public: | ||
| 107 | double value; | 110 | double value; |
| 108 | 111 | ||
| 109 | SrsAmf0Number(double _value = 0.0); | 112 | SrsAmf0Number(double _value = 0.0); |
| @@ -117,8 +120,9 @@ struct SrsAmf0Number : public SrsAmf0Any | @@ -117,8 +120,9 @@ struct SrsAmf0Number : public SrsAmf0Any | ||
| 117 | * 2.7 null Type | 120 | * 2.7 null Type |
| 118 | * null-type = null-marker | 121 | * null-type = null-marker |
| 119 | */ | 122 | */ |
| 120 | -struct SrsAmf0Null : public SrsAmf0Any | 123 | +class SrsAmf0Null : public SrsAmf0Any |
| 121 | { | 124 | { |
| 125 | +public: | ||
| 122 | SrsAmf0Null(); | 126 | SrsAmf0Null(); |
| 123 | virtual ~SrsAmf0Null(); | 127 | virtual ~SrsAmf0Null(); |
| 124 | 128 | ||
| @@ -130,8 +134,9 @@ struct SrsAmf0Null : public SrsAmf0Any | @@ -130,8 +134,9 @@ struct SrsAmf0Null : public SrsAmf0Any | ||
| 130 | * 2.8 undefined Type | 134 | * 2.8 undefined Type |
| 131 | * undefined-type = undefined-marker | 135 | * undefined-type = undefined-marker |
| 132 | */ | 136 | */ |
| 133 | -struct SrsAmf0Undefined : public SrsAmf0Any | 137 | +class SrsAmf0Undefined : public SrsAmf0Any |
| 134 | { | 138 | { |
| 139 | +public: | ||
| 135 | SrsAmf0Undefined(); | 140 | SrsAmf0Undefined(); |
| 136 | virtual ~SrsAmf0Undefined(); | 141 | virtual ~SrsAmf0Undefined(); |
| 137 | 142 | ||
| @@ -143,8 +148,9 @@ struct SrsAmf0Undefined : public SrsAmf0Any | @@ -143,8 +148,9 @@ struct SrsAmf0Undefined : public SrsAmf0Any | ||
| 143 | * object-end-type = UTF-8-empty object-end-marker | 148 | * object-end-type = UTF-8-empty object-end-marker |
| 144 | * 0x00 0x00 0x09 | 149 | * 0x00 0x00 0x09 |
| 145 | */ | 150 | */ |
| 146 | -struct SrsAmf0ObjectEOF : public SrsAmf0Any | 151 | +class SrsAmf0ObjectEOF : public SrsAmf0Any |
| 147 | { | 152 | { |
| 153 | +public: | ||
| 148 | int16_t utf8_empty; | 154 | int16_t utf8_empty; |
| 149 | 155 | ||
| 150 | SrsAmf0ObjectEOF(); | 156 | SrsAmf0ObjectEOF(); |
| @@ -159,7 +165,7 @@ struct SrsAmf0ObjectEOF : public SrsAmf0Any | @@ -159,7 +165,7 @@ struct SrsAmf0ObjectEOF : public SrsAmf0Any | ||
| 159 | * if ordered in map, the string compare order, the FMLE will creash when | 165 | * if ordered in map, the string compare order, the FMLE will creash when |
| 160 | * get the response of connect app. | 166 | * get the response of connect app. |
| 161 | */ | 167 | */ |
| 162 | -struct SrsUnSortedHashtable | 168 | +class SrsUnSortedHashtable |
| 163 | { | 169 | { |
| 164 | private: | 170 | private: |
| 165 | typedef std::pair<std::string, SrsAmf0Any*> SrsObjectPropertyType; | 171 | typedef std::pair<std::string, SrsAmf0Any*> SrsObjectPropertyType; |
| @@ -184,7 +190,7 @@ public: | @@ -184,7 +190,7 @@ public: | ||
| 184 | * anonymous-object-type = object-marker *(object-property) | 190 | * anonymous-object-type = object-marker *(object-property) |
| 185 | * object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker) | 191 | * object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker) |
| 186 | */ | 192 | */ |
| 187 | -struct SrsAmf0Object : public SrsAmf0Any | 193 | +class SrsAmf0Object : public SrsAmf0Any |
| 188 | { | 194 | { |
| 189 | private: | 195 | private: |
| 190 | SrsUnSortedHashtable properties; | 196 | SrsUnSortedHashtable properties; |
| @@ -213,7 +219,7 @@ public: | @@ -213,7 +219,7 @@ public: | ||
| 213 | * associative-count = U32 | 219 | * associative-count = U32 |
| 214 | * object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker) | 220 | * object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker) |
| 215 | */ | 221 | */ |
| 216 | -struct SrsAmf0EcmaArray : public SrsAmf0Any | 222 | +class SrsAmf0EcmaArray : public SrsAmf0Any |
| 217 | { | 223 | { |
| 218 | private: | 224 | private: |
| 219 | SrsUnSortedHashtable properties; | 225 | SrsUnSortedHashtable properties; |
| @@ -238,6 +244,24 @@ public: | @@ -238,6 +244,24 @@ public: | ||
| 238 | }; | 244 | }; |
| 239 | 245 | ||
| 240 | /** | 246 | /** |
| 247 | +* the class to get amf0 object size | ||
| 248 | +*/ | ||
| 249 | +class SrsAmf0Size | ||
| 250 | +{ | ||
| 251 | +public: | ||
| 252 | + static int utf8(std::string value); | ||
| 253 | + static int str(std::string value); | ||
| 254 | + static int number(); | ||
| 255 | + static int null(); | ||
| 256 | + static int undefined(); | ||
| 257 | + static int boolean(); | ||
| 258 | + static int object(SrsAmf0Object* obj); | ||
| 259 | + static int object_eof(); | ||
| 260 | + static int array(SrsAmf0EcmaArray* arr); | ||
| 261 | + static int any(SrsAmf0Any* o); | ||
| 262 | +}; | ||
| 263 | + | ||
| 264 | +/** | ||
| 241 | * read amf0 utf8 string from stream. | 265 | * read amf0 utf8 string from stream. |
| 242 | * 1.3.1 Strings and UTF-8 | 266 | * 1.3.1 Strings and UTF-8 |
| 243 | * UTF-8 = U16 *(UTF8-char) | 267 | * UTF-8 = U16 *(UTF8-char) |
| @@ -311,24 +335,6 @@ extern int srs_amf0_read_ecma_array(SrsStream* stream, SrsAmf0EcmaArray*& value) | @@ -311,24 +335,6 @@ extern int srs_amf0_read_ecma_array(SrsStream* stream, SrsAmf0EcmaArray*& value) | ||
| 311 | extern int srs_amf0_write_ecma_array(SrsStream* stream, SrsAmf0EcmaArray* value); | 335 | extern int srs_amf0_write_ecma_array(SrsStream* stream, SrsAmf0EcmaArray* value); |
| 312 | 336 | ||
| 313 | /** | 337 | /** |
| 314 | -* the class to get amf0 object size | ||
| 315 | -*/ | ||
| 316 | -class SrsAmf0Size | ||
| 317 | -{ | ||
| 318 | -public: | ||
| 319 | - static int utf8(std::string value); | ||
| 320 | - static int str(std::string value); | ||
| 321 | - static int number(); | ||
| 322 | - static int null(); | ||
| 323 | - static int undefined(); | ||
| 324 | - static int boolean(); | ||
| 325 | - static int object(SrsAmf0Object* obj); | ||
| 326 | - static int object_eof(); | ||
| 327 | - static int array(SrsAmf0EcmaArray* arr); | ||
| 328 | - static int any(SrsAmf0Any* o); | ||
| 329 | -}; | ||
| 330 | - | ||
| 331 | -/** | ||
| 332 | * convert the any to specified object. | 338 | * convert the any to specified object. |
| 333 | * @return T*, the converted object. never NULL. | 339 | * @return T*, the converted object. never NULL. |
| 334 | * @remark, user must ensure the current object type, | 340 | * @remark, user must ensure the current object type, |
-
请 注册 或 登录 后发表评论