demonsters / messagepack Goto Github PK
View Code? Open in Web Editor NEWMessage Pack AS3 port
Message Pack AS3 port
AS3 Port for Message Pack: http://msgpack.org/
Hello, thanks for your messagepack module for .as3.
Before that, sorry to my poor English.
When I use this module in my small practice project with python server, some modify made for project use.
In MessagePack.as
function modified as follow:
public static function encode(o:*):ByteArray
{
return MessagePackEncode.encode(o);
}
function modified as follow:
public static function decode(bytes:ByteArray):*
{
return MessagePackDecode.decode(bytes);
}
Last two modify make interface can use as complete static function.
And in MessagePackDecode:
function modified as follow:
private static function decodeArray(input:ByteArray, length:int):Array
{
// Integer to keep count of the array length
// so it knows when to end the array object
var objCount:int = 0;
// Total amount of bytes to check with
var byteLength:int = input.length;
// Creates the array
var array:Array = new Array(byteLength);
while (input.position < byteLength && objCount < length) {
// The byte identifier
var byteType:int = input.readUnsignedByte();
if (byteType > 0x00 && byteType < 0x7f) {
// Positive FixNum
var fixNumPos:int = byteType;
array[objCount] = fixNumPos;
objCount++;
}
else if (byteType > 0xe0 && byteType < 0xff) {
// Negative FixNum
var fixNumNeg:int = byteType;
array[objCount] = fixNumNeg;
objCount++;
}
else if (byteType == 0xc2) {
// false
var fal:Boolean = false;
array[objCount] = fal;
objCount++;
}
else if(byteType == 0xc3) {
// true
var tru:Boolean = true;
array[objCount] = tru;
objCount++;
}
else if (byteType == 0xca) {
// float
var float:Number = input.readFloat();
array[objCount] = float;
objCount++;
}
else if (byteType == 0xcb) {
//double float
var doubleFloat:Number = input.readDouble();
array[objCount] = doubleFloat;
objCount++;
}
else if (byteType == 0xcc) {
// uint 8
var uint8:uint = input.readUnsignedByte();
array[objCount] = uint8;
objCount++;
}
else if (byteType == 0xcd) {
//uint 16
var uint16:uint = input.readShort();
array[objCount] = uint16;
objCount++;
}
else if (byteType == 0xce) {
// uint 32
var uint32:uint = input.readUnsignedInt();
array[objCount] = uint32;
objCount++;
}
else if (byteType == 0xcf) {
// uint 64
}
else if (byteType == 0xd0) {
// int 8
var int8:int = input.readByte();
array[objCount] = int8;
objCount++;
}
else if (byteType == 0xd1) {
// int 16
var int16:int = input.readShort();
array[objCount] = int16;
objCount++;
}
else if (byteType == 0xd2) {
//int 32
var int32:int = input.readInt();
array[objCount] = int32;
objCount++;
}
else if (byteType == 0xda) {
// raw 16
var raw16Arr:ByteArray = new ByteArray();
var raw16Length:Number = input.readShort();
input.readBytes(raw16Arr, 0, raw16Length);
var raw16Str:String = raw16Arr.readUTFBytes(raw16Arr.length);
array[objCount] = raw16Str;
objCount++;
}
else if (byteType == 0xdb) {
// raw 32
var raw32Arr:ByteArray = new ByteArray();
var raw32Length:Number = input.readInt();
input.readBytes(raw16Arr, 0, raw32Length);
var raw32Str:String = raw16Arr.readUTFBytes(raw32Arr.length);
array[objCount] = raw32Str;
objCount++;
}
else if (byteType == 0xdc) {
// array 16
var arr16:Number = input.readShort();
array[objCount] = decodeArray(input, arr16);
objCount++;
}
else if (byteType == 0xdd) {
// array 32
var arr32:Number = input.readUnsignedInt();
array[objCount] = decodeArray(input, arr32);
objCount++;
}
else if (byteType > 0xa0 && byteType < 0xbf) {
// FixRaw
var fixRawArr:ByteArray = new ByteArray();
input.readBytes(fixRawArr, 0, byteType ^ 0xa0);
var fixRawStr:String = fixRawArr.readUTFBytes(fixRawArr.length);
array[objCount] = fixRawStr;
objCount++;
}
else if (byteType >= 0x90 && byteType <= 0x9f) {
// FixArray
var fixArray:Number = byteType;
array[objCount] = decodeArray(input, fixArray);
objCount++;
}
else if (byteType == 0x00){
array[objCount] = 0;
objCount++;
}
}
return array.slice(0, array.indexOf(null));
}
Mainly modify is when byteType == 0xcc, use unsigned read, and when byteType == 0x00 to give a 0 return;
Practice project continued, something new discovered will commit, thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.