[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/rtmp r9879: calculate our size, tweak debu
From: |
rob |
Subject: |
[Gnash-commit] /srv/bzr/gnash/rtmp r9879: calculate our size, tweak debug output. |
Date: |
Mon, 22 Dec 2008 10:43:54 -0800 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9879
committer: address@hidden
branch nick: rtmp
timestamp: Mon 2008-12-22 10:43:54 -0800
message:
calculate our size, tweak debug output.
modified:
libamf/element.cpp
libamf/element.h
=== modified file 'libamf/element.cpp'
--- a/libamf/element.cpp 2008-12-21 16:49:55 +0000
+++ b/libamf/element.cpp 2008-12-22 18:43:54 +0000
@@ -377,6 +377,55 @@
return false;
};
+size_t
+Element::calculateSize()
+{
+// GNASH_REPORT_FUNCTION;
+ return calculateSize();
+}
+
+size_t
+Element::calculateSize(amf::Element &el) const
+{
+// GNASH_REPORT_FUNCTION;
+ size_t outsize = 0;
+
+ // Simple Elements have everything contained in just the class itself.
+ // If thr name is set, it's a property, so the length is
+ // prefixed to the name string.
+ if (el.getNameSize()) {
+ outsize += el.getNameSize() + sizeof(boost::uint16_t);
+ }
+ // If there is any data, then the size of the data plus the header
+ // of the type and the length is next.
+ if (el.getDataSize()) {
+ outsize += el.getDataSize() + AMF_HEADER_SIZE;
+ }
+
+ // If an array has no data, it's undefined, so has a length of zero.
+ if (el.getType() == Element::STRICT_ARRAY_AMF0) {
+ if (el.getDataSize() == 0) {
+ outsize = sizeof(boost::uint32_t) + 1;
+ }
+ }
+
+ // More complex messages have child elements, either properties or
+ // the items in an array, If we have children, count up their size too.
+ // Calculate the total size of the message
+ vector<boost::shared_ptr<amf::Element> > props = el.getProperties();
+ for (size_t i=0; i<props.size(); i++) {
+ outsize += props[i]->getDataSize();
+ if (props[i]->getNameSize()) {
+ outsize += props[i]->getNameSize();
+ outsize += amf::AMF_PROP_HEADER_SIZE;
+ } else {
+ outsize += amf::AMF_HEADER_SIZE;
+ }
+ }
+
+ return outsize;
+}
+
/// \brief Encode this Element (data type object).
/// This encodes this Element and all of it's associated
/// properties into raw binary data in big endoan format.
@@ -718,13 +767,13 @@
// GNASH_REPORT_FUNCTION;
_type = Element::BOOLEAN_AMF0;
try {
- check_buffer(sizeof(bool));
+ check_buffer(1);
} catch (std::exception& e) {
log_error("%s", e.what());
return *this;
}
- *(_buffer->reference()) = flag;
+ *_buffer = flag;
return *this;
}
@@ -1377,11 +1426,14 @@
{
// GNASH_REPORT_FUNCTION;
- if (_name) {
- os << "Element name: " << _name << ", data length is " << getDataSize()
<< endl;
- }
-
os << astype_str[_type] << ": ";
+ if (_name) {
+ os << " property name is: " << _name << ", ";
+ } else {
+ os << "(no name)";
+ }
+ os << endl << "data length is " << getDataSize() << endl;
+
switch (_type) {
case Element::NUMBER_AMF0:
@@ -1432,9 +1484,11 @@
break;
}
-// if (_buffer) {
-// _buffer->dump();
-// }
+ if (_type != Element::BOOLEAN_AMF0) {
+ if (_buffer) {
+ _buffer->dump();
+ }
+ }
if (_properties.size() > 0) {
vector<boost::shared_ptr<Element> >::const_iterator ait;
=== modified file 'libamf/element.h'
--- a/libamf/element.h 2008-12-21 16:49:16 +0000
+++ b/libamf/element.h 2008-12-22 18:43:54 +0000
@@ -721,7 +721,10 @@
/// debugging purposes.
std::vector<boost::shared_ptr<Element> > getProperties() const
{ return _properties; };
-
+
+ size_t calculateSize();
+ size_t calculateSize(amf::Element &el) const;
+
/// \brief Dump the internal data of this class in a human readable form.
/// @remarks This should only be used for debugging purposes.
void dump() const { dump(std::cerr); }
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/rtmp r9879: calculate our size, tweak debug output.,
rob <=