中英文版本的amf3規格說明 收藏
?
譯者申明:由于水平有限,難免有錯誤,請指正。聯系方式 QQ:457873255,TEL:13570497022
?
?
Adobe Systems Inc.
AMF 3 Specification
Category: ActionScript Serialization 類別:AS序列化
?
Action Message Format -- AMF 3
Copyright Notice
Copyright (c) Adobe Systems Inc. (2002-2006). All Rights Reserved.
?
Abstract 概覽
Action Message Format (AMF) is a compact binary format that is used to serialize ActionScript object graphs. Once serialized an AMF encoded object graph may be used to persist and retrieve the public state of an application across sessions or allow two endpoints to communicate through the exchange of strongly typed data.
AMF(Action Message Format 動作信息格式)是用來序列化AS(ActionScript 動作腳本)實例對象(object graphs)的壓縮的二進制格式。序列化的AMF編碼的實例對象可用來持久化,并且在不同的會話中獲得應用的公共狀態,或者允許在兩個端點(比如客戶端和服務器端 --譯者注)通過強類型數據交換進行通信。
?
AMF was introduced in Flash Player 6 in 2001 and remained unchanged with the introduction of ActionScript 2.0 in Flash Player 7 and with the release of Flash Player 8. This version of AMF is referred to as AMF 0 (See [AMF0]). In Flash Player 9, Action Script 3.0 was introduced along with a new ActionScript Virtual Machine (AVM+) - the new data types and language features made possible by these improvements prompted AMF to be updated.? Given the opportunity to release a new version of AMF, several optimizations were also made to the encoding format to remove redundant information from serialized data. This specification defines this updated version of AMF, namely AMF 3.
AMF引進于2001年的FlashPlayer6,并且在引入AS2.0的FlashPlayer7和FlashPlayer8中沒有改變的保留了。這個版本的AMF參考于AMF0(查閱[AMF0])。在FlashPlayer9中,AS3.0同新的AS虛擬機(AVM+)一起被引進—新的數據類型和語言特性的改進致使AMF升級成為可能,給了一個發布新的AMF版本的機會,新版本的AMF在序列化數據的時候做了一些優化,使得編碼格式去除了一些冗余信息。升級后的AMF版本便是AMF3。
?
Table of Contents 目錄(略)
?
1 Introduction 介紹
?
1.1 Purpose 目的
Action Message Format (AMF) is a compact binary format that is used to serialize ActionScript object graphs. Once serialized an AMF encoded object graph may be used to persist and retrieve the public state of an application across sessions or allow two endpoints to communicate through the exchange of strongly typed data. (譯者注:之前有翻譯)
The first version of AMF, referred to as AMF 0, supports sending complex objects by reference which helps to avoid sending redundant instances in an object graph.
第一個版本的AMF,即AMF0,支持在避免了在對象圖中發送冗余的實例的通過引用發送復雜的對象。
It also allows endpoints to restore object relationships and support circular references while avoiding problems such as infinite recursion during serialization.
他也允許端點存儲對象關系,并且支持在避免問題--如在序列化時無窮的遞歸--的情況下的循環引用。
A new version of AMF, referred to as AMF 3 to coincide with the release of ActionScript 3.0, improves on AMF 0 by sending object traits and strings by reference in addition to object instances.
新版本的AMF,即AMF3,與AS3.0版本保持一致,在通過引用發送除對象實例外的對象特性和字符串做了改進。
AMF 3 also supports some new data types introduced in ActionScript 3.0.
AMF3也支持在AS3.0中的一些新的數據類型。
?
1.2 Notational Conventions 標記轉換
1.2.1 Augmented BNF 增強的BNF
Type definitions in this specification use Augmented Backus-Naur Form (ABNF) syntax [RFC2234].在這個規格中類型定義使用參數化的巴克斯范式(ABNF)語法[RFC2234]。
(譯者注:
BNF is a formal meta-syntax used to express context-free Grammars. BNF is one of the most commonly used meta-syntactic notation s for specifying the syntax of programming languages, command sets, PDUs, and similar things. However, pure BNF is rather limited, so the two variations EBNF and ABNF have become more popular.)
?
The reader should be familiar with this notation before reading this document.
讀者在閱讀這個文檔之前應該熟悉這個注解。
?
1.3 Basic Rules 基本規則
Throughout this document bytes are assumed to be octets, or 8-bits.
這個文檔的字節是8位的。
U8
?An unsigned byte (8-bits, an octet)
無符號字節(8位,一個8位字節)
?
U16
?An unsigned 16-bit integer in big endian??? (network) byte order
在網絡中的字節順序中的無符號的占用16個二進制位的整數
?
U32
?An unsigned 32-bit integer in big endian (network) byte order
在網絡中的字節順序中的無符號的占用32個二進制位的整數
?
DOUBLE
?8 byte IEEE-754 double precision floating point value in network byte order (sign bit in low memory).
在網絡中的字節循序的(符號位在低存儲)8字節的IEEE-754雙精度浮點數
?
MB
?A megabyte or 1048576 bytes.
兆字節
?
?
?
More complicated data type rules require special treatment which is outlined below.
更多的復雜的數據類型規則需要特殊的處理,概括如下:
?
1.3.1 Variable Length Unsigned 29-bit Integer Encoding
可變長度的無符號29位整數的編碼
?
AMF 3 makes use of a special compact format for writing integers to reduce the number of bytes required for encoding.
AMF3使用一種特別的壓縮格式來寫整數,用于壓縮編碼的字節數量。
As with a normal 32-bit integer, up to 4 bytes are required to hold the value however the high bit of the first 3 bytes are used as flags to determine whether the next byte is part of the integer.
對于一個正常的32-bit的整數,需要4個字節來存儲,然而前3個字節的最高位是用于標識下一個字節是不是整數的一部分
With up to 3 bits of the 32 bits being used as flags, only 29 significant bits remain for encoding an integer. This means the largest unsigned integer value that can be represented is 229 – 1
在32-bit中多達3個bit是用來標志的,所以對編碼的一個整數僅僅有29個bit有意義。這意味著最大的無符號的整數值是229-1。
?
?
In ABNF syntax, the variable length unsigned 29-bit integer type is described as follows:
在ABNF語法中, 可變長度的無符號的29位的整型數據類型描述如下:
?
?
1.3.2 Strings and UTF-8
AMF 0 and AMF 3 use (non-modified) UTF-8 to encode strings. UTF-8 is the abbreviation for 8-bit Unicode Transformation Format. UTF-8 strings are typically preceded with a byte-length header followed by a sequence of variable length (1 to 4 octets) encoded Unicode code-points.
AMF0和AMF3使用UTF-8來編碼字符串(沒有變化的)。UTF-8是8-bit的Unicode Transformation Format(統一的傳輸格式)的縮寫。UTF-8字符串是典型的字節長度為頭,緊跟著編碼Unicode編碼點的可變長度(1到4個字節)的字節序列。
AMF 3 uses a slightly modified byte-length header; a detailed description is provided below and referred to throughout the document.
AMF3使用一個輕微改變的字節長度頭;適用于整個文檔的具體描述如下。
?
?
In ABNF syntax, [RFC3629] describes UTF-8 as follows:
在ABNF句法,[RFC3629]描述UTF-8如下:
?
?
For AMF 3 a string can be encoded as a string literal or a string reference.
對于AMF3,一個字符串可以作為字面值或引用來編碼。
A variable length unsigned 29-bit integer is used for the header and the first bit is flag that specifies which type of string is encoded.
可變長度的無符號的29-bit的整數用于頭,并且第一個bit標識字符串的編碼。
If the flag is 0, a string literal is encoded and the remaining bits are used to encode the byte-length of the UTF-8 encoded String.
標識為0時,字符串是字面上編碼的,余下的位數是用來編碼UTF-8的編碼的字節的長度。
If the flag is 1, then a string reference is encoded and the remaining bits are used to encode an index to the implicit string reference table.
標識為1時,是字符串引用的編碼,余下的位數是用來編碼直指隱含的字符串引用表的一個索引。
?
(譯者注:標識位的意義前后定義的不一樣)
?
Note that this encoding imposes some theoretical limits on the use of Strings.
注意:這個編碼增加了字符串使用上的理論上的限制。
The number of unique Strings that can be sent by reference is limited to 228 - 1, and the byte-length of each UTF-8 encoded String is limited to 228 - 1 bytes (approx 256 MB).
一個被引用發送的字符串的最大長度是:228-1,每一個UTF-8編碼的字符串長度是228-1字節(大概256MB)。
?
2. Technical Summary 技術摘要
2.1 Summary of improvements 改進的摘要
?
The following is a table of the improvements and changes in AMF 3:
以下是AMF3的改進和改變的目錄:
?
?
?
Object traits can now be sent by reference
對象的特性現在可以被引用發送
Strings can now be sent by reference
字符串可以被引用發送
int/uint type support
對int/uint類型的支持
flash.utils.ByteArray type support, can also be sent by reference
對flash.utils.ByteArray 類型的支持,也可以通過引用發送
flash.utils.IExternalizable support
對flash.utils.IExternalizable的支持。
Variable length encoding scheme for integers to reduce data size
旨在壓縮數據大小的可變長度的整數的編碼策略
References are sent using variable length integer
可變長度的整數的引用發送
String UTF-8 length uses variable length integer
UTF-8的字符串長度使用可變長度的整數
Array count uses variable length integer
數組的長度使用可變長度的整數
A single Array type marker covers both strict and ECMA Arrays
一個單獨的Array數組數據類型覆蓋了嚴格的和ECMA兩個數組
Dates no longer send timezone information
日期不再發送時區信息
Dates can now be sent by reference
日期可以通過引用發送
XMLDocument UTF-8 length uses variable length integer
XMLDocument的UTF-8的長度使用可變長度整數
XMLDocument can now be sent by reference
XMLDocument可以通過引用發送
XML type support, can also be sent by reference
XML也可以通過應用發送
XML UTF-8 length uses variable length integer
ByteArray type length uses variable length integer
Boolean true and false are now sent as one byte type markers
Boolean類型使用一個字節標識。
Unsupported type marker has been removed
不支持類型標志被刪除了
Reserved RecordSet and Movieclip type markers have been removed
保留了RecordSet和Movieclip類型標識被刪除了。
?
2.2 Reference Tables
In AMF 3, Strings, Complex Objects (which in AMF 3 are defined as anonymous Objects, typed Objects, Arrays, Dates, XMLDocument, XML, and ByteArrays) and an Object Type's Traits can now be sent by reference.
在AMF3中,字符串,復雜對象(他是AMF3中定義的匿名對象,類型化的對象,數組,日期,xml文檔,xml, 字節數組)
This means that instead of sending redundant information, these components of AMF can simply refer to an earlier occurrence of a component.
這意味著不發送冗余信息,這些AMF組件可以簡單的參考先前的版本。
This reference is an integer forming a zero-based index that is encoded in the component information, typically in the first number that appears after the relevant type marker (see the type definitions for Object, Array, Date, XMLDocument, XML and ByteArray below for exact details).
這個引用從0開始索引的整數,被編碼在組件信息中,典型地出現在相關的類型標識(詳細情況查閱下面Object, Array, Date, XMLDocument, XML and ByteArray類型定義)之后第一個數字。
These indexes form a virtual "table" of references that a deserializer and serializer must maintain when reading and writing AMF 3 formatted data.
這些索引形式是一個引用的虛擬表,在讀寫AMF3格式的數據的時候必須有一個反序列化器和序列化其來維護這個表。
?
Note that 3 separate reference tables are used for Strings, Complex Objects and
Object Traits respectively.
注意:不同的引用表被用于對應的字符串,復雜對象和對象特性。
?
3 AMF 3 Data Types
3.1 Overview
There are 13 types in AMF 3. A type marker is one byte in length and describes the type of encoded data that follows.
有13個AMF3的類型。一個類型標識占用一個字節,描述跟著他的編碼的數據類型。
?
?
The set of possible type markers are listed below (values are represented in hexadecimal format):
所有可能的類型標識羅列如下(值是用16進制表示的):
?
?
Type markers may be followed by the actual encoded type data, or if the marker represents a single possible value (such as null) then no further information needs to be encoded.
典型的標識后有真正的比啊類型數據,或者如果標識標識一個單獨可能的值(如null),就沒有編碼的信息了。
?
?
AMF 3 makes use of three reference tables for strings, objects and traits (the characteristics of objects that define a strong type such as the class name and public member names).
AMF3使用三個引用表,分別用于字符串,對象和特性(一個強類型的對象特征有如類的名字和公共成員名字)
These tables are considered implicit as they are not encoded as a unique entity in the format.
這些表是隱含著的,因為他們不是作為一個在格式上唯一編碼的實體。
Each type that can be sent by reference may instead be encoded using an index to the appropriate reference table.
每一個可以被引用發送的實體,會使用合適的引用表中的一個索引來編碼。
Strings can be sent by reference using an index to the string table.
字符串能使用字符串引用表中的索引被發送。
Object, Array, XML, XMLDocument, ByteArray, Date and instances of user defined Classes can be sent by reference using an index to the object table.
對象,數組,XML,XMLDocument,ByteArray,Date 和 用法定義的類實例可以使用對象表的索引來進行引用發送。
Objects and instances of user defined Classes have trait information which can also be sent by reference using an index to the traits table.
對象和自定義實例的特性信息也使用特性表中的索引來進行引用發送。
?
3.2 undefined Type 未定義類型
The undefined type is represented by the undefined type marker. No further information is encoded for this value.
未定義類型由未定義類型標識來表示。對于這個值沒有其他的信息。
?
?
Note that endpoints other than the AVM may not have the concept of undefined and may choose to represent undefined as null.
注意:不是AVM的其他終端可能沒有未定義的概念,可能會選擇null來表示未定義的類型。
?
3.3 null Type
The null type is represented by the null type marker. No further information is encoded for this value.
Null類型由null類型標識來表示。對于這個值沒有其他的信息。
?
?
3.4 false Type
The false type is represented by the false type marker and is used to encode a Boolean value of false.
False類型用false類型標識來表示,并且用false的Boolean值來編碼。
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.
注意:在AS3.0中,基本的Object形式的Boolean概念不復存在。對于這個值沒有其他的信息。
?
?
3.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.
(譯者:和false類似)
?
?
3.6 integer type
In AMF 3 integers are serialized using a variable length unsigned 29-bit integer.
在AMF3中,整數是使用可變長度的無符號的29-bit整數來序列化。
The ActionScript 3.0 integer types - a signed 'int' type and an unsigned 'uint' type - are also represented using 29-bits in AVM+.
AS3.0的整數類型,int表示有符號的,uint標識無符號的,在AVM+中也使用29-bit來表示。
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.
如果uint整數大于或等于229,int整數大于等于228,在AVM+中會用雙精度浮點數來表示,并用AMF3的雙精度浮點數來序列化他。
?
?
3.7 double type
The AMF 3 double type is encoded in the same manner as the AMF 0 Number type.
AMF3的雙精度浮點型和AMF0的的雙精度浮點型的編碼是一樣的。
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個字節的IEEE-754的雙精度浮點值(符號位在低位內存)
?
?
3.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.
AMF3中,AS的字符串的值用一個字符串類型來表示,AMF0中的字符串和長字符串的概念不使用了。
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.
空的字符串不會被應用發送
?
?
3.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.
雖然遺產類XMLDocument被保留了下了,AS3.0還是引進了XML類型。
Similar to AMF 0, the structure of an XMLDocument needs to be flattened into a string representation for serialization.
和AMF0類似,XMLDocument的結構需要轉換為字符串表示來序列化。
As with other strings in AMF, the content is encoded in UTF-8.
在AMF中,因為需要字符串,其內容用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.
對于當前產生的XMLDocument實例,可以使用隱含的對象引用表的一個索引來進行引用發送。
?
Note that this encoding imposes some theoretical limits on the use of XMLDocument. The byte-length of each UTF-8 encoded XMLDocument instance is limited to 228 - 1 bytes (approx 256 MB).
(譯者:以上都是之前翻譯了的)
?
3.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.
在AMF3中,AS日期簡單地序列化為一個從公元1970年1月1日零點,使用UTC時區的到現在的毫秒數。
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.
?
?
3.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.
AS的數組是基于他的自然索引來描述的,例如:他們的類型和他們在數組中的位置
The following table outlines the terms and their 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)
索引從0開始,不包含連續索引中的間隙(也就是說:每一個索引對于數組的長度來說都是從0開始定義的)
?
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)
至少包含一個非順序(字符串)索引(一些時候是ECMA數組)
?
?
AMF considers Arrays in two parts, the dense portion and the associative portion.
AMF把數組分為兩個部分,密集部分和關聯部分。
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.
在AMF中寫入的順序是第一個密集部分的大小,空的字符串。
?
?
3.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:
?
?
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)
真實的AS對象實例或沒有別名注冊的類對象實例(反序列化時,他會像對象一樣處理)
?
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).
實現了flash.utils.IExternalizable接口的類實例并且完全控制他的成員的序列化(在他們的特性信息中沒有屬性名)
?
?
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.
?
?
U29O-ref
?U29
?; The first (low) bit is a flag
低位第一位(bit)是一個標志。
; (representing whether an instance
; follows 表示是否跟著個實例對象) with value 0 to imply that
; this is not an instance but a
; reference.
為0時表示不是一個實例而是一個引用。
The remaining 1 to 28
; significant bits are used to encode an
; object reference index (an integer).
余下的1到28個有效的位是用來編碼一個對象引用的索引(一個整數)
?
?
U29O-traits-ref
?U29
?; The first (low) bit is a flag with
; value 1.
第一個低位標志位值為1
The second bit is a flag
; (representing whether a trait
; reference follows) with value 0 to
; imply that this objects traits are
; being sent by reference.
第二個位是個標志位,0表示引用發送對象特性
The remaining
; 1 to 27 significant bits are used to
; encode a trait reference index (an
; integer).
余下的27位表示引用值(一個整數)
?
U29O-traits-ext
?U29
?; The first (low) bit is a flag with
; value 1. The second bit is a flag with
; value 1. The third bit is a flag with
; value 1.
前三位標志位都是1
The remaining 1 to 26
; significant bits are not significant
; (the traits member count would always
; be 0).
余下的26位無意義(特性成員的數量必須是0)
?
U29O-traits
?U29
?; The first (low) bit is a flag with
; value 1. The second bit is a flag with
; value 1. The third bit is a flag with
; value 0.
第一個標志位為1,第二個標志位為1,第三個標志位為0。
The fourth bit is a flag
; specifying whether the type is
; dynamic.
第四個標志位表示類型是不是動態的。
A value of 0 implies not
; dynamic, a value of 1 implies dynamic.
0表示不是動態的,1表示是動態的。
; Dynamic types may have a set of name
; value pairs for dynamic members after
; the sealed member section.
在封裝好的成員之后,動態類型可能擁有一組動態成員的名/值對。
The remaining 1 to 25 significant bits are
; used to encode the number of sealed
; traits member names that follow after
; the class name (an integer).
余下的25位用來編碼封裝好的特性成員的名成的數量(一個整數),在他之后是類名。
?
?
class-name
?UTF-8-vr
?; Note: use the empty string for
; anonymous classes.
注意:對于匿名類,使用空的字符串。
?
dynamic-member
?UTF-8-vr value-type
?; Another dynamic member follows
; until the string-type is the
; empty string.
跟著的另一個動態成員,直到是個空的字符串類型。
?
?
object-type
?object-marker (U29O-ref | (U29O-traits-ext class-name *(U8)) | U29O-traits-ref | (U29O-traits class-name *(UTF-8-vr))) *(value-type) *(dynamic-member)))
?
?
Note that for U29O-traits-ext, after the class-name follows an indeterminable number of bytes as *(U8).
注意對于U29O-traits-ext,類名之后跟著的*(U8)字節的不可決定的成員。
This represents the completely custom serialization of "externalizable" types.
這是表示的完全自定義序列化的外部化類型。
The client and server have an agreement as to how to read in this information.
客戶和服務端有一個協議讀取這部分信息。
?
3.13 XML type
ActionScript 3.0 introduces a new XML type that supports E4X syntax.
AS3.0引進了一個新的XML類型,支持E4X句法。
For serialization purposes the XML type needs to be flattened into a string representation.
XML類型轉換為字符串表示進行序列化。
As with other strings in AMF, the content is encoded using UTF-8.
像AMF的其他字符串一樣,使用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).
?
3.14 ByteArray type
ActionScript 3.0 introduces a new type to hold an Array of bytes, namely ByteArray.
AS3.0引進了新的類型表示字節數組,即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.
AMF3用可變長度的29-bit的整數編碼字節的長度作為前綴,其后跟著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.
?
?
Note that this encoding imposes some theoretical limits on the use of ByteArray. The maximum byte-length of each ByteArray instance is limited to 228 - 1 bytes (approx 256 MB).
?
4. Usages of AMF 3
4.1 NetConnection and AMF 3
In addition to serializing ActionScript types, AMF can be used in the asynchronous invocations of remote services.
因為序列化的AS類型,AMF可用于異步的遠程調用服務。
?
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].
這個消息結構的格式AMF0(參考[AMF0])
A context header value or message body can switch to AMF 3 encoding using the special avmplus-object-marker type.
使用一個特殊的avmplus-object-marker的類型可使一個上下文頭值或消息體切換到AMF3編碼。
Similar to AMF 0, AMF 3 object reference tables, object trait reference tables and string reference tables must be reset each time a new context header or message is processed.
和AMF0類似,AMF3對象引用表,對象特性引用表和字符串引用表必須在每次新的上下文頭或消息處理完時復位一次。
?
4.1.1 NetConnection in ActionScript 3.0
The qualified class name for NetConnection in ActionScript 3.0 is flash.net.NetConnection.
NetConnection在AS3.0中的合適的類名是flash.net.NetConnection。
This class continues to use a 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.
這個類繼續使用一個響應器處理從遠程端點來的結果和狀態,然而,現在需要強類型的響應器類,類的全名是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:
這些事件有:
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.
NetConnection對象報告他的狀態或錯誤的條件時分派
?
securityError
?Dispatched if a call to NetConnection.call() attempts to connect to a server outside the caller's security sandbox.
當NetConnection試圖連接調用者的安全沙箱之外的服務器時發布
?
?
To handle an AMF context header a suitable method needs to be available, matching the header name.
為了處理AMF上下文頭,需要一個可用的合適的方法,并且和頭的名稱相匹配。
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.
NetConnection 現在是一個封裝好的類型,因為他必須是某個子類或者實現合適的接口可以對他的客戶屬性做需要的設定。
?
?
4.2 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.
為了支持字節數組形式的原始數據的操作,AS3.0引入了一個新的數據類型,即flash.utils.ByteArray。
To assist with ActionScript Object serialization and copying, ByteArray implements flash.utils.IDataInput and flash.utils.IDataOutput.
為了輔助AS對象的序列化和復制,ByteArray實現了flash.utils.IDataInput和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.
常用的兩個方法是DataOutput.writeObject和IDataInput.readObject。
These methods encode objects using AMF.
這兩個方法使用AMF格式編碼實例對象。
The version of AMF used to encode object data is controlled by the ByteArray.
編碼實例對象的AMF版本是由ByteArray控制的。
objectEncoding method, which can be set to either AMF 3 or AMF 0.
objectEncoding方法,可以適當是AMF3或者AMF0。
An enumeration type, flash.net.ObjectEncoding, holds the constants for the versions of AMF - ObjectEncoding.AMF0 and ObjectEncoding.AMF3 respectively.
一個枚舉的類型flash.net.ObjectEncoding,擁有AMF版本的常量,分別為ObjectEncoding.AMF0和ObjectEncoding.AMF3。
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).
注意:ByteArray使用AMF的一個版本編碼整個對象。不像NetConnection,ByteArray不在AMF0中開始輸出并且切換到AMF3(通過設定objectEncoding屬性到AMF3)
Also note that ByteArray uses a new set of implicit reference tables for objects, object traits and strings for each readObject and writeObject call.
還有注意:ByteArray對每一個對象的讀寫調用都使用一組新的對象,對象特性和字符串引用表。
?
5. Normative References 標準的參考文檔
[AMF0]
?Adobe Systems Inc. "Action Message Format - AMF 0", June 2006.
?
[RFC2234]
?D. Crocker., et. al. "Augmented BNF for Syntax Specifications: ABNF", RFC 2234, November 1997.
?
[RFC3629]
?Yergeau, F., "UTF-8, a transformation format of ISO 10646", RFC 3629, November 2003.
?
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/Thinkor2k8/archive/2008/11/14/3300570.aspx
?