Gnash
0.8.10
|
00001 // AMF.h Low level functions for manipulating and reading AMF buffers. 00002 // 00003 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 00004 // Free Software Foundation, Inc 00005 // 00006 // This program is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 3 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program; if not, write to the Free Software 00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00019 00020 // This file provides low-level manipulators for AMF buffers. It can be used 00021 // without reliance on libcore. 00022 00023 #ifndef GNASH_AMF_H 00024 #define GNASH_AMF_H 00025 00026 #include <string> 00027 #include <boost/cstdint.hpp> 00028 00029 #include "dsodefs.h" 00030 #include "GnashException.h" 00031 00032 namespace gnash { 00033 class SimpleBuffer; 00034 } 00035 00036 namespace gnash { 00037 00039 // 00043 namespace amf { 00044 00045 enum Type { 00046 NOTYPE = -1, 00047 NUMBER_AMF0 = 0x00, 00048 BOOLEAN_AMF0 = 0x01, 00049 STRING_AMF0 = 0x02, 00050 OBJECT_AMF0 = 0x03, 00051 MOVIECLIP_AMF0 = 0x04, 00052 NULL_AMF0 = 0x05, 00053 UNDEFINED_AMF0 = 0x06, 00054 REFERENCE_AMF0 = 0x07, 00055 ECMA_ARRAY_AMF0 = 0x08, 00056 OBJECT_END_AMF0 = 0x09, 00057 STRICT_ARRAY_AMF0 = 0x0a, 00058 DATE_AMF0 = 0x0b, 00059 LONG_STRING_AMF0 = 0x0c, 00060 UNSUPPORTED_AMF0 = 0x0d, 00061 RECORD_SET_AMF0 = 0x0e, 00062 XML_OBJECT_AMF0 = 0x0f, 00063 TYPED_OBJECT_AMF0 = 0x10 00064 }; 00065 00067 // 00069 class DSOEXPORT 00070 AMFException : public GnashException 00071 { 00072 public: 00073 AMFException(const std::string& msg) 00074 : 00075 GnashException(msg) 00076 {} 00077 }; 00078 00080 // 00083 // 00085 DSOEXPORT double readNumber(const boost::uint8_t*& pos, 00086 const boost::uint8_t* end); 00087 00089 // 00092 // 00094 DSOEXPORT bool readBoolean(const boost::uint8_t*& pos, 00095 const boost::uint8_t* end); 00096 00098 // 00101 // 00103 DSOEXPORT std::string readString(const boost::uint8_t*& pos, 00104 const boost::uint8_t* end); 00105 00107 // 00110 // 00112 DSOEXPORT std::string readLongString(const boost::uint8_t*& pos, 00113 const boost::uint8_t* end); 00114 00116 // 00118 inline boost::uint16_t 00119 readNetworkShort(const boost::uint8_t* buf) 00120 { 00121 const boost::uint16_t s = buf[0] << 8 | buf[1]; 00122 return s; 00123 } 00124 00126 // 00128 inline boost::uint32_t 00129 readNetworkLong(const boost::uint8_t* buf) 00130 { 00131 const boost::uint32_t s = buf[0] << 24 | buf[1] << 16 | 00132 buf[2] << 8 | buf[3]; 00133 return s; 00134 } 00135 00137 // 00140 // 00144 DSOEXPORT void write(SimpleBuffer& buf, const std::string& str); 00145 00147 // 00150 inline void write(SimpleBuffer& buf, const char* str) { 00151 return write(buf, std::string(str)); 00152 } 00153 00155 // 00157 // 00161 DSOEXPORT void write(SimpleBuffer& buf, double d); 00162 00164 // 00166 // 00170 DSOEXPORT void write(SimpleBuffer& buf, bool b); 00171 00173 // 00177 DSOEXPORT void writePlainString(SimpleBuffer& buf, const std::string& str, 00178 Type t); 00179 00181 // 00183 DSOEXPORT void writePlainNumber(SimpleBuffer& buf, double d); 00184 00186 // 00189 template<typename T> 00190 void 00191 writeProperty(SimpleBuffer& buf, const std::string& name, const T& t) 00192 { 00193 writePlainString(buf, name, STRING_AMF0); 00194 write(buf, t); 00195 } 00196 00197 } // namespace amf 00198 } // namespace gnash 00199 00200 #endif