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,
63  TYPED_OBJECT_AMF0 = 0x10
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 {
194  write(buf, t);
195 }
196 
197 } // namespace amf
198 } // namespace gnash
199 
200 #endif
AMF.h
gnash::amf::AMFException
Exception for handling malformed buffers.
Definition: AMF.h:71
gnash::amf::MOVIECLIP_AMF0
@ MOVIECLIP_AMF0
Definition: AMF.h:51
name
std::string name
Definition: LocalConnection_as.cpp:149
gnash::key::d
@ d
Definition: GnashKey.h:150
gnash::SimpleBuffer::appendNetworkLong
void appendNetworkLong(const std::uint32_t l)
Append 4 bytes to the buffer.
Definition: SimpleBuffer.h:169
gnash::amf::readBoolean
bool readBoolean(const std::uint8_t *&pos, const std::uint8_t *_end)
Read a boolean value from the buffer.
Definition: AMF.cpp:50
gnash::GnashException
Top-level gnash exception.
Definition: GnashException.h:31
SimpleBuffer.h
gnash::amf::readLongString
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
gnash::key::T
@ T
Definition: GnashKey.h:132
gnash::amf::TYPED_OBJECT_AMF0
@ TYPED_OBJECT_AMF0
Definition: AMF.h:63
dsodefs.h
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
_
#define _(String)
Definition: log.h:44
gnash::amf::XML_OBJECT_AMF0
@ XML_OBJECT_AMF0
Definition: AMF.h:62
gnash::SimpleBuffer::appendByte
void appendByte(const std::uint8_t b)
Append a byte to the buffer.
Definition: SimpleBuffer.h:140
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::amf::STRICT_ARRAY_AMF0
@ STRICT_ARRAY_AMF0
Definition: AMF.h:57
gnash::amf::NOTYPE
@ NOTYPE
Definition: AMF.h:46
gnash::key::s
@ s
Definition: GnashKey.h:165
gnash::amf::LONG_STRING_AMF0
@ LONG_STRING_AMF0
Definition: AMF.h:59
gnash::amf::NULL_AMF0
@ NULL_AMF0
Definition: AMF.h:52
gnash::amf::readNetworkShort
std::uint16_t readNetworkShort(const std::uint8_t *buf)
Read an unsigned 16-bit value in network byte order.
Definition: AMF.h:119
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::amf::RECORD_SET_AMF0
@ RECORD_SET_AMF0
Definition: AMF.h:61
gnash::amf::readNetworkLong
std::uint32_t readNetworkLong(const std::uint8_t *buf)
Read an unsigned 32-bit value in network byte order.
Definition: AMF.h:129
gnash::key::t
@ t
Definition: GnashKey.h:166
gnash::amf::OBJECT_END_AMF0
@ OBJECT_END_AMF0
Definition: AMF.h:56
gnash::amf::write
void write(SimpleBuffer &buf, const std::string &str)
Write a string to an AMF buffer.
Definition: AMF.cpp:161
gnash::amf::Type
Type
Definition: AMF.h:45
gnash::amf::readString
std::string readString(const std::uint8_t *&pos, const std::uint8_t *end)
Read a string value from the buffer.
Definition: AMF.cpp:87
gnash::amf::DATE_AMF0
@ DATE_AMF0
Definition: AMF.h:58
gnash::amf::OBJECT_AMF0
@ OBJECT_AMF0
Definition: AMF.h:50
gnash::amf::writePlainString
void writePlainString(SimpleBuffer &buf, const std::string &str, Type t)
Encode a plain short string to an AMF buffer.
Definition: AMF.cpp:133
gnash::amf::ECMA_ARRAY_AMF0
@ ECMA_ARRAY_AMF0
Definition: AMF.h:55
gnash::amf::NUMBER_AMF0
@ NUMBER_AMF0
Definition: AMF.h:47
gnash::amf::writeProperty
void writeProperty(SimpleBuffer &buf, const std::string &name, const T &t)
Encode a string-value pair.
Definition: AMF.h:191
gnash::amf::REFERENCE_AMF0
@ REFERENCE_AMF0
Definition: AMF.h:54
log.h
gnash::image::end
pixel_iterator< T > end(GnashImage &im)
Definition: ImageIterators.h:198
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::amf::UNDEFINED_AMF0
@ UNDEFINED_AMF0
Definition: AMF.h:53
DSOEXPORT
#define DSOEXPORT
Definition: dsodefs.h:55
gnash::amf::STRING_AMF0
@ STRING_AMF0
Definition: AMF.h:49
gnash::amf::UNSUPPORTED_AMF0
@ UNSUPPORTED_AMF0
Definition: AMF.h:60
gnash::SimpleBuffer::append
void append(const void *inData, size_t size)
Append data to the buffer.
Definition: SimpleBuffer.h:123
gnash::amf::AMFException::AMFException
AMFException(const std::string &msg)
Definition: AMF.h:73
gnash::amf::readNumber
double readNumber(const std::uint8_t *&pos, const std::uint8_t *end)
Read a number from an AMF buffer.
Definition: AMF.cpp:65
gnash::amf::BOOLEAN_AMF0
@ BOOLEAN_AMF0
Definition: AMF.h:48
gnash::key::u
@ u
Definition: GnashKey.h:167
GnashException.h
x
std::int32_t x
Definition: BitmapData_as.cpp:434
gnash::amf::writePlainNumber
void writePlainNumber(SimpleBuffer &buf, double d)
Write a number to an AMF buffer.
Definition: AMF.cpp:154
gnash::SimpleBuffer::appendNetworkShort
void appendNetworkShort(const std::uint16_t s)
Append 2 bytes to the buffer.
Definition: SimpleBuffer.h:154
gnash::key::b
@ b
Definition: GnashKey.h:148
gnash::SimpleBuffer
A simple buffer of bytes.
Definition: SimpleBuffer.h:38