Comparing version 1.0.0 to 1.1.0
@@ -126,5 +126,5 @@ (function() { | ||
ret = (function() { | ||
var i, ref, results; | ||
var j, ref, results; | ||
results = []; | ||
for (x = i = 0, ref = len - 1; 0 <= ref ? i <= ref : i >= ref; x = 0 <= ref ? ++i : --i) { | ||
for (x = j = 0, ref = len - 1; 0 <= ref ? j <= ref : j >= ref; x = 0 <= ref ? ++j : --j) { | ||
results.push(this.decode(AMF0)); | ||
@@ -223,3 +223,3 @@ } | ||
AMF3.ARRAY.decode = function() { | ||
var header, key, named, ret, x; | ||
var header, i, key, named, ret; | ||
header = this.readAMFHeader(); | ||
@@ -237,10 +237,8 @@ if (!header.isDef) { | ||
} | ||
ret = (function() { | ||
var i, ref, results; | ||
results = []; | ||
for (x = i = 0, ref = header.value - 1; 0 <= ref ? i <= ref : i >= ref; x = 0 <= ref ? ++i : --i) { | ||
results.push(this.decode(AMF3)); | ||
} | ||
return results; | ||
}).call(this); | ||
ret = []; | ||
i = 0; | ||
while (i < header.value) { | ||
ret.push(this.decode(AMF3)); | ||
i++; | ||
} | ||
this.amf3ObjectReferences.push(ret); | ||
@@ -251,3 +249,3 @@ return ret; | ||
readAMF3ObjectHeader = function(flags) { | ||
var i, isDynamic, isExternalizable, name, ref, staticKeyLen, trait, x; | ||
var isDynamic, isExternalizable, j, name, ref, staticKeyLen, trait, x; | ||
if (flags & 1 === 0) { | ||
@@ -262,3 +260,3 @@ return this.amf3TraitReferences[flags >> 1]; | ||
if (staticKeyLen !== 0) { | ||
for (x = i = 0, ref = staticKeyLen - 1; 0 <= ref ? i <= ref : i >= ref; x = 0 <= ref ? ++i : --i) { | ||
for (x = j = 0, ref = staticKeyLen - 1; 0 <= ref ? j <= ref : j >= ref; x = 0 <= ref ? ++j : --j) { | ||
trait.staticFields.push(this.deserialize(AMF3.STRING, AMF3)); | ||
@@ -272,3 +270,3 @@ } | ||
AMF3.OBJECT.decode = function() { | ||
var header, i, key, len1, ref, ret, trait, x; | ||
var header, j, key, len1, ref, ret, trait, x; | ||
header = this.readAMFHeader(); | ||
@@ -287,4 +285,4 @@ if (!header.isDef) { | ||
ref = trait.staticFields; | ||
for (i = 0, len1 = ref.length; i < len1; i++) { | ||
x = ref[i]; | ||
for (j = 0, len1 = ref.length; j < len1; j++) { | ||
x = ref[j]; | ||
ret[x] = this.decode(AMF3); | ||
@@ -319,5 +317,5 @@ } | ||
res = (function() { | ||
var i, ref, results; | ||
var j, ref, results; | ||
results = []; | ||
for (x = i = 0, ref = header.value - 1; 0 <= ref ? i <= ref : i >= ref; x = 0 <= ref ? ++i : --i) { | ||
for (x = j = 0, ref = header.value - 1; 0 <= ref ? j <= ref : j >= ref; x = 0 <= ref ? ++j : --j) { | ||
results.push(func.call(this)); | ||
@@ -356,3 +354,3 @@ } | ||
AMF3.DICTIONARY.decode = function() { | ||
var header, i, ref, ret, x; | ||
var header, j, ref, ret, x; | ||
header = this.readAMFHeader(); | ||
@@ -364,3 +362,3 @@ if (!header.isDef) { | ||
ret = {}; | ||
for (x = i = 0, ref = header.value - 1; 0 <= ref ? i <= ref : i >= ref; x = 0 <= ref ? ++i : --i) { | ||
for (x = j = 0, ref = header.value - 1; 0 <= ref ? j <= ref : j >= ref; x = 0 <= ref ? ++j : --j) { | ||
ret[JSON.stringify(this.decode(AMF3))] = this.decode(AMF3); | ||
@@ -367,0 +365,0 @@ } |
@@ -366,3 +366,3 @@ (function() { | ||
header = (header | 2) | 1; | ||
this.write(header); | ||
AMF3.INTEGER.encode.call(this, header); | ||
this.serialize(value["__class"], AMF3); | ||
@@ -369,0 +369,0 @@ if (externalizable) { |
@@ -98,14 +98,14 @@ (function() { | ||
BOOLEAN: new AMFType(0x01, "BOOLEAN"), | ||
STRING: new AMFType(0x03, "STRING"), | ||
OBJECT: new AMFType(0x04, "OBJECT", true), | ||
MOVIECLIP: new AMFType(0x05, "MOVIECLIP"), | ||
NULL: new AMFType(0x06, "NULL"), | ||
UNDEFINED: new AMFType(0x07, "UNDEFINED"), | ||
REFERENCE: new AMFType(0x08, "REFERENCE"), | ||
ECMA_ARRAY: new AMFType(0x09, "ECMA_ARRAY", true), | ||
OBJECT_END: new AMFType(0x0a, "OBJECT_END"), | ||
STRICT_ARRAY: new AMFType(0x0b, "STRICT_ARRAY", true), | ||
DATE: new AMFType(0x0c, "DATE"), | ||
LONG_STRING: new AMFType(0x0d, "LONG_STRING"), | ||
UNSUPPORTED: new AMFType(0x0e, "UNSUPPORTED"), | ||
STRING: new AMFType(0x02, "STRING"), | ||
OBJECT: new AMFType(0x03, "OBJECT", true), | ||
MOVIECLIP: new AMFType(0x04, "MOVIECLIP"), | ||
NULL: new AMFType(0x05, "NULL"), | ||
UNDEFINED: new AMFType(0x06, "UNDEFINED"), | ||
REFERENCE: new AMFType(0x07, "REFERENCE"), | ||
ECMA_ARRAY: new AMFType(0x08, "ECMA_ARRAY", true), | ||
OBJECT_END: new AMFType(0x09, "OBJECT_END"), | ||
STRICT_ARRAY: new AMFType(0x0a, "STRICT_ARRAY", true), | ||
DATE: new AMFType(0x0b, "DATE"), | ||
LONG_STRING: new AMFType(0x0c, "LONG_STRING"), | ||
UNSUPPORTED: new AMFType(0x0d, "UNSUPPORTED"), | ||
XML: new AMFType(0x0f, "XML"), | ||
@@ -112,0 +112,0 @@ TYPED_OBJECT: new AMFType(0x10, "TYPED_OBJECT", true), |
{ | ||
"name": "amfjs", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A simple AMF (ActionScript Message Format) library for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/amf-js.js", |
@@ -1,1 +0,51 @@ | ||
# AMF.js | ||
## AMF.js | ||
As a simple AMF (Action Message Format) library for Node.js, AMF.js is capable of encoding and decoding most AMF0 and AMF3 types. Simply hook the AMFEncoder or AMFDecoder up to a stream and it will be able to read or write to/from the stream. | ||
# Installation | ||
npm install [--save-dev] amfjs | ||
# Usage | ||
- __Encoding__ | ||
``` | ||
var amfjs = require("amfjs") | ||
var encoder = new amfjs.AMFEncoder(someKindOfWritableStream) | ||
encoder.writeObject(10, amfjs.AMF0) //Write as AMF0 | ||
encoder.writeObject(10, amfjs.AMF3) //Write as AMF3 | ||
``` | ||
- __Decoding__ | ||
``` | ||
var amfjs = require("amfjs") | ||
var decoder = new amfjs.AMFDecoder(someKindOfReadableStream) | ||
var value = decoder.decode(amfjs.AMF0) //Decode an AMF0 object | ||
var value = decoder.decode(amfjs.AMF3) //Decode an AMF3 object | ||
``` | ||
- __Encoding custom objects__ | ||
Simply extend the Serializable class and call `writeObject` with an instance of your class. Any fields in the serializable not starting with `__` will automatically be encoded: | ||
``` | ||
class MySerializable extends Serializable | ||
constructor: -> | ||
super "name.of.the.serializable" | ||
``` | ||
- __Custom Externalizables__ | ||
Simply extend the Externalizable class and register it in the decoder to allow for the custom encoding of objects. The `write` method will be called whenever an Externalizable needs to be encoded and the `this` value will be set to the encoder. The static `read` method will be called whenever an object with the Externizable's class is found. As with `write`, while invoking `read` the `this` value is set to the decoder. | ||
``` | ||
class MyExternalizable extends Externalizable | ||
constructor: -> | ||
super "name.of.the.externalizable" | ||
write: -> | ||
//Do some writing stuff | ||
@write 0x10 | ||
@read: -> | ||
//Do some reading stuff and return the read object | ||
@readByte() | ||
return new MyExternalizable() | ||
//Register the externalizable | ||
var amfjs = require("amfjs") | ||
amfjs.AMFDecoder.register("name.of.the.externalizable", MyExternalizable, amfjs.AMF0) //Or AMF3 | ||
``` | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73492
52
1105