MessagePack for ActionScript3 /[ActionScript3]
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

MessagePack for ActionScript3

msgpack-as3 is an implementation of the latest MessagePack specification for ActionScript3 language (Flash, Flex and AIR).

Basic Usage

Serialize and Deserialize

The usage of MsgPack class is very simple. You need create an object and call read and write methods.

```actionscript // message pack object created var msgpack:MsgPack = new MsgPack();

// encode an array var bytes:ByteArray = msgpack.write([1, 2, 3, 4, 5]);

// rewind the buffer bytes.position = 0;

// print the decoded object trace(;

### Flags
<p>Currently there are three flags which you may use to initialize a MsgPack object:</p>
* <code>MsgPackFlags.READ_STRING_AS_BYTE_ARRAY</code>: message pack string data is read as byte array instead of string;
* <code>MsgPackFlags.ACCEPT_LITTLE_ENDIAN</code>: MsgPack objects will work with little endian buffers (message pack specification defines big endian as default).
* <code>MsgPackFlags.SPEC2013_COMPATIBILITY</code>: MsgPack will run in backwards compatibility mode.

var msg:MsgPack;

// use logical operator OR to set the flags.
msgpack = new MsgPack(MsgPackFlags.READ_STRING_AS_BYTE_ARRAY | MsgPackFlags.ACCEPT_LITTLE_ENDIAN);

Advanced Usage


You can create your own Extension Workers by extending the ExtensionWorker Class and then assigning it to the MsgPack Factory.

The following example assigns a custom worker which extends the ExtensionWorker Class.

```actionscript var msgpack:MsgPack = new MsgPack();

// Assign the new worker to the factory. msgpack.factory.assign(new CustomWorker());

<p>For more information regarding Extensions refer to the MessagePack specification.</p>

### Priorities
<p>Worker priority behaves similar to how the Adobe Event Dispatcher priorities work. In MessagePack, deciding which worker will be use for serializing/deserializing depends on two(2) factors.</p>
1. The order in which the worker was assigned to the factory.
2. The priority of the worker. Higher values take precedence.

All workers have a default priority of 0.

<p>In the following example <code>workerB</code> will never be used because it's assign after <code>workerA</code></p>
var msgpack:MsgPack = new MsgPack();

var workerA:StringWorker = new StringWorker();
var workerB:DifferentStringWorker = new DifferentStringWorker();


However if we adjust the priority of workerB, then workerA will never be used.

```actionscript var msgpack:MsgPack = new MsgPack();

var workerA:StringWorker = new StringWorker(); var workerB:DifferentStringWorker = new DifferentStringWorker(null, 1);

msgpack.factory.assign(workerA); msgpack.factory.assign(workerB);

## Credits
This application uses Open Source components. You can find the source code of their open source projects along with license information below. We acknowledge and are grateful to these developers for their contributions to open source.

Project: as3-msgpack  
Copyright (C) 2013 Lucas Teixeira  
License (Apache V2.0)