目录(?)[-]

  1. OpenRTMFPCumulus Primer15AMF解析之数据类型定义
    1. 数据类型
    2. undefined Type
    3. null Type
    4. false type
    5. true type
    6. integer type
    7. double type
    8. String type
    9. XMLDocument type
    10. Date type
    11. Array type
    12. Object type
    13. XML type
    14. ByteArray
    15. Usages of AMF3
      1. NetConnection and AMF 3
      2. NetConnection in ActionScript 30
      3. ByteArray IDataInput and IDataOutput
    16. Reference
 

OpenRTMFP/Cumulus Primer(15)AMF解析之数据类型定义

  • Author: 柳大·Poechant(钟超)
  • Email: zhongchao.ustc#gmail.com (#->@)
  • Blog: Blog.CSDN.net/Poechant
  • Date: April 24th, 2012

1 数据类型

各种数据类型的标示都在 AMF.h 中定义为宏

#define AMF_NUMBER              0x00    // 浮点数
#define AMF_BOOLEAN 0x01 // 布尔型
#define AMF_STRING 0x02 // 字符串
#define AMF_BEGIN_OBJECT 0x03 // 对象,开始
#define AMF_NULL 0x05 // null
#define AMF_UNDEFINED 0x06
#define AMF_REFERENCE 0x07
#define AMF_MIXED_ARRAY 0x08
#define AMF_END_OBJECT 0x09 // 对象,结束
#define AMF_BEGIN_TYPED_OBJECT 0x10
#define AMF_STRICT_ARRAY 0x0A
#define AMF_DATE 0x0B // 日期
#define AMF_LONG_STRING 0x0C // 字符串
#define AMF_UNSUPPORTED 0x0D #define AMF_AVMPLUS_OBJECT 0x11
#define AMF_END 0xFF #define AMF3_UNDEFINED 0x00
#define AMF3_NULL 0x01
#define AMF3_FALSE 0x02
#define AMF3_TRUE 0x03
#define AMF3_INTEGER 0x04
#define AMF3_NUMBER 0x05
#define AMF3_STRING 0x06
#define AMF3_DATE 0x08
#define AMF3_ARRAY 0x09
#define AMF3_OBJECT 0x0A
#define AMF3_BYTEARRAY 0x0C
#define AMF3_DICTIONARY 0x11

并定义了一个枚举类表示数据类型:

class AMF {
public:
enum Type {
Null=0,
Boolean,
Integer,
Number,
String,
Date,
Array,
Object,
ByteArray,
Dictionary,
RawObjectContent,
End
};
};

2 undefined Type

The undefined type is represented by the undefined type marker. No further information is encoded for this value.

3 null Type

The null type is represented by the null type marker. No further information is encoded for this value.

4 false type

The false type is represented by the false type marker and is used to encode a Boolean value of false. Note that in ActionScript 3.0 the concept of a primitive and Object form of Boolean does not exist. No further information is encoded for this value.

5 true type

The true type is represented by the true type marker and is used to encode a Boolean value of true. Note that in ActionScript 3.0 the concept of a primitive and Object form of Boolean does not exist. No further information is encoded for this value.

6 integer type

In AMF 3 integers are serialized using a variable length unsigned 29-bit integer. The ActionScript 3.0 integer types - a signed ‘int’ type and an unsigned ‘uint’ type - are also represented using 29-bits in AVM+. If the value of an unsigned integer (uint) is greater or equal to 229 or if the value of a signed integer (int) is greater than or equal to 228 then it will be represented by AVM+ as a double and thus serialized in using the AMF 3 double type.

7 double type

The AMF 3 double type is encoded in the same manner as the AMF 0 Number type. This type is used to encode an ActionScript Number or an ActionScript int of value greater than or equal to 228 or an ActionScript uint of value greater than or equal to 229. The encoded value is always an 8 byte IEEE-754 double precision floating point value in network byte order (sign bit in low memory).

