gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/rtmp r9977: add a flag to not encode as an


From: rob
Subject: [Gnash-commit] /srv/bzr/gnash/rtmp r9977: add a flag to not encode as an object, but merely as a list of the properties
Date: Tue, 10 Feb 2009 17:27:07 +0100
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9977
committer: address@hidden
branch nick: rtmp
timestamp: Tue 2009-02-10 17:27:07 +0100
message:
  add a flag to not encode as an object, but merely as a list of the properties
  as used by some response packets.
  if makeString() is done to an existing object, replace the old value with the
  new one after adjusting the buffer size if need be.
modified:
  libamf/element.cpp
  libamf/element.h
=== modified file 'libamf/element.cpp'
--- a/libamf/element.cpp        2009-02-04 21:18:47 +0000
+++ b/libamf/element.cpp        2009-02-10 16:27:07 +0000
@@ -457,6 +457,14 @@
 Element::encode()
 {
 //    GNASH_REPORT_FUNCTION;
+
+    return encode(false);
+}
+
+boost::shared_ptr<Buffer>
+Element::encode(bool notobject)
+{
+//    GNASH_REPORT_FUNCTION;
     size_t size = 0;
     boost::shared_ptr<Buffer> buf;
     if (_type == Element::OBJECT_AMF0) {
@@ -468,7 +476,9 @@
            size += AMF_PROP_HEADER_SIZE;
        }
        buf.reset(new Buffer(size+24)); // FIXME: why are we several bytes off ?
-       *buf = Element::OBJECT_AMF0;
+       if (!notobject) {
+           *buf = Element::OBJECT_AMF0;
+       }
        if (_name > 0) {
            size_t length = getNameSize();
            boost::uint16_t enclength = length;
@@ -493,10 +503,12 @@
            }
        }
 //     log_debug("FIXME: Terminating object");
-       boost::uint8_t pad = 0;
-       *buf += pad;
-       *buf += pad;
-       *buf += TERMINATOR;
+       if (!notobject) {
+           boost::uint8_t pad = 0;
+           *buf += pad;
+           *buf += pad;
+           *buf += TERMINATOR;
+       }
        return buf;
     } else {
            return AMF::encodeElement(*this);
@@ -598,12 +610,19 @@
 //    GNASH_REPORT_FUNCTION;
     _type = Element::STRING_AMF0;
 
-    // Make room for an additional NULL terminator
-    try {
-       check_buffer(size+1);
-    } catch (std::exception& e) {
-       log_error("%s", e.what());
-       return *this;
+    // If there is an existing string, 
+    if (_buffer) {
+       if (_buffer->size() > size) {
+           _buffer->resize(size);
+       }
+    } else {
+       // Make room for an additional NULL terminator
+       try {
+           check_buffer(size+1);
+       } catch (std::exception& e) {
+           log_error("%s", e.what());
+           return *this;
+       }
     }
     _buffer->clear();          // FIXME: this could be a performance issue
     _buffer->copy(data, size);
@@ -1475,7 +1494,7 @@
     if (_name) {
        os << " property name is: \"" << _name << "\", ";
     } else {
-       os << "(no name)";
+       os << "(no name), ";
     }
     os << "data length is " << getDataSize() << endl;
 

=== modified file 'libamf/element.h'
--- a/libamf/element.h  2008-12-31 04:01:32 +0000
+++ b/libamf/element.h  2009-02-10 16:27:07 +0000
@@ -722,8 +722,13 @@
     ///                This encodes this Element and all of it's associated
     ///                properties into raw binary data in big endoan format.
     ///
+    /// @param notobject Flag to not encode the element as an object,
+    ///                instead it's just a list of properties. This is used 
when
+    ///                formatting onStatus response packets.
+    ///
     /// @return a smart pointer to a Buffer class.
     boost::shared_ptr<Buffer> encode();
+    boost::shared_ptr<Buffer> encode(bool notobject);
 
     /// \brief Get the array of properties for this Element.
     ///


reply via email to

[Prev in Thread] Current Thread [Next in Thread]