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 <cstdint>
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 std::uint8_t*& pos,
86  const std::uint8_t* end);
87 
89 //
92 //
94 DSOEXPORT bool readBoolean(const std::uint8_t*& pos,
95  const std::uint8_t* end);
96 
98 //
101 //
103 DSOEXPORT std::string readString(const std::uint8_t*& pos,
104  const std::uint8_t* end);
105 
107 //
110 //
112 DSOEXPORT std::string readLongString(const std::uint8_t*& pos,
113  const std::uint8_t* end);
114 
116 //
118 inline std::uint16_t
119 readNetworkShort(const std::uint8_t* buf)
120 {
121  const std::uint16_t s = buf[0] << 8 | buf[1];
122  return s;
123 }
124 
126 //
128 inline std::uint32_t
129 readNetworkLong(const std::uint8_t* buf)
130 {
131  const std::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
Definition: GnashKey.h:150
Definition: AMF.h:55
Definition: AMF.h:49
std::uint16_t readNetworkShort(const std::uint8_t *buf)
Read an unsigned 16-bit value in network byte order.
Definition: AMF.h:119
void write(SimpleBuffer &buf, const std::string &str)
Write a string to an AMF buffer.
Definition: AMF.cpp:161
Definition: AMF.h:56
bool readBoolean(const std::uint8_t *&pos, const std::uint8_t *_end)
Read a boolean value from the buffer.
Definition: AMF.cpp:50
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
AMFException(const std::string &msg)
Definition: AMF.h:73
Definition: AMF.h:47
Type
Definition: AMF.h:45
std::string readString(const std::uint8_t *&pos, const std::uint8_t *end)
Read a string value from the buffer.
Definition: AMF.cpp:87
void writePlainString(SimpleBuffer &buf, const std::string &str, Type t)
Encode a plain short string to an AMF buffer.
Definition: AMF.cpp:133
Definition: GnashKey.h:166
Exception for handling malformed buffers.
Definition: AMF.h:69
Definition: AMF.h:48
Definition: AMF.h:52
Definition: AMF.h:63
std::uint32_t readNetworkLong(const std::uint8_t *buf)
Read an unsigned 32-bit value in network byte order.
Definition: AMF.h:129
Definition: AMF.h:61
Definition: AMF.h:62
Definition: AMF.h:51
Definition: AMF.h:57
Definition: GnashKey.h:148
#define DSOEXPORT
Definition: dsodefs.h:55
void writeProperty(SimpleBuffer &buf, const std::string &name, const T &t)
Encode a string-value pair.
Definition: AMF.h:191
Definition: AMF.h:58
Definition: AMF.h:50
Definition: GnashKey.h:132
Definition: AMF.h:53
Definition: AMF.h:54
pixel_iterator< T > end(GnashImage &im)
Definition: ImageIterators.h:198
A simple buffer of bytes.
Definition: SimpleBuffer.h:38
Definition: AMF.h:60
Definition: AMF.h:46
Definition: AMF.h:59
Definition: GnashKey.h:165
double readNumber(const std::uint8_t *&pos, const std::uint8_t *end)
Read a number from an AMF buffer.
Definition: AMF.cpp:65
std::string readLongString(const std::uint8_t *&pos, const std::uint8_t *end)
Read a long string value from the buffer.
Definition: AMF.cpp:109
std::string name
Definition: LocalConnection_as.cpp:149
Top-level gnash exception.
Definition: GnashException.h:30
void writePlainNumber(SimpleBuffer &buf, double d)
Write a number to an AMF buffer.
Definition: AMF.cpp:154