/usr/include/gnash/AMF.h is in gnash-dev 0.8.11~git20160109-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | // AMF.h Low level functions for manipulating and reading AMF buffers.
//
// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
// Free Software Foundation, Inc
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// This file provides low-level manipulators for AMF buffers. It can be used
// without reliance on libcore.
#ifndef GNASH_AMF_H
#define GNASH_AMF_H
#include <string>
#include <cstdint>
#include "dsodefs.h"
#include "GnashException.h"
namespace gnash {
class SimpleBuffer;
}
namespace gnash {
/// Functions and classes for handling AMF.
//
/// AMF is a simple serialization format for ActionScript objects and values,
/// allowing them to be stored and transmitted. The AMF namespace provides
/// both low-level and high-level conversion to and from AMF buffers.
namespace amf {
enum Type {
NOTYPE = -1,
NUMBER_AMF0 = 0x00,
BOOLEAN_AMF0 = 0x01,
STRING_AMF0 = 0x02,
OBJECT_AMF0 = 0x03,
MOVIECLIP_AMF0 = 0x04,
NULL_AMF0 = 0x05,
UNDEFINED_AMF0 = 0x06,
REFERENCE_AMF0 = 0x07,
ECMA_ARRAY_AMF0 = 0x08,
OBJECT_END_AMF0 = 0x09,
STRICT_ARRAY_AMF0 = 0x0a,
DATE_AMF0 = 0x0b,
LONG_STRING_AMF0 = 0x0c,
UNSUPPORTED_AMF0 = 0x0d,
RECORD_SET_AMF0 = 0x0e,
XML_OBJECT_AMF0 = 0x0f,
TYPED_OBJECT_AMF0 = 0x10
};
/// Exception for handling malformed buffers.
//
/// All low-level reading operations can throw this error.
class DSOEXPORT
AMFException : public GnashException
{
public:
AMFException(const std::string& msg)
:
GnashException(msg)
{}
};
/// Read a number from an AMF buffer
//
/// This does not read a type byte; use AMF::Reader when the type should
/// be determined from the buffer.
//
/// This function will throw an AMFException if it encounters ill-formed AMF.
DSOEXPORT double readNumber(const std::uint8_t*& pos,
const std::uint8_t* end);
/// Read a boolean value from the buffer.
//
/// This does not read a type byte; use AMF::Reader when the type should
/// be determined from the buffer.
//
/// This function will throw an AMFException if it encounters ill-formed AMF.
DSOEXPORT bool readBoolean(const std::uint8_t*& pos,
const std::uint8_t* end);
/// Read a string value from the buffer.
//
/// This does not read a type byte; use AMF::Reader when the type should
/// be determined from the buffer.
//
/// This function will throw an AMFException if it encounters ill-formed AMF.
DSOEXPORT std::string readString(const std::uint8_t*& pos,
const std::uint8_t* end);
/// Read a long string value from the buffer.
//
/// This does not read a type byte; use AMF::Reader when the type should
/// be determined from the buffer.
//
/// This function will throw an AMFException if it encounters ill-formed AMF.
DSOEXPORT std::string readLongString(const std::uint8_t*& pos,
const std::uint8_t* end);
/// Read an unsigned 16-bit value in network byte order.
//
/// You must ensure that the buffer contains at least 2 bytes!
inline std::uint16_t
readNetworkShort(const std::uint8_t* buf)
{
const std::uint16_t s = buf[0] << 8 | buf[1];
return s;
}
/// Read an unsigned 32-bit value in network byte order.
//
/// You must ensure that the buffer contains at least 4 bytes!
inline std::uint32_t
readNetworkLong(const std::uint8_t* buf)
{
const std::uint32_t s = buf[0] << 24 | buf[1] << 16 |
buf[2] << 8 | buf[3];
return s;
}
/// Write a string to an AMF buffer.
//
/// This function writes the type byte and the string value. It also handles
/// both long and short strings automatically.
//
/// This is overloaded for automatic type deduction to allow the use of
/// a template for more complex operations. You must be careful when using
/// it!
DSOEXPORT void write(SimpleBuffer& buf, const std::string& str);
/// Write a C string to an AMF buffer.
//
/// The overload is necessary to prevent const char* being resolved to the
/// boolean overload.
inline void write(SimpleBuffer& buf, const char* str) {
return write(buf, std::string(str));
}
/// Write a number to an AMF buffer.
//
/// This function writes the type byte and the double value.
//
/// This is overloaded for automatic type deduction to allow the use of
/// a template for more complex operations. You must be careful when using
/// it!
DSOEXPORT void write(SimpleBuffer& buf, double d);
/// Write a boolean value to an AMF buffer.
//
/// This function writes the type byte and the boolean value.
//
/// This is overloaded for automatic type deduction to allow the use of
/// a template for more complex operations. You must be careful when using
/// it!
DSOEXPORT void write(SimpleBuffer& buf, bool b);
/// Encode a plain short string to an AMF buffer.
//
/// This does not encode a type byte; it is used for cases where a string is
/// required, such as for the name of an object property, and therefore does
/// not use a type byte.
DSOEXPORT void writePlainString(SimpleBuffer& buf, const std::string& str,
Type t);
/// Write a number to an AMF buffer.
//
/// This function writes the double value without a type byte.
DSOEXPORT void writePlainNumber(SimpleBuffer& buf, double d);
/// Encode a string-value pair.
//
/// This is used for object properties; the string is always encoded with
/// a 2-byte length.
template<typename T>
void
writeProperty(SimpleBuffer& buf, const std::string& name, const T& t)
{
writePlainString(buf, name, STRING_AMF0);
write(buf, t);
}
} // namespace amf
} // namespace gnash
#endif
|