Documented and nicified AMF parsing. Updated all existing code for this change, except for RTMP connector (which gets a rewrite, like, today).
This commit is contained in:
parent
1b86b9a5ef
commit
fab932253d
10 changed files with 404 additions and 341 deletions
68
util/amf.h
Normal file
68
util/amf.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
//#include <string.h>
|
||||
#include <string>
|
||||
|
||||
/// Holds all AMF parsing and creation related functions and classes.
|
||||
namespace AMF{
|
||||
|
||||
/// Enumerates all possible AMF0 types, adding a special DDVTECH container type for ease of use.
|
||||
enum obj0type {
|
||||
AMF0_NUMBER = 0x00,
|
||||
AMF0_BOOL = 0x01,
|
||||
AMF0_STRING = 0x02,
|
||||
AMF0_OBJECT = 0x03,
|
||||
AMF0_MOVIECLIP = 0x04,
|
||||
AMF0_NULL = 0x05,
|
||||
AMF0_UNDEFINED = 0x06,
|
||||
AMF0_REFERENCE = 0x07,
|
||||
AMF0_ECMA_ARRAY = 0x08,
|
||||
AMF0_OBJ_END = 0x09,
|
||||
AMF0_STRICT_ARRAY = 0x0A,
|
||||
AMF0_DATE = 0x0B,
|
||||
AMF0_LONGSTRING = 0x0C,
|
||||
AMF0_UNSUPPORTED = 0x0D,
|
||||
AMF0_RECORDSET = 0x0E,
|
||||
AMF0_XMLDOC = 0x0F,
|
||||
AMF0_TYPED_OBJ = 0x10,
|
||||
AMF0_UPGRADE = 0x11,
|
||||
AMF0_DDV_CONTAINER = 0xFF
|
||||
};
|
||||
|
||||
/// Recursive class that holds AMF0 objects.
|
||||
/// It supports all AMF0 types (defined in AMF::obj0type), adding support for a special DDVTECH container type.
|
||||
class Object {
|
||||
public:
|
||||
std::string Indice();
|
||||
obj0type GetType();
|
||||
double NumValue();
|
||||
std::string StrValue();
|
||||
const char * Str();
|
||||
int hasContent();
|
||||
void addContent(AMF::Object c);
|
||||
Object* getContentP(int i);
|
||||
Object getContent(int i);
|
||||
Object* getContentP(std::string s);
|
||||
Object getContent(std::string s);
|
||||
Object(std::string indice, double val, obj0type setType = AMF0_NUMBER);
|
||||
Object(std::string indice, std::string val, obj0type setType = AMF0_STRING);
|
||||
Object(std::string indice, obj0type setType = AMF0_OBJECT);
|
||||
void Print(std::string indent = "");
|
||||
std::string Pack();
|
||||
protected:
|
||||
std::string myIndice; ///< Holds this objects indice, if any.
|
||||
obj0type myType; ///< Holds this objects AMF0 type.
|
||||
std::string strval; ///< Holds this objects string value, if any.
|
||||
double numval; ///< Holds this objects numeric value, if any.
|
||||
std::vector<Object> contents; ///< Holds this objects contents, if any (for container types).
|
||||
};//AMFType
|
||||
|
||||
/// Parses a C-string to a valid AMF::Object.
|
||||
Object parse(const unsigned char * data, unsigned int len);
|
||||
/// Parses a std::string to a valid AMF::Object.
|
||||
Object parse(std::string data);
|
||||
/// Parses a single AMF0 type - used recursively by the AMF::parse() functions.
|
||||
Object parseOne(const unsigned char *& data, unsigned int &len, unsigned int &i, std::string name);
|
||||
|
||||
};//AMF namespace
|
Loading…
Add table
Add a link
Reference in a new issue