MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
amf.h
Go to the documentation of this file.
1 
4 #pragma once
5 #include <vector>
6 #include <iostream>
7 #include <string>
8 
10 namespace AMF {
11 
13  enum obj0type {
14  AMF0_NUMBER = 0x00,
15  AMF0_BOOL = 0x01,
16  AMF0_STRING = 0x02,
17  AMF0_OBJECT = 0x03,
18  AMF0_MOVIECLIP = 0x04,
19  AMF0_NULL = 0x05,
20  AMF0_UNDEFINED = 0x06,
21  AMF0_REFERENCE = 0x07,
22  AMF0_ECMA_ARRAY = 0x08,
23  AMF0_OBJ_END = 0x09,
24  AMF0_STRICT_ARRAY = 0x0A,
25  AMF0_DATE = 0x0B,
26  AMF0_LONGSTRING = 0x0C,
27  AMF0_UNSUPPORTED = 0x0D,
28  AMF0_RECORDSET = 0x0E,
29  AMF0_XMLDOC = 0x0F,
30  AMF0_TYPED_OBJ = 0x10,
31  AMF0_UPGRADE = 0x11,
32  AMF0_DDV_CONTAINER = 0xFF
33  };
34 
36  enum obj3type {
37  AMF3_UNDEFINED = 0x00,
38  AMF3_NULL = 0x01,
39  AMF3_FALSE = 0x02,
40  AMF3_TRUE = 0x03,
41  AMF3_INTEGER = 0x04,
42  AMF3_DOUBLE = 0x05,
43  AMF3_STRING = 0x06,
44  AMF3_XMLDOC = 0x07,
45  AMF3_DATE = 0x08,
46  AMF3_ARRAY = 0x09,
47  AMF3_OBJECT = 0x0A,
48  AMF3_XML = 0x0B,
49  AMF3_BYTES = 0x0C,
50  AMF3_DDV_CONTAINER = 0xFF
51  };
52 
55  class Object {
56  public:
57  std::string Indice();
58  obj0type GetType();
59  double NumValue();
60  std::string StrValue();
61  const char * Str();
62  int hasContent();
63  void addContent(AMF::Object c);
64  Object * getContentP(unsigned int i);
65  Object getContent(unsigned int i);
66  Object * getContentP(std::string s);
67  Object getContent(std::string s);
68  Object();
69  Object(std::string indice, double val, obj0type setType = AMF0_NUMBER);
70  Object(std::string indice, std::string val, obj0type setType = AMF0_STRING);
71  Object(std::string indice, obj0type setType = AMF0_OBJECT);
72  std::string Print(std::string indent = "");
73  std::string Pack();
74  protected:
75  std::string myIndice;
77  std::string strval;
78  double numval;
79  std::vector<Object> contents;
80  };
81  //AMFType
82 
84  Object parse(const unsigned char * data, unsigned int len);
86  Object parse(std::string data);
88  Object parseOne(const unsigned char *& data, unsigned int & len, unsigned int & i, std::string name);
89 
92  class Object3 {
93  public:
94  std::string Indice();
95  obj3type GetType();
96  double DblValue();
97  int IntValue();
98  std::string StrValue();
99  const char * Str();
100  int hasContent();
101  void addContent(AMF::Object3 c);
102  Object3 * getContentP(int i);
103  Object3 getContent(int i);
104  Object3 * getContentP(std::string s);
105  Object3 getContent(std::string s);
106  Object3();
107  Object3(std::string indice, int val, obj3type setType = AMF3_INTEGER);
108  Object3(std::string indice, double val, obj3type setType = AMF3_DOUBLE);
109  Object3(std::string indice, std::string val, obj3type setType = AMF3_STRING);
110  Object3(std::string indice, obj3type setType = AMF3_OBJECT);
111  std::string Print(std::string indent = "");
112  std::string Pack();
113  protected:
114  std::string myIndice;
115  obj3type myType;
116  std::string strval;
117  double dblval;
118  int intval;
119  std::vector<Object3> contents;
120  };
121  //AMFType
122 
124  Object3 parse3(const unsigned char * data, unsigned int len);
126  Object3 parse3(std::string data);
128  Object3 parseOne3(const unsigned char *& data, unsigned int & len, unsigned int & i, std::string name);
129 
130 } //AMF namespace
Definition: amf.h:41
std::string Pack()
Packs the AMF object to a std::string for transfer over the network.
Definition: amf.cpp:226
const char * Str()
Returns the C-string value of this object, if available.
Definition: amf.cpp:32
Definition: amf.h:19
Definition: amf.h:44
Definition: amf.h:43
Object3 parseOne3(const unsigned char *&data, unsigned int &len, unsigned int &i, std::string name)
Parses a single AMF3 type - used recursively by the AMF::parse3() functions.
Definition: amf.cpp:781
Definition: amf.h:24
Definition: amf.h:25
std::vector< Object > contents
Holds this objects contents, if any (for container types).
Definition: amf.h:79
Definition: amf.h:14
std::string strval
Holds this objects string value, if any.
Definition: amf.h:77
Definition: amf.h:48
Definition: amf.h:39
Object parseOne(const unsigned char *&data, unsigned int &len, unsigned int &i, std::string name)
Parses a single AMF0 type - used recursively by the AMF::parse() functions.
Definition: amf.cpp:369
Object * getContentP(unsigned int i)
Returns a pointer to the object held at indice i.
Definition: amf.cpp:50
Definition: amf.h:15
Object getContent(unsigned int i)
Returns a copy of the object held at indice i.
Definition: amf.cpp:60
Object()
Default constructor.
Definition: amf.cpp:90
Definition: amf.h:28
Definition: amf.h:32
obj0type GetType()
Returns the AMF::obj0type AMF0 object type for this object.
Definition: amf.cpp:14
double numval
Holds this objects numeric value, if any.
Definition: amf.h:78
Definition: amf.h:21
obj0type myType
Holds this objects AMF0 type.
Definition: amf.h:76
obj0type
Enumerates all possible AMF0 types, adding a special DDVTECH container type for ease of use...
Definition: amf.h:13
Definition: amf.h:47
Object parse(const unsigned char *data, unsigned int len)
Parses a C-string to a valid AMF::Object.
Definition: amf.cpp:506
Definition: amf.h:20
Definition: amf.h:45
Definition: amf.h:30
Recursive class that holds AMF0 objects.
Definition: amf.h:55
Definition: amf.h:22
std::string StrValue()
Returns the std::string value of this object, if available.
Definition: amf.cpp:26
Definition: amf.h:23
Definition: amf.h:40
std::string myIndice
Holds this objects indice, if any.
Definition: amf.h:75
obj3type
Enumerates all possible AMF3 types, adding a special DDVTECH container type for ease of use...
Definition: amf.h:36
Holds all AMF parsing and creation related functions and classes.
Definition: amf.h:10
Definition: amf.h:27
void addContent(AMF::Object c)
Adds an AMF::Object to this object. Works for all types, but only makes sense for container types...
Definition: amf.cpp:43
Definition: amf.h:42
Definition: amf.h:18
Definition: amf.h:16
Definition: amf.h:50
double NumValue()
Returns the numeric value of this object, if available.
Definition: amf.cpp:20
Definition: amf.h:29
Definition: amf.h:17
Definition: amf.h:31
Recursive class that holds AMF3 objects.
Definition: amf.h:92
Definition: amf.h:49
Definition: amf.h:46
int hasContent()
Returns a count of the amount of objects this object currently holds.
Definition: amf.cpp:38
Definition: amf.h:26
Definition: amf.h:37
Definition: amf.h:38
std::string Indice()
Returns the std::string Indice for the current object, if available.
Definition: amf.cpp:9
Object3 parse3(const unsigned char *data, unsigned int len)
Parses a C-string to a valid AMF::Object3.
Definition: amf.cpp:1128
std::string Print(std::string indent="")
Return the contents as a human-readable string.
Definition: amf.cpp:133