35
34
public static var DEFAULT_RESOLVER : TypeResolver = Type;
36
static var BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%:";
39
static var CODES = null;
41
static function initCodes() {
44
new flash.utils.ByteArray();
48
for( i in 0...BASE64.length )
49
codes[untyped BASE64.cca(i)] = i;
86
inline function get(p) : Int {
88
return untyped buf.cca(p);
90
return untyped __dollar__sget(buf.__s,p);
92
return buf.charCodeAt(p);
69
96
function readDigits() {
74
var c = buf.charCodeAt(pos);
103
// if flash9, it returns 0 so we will break later
104
#elseif (flash || js)
77
111
if( c == 45 ) { // negative sign
111
145
var constr = Reflect.field(edecl,tag);
112
146
if( constr == null )
113
147
throw "Unknown enum tag "+Type.getEnumName(edecl)+"."+tag;
114
if( buf.charCodeAt(pos++) != 58 ) // ':'
148
if( get(pos++) != 58 ) // ':'
115
149
throw "Invalid enum format";
116
150
var nargs = readDigits();
117
151
if( nargs == 0 ) {
228
263
return unserializeEnum(edecl,tag);
230
265
var l = new List();
231
while( buf.charCodeAt(pos) != 104 /*h*/ )
267
while( get(pos) != 104 /*h*/ )
232
268
l.add(unserialize());
236
272
var h = new Hash();
237
while( buf.charCodeAt(pos) != 104 /*h*/ ) {
274
while( get(pos) != 104 /*h*/ ) {
238
275
var s = unserialize();
239
276
h.set(s,unserialize());
255
293
var d = Date.fromString(buf.substr(pos,19));
260
297
var len = readDigits();
261
299
if( buf.charAt(pos++) != ":" || length - pos < len )
262
throw "Invalid string length";
300
throw "Invalid bytes length";
264
var s = neko.Utf8.sub(buf,pos-upos,len);
266
upos += s.length - len;
268
var s = buf.substr(pos,len);
302
var bytes = haxe.io.Bytes.ofData( base_decode(untyped buf.substr(pos,len).__s,untyped BASE64.__s) );
305
if( codes == null ) {
309
var b = new haxe.io.BytesBuffer();
312
var max = i + (len - rest);
314
var c1 = codes[untyped buf.cca(i++)];
315
var c2 = codes[untyped buf.cca(i++)];
316
b.addByte((c1 << 2) | (c2 >> 4));
317
var c3 = codes[untyped buf.cca(i++)];
318
b.addByte(((c2 << 4) | (c3 >> 2)) #if !flash9 & 0xFF #end );
319
var c4 = codes[untyped buf.cca(i++)];
320
b.addByte(((c3 << 6) | c4) #if !flash9 & 0xFF #end );
323
var c1 = codes[untyped buf.cca(i++)];
324
var c2 = codes[untyped buf.cca(i++)];
325
b.addByte((c1 << 2) | (c2 >> 4));
327
var c3 = codes[untyped buf.cca(i++)];
328
b.addByte(((c2 << 4) | (c3 >> 2)) #if !flash9 & 0xFF #end );
331
var bytes = b.getBytes();