8 String type

ActionScript String values are represented using a single string type in AMF 3 - the concept of string and long string types from AMF 0 is not used.

Strings can be sent as a reference to a previously occurring String by using an index to the implicit string reference table.

Strings are encoding using UTF-8 - however the header may either describe a string literal or a string reference.

The empty String is never sent by reference.

9 XMLDocument type

ActionScript 3.0 introduced a new XML type (see 3.13) however the legacy XMLDocument type is retained in the language as flash.xml.XMLDocument. Similar to AMF 0, the structure of an XMLDocument needs to be flattened into a string representation for serialization. As with other strings in AMF, the content is encoded in UTF-8.

XMLDocuments can be sent as a reference to a previously occurring XMLDocument instance by using an index to the implicit object reference table.

10 Date type

In AMF 3 an ActionScript Date is serialized simply as the number of milliseconds elapsed since the epoch of midnight, 1st Jan 1970 in the UTC time zone. Local time zone information is not sent.

Dates can be sent as a reference to a previously occurring Date instance by using an index to the implicit object reference table.

11 Array type

ActionScript Arrays are described based on the nature of their indices, i.e. their type and how they are positioned in the Array. The following table outlines the terms and their meaning:

term meaning
strict contains only ordinal (numeric) indices
dense ordinal indices start at 0 and do not contain gaps between successive indices (that is, every index is defined from 0 for the length of the array)
sparse contains at least one gap between two indices
associative contains at least one non-ordinal (string) index (sometimes referred to as an ECMA Array)

AMF considers Arrays in two parts, the dense portion and the associative portion. The binary representation of the associative portion consists of name/value pairs (potentially none) terminated by an empty string. The binary representation of the dense portion is the size of the dense portion (potentially zero) followed by an ordered list of values (potentially none). The order these are written in AMF is first the size of the dense portion, an empty string terminated list of name/value pairs, followed by size values.

Arrays can be sent as a reference to a previously occurring Array by using an index to the implicit object reference table.

12 Object type

A single AMF 3 type handles ActionScript Objects and custom user classes. The term ‘traits’ is used to describe the defining characteristics of a class. In addition to ‘anonymous’ objects and ‘typed’ objects, ActionScript 3.0 introduces two further traits to describe how objects are serialized, namely ‘dynamic’ and ‘externalizable’. The following table outlines the terms and their meanings:

term meaning
Anonymous an instance of the actual ActionScript Object type or an instance of a Class without a registered alias (that will be treated like an Object on deserialization)
Typed an instance of a Class with a registered alias
Dynamic an instance of a Class definition with the dynamic trait declared; public variable members can be added and removed from instances dynamically at runtime
Externalizable an instance of a Class that implements flash.utils.IExternalizable and completely controls the serialization of its members (no property names are included in the trait information).

In addition to these characteristics, an object’s traits information may also include a set of public variable and public read-writeable property names defined on a Class (i.e. public members that are not Functions). The order of the member names is important as the member values that follow the traits information will be in the exact same order. These members are considered sealed members as they are explicitly defined by the type.

If the type is dynamic, a further section may be included after the sealed members that lists dynamic members as name / value pairs. One continues to read in dynamic members until a name that is the empty string is encountered.

Objects can be sent as a reference to a previously occurring Object by using an index to the implicit object reference table. Further more, trait information can also be sent as a reference to a previously occurring set of traits by using an index to the implicit traits reference table.

13 XML type

ActionScript 3.0 introduces a new XML type that supports E4X syntax. For serialization purposes the XML type needs to be flattened into a string representation. As with other strings in AMF, the content is encoded using UTF-8.

XML instances can be sent as a reference to a previously occurring XML instance by using an index to the implicit object reference table.

Note that this encoding imposes some theoretical limits on the use of XML. The byte- length of each UTF-8 encoded XML instance is limited to 228 - 1 bytes (approx 256 MB).

