• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

amf_msg.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 // This file is for the low level support for encoding and decoding AMF objects.
00020 // As this class has no data associated with it, all the methods are static as
00021 // they are for convenience only.
00022 // All the encoding methods return a Buffer class, which is simply an array on
00023 // of unsigned bytes, and a byte count.
00024 // The only extraction classes parse either a raw AMF object or the larger
00025 // "variable"
00026 
00027 #ifndef _AMF_MSG_H_
00028 #define _AMF_MSG_H_
00029 
00030 #include <string>
00031 #include <vector>
00032 
00033 #include <boost/cstdint.hpp>
00034 #include <boost/shared_ptr.hpp>
00035 
00036 #include "element.h"
00037 #include "dsodefs.h"
00038 
00040 namespace cygnal
00041 {
00042 
00043 // forward declaration
00044 class Buffer;
00045 class Element;
00046 
00049 //
00054 class DSOEXPORT AMF_msg {
00055   public:
00056     typedef enum {
00057         AMF0 = 0x00,
00058         AMF3 = 0x11
00059     } amf_version_e;
00060     typedef struct {
00061         boost::uint16_t version;
00062         boost::uint16_t headers;
00063         boost::uint16_t messages;
00064     } context_header_t;
00065     typedef struct {
00066         std::string     target;
00067         std::string     response;
00068         size_t          size;
00069     } message_header_t;
00070     typedef struct {
00071         message_header_t header;
00072         boost::shared_ptr<cygnal::Element> data;
00073     } amf_message_t;
00074 
00075     size_t addMessage(boost::shared_ptr<amf_message_t> msg)
00076     {
00077         _messages.push_back(msg); return _messages.size();
00078     };
00079     boost::shared_ptr<amf_message_t> &getMessage(int x) { return _messages[x]; };
00080     size_t messageCount() { return _messages.size(); };
00081     
00082     // These methods create the raw data of the AMF packet from Elements
00083     static boost::shared_ptr<cygnal::Buffer> encodeContextHeader(context_header_t *head);
00084     static boost::shared_ptr<cygnal::Buffer> encodeContextHeader(boost::uint16_t version,
00085                                                               boost::uint16_t headers,
00086                                                               boost::uint16_t messages);
00087 
00088     static boost::shared_ptr<cygnal::Buffer> encodeMsgHeader(message_header_t *head);
00089     static boost::shared_ptr<cygnal::Buffer> encodeMsgHeader(const std::string &target,
00090                                           const std::string &response, size_t size);
00091     
00092     // These methods parse the raw data of the AMF packet into data structures
00093     static boost::shared_ptr<context_header_t> parseContextHeader(cygnal::Buffer &data);
00094     static boost::shared_ptr<context_header_t> parseContextHeader(boost::uint8_t *data, size_t size);
00095     
00096     static boost::shared_ptr<message_header_t> parseMessageHeader(cygnal::Buffer &data);
00097     static boost::shared_ptr<message_header_t> parseMessageHeader(boost::uint8_t *data, size_t size);
00098 
00099     // These methods parse the entire packet. which consists of multiple messages
00100     boost::shared_ptr<context_header_t> parseAMFPacket(cygnal::Buffer &buf);
00101     boost::shared_ptr<context_header_t> parseAMFPacket(boost::uint8_t *data,
00102                                                        size_t size);
00103 
00104     // This methods create an entire packet from multiple messages, already parsed in
00105     boost::shared_ptr<cygnal::Buffer> encodeAMFPacket();
00106     boost::shared_ptr<cygnal::Buffer> encodeAMFPacket(const std::string &target,
00107                                      const std::string &response, size_t size);
00108     
00109     static void dump(context_header_t &data);
00110     static void dump(message_header_t &data);
00111     void dump();
00112     
00113 private:
00114     std::vector<boost::shared_ptr<amf_message_t> > _messages;
00115 //     context_header_t    _context_header;
00116 };
00117 
00118 } // end of amf namespace
00119 
00120 // end of _AMF_MSG_H_
00121 #endif
00122 
00123 // local Variables:
00124 // mode: C++
00125 // indent-tabs-mode: t
00126 // End:

Generated on Thu Sep 30 2010 14:34:55 for Gnash by  doxygen 1.7.1