GithubHelp home page GithubHelp logo

wldp / as3-msgpack Goto Github PK

View Code? Open in Web Editor NEW

This project forked from loteixeira/as3-msgpack

0.0 0.0 0.0 1.17 MB

MessagePack for ActionScript3 / msgpack.org[ActionScript3]

JavaScript 30.37% CSS 7.65% ActionScript 61.98%

as3-msgpack's Introduction

as3-msgpack v1.0.1

as3-msgpack is a implementation of MessagePack specification for Actionscript3 language (Flash, Flex and AIR).

Getting started: http://loteixeira.github.io/lib/2013/08/19/as3-msgpack/
Download the lastest release: https://github.com/loteixeira/as3-msgpack/archive/v1.0.1.zip
See online documentation: http://disturbedcoder.com/files/as3-msgpack/
Check the wishlist: https://github.com/loteixeira/as3-msgpack/blob/master/WISHLIST.md

about message pack format

MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON but it's faster and smaller. For example, small integers (like flags or error code) are encoded into a single byte, and typical short strings only require an extra byte in addition to the strings themselves.

Check the website: http://msgpack.org

supported types

Message pack specification was built to work mostly with primitive types. You shouldn't expect a serialization library, because msgpack is similiar to JSON - but is based on binary data instead of text.
The types available are: signed/unsigned integer, single/double precision floating point, nil (null), boolean, array, associative array (map) and raw buffer.
These types are mapped to Actionscript3 as the following:

* signed integer -> int * unsigned integer -> uint * single/double precision floating point -> Number * nil -> null * boolean -> Boolean * array -> Array * associative array -> Object * raw buffer -> String or ByteArray

changes

1.0.0 to 1.0.1

  • Using make tool to compile the binaries instead of batch files.
  • Improving README.md
  • Creating msgpack.org.md (as3-msgpack API document for msgpack.org)

0.4.1 to 1.0.0

  • The access interface has been totally modified. Now isn't possible to use singletons, to read/write message pack data you'll need create an object.
  • The names of classes and files were updated. The class MessagePack became MsgPack and the library MessagePack.swc became msgpack.swc.
  • Stream reading is available. If you read data from a buffer (IDataInput) and the object is not complete, the library stores the current status and then wait for more bytes.

folders

  • bin: binaries (library and test applications);
  • lib: libraries used by test applications;
  • doc: documentation generated by asdoc;
  • src_lib: source code of the library;
  • src_test: source code of test applications (including a server and a client which exchange streaming messagepack packets through sockets);

examples

basic usage

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(msgpack.read(bytes));


### streaming
<p>You may read streaming data making successive calls to msgpack.read method. Each MsgPack object can handle one stream at time.<br>
If all bytes are not available, the method returns incomplete (a special object).</p>
```actionscript
package
{
	import flash.events.*;
	import flash.net.*;

	import org.msgpack.*;

	public class Streamer
	{
		private var msgpack:MsgPack;
		private var socket:Socket;

		public function Streamer()
		{
			msgpack = new MsgPack();

			// flash sockets implements the interfaces IDataInput and IDataOutput.
			// thus, these objects may be directly connected to as3-msgpack.
			socket = new Socket();
			socket.addEventListener(ProgressEvent.SOCKET_DATA, socketData);
			// connecting to our hypothetical server
			socket.connect("localhost", 5555);
		}

		public function send(data:*):void
		{
			// we'll write the encoded object straight into the socket (since it implements IDataOutput interface).
			msgpack.write(data, socket);
			socket.flush();
		}

		private function socketData(e:ProgressEvent):void
		{
			// until the data is ready, this call returns incomplete.
			var data:* = msgpack.read(socket);

			// is the object complete?
			if (data != incomplete)
			{
				trace("OBJECT READY:");
				trace(data);
			}
		}
	}
}

using flags

Currently there are two flags which you may use to initialize a MsgPack object:

* MsgPackFlags.READ_RAW_AS_BYTE_ARRAY: message pack raw data is read as byte array instead of string; * MsgPackFlags.ACCEPT_LITTLE_ENDIAN: MsgPack objects will work with little endian buffers (message pack specification defines big endian as default).
var msg:MsgPack;

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

as3-msgpack's People

Contributors

loteixeira avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.