14 ByteArray

ActionScript 3.0 introduces a new type to hold an Array of bytes, namely ByteArray. AMF 3 serializes this type using a variable length encoding 29-bit integer for the byte- length prefix followed by the raw bytes of the ByteArray.

ByteArray instances can be sent as a reference to a previously occurring ByteArray instance by using an index to the implicit object reference table.

15 Usages of AMF3

15.1 NetConnection and AMF 3

In addition to serializing ActionScript types, AMF can be used in the asynchronous invocations of remote services. A simple messaging structure is used to send a batch of requests to a remote endpoint. The format of this messaging structure is AMF 0 (See [AMF0]. A context header value or message body can switch to AMF 3 encoding using the special avmplus-object-marker type.

15.2 NetConnection in ActionScript 3.0

The qualified class name for NetConnection in ActionScript 3.0 is flash.net.NetConnection. This class continues to usea responder to handle result and status responses from a remote endpoint, however, a strongly typed Responder class is now required. The fully qualified class name is flash.net.Responder. For events other than normal result and status responses NetConnection dispatches events for which the developer can add listeners. These events are outlined below:

event operation
asyncError Dispatched when an exception is thrown asynchronously - i.e. from native asynchronous code.
ioError Dispatched when an input or output error occurs that causes a network operation to fail.
netStatus Dispatched when a NetConnection object is reporting its status or error condition.
securityError Dispatched if a call to NetConnection.call() attempts to connect to a server outside the caller’s security sandbox.

To handle an AMF context header a suitable method needs to be available, matching the header name. NetConnection is now a sealed type so either it must be subclassed or an object with a suitable implementation needs to be set for the NetConnection client property.

15.3 ByteArray, IDataInput and IDataOutput

ActionScript 3.0 introduced a new type to support the manipulation of raw data in the form of an Array of bytes, namely flash.utils.ByteArray. To assist with ActionScript Object serialization and copying, ByteArray implements flash.utils.IDataInput and flash.utils.IDataOutput. These interfaces specify utility methods that help write common types to byte streams. Two methods of interest are IDataOutput.writeObject and IDataInput.readObject. These methods encode objects using AMF. The version of AMF used to encode object data is controlled by the ByteArray.objectEncoding method, which can be set to either AMF 3 or AMF 0. An enumeration type, flash.net.ObjectEncoding, holds the constants for the versions of AMF - ObjectEncoding.AMF0 and ObjectEncoding.AMF3 respectively.

Note that ByteArray.writeObject uses one version of AMF to encode the entire object. Unlike NetConnection, ByteArray does not start out in AMF 0 and switch to AMF 3 (with the objectEncoding property set to AMF 3). Also note that ByteArray uses a new set of implicit reference tables for objects, object traits and strings for each readObject and writeObject call.

Reference

  1. [AMF3] Adobe Systems Inc. “Action Message Format - AMF 3”
  2. [AMF0] Adobe Systems Inc. “Action Message Format - AMF 0”

-

转载:Blog.CSDN.net/Poechant

AMF解析之数据类型定义 (转)的更多相关文章

  1. MySQL 5.7 深度解析: JSON数据类型使用

    http://www.actionsky.com/docs/archives/156  2015年12月25日  杨涛涛 JSON (JavaScriptObject Notation) 是一种轻量级 ...

  2. java数据类型定义与输出

    JAVA数据类型分基本数据类型和引用数据类型. 一.基本数据类型 Java里面包含8个基本数据类型,分别是: boolean.byte.char.short.int.float.douboe.long ...

  3. C#基础 常用语&数据类型定义&类型转换

    int temp = Console.Read(); Console.WriteLine(temp); Console.Read(); Console.Write("  ");直接 ...

  4. MS datatype define(微软数据类型定义)

    这里根据MS文档整理了微软数据类型的定义, 参考文档:https://docs.microsoft.com/zh-cn/openspecs/windows_protocols/ms-dtyp/2463 ...

  5. stm32中的数据类型定义

    STM32F10X.H #include "core_cm3.h" #include "system_stm32f10x.h" #include <std ...

  6. ES5:深入解析如何js定义类或对象。

    1.原始方式 var oCar = new  Object; oCar.color = "blue"; oCar.showColor = function(){alert(this ...

  7. STM32数据类型定义

    #ifndef __STM32F10x_TYPE_H #define __STM32F10x_TYPE_H typedef signed long s32; typedef signed short ...

  8. XML概念定义以及如何定义xml文件编写约束条件java解析xml DTD XML Schema JAXP java xml解析 dom4j 解析 xpath dom sax

    本文主要涉及:xml概念描述,xml的约束文件,dtd,xsd文件的定义使用,如何在xml中引用xsd文件,如何使用java解析xml,解析xml方式dom sax,dom4j解析xml文件 XML来 ...

  9. SQLServer之数据类型解析

    数字 int.bigint.smallint 和 tinyint 使用整数数据的精确数字数据类型. 数据类型 范围 存储 tinyint 0 到 255. 1 字节 smallint -2^15 (- ...

随机推荐

  1. (转)程序员应该知道的10个eclipse调试技巧

    调试不仅可以查找到应用程序缺陷所在,还可以解决缺陷.对于Java程序员来说,他们不仅要学会如何在Eclipse里面开发像样的程序,更需要学会如何调试程序.本文介绍了Java程序员必知的10个调试技巧, ...

  2. LeetCode OJ:Combination Sum (组合之和)

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...

  3. windows7自动登录后锁定 & 其他VBS

    首先设置自动登录(原已设置登录密码),在开始菜单搜索框输 入 “netplwiz” 按 回车,打开高级用户控制面板,然后取消对“要使用本机,用户需输入用户名和密码(E)”项的勾选,系统弹出窗口要求输入 ...

  4. jquery 中多条件选择器,相对选择器,层次选择器的区别

    一.Jquery常用的过滤选择器如下所示: 1.:first,选取第一个元素,比如$("div:first")选取第一个div元素 2.:last,选取最后一个元素,比如$(&qu ...

  5. 2——FFMPEG之协议(文件)操作----AVIOContext, URLContext, URLProtocol

    协议操作对象结构: 协议(文件)操作的顶层结构是AVIOContext,这个对象实现了带缓冲的读写操作:FFMPEG的输入对象AVFormat的pb字段指向一个AVIOContext. AVIOCon ...

  6. BloomFilter布隆过滤器使用

    从上一篇可以得知,BloomFilter的关键在于hash算法的设定和bit数组的大小确定,通过权衡得到一个错误概率可以接受的结果. 算法比较复杂,也不是我们研究的范畴,我们直接使用已有的实现. go ...

  7. Python 字符串相似性的几种度量方法

    字符串的相似性比较应用场合很多,像拼写纠错.文本去重.上下文相似性等. 评价字符串相似度最常见的办法就是:把一个字符串通过插入.删除或替换这样的编辑操作,变成另外一个字符串,所需要的最少编辑次数,这种 ...

  8. 狗狗有关的知识tips

    <h5>tips1</h5>狗狗脑袋里最关心的事:一是食物,二是性.想教育狗,就要顺应狗狗的想法,而不是一味地以暴力相待.<h5>tips2</h5>” ...

  9. 十三、python沉淀之路--文件操作

    一.文件的读操作 例1 f = open('学习',encoding='utf-8') #首先要打开文件,不然直接读,是读不出来的 data = f.read() #read后的括号里不添加任何东西 ...

  10. poj 3415 Common Substrings——后缀数组+单调栈

    题目:http://poj.org/problem?id=3415 因为求 LCP 是后缀数组的 ht[ ] 上的一段取 min ,所以考虑算出 ht[ ] 之后枚举每个位置作为右端的贡献. 一开始想 ...