Gnash  0.8.11dev
AMF.h
Go to the documentation of this file.
1 // AMF.h Low level functions for manipulating and reading AMF buffers.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 // This file provides low-level manipulators for AMF buffers. It can be used
21 // without reliance on libcore.
22 
23 #ifndef GNASH_AMF_H
24 #define GNASH_AMF_H
25 
26 #include <string>
27 #include <boost/cstdint.hpp>
28 
29 #include "dsodefs.h"
30 #include "GnashException.h"
31 
32 namespace gnash {
33  class SimpleBuffer;
34 }
35 
36 namespace gnash {
37 
39 //
43 namespace amf {
44 
45 enum Type {
46  NOTYPE = -1,
47  NUMBER_AMF0 = 0x00,
48  BOOLEAN_AMF0 = 0x01,
49  STRING_AMF0 = 0x02,
50  OBJECT_AMF0 = 0x03,
52  NULL_AMF0 = 0x05,
58  DATE_AMF0 = 0x0b,
64 };
65 
67 //
69 class DSOEXPORT
71 {
72 public:
73  AMFException(const std::string& msg)
74  :
75  GnashException(msg)
76  {}
77 };
78 
80 //
83 //
85 DSOEXPORT double readNumber(const boost::uint8_t*& pos,
86  const boost::uint8_t* end);
87 
89 //
92 //
94 DSOEXPORT bool readBoolean(const boost::uint8_t*& pos,
95  const boost::uint8_t* end);
96 
98 //
101 //
103 DSOEXPORT std::string readString(const boost::uint8_t*& pos,
104  const boost::uint8_t* end);
105 
107 //
110 //
112 DSOEXPORT std::string readLongString(const boost::uint8_t*& pos,
113  const boost::uint8_t* end);
114 
116 //
118 inline boost::uint16_t
119 readNetworkShort(const boost::uint8_t* buf)
120 {
121  const boost::uint16_t s = buf[0] << 8 | buf[1];
122  return s;
123 }
124 
126 //
128 inline boost::uint32_t
129 readNetworkLong(const boost::uint8_t* buf)
130 {
131  const boost::uint32_t s = buf[0] << 24 | buf[1] << 16 |
132  buf[2] << 8 | buf[3];
133  return s;
134 }
135 
137 //
140 //
144 DSOEXPORT void write(SimpleBuffer& buf, const std::string& str);
145 
147 //
150 inline void write(SimpleBuffer& buf, const char* str) {
151  return write(buf, std::string(str));
152 }
153 
155 //
157 //
161 DSOEXPORT void write(SimpleBuffer& buf, double d);
162 
164 //
166 //
170 DSOEXPORT void write(SimpleBuffer& buf, bool b);
171 
173 //
177 DSOEXPORT void writePlainString(SimpleBuffer& buf, const std::string& str,
178  Type t);
179 
181 //
183 DSOEXPORT void writePlainNumber(SimpleBuffer& buf, double d);
184 
186 //
189 template<typename T>
190 void
191 writeProperty(SimpleBuffer& buf, const std::string& name, const T& t)
192 {
193  writePlainString(buf, name, STRING_AMF0);
194  write(buf, t);
195 }
196 
197 } // namespace amf
198 } // namespace gnash
199 
200 #endif