"Fossies" - the Fresh Open Source Software Archive 
Member "gnash-0.8.10/cygnal/libamf/amf_msg.h" (19 Jan 2012, 4574 Bytes) of package /linux/www/old/gnash-0.8.10.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 // This file is for the low level support for encoding and decoding AMF objects.
20 // As this class has no data associated with it, all the methods are static as
21 // they are for convenience only.
22 // All the encoding methods return a Buffer class, which is simply an array on
23 // of unsigned bytes, and a byte count.
24 // The only extraction classes parse either a raw AMF object or the larger
25 // "variable"
26
27 #ifndef _AMF_MSG_H_
28 #define _AMF_MSG_H_
29
30 #include <string>
31 #include <vector>
32
33 #include <boost/cstdint.hpp>
34 #include <boost/shared_ptr.hpp>
35
36 #include "element.h"
37 #include "dsodefs.h"
38
39 /// Action Message Format specific classes of libamf.
40 namespace cygnal
41 {
42
43 // forward declaration
44 class Buffer;
45 class Element;
46
47 /// All numbers in AMF format are 8 byte doubles.
48 /// Binary representation of an ActionScript object.
49 //
50 /// AMF is used to send objects, whether to a SharedObject .sol file,
51 /// a memory based LocalConnection segment, or over an RTMP connection
52 /// for streaming.
53 ///
54 class DSOEXPORT AMF_msg {
55 public:
56 typedef enum {
57 AMF0 = 0x00,
58 AMF3 = 0x11
59 } amf_version_e;
60 typedef struct {
61 boost::uint16_t version;
62 boost::uint16_t headers;
63 boost::uint16_t messages;
64 } context_header_t;
65 typedef struct {
66 std::string target;
67 std::string response;
68 size_t size;
69 } message_header_t;
70 typedef struct {
71 message_header_t header;
72 boost::shared_ptr<cygnal::Element> data;
73 } amf_message_t;
74
75 size_t addMessage(boost::shared_ptr<amf_message_t> msg)
76 {
77 _messages.push_back(msg); return _messages.size();
78 };
79 boost::shared_ptr<amf_message_t> &getMessage(int x) { return _messages[x]; };
80 size_t messageCount() { return _messages.size(); };
81
82 // These methods create the raw data of the AMF packet from Elements
83 static boost::shared_ptr<cygnal::Buffer> encodeContextHeader(context_header_t *head);
84 static boost::shared_ptr<cygnal::Buffer> encodeContextHeader(boost::uint16_t version,
85 boost::uint16_t headers,
86 boost::uint16_t messages);
87
88 static boost::shared_ptr<cygnal::Buffer> encodeMsgHeader(message_header_t *head);
89 static boost::shared_ptr<cygnal::Buffer> encodeMsgHeader(const std::string &target,
90 const std::string &response, size_t size);
91
92 // These methods parse the raw data of the AMF packet into data structures
93 static boost::shared_ptr<context_header_t> parseContextHeader(cygnal::Buffer &data);
94 static boost::shared_ptr<context_header_t> parseContextHeader(boost::uint8_t *data, size_t size);
95
96 static boost::shared_ptr<message_header_t> parseMessageHeader(cygnal::Buffer &data);
97 static boost::shared_ptr<message_header_t> parseMessageHeader(boost::uint8_t *data, size_t size);
98
99 // These methods parse the entire packet. which consists of multiple messages
100 boost::shared_ptr<context_header_t> parseAMFPacket(cygnal::Buffer &buf);
101 boost::shared_ptr<context_header_t> parseAMFPacket(boost::uint8_t *data,
102 size_t size);
103
104 // This methods create an entire packet from multiple messages, already parsed in
105 boost::shared_ptr<cygnal::Buffer> encodeAMFPacket();
106 boost::shared_ptr<cygnal::Buffer> encodeAMFPacket(const std::string &target,
107 const std::string &response, size_t size);
108
109 static void dump(context_header_t &data);
110 static void dump(message_header_t &data);
111 void dump();
112
113 private:
114 std::vector<boost::shared_ptr<amf_message_t> > _messages;
115 // context_header_t _context_header;
116 };
117
118 } // end of amf namespace
119
120 // end of _AMF_MSG_H_
121 #endif
122
123 // local Variables:
124 // mode: C++
125 // indent-tabs-mode: t
126 // End: