amf.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef amf_H_
  2. #define amf_H_
  3. #include <vector>
  4. #include <map>
  5. #include <stdexcept>
  6. #include "unicode/uniString.h"
  7. enum AMF0Marker_t
  8. {
  9. AMF0_number_marker = 0x00,
  10. AMF0_boolean_marker,
  11. AMF0_string_marker,
  12. AMF0_object_marker,
  13. AMF0_movieclip_marker,
  14. AMF0_null_marker,
  15. AMF0_undefined_marker,
  16. AMF0_reference_marker,
  17. AMF0_ecma_array_marker,
  18. AMF0_object_end_marker,
  19. AMF0_strict_array_marker,
  20. AMF0_date_marker,
  21. AMF0_long_string_marker,
  22. AMF0_unsupported_marker,
  23. AMF0_recordset_marker,
  24. AMF0_xml_Document_marker,
  25. AMF0_typed_object_marker,
  26. AMF0_amvplus_object_marker
  27. };
  28. enum AMF3Marker_t
  29. {
  30. AMF3_undefined_marker = 0x00,
  31. AMF3_null_marker,
  32. AMF3_false_marker,
  33. AMF3_true_marker,
  34. AMF3_integer_marker,
  35. AMF3_double_marker,
  36. AMF3_string_marker,
  37. AMF3_xml_doc_marker,
  38. AMF3_date_marker,
  39. AMF3_array_marker,
  40. AMF3_object_marker,
  41. AMF3_xml_marker,
  42. AMF3_byte_array_marker,
  43. };
  44. struct AMFStrictArray
  45. {
  46. };
  47. struct AMFDate
  48. {
  49. };
  50. class AMFVal;
  51. struct AMFEMCAArray
  52. {
  53. private:
  54. typedef std::map<uniString::utf8,AMFVal*> propertyMap_t;
  55. std::map<uniString::utf8,AMFVal*> m_properties;
  56. public:
  57. AMFEMCAArray() throw();
  58. ~AMFEMCAArray() throw();
  59. AMFEMCAArray(const AMFEMCAArray &obj) throw();
  60. AMFEMCAArray& operator=(const AMFEMCAArray &obj) throw();
  61. void loadFromBitstream(const char *&bitstream,int &bitstreamLen,int mode,const uniString::utf8 &logMsgPrefix) throw(std::exception);
  62. const AMFVal* getProperty(const uniString::utf8 &key) const throw();
  63. void addProperty(const uniString::utf8 &key,AMFVal *v) throw(std::exception); // takes possession of "v"
  64. void clearProperties() throw();
  65. void serialize(std::vector<__uint8> &s,int mode,const uniString::utf8 &logMsgPrefix) const throw(std::exception);
  66. uniString::utf8 prettyPrint(int mode,const uniString::utf8 &tabs) const throw();
  67. };
  68. class AMFObject
  69. {
  70. private:
  71. typedef std::map<uniString::utf8,AMFVal*> propertyMap_t;
  72. std::map<uniString::utf8,AMFVal*> m_properties;
  73. public:
  74. AMFObject() throw();
  75. ~AMFObject() throw();
  76. AMFObject(const AMFObject &obj) throw();
  77. AMFObject& operator=(const AMFObject &obj) throw();
  78. void loadFromBitstream(const char *&bitstream,int &bitstreamLen,int mode,const uniString::utf8 &logMsgPrefix) throw(std::exception);
  79. const AMFVal* getProperty(const uniString::utf8 &key) const throw();
  80. void addProperty(const uniString::utf8 &key,AMFVal *v) throw(std::exception); // takes possession of "v"
  81. void clearProperties() throw();
  82. void serialize(std::vector<__uint8> &s,int mode,const uniString::utf8 &logMsgPrefix) const throw(std::exception);
  83. uniString::utf8 prettyPrint(int mode,const uniString::utf8 &tabs) const throw();
  84. };
  85. class AMFVal
  86. {
  87. private:
  88. AMF0Marker_t m_type0; // type
  89. AMF3Marker_t m_type3;
  90. // value depends on type
  91. int m_integer_val;
  92. double m_number_val;
  93. bool m_boolean_val;
  94. uniString::utf8 m_string_val;
  95. AMFObject m_object_val;
  96. __uint16 m_reference_val;
  97. AMFEMCAArray m_ecma_array_val;
  98. AMFStrictArray m_strict_array_val;
  99. AMFDate m_date_val;
  100. public:
  101. void loadFromBitstream(const char *&bitstream,int &bitstreamLen,int mode,const uniString::utf8 &logMsgPrefix) throw(std::exception);
  102. const uniString::utf8 &getString() const throw(std::exception);
  103. double getNumber() const throw(std::exception);
  104. bool getBool() const throw(std::exception);
  105. const AMFObject& getObject() const throw(std::exception);
  106. int getInteger() const throw(std::exception);
  107. AMFVal() throw(): m_type0(AMF0_null_marker),m_type3(AMF3_undefined_marker){}
  108. AMFVal(double v) throw(): m_type0(AMF0_number_marker),m_type3(AMF3_undefined_marker) ,m_number_val(v){}
  109. AMFVal(bool v) throw(): m_type0(AMF0_boolean_marker),m_type3(AMF3_undefined_marker),m_boolean_val(v){}
  110. AMFVal(const uniString::utf8 &v) throw(): m_type0(AMF0_string_marker),m_type3(AMF3_undefined_marker) ,m_string_val(v){}
  111. AMFVal(const AMFObject &v) throw(): m_type0(AMF0_object_marker),m_type3(AMF3_undefined_marker) ,m_object_val(v){}
  112. AMFVal(const AMFEMCAArray &v) throw(): m_type0(AMF0_ecma_array_marker),m_type3(AMF3_undefined_marker),m_ecma_array_val(v){}
  113. void serialize(std::vector<__uint8> &s,int mode,const uniString::utf8 &logMsgPrefix) const throw(std::exception);
  114. uniString::utf8 prettyPrint(int mode,const uniString::utf8 &tabs) const throw();
  115. };
  116. class AMFEncoding
  117. {
  118. private:
  119. std::vector<AMFVal> m_values;
  120. int m_mode;
  121. public:
  122. AMFEncoding(int mode = 0) throw():m_mode(mode){}
  123. ~AMFEncoding() throw(){}
  124. void clear() throw() { m_values.clear(); }
  125. void loadFromBitstream(const char *bitstream,int bitstreamLen,const uniString::utf8 &logMsgPrefix) throw(std::exception);
  126. const AMFVal& getValue(size_t index) const throw(std::exception);
  127. void appendValue(const AMFVal &v) throw();
  128. void serialize(std::vector<__uint8> &s,const uniString::utf8 &logMsgPrefix) const throw(std::exception);
  129. uniString::utf8 prettyPrint() const throw();
  130. };
  131. #endif