[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r11957: Minor changes.
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r11957: Minor changes. |
Date: |
Thu, 18 Feb 2010 14:55:30 +0100 |
User-agent: |
Bazaar (2.0.3) |
------------------------------------------------------------
revno: 11957 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Thu 2010-02-18 14:55:30 +0100
message:
Minor changes.
modified:
libcore/AMF.cpp
libcore/AMF.h
=== modified file 'libcore/AMF.cpp'
--- a/libcore/AMF.cpp 2010-02-15 10:46:53 +0000
+++ b/libcore/AMF.cpp 2010-02-18 13:41:08 +0000
@@ -43,13 +43,6 @@
namespace {
- as_value readNumber(const boost::uint8_t*& pos, const boost::uint8_t*
_end);
- as_value readBoolean(const boost::uint8_t*& pos,
- const boost::uint8_t* _end);
- as_value readString(const boost::uint8_t*& pos, const boost::uint8_t*
_end);
- as_value readLongString(const boost::uint8_t*& pos,
- const boost::uint8_t* _end);
-
inline boost::uint16_t readNetworkShort(const boost::uint8_t* buf);
inline boost::uint32_t readNetworkLong(const boost::uint8_t* buf);
@@ -58,11 +51,11 @@
namespace {
/// Class used to serialize properties of an object to a buffer
-class PropsBufSerializer : public AbstractPropertyVisitor
+class ObjectSerializer : public AbstractPropertyVisitor
{
public:
- PropsBufSerializer(Writer& w, VM& vm)
+ ObjectSerializer(Writer& w, VM& vm)
:
_writer(w),
_st(vm.getStringTable()),
@@ -119,19 +112,6 @@
};
-/// Exception for handling malformed buffers.
-//
-/// This exception is for internal use only! Do not throw it outside this
-/// TU.
-struct
-AMFException : public GnashException
-{
- AMFException(const std::string& msg)
- :
- GnashException(msg)
- {}
-};
-
}
bool
@@ -266,7 +246,7 @@
_buf.appendByte(OBJECT_AMF0);
}
- PropsBufSerializer props(*this, vm);
+ ObjectSerializer props(*this, vm);
obj->visitProperties<IsEnumerable>(props);
if (!props.success()) {
log_error("Could not serialize object");
@@ -695,9 +675,8 @@
return word;
}
-namespace {
-as_value
+bool
readBoolean(const boost::uint8_t*& pos, const boost::uint8_t* _end)
{
if (pos == _end) {
@@ -712,11 +691,11 @@
return val;
}
-as_value
-readNumber(const boost::uint8_t*& pos, const boost::uint8_t* _end)
+double
+readNumber(const boost::uint8_t*& pos, const boost::uint8_t* end)
{
- if (_end - pos < 8) {
+ if (end - pos < 8) {
throw AMFException("Read past _end of buffer for number type");
}
@@ -731,20 +710,20 @@
log_debug("amf0 read double: %e", dub);
#endif
- return as_value(d);
+ return d;
}
-as_value
-readString(const boost::uint8_t*& pos, const boost::uint8_t* _end)
+std::string
+readString(const boost::uint8_t*& pos, const boost::uint8_t* end)
{
- if (_end - pos < 2) {
+ if (end - pos < 2) {
throw AMFException("Read past _end of buffer for string length");
}
const boost::uint16_t si = readNetworkShort(pos);
pos += 2;
- if (_end - pos < si) {
+ if (end - pos < si) {
throw AMFException("Read past _end of buffer for string type");
}
@@ -753,19 +732,19 @@
#ifdef GNASH_DEBUG_AMF_DESERIALIZE
log_debug("amf0 read string: %s", str);
#endif
- return as_value(str);
+ return str;
}
-as_value
-readLongString(const boost::uint8_t*& pos, const boost::uint8_t* _end)
+std::string
+readLongString(const boost::uint8_t*& pos, const boost::uint8_t* end)
{
- if (_end - pos < 4) {
+ if (end - pos < 4) {
throw AMFException("Read past _end of buffer for long string length");
}
const boost::uint32_t si = readNetworkLong(pos);
pos += 4;
- if (_end - pos < si) {
+ if (end - pos < si) {
throw AMFException("Read past _end of buffer for long string type");
}
@@ -776,10 +755,12 @@
log_debug("amf0 read long string: %s", str);
#endif
- return as_value(str);
+ return str;
}
+namespace {
+
inline boost::uint16_t
readNetworkShort(const boost::uint8_t* buf)
{
=== modified file 'libcore/AMF.h'
--- a/libcore/AMF.h 2010-02-15 10:46:53 +0000
+++ b/libcore/AMF.h 2010-02-18 07:43:24 +0000
@@ -26,6 +26,7 @@
#include "as_value.h"
#include "dsodefs.h"
+#include "GnashException.h"
namespace gnash {
class as_object;
@@ -122,6 +123,19 @@
};
+/// Exception for handling malformed buffers.
+//
+/// This exception is thrown only during reading.
+struct DSOEXPORT
+AMFException : public GnashException
+{
+ AMFException(const std::string& msg)
+ :
+ GnashException(msg)
+ {}
+};
+
+
/// Deserialize an AMF buffer to as_values.
//
/// This class relies on the public interface of as_value because we don't
@@ -140,6 +154,17 @@
class Reader
{
public:
+
+ /// Construct a Reader with pointers into an AMF buffer.
+ //
+ /// You can use the AMF::Reader in combination with other reads on the
+ /// data as long as the read position is never moved after end.
+ //
+ /// @param pos The read position in the buffer. This is moved after
+ /// every read to point to the next data field. You must
+ /// ensure that pos is not greater than end on every read.
+ /// @param end The end of the buffer.
+ /// @param gl A global reference for creating objects when necessary.
Reader(const boost::uint8_t*& pos, const boost::uint8_t* end, Global_as&
gl)
:
_pos(pos),
@@ -190,6 +215,39 @@
};
+/// 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.
+double readNumber(const boost::uint8_t*& pos, const boost::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.
+bool readBoolean(const boost::uint8_t*& pos, const boost::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.
+std::string readString(const boost::uint8_t*& pos, const boost::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.
+std::string readLongString(const boost::uint8_t*& pos,
+ const boost::uint8_t* end);
+
/// Swap bytes in raw data.
//
/// This only swaps bytes if the host byte order is little endian.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r11957: Minor changes.,
Benjamin Wolsey <=