├── test ├── fixtures │ ├── v2 │ │ ├── double │ │ │ ├── 0.bin │ │ │ ├── 1.bin │ │ │ ├── 127.bin │ │ │ ├── 10.1.bin │ │ │ ├── 10.bin │ │ │ ├── -128.bin │ │ │ ├── -32768.bin │ │ │ ├── 10.123.bin │ │ │ ├── 32767.bin │ │ │ ├── 32768.bin │ │ │ ├── -0x800000.bin │ │ │ ├── -127.9999.bin │ │ │ ├── 126.9989.bin │ │ │ ├── -0x80000000.bin │ │ │ ├── -2147483647.bin │ │ │ ├── -2147483648.bin │ │ │ ├── -2147483649.bin │ │ │ ├── -32767.999.bin │ │ │ ├── 2147483646.bin │ │ │ ├── 2147483647.bin │ │ │ ├── 2147483648.bin │ │ │ ├── 32766.99999.bin │ │ │ ├── 32767.99999.bin │ │ │ ├── -2147483647.0.bin │ │ │ ├── 2147483646.456.bin │ │ │ └── -2147483610.123.bin │ │ ├── long │ │ │ ├── 2048.bin │ │ │ ├── -262144.bin │ │ │ ├── 0.bin │ │ │ ├── -7.bin │ │ │ ├── -8.bin │ │ │ ├── -9.bin │ │ │ ├── 14.bin │ │ │ ├── 15.bin │ │ │ ├── 16.bin │ │ │ ├── 255.bin │ │ │ ├── -2048.bin │ │ │ ├── -2049.bin │ │ │ ├── 2047.bin │ │ │ ├── 262143.bin │ │ │ ├── -2147483647.bin │ │ │ ├── -2147483648.bin │ │ │ ├── 2147483646.bin │ │ │ ├── 2147483647.bin │ │ │ └── 2147483648.bin │ │ ├── list │ │ │ ├── untyped_[].bin │ │ │ ├── [string.bin │ │ │ ├── typed_list.bin │ │ │ ├── [int.bin │ │ │ ├── typed_list_8.bin │ │ │ ├── untyped_list.bin │ │ │ └── untyped_list_8.bin │ │ ├── string │ │ │ ├── empty.bin │ │ │ ├── foo.bin │ │ │ ├── chinese.bin │ │ │ ├── 0123456789012345678901234567890.bin │ │ │ ├── 01234567890123456789012345678901.bin │ │ │ ├── utf8_32767.bin │ │ │ ├── utf8_32768.bin │ │ │ ├── utf8_32769.bin │ │ │ ├── utf8_65534.bin │ │ │ ├── utf8_65535.bin │ │ │ ├── utf8_65536.bin │ │ │ ├── utf8_65537.bin │ │ │ ├── large_string_32767.bin │ │ │ ├── large_string_32768.bin │ │ │ ├── large_string_32769.bin │ │ │ ├── large_string_65534.bin │ │ │ ├── large_string_65535.bin │ │ │ ├── large_string_65536.bin │ │ │ ├── large_string_65537.bin │ │ │ ├── large_string_chars.bin │ │ │ ├── large_string_chars_65536.bin │ │ │ └── text4k.bin │ │ ├── date │ │ │ ├── 894621060000.bin │ │ │ ├── 128849018880000.bin │ │ │ ├── now.bin │ │ │ ├── 894621091000.bin │ │ │ └── -128849018940000.bin │ │ ├── map │ │ │ ├── foo_empty.bin │ │ │ ├── hashtable.bin │ │ │ ├── car.bin │ │ │ ├── car1.bin │ │ │ ├── car2.bin │ │ │ ├── foo_bar.bin │ │ │ ├── generic.bin │ │ │ ├── car_list.bin │ │ │ ├── one_car_list.bin │ │ │ └── two_car_list.bin │ │ ├── number │ │ │ ├── 262144.bin │ │ │ ├── 0.bin │ │ │ ├── 1.bin │ │ │ ├── -16.bin │ │ │ ├── -256.bin │ │ │ ├── 10.bin │ │ │ ├── 16.bin │ │ │ ├── 2047.bin │ │ │ ├── 255.bin │ │ │ ├── 256.bin │ │ │ ├── 46.bin │ │ │ ├── 47.bin │ │ │ ├── -2048.bin │ │ │ ├── 262143.bin │ │ │ ├── -262144.bin │ │ │ └── -262145.bin │ │ ├── bytes │ │ │ ├── 15.bin │ │ │ ├── 16.bin │ │ │ ├── 32767.bin │ │ │ ├── 32768.bin │ │ │ ├── 32769.bin │ │ │ ├── 42769.bin │ │ │ ├── 65535.bin │ │ │ └── 82769.bin │ │ ├── enum │ │ │ ├── red.bin │ │ │ ├── blue.bin │ │ │ ├── green.bin │ │ │ └── lists.bin │ │ ├── object │ │ │ ├── AtomicLong0.bin │ │ │ ├── AtomicLong1.bin │ │ │ └── ConnectionRequest.bin │ │ └── exception │ │ │ ├── IOException.bin │ │ │ ├── UndeclaredThrowableException.bin │ │ │ ├── UndeclaredThrowableException2.bin │ │ │ └── UndeclaredThrowableException3.bin │ ├── v1 │ │ ├── double │ │ │ ├── 0.bin │ │ │ ├── 10.1.bin │ │ │ ├── 10.bin │ │ │ ├── 1.bin │ │ │ ├── -128.bin │ │ │ ├── 127.bin │ │ │ ├── -32768.bin │ │ │ ├── 10.123.bin │ │ │ ├── 32767.bin │ │ │ ├── 32768.bin │ │ │ ├── -127.9999.bin │ │ │ ├── 126.9989.bin │ │ │ ├── -2147483647.bin │ │ │ ├── -2147483648.bin │ │ │ ├── -2147483649.bin │ │ │ ├── -32767.999.bin │ │ │ ├── 2147483646.bin │ │ │ ├── 2147483647.bin │ │ │ ├── 2147483648.bin │ │ │ ├── 32766.99999.bin │ │ │ ├── 32767.99999.bin │ │ │ ├── -2147483647.0.bin │ │ │ ├── 2147483646.456.bin │ │ │ └── -2147483610.123.bin │ │ ├── long │ │ │ ├── 0.bin │ │ │ ├── 14.bin │ │ │ ├── 15.bin │ │ │ ├── 16.bin │ │ │ ├── 2048.bin │ │ │ ├── -7.bin │ │ │ ├── -8.bin │ │ │ ├── -9.bin │ │ │ ├── 255.bin │ │ │ ├── -2048.bin │ │ │ ├── -2049.bin │ │ │ ├── 2047.bin │ │ │ ├── 262143.bin │ │ │ ├── -262144.bin │ │ │ ├── -2147483647.bin │ │ │ ├── -2147483648.bin │ │ │ ├── 2147483646.bin │ │ │ ├── 2147483647.bin │ │ │ └── 2147483648.bin │ │ ├── number │ │ │ ├── 0.bin │ │ │ ├── 1.bin │ │ │ ├── 16.bin │ │ │ ├── 256.bin │ │ │ ├── 46.bin │ │ │ ├── 47.bin │ │ │ ├── 10.bin │ │ │ ├── 262144.bin │ │ │ ├── -16.bin │ │ │ ├── -256.bin │ │ │ ├── 2047.bin │ │ │ ├── 255.bin │ │ │ ├── -2048.bin │ │ │ ├── 262143.bin │ │ │ ├── -262144.bin │ │ │ └── -262145.bin │ │ ├── string │ │ │ ├── empty.bin │ │ │ ├── foo.bin │ │ │ ├── chinese.bin │ │ │ ├── 0123456789012345678901234567890.bin │ │ │ ├── 01234567890123456789012345678901.bin │ │ │ ├── utf8_32767.bin │ │ │ ├── utf8_32768.bin │ │ │ ├── utf8_32769.bin │ │ │ ├── utf8_65534.bin │ │ │ ├── utf8_65535.bin │ │ │ ├── utf8_65536.bin │ │ │ ├── utf8_65537.bin │ │ │ ├── large_string_32767.bin │ │ │ ├── large_string_32768.bin │ │ │ ├── large_string_32769.bin │ │ │ ├── large_string_65534.bin │ │ │ ├── large_string_65535.bin │ │ │ ├── large_string_65536.bin │ │ │ ├── large_string_65537.bin │ │ │ ├── large_string_chars.bin │ │ │ └── text4k.bin │ │ ├── list │ │ │ ├── untyped_[].bin │ │ │ ├── [int.bin │ │ │ ├── [string.bin │ │ │ ├── untyped_list.bin │ │ │ └── typed_list.bin │ │ ├── map │ │ │ ├── foo_empty.bin │ │ │ ├── foo_bar.bin │ │ │ ├── generic.bin │ │ │ ├── car.bin │ │ │ ├── car1.bin │ │ │ ├── one_car_list.bin │ │ │ ├── car2.bin │ │ │ ├── two_car_list.bin │ │ │ └── car_list.bin │ │ ├── enum │ │ │ ├── blue.bin │ │ │ ├── red.bin │ │ │ ├── green.bin │ │ │ └── lists.bin │ │ ├── object │ │ │ ├── AtomicLong0.bin │ │ │ ├── AtomicLong1.bin │ │ │ └── ConnectionRequest.bin │ │ ├── date │ │ │ ├── now.bin │ │ │ ├── 894621060000.bin │ │ │ └── 894621091000.bin │ │ ├── bytes │ │ │ ├── 32767.bin │ │ │ ├── 32768.bin │ │ │ ├── 32769.bin │ │ │ ├── 42769.bin │ │ │ ├── 65535.bin │ │ │ └── 82769.bin │ │ └── exception │ │ │ ├── IOException.bin │ │ │ ├── UndeclaredThrowableException.bin │ │ │ └── UndeclaredThrowableException2.bin │ └── 4k.txt ├── support │ └── fixture.png ├── utils.js ├── utils.test.js ├── null.test.js ├── boolean.test.js ├── array.test.js ├── decode.circular.test.js ├── date.test.js ├── v2.list.encode.test.js ├── exception.test.js ├── binary.test.js ├── list.test.js └── int.test.js ├── .gitignore ├── src ├── hessian_array.cc ├── hessian_bool.cc ├── hessian_bytes.cc ├── hessian_double.cc ├── hessian_map.cc ├── hessian_ref.cc ├── hessian_object.cc ├── hessian_hash_map.cc ├── hessian_null.cc ├── hessian_pool.cc ├── hessian_date.cc ├── hessian_int.cc ├── hessian_long.cc ├── hessian_string.cc └── hessian.cc ├── include ├── hessian │ ├── encode.h │ ├── pool.h │ └── decode.h └── hessian.h ├── LICENSE ├── index.js ├── package.json ├── README.md ├── lib ├── utils.js └── object.js └── benchmark ├── README.md ├── encode.js └── decode.js /test/fixtures/v2/double/0.bin: -------------------------------------------------------------------------------- 1 | [ -------------------------------------------------------------------------------- /test/fixtures/v2/double/1.bin: -------------------------------------------------------------------------------- 1 | \ -------------------------------------------------------------------------------- /test/fixtures/v2/double/127.bin: -------------------------------------------------------------------------------- 1 | ] -------------------------------------------------------------------------------- /test/fixtures/v2/long/2048.bin: -------------------------------------------------------------------------------- 1 | < -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *~ 3 | -------------------------------------------------------------------------------- /test/fixtures/v1/double/0.bin: -------------------------------------------------------------------------------- 1 | D -------------------------------------------------------------------------------- /test/fixtures/v1/long/0.bin: -------------------------------------------------------------------------------- 1 | L -------------------------------------------------------------------------------- /test/fixtures/v1/long/14.bin: -------------------------------------------------------------------------------- 1 | L -------------------------------------------------------------------------------- /test/fixtures/v1/long/15.bin: -------------------------------------------------------------------------------- 1 | L -------------------------------------------------------------------------------- /test/fixtures/v1/long/16.bin: -------------------------------------------------------------------------------- 1 | L -------------------------------------------------------------------------------- /test/fixtures/v1/number/0.bin: -------------------------------------------------------------------------------- 1 | I -------------------------------------------------------------------------------- /test/fixtures/v1/number/1.bin: -------------------------------------------------------------------------------- 1 | I -------------------------------------------------------------------------------- /test/fixtures/v1/number/16.bin: -------------------------------------------------------------------------------- 1 | I -------------------------------------------------------------------------------- /test/fixtures/v1/number/256.bin: -------------------------------------------------------------------------------- 1 | I -------------------------------------------------------------------------------- /test/fixtures/v1/number/46.bin: -------------------------------------------------------------------------------- 1 | I. -------------------------------------------------------------------------------- /test/fixtures/v1/number/47.bin: -------------------------------------------------------------------------------- 1 | I/ -------------------------------------------------------------------------------- /test/fixtures/v1/string/empty.bin: -------------------------------------------------------------------------------- 1 | S -------------------------------------------------------------------------------- /test/fixtures/v1/string/foo.bin: -------------------------------------------------------------------------------- 1 | Sfoo -------------------------------------------------------------------------------- /test/fixtures/v2/double/10.1.bin: -------------------------------------------------------------------------------- 1 | _'t -------------------------------------------------------------------------------- /test/fixtures/v2/double/10.bin: -------------------------------------------------------------------------------- 1 | ] 2 | -------------------------------------------------------------------------------- /test/fixtures/v2/list/untyped_[].bin: -------------------------------------------------------------------------------- 1 | x -------------------------------------------------------------------------------- /test/fixtures/v2/long/-262144.bin: -------------------------------------------------------------------------------- 1 | 8 -------------------------------------------------------------------------------- /test/fixtures/v2/string/empty.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/v2/string/foo.bin: -------------------------------------------------------------------------------- 1 | foo -------------------------------------------------------------------------------- /test/fixtures/v1/double/10.1.bin: -------------------------------------------------------------------------------- 1 | D@$333333 -------------------------------------------------------------------------------- /test/fixtures/v1/double/10.bin: -------------------------------------------------------------------------------- 1 | D@$ -------------------------------------------------------------------------------- /test/fixtures/v1/list/untyped_[].bin: -------------------------------------------------------------------------------- 1 | Vlz -------------------------------------------------------------------------------- /test/fixtures/v1/long/2048.bin: -------------------------------------------------------------------------------- 1 | L -------------------------------------------------------------------------------- /test/fixtures/v1/number/10.bin: -------------------------------------------------------------------------------- 1 | I 2 | -------------------------------------------------------------------------------- /test/fixtures/v1/number/262144.bin: -------------------------------------------------------------------------------- 1 | I -------------------------------------------------------------------------------- /test/fixtures/v2/date/894621060000.bin: -------------------------------------------------------------------------------- 1 | Kハ -------------------------------------------------------------------------------- /test/fixtures/v2/map/foo_empty.bin: -------------------------------------------------------------------------------- 1 | HfooZ -------------------------------------------------------------------------------- /test/fixtures/v2/number/262144.bin: -------------------------------------------------------------------------------- 1 | I -------------------------------------------------------------------------------- /test/fixtures/v1/map/foo_empty.bin: -------------------------------------------------------------------------------- 1 | MtSfooSz -------------------------------------------------------------------------------- /test/fixtures/v2/bytes/15.bin: -------------------------------------------------------------------------------- 1 | /AAAAAAAAAAAAAAA -------------------------------------------------------------------------------- /test/fixtures/v2/bytes/16.bin: -------------------------------------------------------------------------------- 1 | 4AAAAAAAAAAAAAAAA -------------------------------------------------------------------------------- /test/fixtures/v2/list/[string.bin: -------------------------------------------------------------------------------- 1 | s[string1@3 -------------------------------------------------------------------------------- /test/fixtures/v1/string/chinese.bin: -------------------------------------------------------------------------------- 1 | S 2 | 中文 Chinese -------------------------------------------------------------------------------- /test/fixtures/v2/date/128849018880000.bin: -------------------------------------------------------------------------------- 1 | Ju0 -------------------------------------------------------------------------------- /test/fixtures/v2/string/chinese.bin: -------------------------------------------------------------------------------- 1 | 2 | 中文 Chinese -------------------------------------------------------------------------------- /test/fixtures/v1/list/[int.bin: -------------------------------------------------------------------------------- 1 | Vt[intlIIIz -------------------------------------------------------------------------------- /test/fixtures/v1/list/[string.bin: -------------------------------------------------------------------------------- 1 | Vt[stringlS1S@S3z -------------------------------------------------------------------------------- /test/fixtures/v1/list/untyped_list.bin: -------------------------------------------------------------------------------- 1 | VlIISfooz -------------------------------------------------------------------------------- /test/fixtures/v1/enum/blue.bin: -------------------------------------------------------------------------------- 1 | Mthessian.Main$ColorSnameSBLUEz -------------------------------------------------------------------------------- /test/fixtures/v1/enum/red.bin: -------------------------------------------------------------------------------- 1 | Mthessian.Main$ColorSnameSREDz -------------------------------------------------------------------------------- /test/fixtures/v1/enum/green.bin: -------------------------------------------------------------------------------- 1 | Mthessian.Main$ColorSnameSGREENz -------------------------------------------------------------------------------- /test/fixtures/v2/list/typed_list.bin: -------------------------------------------------------------------------------- 1 | rhessian.demo.SomeArrayListok some list -------------------------------------------------------------------------------- /test/fixtures/v2/map/hashtable.bin: -------------------------------------------------------------------------------- 1 | Mjava.util.Hashtable中文key 中文哈哈valuefoobarZ -------------------------------------------------------------------------------- /test/fixtures/v1/list/typed_list.bin: -------------------------------------------------------------------------------- 1 | Vthessian.demo.SomeArrayListlSokS some listz -------------------------------------------------------------------------------- /test/fixtures/v1/string/0123456789012345678901234567890.bin: -------------------------------------------------------------------------------- 1 | S0123456789012345678901234567890 -------------------------------------------------------------------------------- /test/fixtures/v2/string/0123456789012345678901234567890.bin: -------------------------------------------------------------------------------- 1 | 0123456789012345678901234567890 -------------------------------------------------------------------------------- /test/fixtures/v1/string/01234567890123456789012345678901.bin: -------------------------------------------------------------------------------- 1 | S 01234567890123456789012345678901 -------------------------------------------------------------------------------- /test/fixtures/v2/string/01234567890123456789012345678901.bin: -------------------------------------------------------------------------------- 1 | S 01234567890123456789012345678901 -------------------------------------------------------------------------------- /test/fixtures/v1/object/AtomicLong0.bin: -------------------------------------------------------------------------------- 1 | Mt&java.util.concurrent.atomic.AtomicLongSvalueLz -------------------------------------------------------------------------------- /test/fixtures/v1/object/AtomicLong1.bin: -------------------------------------------------------------------------------- 1 | Mt&java.util.concurrent.atomic.AtomicLongSvalueLz -------------------------------------------------------------------------------- /test/support/fixture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/support/fixture.png -------------------------------------------------------------------------------- /test/fixtures/v2/long/0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/0.bin -------------------------------------------------------------------------------- /test/fixtures/v1/date/now.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/date/now.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/1.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/-7.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/-7.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/-8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/-8.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/-9.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/-9.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/255.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/255.bin -------------------------------------------------------------------------------- /test/fixtures/v2/date/now.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/date/now.bin -------------------------------------------------------------------------------- /test/fixtures/v2/enum/red.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/enum/red.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/-7.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/-7.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/-8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/-8.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/-9.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/-9.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/14.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/14.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/15.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/15.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/16.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/16.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/255.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/255.bin -------------------------------------------------------------------------------- /test/fixtures/v2/map/car.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/map/car.bin -------------------------------------------------------------------------------- /test/fixtures/v2/map/car1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/map/car1.bin -------------------------------------------------------------------------------- /test/fixtures/v2/map/car2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/map/car2.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/0.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/1.bin -------------------------------------------------------------------------------- /test/fixtures/v1/bytes/32767.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/bytes/32767.bin -------------------------------------------------------------------------------- /test/fixtures/v1/bytes/32768.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/bytes/32768.bin -------------------------------------------------------------------------------- /test/fixtures/v1/bytes/32769.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/bytes/32769.bin -------------------------------------------------------------------------------- /test/fixtures/v1/bytes/42769.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/bytes/42769.bin -------------------------------------------------------------------------------- /test/fixtures/v1/bytes/65535.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/bytes/65535.bin -------------------------------------------------------------------------------- /test/fixtures/v1/bytes/82769.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/bytes/82769.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/-128.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/-128.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/127.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/127.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/-2048.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/-2048.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/-2049.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/-2049.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/2047.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/2047.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/262143.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/262143.bin -------------------------------------------------------------------------------- /test/fixtures/v1/map/foo_bar.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/map/foo_bar.bin -------------------------------------------------------------------------------- /test/fixtures/v1/map/generic.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/map/generic.bin -------------------------------------------------------------------------------- /test/fixtures/v1/number/-16.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/number/-16.bin -------------------------------------------------------------------------------- /test/fixtures/v1/number/-256.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/number/-256.bin -------------------------------------------------------------------------------- /test/fixtures/v1/number/2047.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/number/2047.bin -------------------------------------------------------------------------------- /test/fixtures/v1/number/255.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/number/255.bin -------------------------------------------------------------------------------- /test/fixtures/v2/bytes/32767.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/bytes/32767.bin -------------------------------------------------------------------------------- /test/fixtures/v2/bytes/32768.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/bytes/32768.bin -------------------------------------------------------------------------------- /test/fixtures/v2/bytes/32769.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/bytes/32769.bin -------------------------------------------------------------------------------- /test/fixtures/v2/bytes/42769.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/bytes/42769.bin -------------------------------------------------------------------------------- /test/fixtures/v2/bytes/65535.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/bytes/65535.bin -------------------------------------------------------------------------------- /test/fixtures/v2/bytes/82769.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/bytes/82769.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/-128.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/-128.bin -------------------------------------------------------------------------------- /test/fixtures/v2/enum/blue.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/enum/blue.bin -------------------------------------------------------------------------------- /test/fixtures/v2/enum/green.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/enum/green.bin -------------------------------------------------------------------------------- /test/fixtures/v2/enum/lists.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/enum/lists.bin -------------------------------------------------------------------------------- /test/fixtures/v2/list/[int.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/list/[int.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/-2048.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/-2048.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/-2049.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/-2049.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/2047.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/2047.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/262143.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/262143.bin -------------------------------------------------------------------------------- /test/fixtures/v2/map/foo_bar.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/map/foo_bar.bin -------------------------------------------------------------------------------- /test/fixtures/v2/map/generic.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/map/generic.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/-16.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/-16.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/-256.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/-256.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/10.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/10.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/16.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/16.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/2047.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/2047.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/255.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/255.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/256.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/256.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/46.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/46.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/47.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/47.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/-32768.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/-32768.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/10.123.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/10.123.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/32767.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/32767.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/32768.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/32768.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/-262144.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/-262144.bin -------------------------------------------------------------------------------- /test/fixtures/v1/number/-2048.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/number/-2048.bin -------------------------------------------------------------------------------- /test/fixtures/v1/number/262143.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/number/262143.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/-32768.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/-32768.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/10.123.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/10.123.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/32767.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/32767.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/32768.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/32768.bin -------------------------------------------------------------------------------- /test/fixtures/v2/map/car_list.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/map/car_list.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/-2048.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/-2048.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/262143.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/262143.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/-127.9999.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/-127.9999.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/126.9989.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/126.9989.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/-2147483647.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/-2147483647.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/-2147483648.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/-2147483648.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/2147483646.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/2147483646.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/2147483647.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/2147483647.bin -------------------------------------------------------------------------------- /test/fixtures/v1/long/2147483648.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/long/2147483648.bin -------------------------------------------------------------------------------- /test/fixtures/v1/number/-262144.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/number/-262144.bin -------------------------------------------------------------------------------- /test/fixtures/v1/number/-262145.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/number/-262145.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/-0x800000.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/-0x800000.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/-127.9999.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/-127.9999.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/126.9989.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/126.9989.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/-2147483647.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/-2147483647.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/-2147483648.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/-2147483648.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/2147483646.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/2147483646.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/2147483647.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/2147483647.bin -------------------------------------------------------------------------------- /test/fixtures/v2/long/2147483648.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/long/2147483648.bin -------------------------------------------------------------------------------- /test/fixtures/v2/map/one_car_list.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/map/one_car_list.bin -------------------------------------------------------------------------------- /test/fixtures/v2/map/two_car_list.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/map/two_car_list.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/-262144.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/-262144.bin -------------------------------------------------------------------------------- /test/fixtures/v2/number/-262145.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/number/-262145.bin -------------------------------------------------------------------------------- /test/fixtures/v1/date/894621060000.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/date/894621060000.bin -------------------------------------------------------------------------------- /test/fixtures/v1/date/894621091000.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/date/894621091000.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/-2147483647.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/-2147483647.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/-2147483648.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/-2147483648.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/-2147483649.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/-2147483649.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/-32767.999.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/-32767.999.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/2147483646.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/2147483646.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/2147483647.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/2147483647.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/2147483648.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/2147483648.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/32766.99999.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/32766.99999.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/32767.99999.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/32767.99999.bin -------------------------------------------------------------------------------- /test/fixtures/v1/map/car.bin: -------------------------------------------------------------------------------- 1 | Mthessian.demo.CarSaSaScScSbSbSmodelSBeetleScolorS 2 | aquamarineSmileageIz -------------------------------------------------------------------------------- /test/fixtures/v1/map/car1.bin: -------------------------------------------------------------------------------- 1 | Mthessian.demo.CarSelfScolorS 2 | aquamarineSmodelSBeetleSmileageISselfRSprevNz -------------------------------------------------------------------------------- /test/fixtures/v1/string/utf8_32767.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/utf8_32767.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/utf8_32768.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/utf8_32768.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/utf8_32769.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/utf8_32769.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/utf8_65534.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/utf8_65534.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/utf8_65535.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/utf8_65535.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/utf8_65536.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/utf8_65536.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/utf8_65537.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/utf8_65537.bin -------------------------------------------------------------------------------- /test/fixtures/v2/date/894621091000.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/date/894621091000.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/-0x80000000.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/-0x80000000.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/-2147483647.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/-2147483647.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/-2147483648.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/-2147483648.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/-2147483649.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/-2147483649.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/-32767.999.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/-32767.999.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/2147483646.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/2147483646.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/2147483647.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/2147483647.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/2147483648.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/2147483648.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/32766.99999.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/32766.99999.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/32767.99999.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/32767.99999.bin -------------------------------------------------------------------------------- /test/fixtures/v2/list/typed_list_8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/list/typed_list_8.bin -------------------------------------------------------------------------------- /test/fixtures/v2/list/untyped_list.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/list/untyped_list.bin -------------------------------------------------------------------------------- /test/fixtures/v2/object/AtomicLong0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/object/AtomicLong0.bin -------------------------------------------------------------------------------- /test/fixtures/v2/object/AtomicLong1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/object/AtomicLong1.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/utf8_32767.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/utf8_32767.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/utf8_32768.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/utf8_32768.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/utf8_32769.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/utf8_32769.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/utf8_65534.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/utf8_65534.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/utf8_65535.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/utf8_65535.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/utf8_65536.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/utf8_65536.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/utf8_65537.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/utf8_65537.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/-2147483647.0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/-2147483647.0.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/2147483646.456.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/2147483646.456.bin -------------------------------------------------------------------------------- /test/fixtures/v2/date/-128849018940000.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/date/-128849018940000.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/-2147483647.0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/-2147483647.0.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/2147483646.456.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/2147483646.456.bin -------------------------------------------------------------------------------- /test/fixtures/v2/exception/IOException.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/exception/IOException.bin -------------------------------------------------------------------------------- /test/fixtures/v2/list/untyped_list_8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/list/untyped_list_8.bin -------------------------------------------------------------------------------- /test/fixtures/v1/double/-2147483610.123.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/double/-2147483610.123.bin -------------------------------------------------------------------------------- /test/fixtures/v2/double/-2147483610.123.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/double/-2147483610.123.bin -------------------------------------------------------------------------------- /test/fixtures/v1/map/one_car_list.bin: -------------------------------------------------------------------------------- 1 | VlMthessian.demo.CarSaSaScScSbSbSmodelSmodel 1ScolorS 2 | aquamarineSmileageIzz -------------------------------------------------------------------------------- /test/fixtures/v1/string/large_string_32767.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/large_string_32767.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/large_string_32768.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/large_string_32768.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/large_string_32769.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/large_string_32769.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/large_string_65534.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/large_string_65534.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/large_string_65535.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/large_string_65535.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/large_string_65536.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/large_string_65536.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/large_string_65537.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/large_string_65537.bin -------------------------------------------------------------------------------- /test/fixtures/v1/string/large_string_chars.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v1/string/large_string_chars.bin -------------------------------------------------------------------------------- /test/fixtures/v2/object/ConnectionRequest.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/object/ConnectionRequest.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/large_string_32767.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/large_string_32767.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/large_string_32768.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/large_string_32768.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/large_string_32769.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/large_string_32769.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/large_string_65534.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/large_string_65534.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/large_string_65535.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/large_string_65535.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/large_string_65536.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/large_string_65536.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/large_string_65537.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/large_string_65537.bin -------------------------------------------------------------------------------- /test/fixtures/v2/string/large_string_chars.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/large_string_chars.bin -------------------------------------------------------------------------------- /test/fixtures/v1/enum/lists.bin: -------------------------------------------------------------------------------- 1 | VlMthessian.Main$ColorSnameSBLUEzMthessian.Main$ColorSnameSREDzMthessian.Main$ColorSnameSGREENzz -------------------------------------------------------------------------------- /test/fixtures/v1/object/ConnectionRequest.bin: -------------------------------------------------------------------------------- 1 | Mthessian.ConnectionRequestSctxMt(hessian.ConnectionRequest$RequestContextSidIeSthis$0Rzz -------------------------------------------------------------------------------- /test/fixtures/v2/string/large_string_chars_65536.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/string/large_string_chars_65536.bin -------------------------------------------------------------------------------- /test/fixtures/v2/exception/UndeclaredThrowableException.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/exception/UndeclaredThrowableException.bin -------------------------------------------------------------------------------- /test/fixtures/v2/exception/UndeclaredThrowableException2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/exception/UndeclaredThrowableException2.bin -------------------------------------------------------------------------------- /test/fixtures/v2/exception/UndeclaredThrowableException3.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmq20/fast-hessian/HEAD/test/fixtures/v2/exception/UndeclaredThrowableException3.bin -------------------------------------------------------------------------------- /test/fixtures/v1/map/car2.bin: -------------------------------------------------------------------------------- 1 | Mthessian.demo.CarSelfScolorS 2 | aquamarineSmodelSBeetleSmileageISselfRSprevMthessian.demo.CarSelfScolorS 3 | aquamarineSmodelSBeetleSmileageISselfRSprevNzz -------------------------------------------------------------------------------- /test/fixtures/v1/map/two_car_list.bin: -------------------------------------------------------------------------------- 1 | VlMthessian.demo.CarSaSaScScSbSbSmodelSmodel 1ScolorS 2 | aquamarineSmileageIzMthessian.demo.CarSaSaScScSbSbSmodelSmodel 2ScolorS 3 | aquamarineSmileageIzz -------------------------------------------------------------------------------- /test/fixtures/v1/exception/IOException.bin: -------------------------------------------------------------------------------- 1 | Mtjava.io.IOExceptionS detailMessageS#this is a java IOException instanceScauseRS 2 | stackTraceVt[java.lang.StackTraceElementlMtjava.lang.StackTraceElementSdeclaringClassS hessian.MainS 3 | methodNameSmainSfileNameS Main.javaS 4 | lineNumberIzzz -------------------------------------------------------------------------------- /test/fixtures/v1/map/car_list.bin: -------------------------------------------------------------------------------- 1 | VlMthessian.demo.CarSaSaScScSbSbSmodelSmodel 1ScolorS 2 | aquamarineSmileageIzMthessian.demo.CarSaSaScScSbSbSmodelSmodel 2ScolorS 3 | aquamarineSmileageIzMthessian.demo.CarSaSaScScSbSbSmodelSmodel 3ScolorS 4 | aquamarineSmileageIzz -------------------------------------------------------------------------------- /src/hessian_array.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | short hessian_decode_array(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/hessian_bool.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | short hessian_decode_bool(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/hessian_bytes.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | short hessian_decode_bytes(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/hessian_double.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | short hessian_decode_double(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 11 | { 12 | return 0; 13 | } -------------------------------------------------------------------------------- /src/hessian_map.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | short hessian_decode_map(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/hessian_ref.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | short hessian_decode_ref(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/hessian_object.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | short hessian_decode_object(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/hessian_hash_map.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | short hessian_decode_hash_map(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 11 | { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/v1/exception/UndeclaredThrowableException.bin: -------------------------------------------------------------------------------- 1 | Mt.java.lang.reflect.UndeclaredThrowableExceptionSundeclaredThrowableMtjava.io.IOExceptionS detailMessageS#this is a java IOException instanceScauseRS 2 | stackTraceVt[java.lang.StackTraceElementlMtjava.lang.StackTraceElementSdeclaringClassS hessian.MainS 3 | methodNameSmainSfileNameS Main.javaS 4 | lineNumberIzzzS detailMessageNScauseNS 5 | stackTraceVt[java.lang.StackTraceElementlMtjava.lang.StackTraceElementSdeclaringClassS hessian.MainS 6 | methodNameSmainSfileNameS Main.javaS 7 | lineNumberI zzz -------------------------------------------------------------------------------- /test/fixtures/v1/exception/UndeclaredThrowableException2.bin: -------------------------------------------------------------------------------- 1 | Mt.java.lang.reflect.UndeclaredThrowableExceptionSundeclaredThrowableMtjava.io.IOExceptionS detailMessageS#this is a java IOException instanceScauseRS 2 | stackTraceVt[java.lang.StackTraceElementlMtjava.lang.StackTraceElementSdeclaringClassS hessian.MainS 3 | methodNameSmainSfileNameS Main.javaS 4 | lineNumberIzzzS detailMessageS模拟测试异常ScauseNS 5 | stackTraceVt[java.lang.StackTraceElementlMtjava.lang.StackTraceElementSdeclaringClassS hessian.MainS 6 | methodNameSmainSfileNameS Main.javaS 7 | lineNumberIzzz -------------------------------------------------------------------------------- /test/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hessian.js - test/utils.js 3 | * 4 | * Copyright(c) fengmk2 and other contributors. 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | 'use strict'; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var fs = require('fs'); 18 | var path = require('path'); 19 | var fixtures = path.join(__dirname, 'fixtures'); 20 | 21 | exports.bytes = function (name) { 22 | return fs.readFileSync(path.join(fixtures, name + '.bin')); 23 | }; 24 | 25 | exports.string = function (name) { 26 | return fs.readFileSync(path.join(fixtures, name + '.txt'), 'utf8'); 27 | }; 28 | -------------------------------------------------------------------------------- /test/utils.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hessian.js - test/utils.test.js 3 | * 4 | * Copyright(c) 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var should = require('should'); 18 | var utils = require('../lib/utils'); 19 | 20 | describe('utils.test.js', function () { 21 | describe('getSerializer()', function () { 22 | it('should [int get writeArray', function () { 23 | utils.getSerializer('[int').should.equal('writeArray'); 24 | }); 25 | 26 | it('should [string get writeArray', function () { 27 | utils.getSerializer('[string').should.equal('writeArray'); 28 | }); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /src/hessian_null.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | short hessian_decode_null(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 11 | { 12 | if (1 == buf_length && 'N' == buf[0]) { 13 | return 1; 14 | } else { 15 | return 0; 16 | } 17 | } 18 | 19 | v8::Local hessian_encode_null(v8::Isolate *isolate) 20 | { 21 | v8::EscapableHandleScope handle_scope(isolate); 22 | v8::Local ret = HessianPool::Get(isolate, 1); 23 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 24 | out[0] = 'N'; 25 | return handle_scope.Escape(ret); 26 | } 27 | -------------------------------------------------------------------------------- /include/hessian/encode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #ifndef HESSIAN_ENCODE_H_6392FA14 9 | #define HESSIAN_ENCODE_H_6392FA14 10 | 11 | #include "node.h" 12 | 13 | v8::Local hessian_encode_null(v8::Isolate *isolate); 14 | v8::Local hessian_encode_int(const int32_t val, v8::Isolate *isolate); 15 | v8::Local hessian_encode_date(const uint64_t milliEpoch, v8::Isolate *isolate); 16 | v8::Local hessian_encode_long(const int64_t val, v8::Isolate *isolate); 17 | v8::Local hessian_encode_string(const v8::Local &str, v8::Isolate *isolate); 18 | 19 | #endif /* end of include guard: HESSIAN_ENCODE_H_6392FA14 */ 20 | -------------------------------------------------------------------------------- /test/null.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hessian.js - test/null.test.js 3 | * 4 | * Copyright(c) 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var should = require('should'); 18 | var hessian = require('../'); 19 | 20 | describe('null.test.js', function () { 21 | it('should read null', function () { 22 | var a = hessian.decode(new Buffer('N')); 23 | should.ok(a === null); 24 | }); 25 | 26 | it('should write null', function () { 27 | hessian.encode(null).should.eql(new Buffer('N')); 28 | }); 29 | 30 | describe('v2.0', function () { 31 | it('should read write as 1.0', function () { 32 | hessian.encode(null, '2.0').should.eql(new Buffer('N')); 33 | should.ok(hessian.decode(new Buffer('N'), '2.0') === null); 34 | }); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /include/hessian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #ifndef HESSIAN_H_B37B4F17 9 | #define HESSIAN_H_B37B4F17 10 | 11 | #ifdef _WIN32 12 | #include 13 | #else 14 | #include 15 | #endif 16 | 17 | #ifdef __linux__ 18 | #include 19 | #define htonll __bswap_64 20 | #define ntohll __bswap_64 21 | #endif 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include "hessian/pool.h" 31 | #include "hessian/encode.h" 32 | #include "hessian/decode.h" 33 | 34 | #include "node.h" 35 | #include "env.h" 36 | #include "env-inl.h" 37 | 38 | void hessian_encode(const v8::FunctionCallbackInfo& args); 39 | void hessian_decode(const v8::FunctionCallbackInfo& args); 40 | 41 | #endif /* end of include guard: HESSIAN_H_B37B4F17 */ 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Minqi Pan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/boolean.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hessian.js - test/boolean.test.js 3 | * 4 | * Copyright(c) 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var should = require('should'); 18 | var hessian = require('../'); 19 | 20 | describe('boolean.test.js', function () { 21 | it('should read true and false', function () { 22 | hessian.decode(new Buffer('T')).should.equal(true); 23 | hessian.decode(new Buffer('F')).should.equal(false); 24 | }); 25 | 26 | it('should write true and false', function () { 27 | hessian.encode(true).should.eql(new Buffer('T')); 28 | hessian.encode(false).should.eql(new Buffer('F')); 29 | }); 30 | 31 | describe('v2.0', function () { 32 | it('should read write as 1.0', function () { 33 | hessian.encode(true, '2.0').should.eql(new Buffer('T')); 34 | hessian.encode(false, '2.0').should.eql(new Buffer('F')); 35 | hessian.decode(new Buffer('T'), '2.0').should.equal(true); 36 | hessian.decode(new Buffer('F'), '2.0').should.equal(false); 37 | }); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /include/hessian/pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #ifndef HESSIAN_POOL_H_cQkdBmMC 9 | #define HESSIAN_POOL_H_cQkdBmMC 10 | 11 | #include "node.h" 12 | 13 | class HessianPool { 14 | public: 15 | static v8::Local Get(v8::Isolate *isolate, size_t size); 16 | inline explicit HessianPool(v8::Isolate *isolate, v8::Local ab) : 17 | isolate_(isolate), offset_(0), ab_(isolate, ab) { assert(!ab_.IsEmpty()); } 18 | inline ~HessianPool() { assert(ab_.IsEmpty()); } 19 | inline bool canAccomodate(size_t size) { return (size <= pool_size - offset_); } 20 | void MakeWeak(); 21 | 22 | private: 23 | static const size_t pool_size = 128 * 1024; 24 | static const size_t in_pool_threshold = pool_size / 2; 25 | static_assert(in_pool_threshold <= pool_size, "in-pool threshold should be bound by pool size"); 26 | static HessianPool *pool; 27 | static void WeakCallback(const v8::WeakCallbackInfo& data); 28 | v8::Local Allocate(size_t size); 29 | v8::Isolate *isolate_; 30 | size_t offset_; 31 | v8::Persistent ab_; 32 | }; 33 | 34 | #endif /* end of include guard: HESSIAN_POOL_H_cQkdBmMC */ 35 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright(c) node-modules and other contributors. 3 | * MIT Licensed 4 | * 5 | * Authors: 6 | * dead_horse (http://deadhorse.me) 7 | * fengmk2 (http://fengmk2.com) 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var EncoderV1 = exports.EncoderV1 = exports.Encoder = require('./lib/v1/encoder'); 13 | var DecoderV1 = exports.DecoderV1 = exports.Decoder = require('./lib/v1/decoder'); 14 | 15 | var EncoderV2 = exports.EncoderV2 = require('./lib/v2/encoder'); 16 | var DecoderV2 = exports.DecoderV2 = require('./lib/v2/decoder'); 17 | 18 | exports.encoderV1 = new EncoderV1({size: 1024 * 1024}); 19 | exports.encoderV2 = new EncoderV2({size: 1024 * 1024}); 20 | 21 | exports.decode = function decode(buf, version, withType) { 22 | if (typeof version === 'boolean') { 23 | // buf, withType, version 24 | var t = version; 25 | version = withType; 26 | withType = t; 27 | } 28 | 29 | withType = !!withType; 30 | 31 | if (version === '2.0') { 32 | return process.hessian_decode(buf, withType); 33 | } 34 | return new DecoderV1(buf).read(withType); 35 | }; 36 | 37 | exports.encode = function encode(obj, version) { 38 | if (version === '2.0') { 39 | return process.hessian_encode(obj); 40 | } else { 41 | var encoder; 42 | encoder = exports.encoderV1; 43 | encoder.reset(); 44 | return encoder.write(obj).get(); 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /src/hessian_pool.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | HessianPool *HessianPool::pool = nullptr; 11 | 12 | v8::Local HessianPool::Get(v8::Isolate *isolate, size_t size) 13 | { 14 | // TODO mutex 15 | v8::EscapableHandleScope handle_scope(isolate); 16 | if (size < in_pool_threshold) { 17 | if (nullptr == pool) { 18 | pool = new HessianPool(isolate, v8::ArrayBuffer::New(isolate, pool_size)); 19 | } else if (!pool->canAccomodate(size)) { 20 | pool->MakeWeak(); 21 | pool = new HessianPool(isolate, v8::ArrayBuffer::New(isolate, pool_size)); 22 | } 23 | return handle_scope.Escape(pool->Allocate(size)); 24 | } else { 25 | return handle_scope.Escape(v8::Uint8Array::New(v8::ArrayBuffer::New(isolate, size), 0, size)); 26 | } 27 | } 28 | 29 | v8::Local HessianPool::Allocate(size_t size) 30 | { 31 | v8::EscapableHandleScope handle_scope(isolate_); 32 | assert(offset_ + size <= pool_size); 33 | v8::Local ret = v8::Uint8Array::New(ab_.Get(isolate_), offset_, size); 34 | offset_ += size; 35 | return handle_scope.Escape(ret); 36 | } 37 | 38 | void HessianPool::MakeWeak() 39 | { 40 | ab_.MarkIndependent(); 41 | ab_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter); 42 | } 43 | 44 | void HessianPool::WeakCallback(const v8::WeakCallbackInfo& data) 45 | { 46 | HessianPool *self = data.GetParameter(); 47 | self->ab_.Reset(); 48 | delete self; 49 | } 50 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fast-hessian", 3 | "version": "0.1.0", 4 | "description": "High-performance C++ implementation of Hessian 2.0 Serialization Protocol for Node.js.", 5 | "main": "index.js", 6 | "files": [ 7 | "index.js", 8 | "lib/", 9 | "src/", 10 | "include/" 11 | ], 12 | "scripts": { 13 | "test": "mocha -R spec -t 15000 -r should test/*.test.js", 14 | "test-cov": "istanbul cover _mocha -- -t 15000 -r should test/*.test.js", 15 | "lint": "jshint .", 16 | "ci": "npm run lint && npm run test-cov", 17 | "autod": "autod -w --prefix '~' -e benchmark", 18 | "benchmark": "node benchmark/encode.js && node benchmark/decode.js" 19 | }, 20 | "repository": { 21 | "type": "git", 22 | "url": "git://github.com/pmq20/fast-hessian.git" 23 | }, 24 | "keywords": [ 25 | "hessian", 26 | "protocol", 27 | "java", 28 | "rpc", 29 | "serialization" 30 | ], 31 | "author": "Minqi Pan ", 32 | "license": "MIT", 33 | "bugs": { 34 | "url": "https://github.com/pmq20/fast-hessian/issues", 35 | "email": "pmq2001@gmail.com" 36 | }, 37 | "homepage": "https://github.com/pmq20/fast-hessian", 38 | "dependencies": { 39 | "byte": "~1.1.5", 40 | "debug": "~2.2.0", 41 | "is-type-of": "~1.0.0", 42 | "utility": "~1.6.0", 43 | "long": "~3.1.0" 44 | }, 45 | "devDependencies": { 46 | "autod": "*", 47 | "beautify-benchmark": "*", 48 | "benchmark": "*", 49 | "istanbul": "*", 50 | "js-to-java": "2", 51 | "jshint": "*", 52 | "mocha": "*", 53 | "should": "10" 54 | }, 55 | "engines": { 56 | "node": ">= 0.12.0" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/array.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright(c) node-modules and other contributors. 3 | * MIT Licensed 4 | * 5 | * Authors: 6 | * 汤尧 (http://tangyao.me) 7 | */ 8 | 9 | "use strict"; 10 | 11 | /** 12 | * Module dependencies. 13 | */ 14 | 15 | var should = require('should'); 16 | var hessian = require('../'); 17 | 18 | describe('array.test.js', function () { 19 | it('should write null v1', function () { 20 | var b = hessian.encode([ 21 | { 22 | $class: '[java.lang.Integer', 23 | $: null 24 | }, 25 | { 26 | $class: '[java.lang.Integer', 27 | $: [1] 28 | } 29 | ]); 30 | var a = hessian.decode(b); 31 | a.should.eql([null, [1]]); 32 | }); 33 | 34 | it('should write undefined v1', function () { 35 | var b = hessian.encode([ 36 | { 37 | $class: '[java.lang.Integer', 38 | $: undefined 39 | }, 40 | { 41 | $class: '[java.lang.Integer', 42 | $: [1] 43 | } 44 | ]); 45 | var a = hessian.decode(b); 46 | a.should.eql([null, [1]]); 47 | }); 48 | 49 | it('should write null v2', function () { 50 | var b = hessian.encode([ 51 | { 52 | $class: '[java.lang.Integer', 53 | $: null 54 | }, 55 | { 56 | $class: '[java.lang.Integer', 57 | $: [1] 58 | } 59 | ], '2.0'); 60 | var a = hessian.decode(b, '2.0'); 61 | a.should.eql([null, [1]]); 62 | }); 63 | 64 | it('should write undefined v2', function () { 65 | var b = hessian.encode([ 66 | { 67 | $class: '[java.lang.Integer', 68 | $: undefined 69 | }, 70 | { 71 | $class: '[java.lang.Integer', 72 | $: [1] 73 | } 74 | ], '2.0'); 75 | var a = hessian.decode(b, '2.0'); 76 | a.should.eql([null, [1]]); 77 | }); 78 | }); 79 | -------------------------------------------------------------------------------- /src/hessian_date.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | short hessian_decode_date(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 11 | { 12 | node::Environment* env = node::Environment::GetCurrent(args); 13 | v8::EscapableHandleScope scope(env->isolate()); 14 | uint8_t code = buf[0]; 15 | if (buf_length >= 9 && code == 0x4a) { 16 | v8::Local date = v8::Date::New(env->context(), 17 | ntohll(*(uint64_t *)(buf + 1))).ToLocalChecked(); 18 | scope.Escape(date); 19 | args.GetReturnValue().Set(date); 20 | return 1; 21 | } 22 | if (buf_length >= 5 && code == 0x4b) { 23 | v8::Local date = v8::Date::New(env->context(), 24 | *(uint32_t *)(buf + 1) * 60000).ToLocalChecked(); 25 | scope.Escape(date); 26 | args.GetReturnValue().Set(date); 27 | return 1; 28 | } 29 | return 0; 30 | } 31 | 32 | v8::Local hessian_encode_date(const uint64_t milliEpoch, v8::Isolate *isolate) 33 | { 34 | v8::EscapableHandleScope handle_scope(isolate); 35 | if ((milliEpoch % 60000) == 0) { 36 | uint64_t minutes = milliEpoch / 60000; 37 | if (minutes <= 0x7fffffff) { 38 | v8::Local ret = HessianPool::Get(isolate, 5); 39 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 40 | out[0] = 0x4b; 41 | *(int32_t *)(out + 1) = htonl((uint32_t)minutes); 42 | return handle_scope.Escape(ret); 43 | } 44 | } 45 | v8::Local ret = HessianPool::Get(isolate, 9); 46 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 47 | out[0] = 0x4a; 48 | *(int64_t *)(out + 1) = htonll(milliEpoch); 49 | return handle_scope.Escape(ret); 50 | } 51 | -------------------------------------------------------------------------------- /test/decode.circular.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hessian.js - test/decode.circular.test.js 3 | * 4 | * Copyright(c) 5 | * 6 | * Authors: 7 | * tangyao (http://tangyao.me/) 8 | */ 9 | 10 | 'use strict'; 11 | 12 | /** 13 | * Module dependencies. 14 | */ 15 | 16 | var should = require('should'); 17 | var hessian = require('../'); 18 | var utils = require('./utils'); 19 | 20 | describe('test/decode.circular.test.js', function () { 21 | 22 | it('v1 decode()', function () { 23 | var data = new Buffer([77, 116, 0, 49, 99, 111, 109, 46, 97, 108, 105, 112, 97, 121, 46, 99, 111, 110, 102, 105, 103, 115, 101, 114, 118, 101, 114, 46, 99, 111, 110, 102, 114, 101, 103, 95, 116, 101, 115, 116, 46, 79, 110, 108, 105, 110, 101, 77, 111, 100, 117, 108, 101, 83, 0, 6, 109, 111, 100, 117, 108, 101, 83, 0, 1, 97, 83, 0, 4, 100, 101, 115, 99, 83, 0, 1, 98, 83, 0, 8, 118, 101, 114, 115, 105, 111, 110, 115, 86, 108, 0, 0, 0, 1, 77, 116, 0, 57, 99, 111, 109, 46, 97, 108, 105, 112, 97, 121, 46, 99, 111, 110, 102, 105, 103, 115, 101, 114, 118, 101, 114, 46, 99, 111, 110, 102, 114, 101, 103, 95, 116, 101, 115, 116, 46, 79, 110, 108, 105, 110, 101, 77, 111, 100, 117, 108, 101, 36, 86, 101, 114, 115, 105, 111, 110, 83, 0, 7, 118, 101, 114, 115, 105, 111, 110, 83, 0, 1, 99, 83, 0, 6, 97, 115, 115, 101, 116, 115, 86, 108, 0, 0, 0, 1, 83, 0, 1, 105, 122, 83, 0, 6, 116, 104, 105, 115, 36, 48, 82, 0, 0, 0, 0, 122, 122, 122]); 24 | var rs = hessian.decode(data); 25 | JSON.stringify(rs).should.eql('{"module":"a","desc":"b","versions":[{"version":"c","assets":["i"]}]}'); 26 | }); 27 | 28 | 29 | it('v2 decode()', function () { 30 | var javabuf = utils.bytes('v2/object/ConnectionRequest'); 31 | var connreq1 = hessian.decode(javabuf, '2.0'); 32 | connreq1.should.have.keys('ctx'); 33 | connreq1.ctx.should.have.keys('id'); 34 | JSON.stringify(connreq1).should.eql('{"ctx":{"id":101}}'); 35 | }); 36 | 37 | }); 38 | -------------------------------------------------------------------------------- /include/hessian/decode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #ifndef HESSIAN_DECODE_H_9A447E20 9 | #define HESSIAN_DECODE_H_9A447E20 10 | 11 | #include "node.h" 12 | 13 | short hessian_decode_string(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 14 | short hessian_decode_bytes(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 15 | short hessian_decode_long(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 16 | short hessian_decode_object(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 17 | short hessian_decode_double(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 18 | short hessian_decode_bool(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 19 | short hessian_decode_hash_map(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 20 | short hessian_decode_int(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 21 | short hessian_decode_date(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 22 | short hessian_decode_map(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 23 | short hessian_decode_null(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 24 | short hessian_decode_ref(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 25 | short hessian_decode_array(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args); 26 | 27 | #endif /* end of include guard: HESSIAN_DECODE_H_9A447E20 */ 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fast Hessian 2 | 3 | High-performance C++ implementation of Hessian 2.0 Serialization Protocol for Node.js. 4 | 5 | External Javascript API are 100% compatible with [Hessian.js](https://github.com/node-modules/hessian.js), serving as a drop-in replacement. Only the Hessian 2.0 part is re-implemented in C++; Hessian 1.0 is untouched with its original implementation. 6 | 7 | ## Why is it fast? 8 | 9 | - When encoding, Fast Hessian maintains a shared memory pool so that less memory allocations are invoked. 10 | - cf. [include/hessian/pool.h](https://github.com/pmq20/fast-hessian/blob/master/include/hessian/pool.h) and [src/hessian_pool.cc](https://github.com/pmq20/fast-hessian/blob/master/src/hessian_pool.cc) 11 | - When decoding, Fast Hessian produces no temporary buffers and outputs the result directly. 12 | 13 | ## Compete with Hessian.js 14 | 15 | **Environment: node 8.0.0-pre + v8 5.8.283.38** 16 | 17 | ### Encoding 18 | 19 | Hessian.js encode: number x 1,560,679 ops/sec ±0.73% (90 runs sampled) 20 | Fast Hessian encode: number x 3,032,388 ops/sec ±0.44% (90 runs sampled) 21 | 22 | Hessian.js encode: date x 906,503 ops/sec ±1.42% (87 runs sampled) 23 | Fast Hessian encode: date x 1,893,531 ops/sec ±0.51% (92 runs sampled) 24 | 25 | Hessian.js encode: string x 1,137,613 ops/sec ±1.30% (91 runs sampled) 26 | Fast Hessian encode: string x 1,877,451 ops/sec ±0.44% (95 runs sampled) 27 | 28 | ### Decoding 29 | 30 | Hessian.js decode: number x 4,479,530 ops/sec ±0.29% (96 runs sampled) 31 | Fast Hessian decode: number x 11,770,862 ops/sec ±0.42% (91 runs sampled) 32 | 33 | Hessian.js decode: date x 1,270,513 ops/sec ±0.91% (90 runs sampled) 34 | Fast Hessian decode: date x 4,697,034 ops/sec ±0.32% (93 runs sampled) 35 | 36 | Hessian.js decode: string x 652,283 ops/sec ±1.04% (93 runs sampled) 37 | Fast Hessian decode: string x 2,710,455 ops/sec ±1.58% (76 runs sampled) 38 | 39 | ## See Also 40 | 41 | * [Hessian 2.0 Serialization Protocol](http://hessian.caucho.com/doc/hessian-serialization.html): a dynamically-typed, binary serialization and Web Services protocol designed for object-oriented transmission. 42 | * [Hessian.js](https://github.com/node-modules/hessian.js): Hessian Serialization 1.0 and 2.0 written in pure JavaScript. 43 | -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hessian.js - lib/utils.js 3 | * Copyright(c) 4 | * MIT Licensed 5 | * 6 | * Authors: 7 | * dead_horse (http://deadhorse.me) 8 | */ 9 | 10 | 'use strict'; 11 | 12 | var debug = require('debug')('hessian.js:utils'); 13 | var Long = require('long'); 14 | var object = require('./object'); 15 | 16 | var MAX_SAFE_INT = Long.fromNumber(Math.pow(2, 53) - 1); 17 | var MIN_SAFE_INT = Long.fromNumber(1 - Math.pow(2, 53)); 18 | 19 | var MAX_BYTE_TRUNK_SIZE = exports.MAX_BYTE_TRUNK_SIZE = 0x8000; 20 | var MAX_CHAR_TRUNK_SIZE = exports.MAX_CHAR_TRUNK_SIZE = 0x8000; 21 | 22 | // Map feature detect 23 | exports.supportES6Map = typeof Map === 'function' && typeof Map.prototype.forEach === 'function'; 24 | 25 | exports.getSerializer = function (type) { 26 | // get from SERIALIZER_MAP 27 | if (object.SERIALIZER_MAP[type]) { 28 | return 'write' + object.SERIALIZER_MAP[type]; 29 | } 30 | // array: [int 31 | if (type[0] === '[') { 32 | return 'writeArray'; 33 | } 34 | // object 35 | return 'writeObject'; 36 | }; 37 | 38 | exports.isJavaObject = function (type) { 39 | return type === object.Object; 40 | }; 41 | 42 | exports.handleLong = function (val) { 43 | if (val.greaterThan(MAX_SAFE_INT) || val.lessThan(MIN_SAFE_INT)) { 44 | val = val.toString(); 45 | debug('[hessian.js Warning] Read a not safe long(%s), translate it to string', val); 46 | return val; 47 | } 48 | return val.toNumber(); 49 | }; 50 | 51 | exports.lengthOfUTF8 = function (head) { 52 | if (head < 0x80) { 53 | return 1; 54 | } 55 | if ((head & 0xe0) === 0xc0) { 56 | return 2; 57 | } 58 | 59 | if ((head & 0xf0) === 0xe0) { 60 | return 3; 61 | } 62 | throw new Error('string is not valid UTF-8 encode'); 63 | }; 64 | 65 | var _hasOwnProperty = Object.prototype.hasOwnProperty; 66 | /* jshint -W001 */ 67 | exports.hasOwnProperty = function hasOwnProperty(obj, property) { 68 | return _hasOwnProperty.call(obj, property); 69 | }; 70 | 71 | exports.addByteCodes = function addByteCodes(map, codes, method) { 72 | for (var i = 0; i < codes.length; i++) { 73 | var code = codes[i]; 74 | if (Array.isArray(code)) { 75 | var startCode = code[0]; 76 | var endCode = code[1]; 77 | for (var c = startCode; c <= endCode; c++) { 78 | map[c] = method; 79 | } 80 | } else { 81 | map[code] = method; 82 | } 83 | } 84 | }; 85 | -------------------------------------------------------------------------------- /src/hessian_int.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | #define INT_DIRECT_MIN -0x10 11 | #define INT_DIRECT_MAX 0x2f 12 | #define INT_ZERO 0x90 13 | 14 | #define INT_BYTE_MIN -0x800 15 | #define INT_BYTE_MAX 0x7ff 16 | #define INT_BYTE_ZERO 0xc8 17 | 18 | #define INT_SHORT_MIN -0x40000 19 | #define INT_SHORT_MAX 0x3ffff 20 | #define INT_SHORT_ZERO 0xd4 21 | 22 | short hessian_decode_int(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 23 | { 24 | uint8_t code = buf[0]; 25 | if (code >= 0x80 && code <= 0xbf) { 26 | args.GetReturnValue().Set(code - 0x90); 27 | return 1; 28 | } 29 | if (buf_length >= 2 && code >= 0xc0 && code <= 0xcf) { 30 | args.GetReturnValue().Set(((code - 0xc8) << 8) + buf[1]); 31 | return 1; 32 | } 33 | if (buf_length >= 3 && code >= 0xd0 && code <= 0xd7) { 34 | args.GetReturnValue().Set(((code - 0xd4) << 16) + (buf[1] << 8) + buf[2]); 35 | return 1; 36 | } 37 | if (buf_length >= 5 && code == 0x49) { 38 | args.GetReturnValue().Set(static_cast(ntohl(*(int32_t *)(buf + 1)))); 39 | return 1; 40 | } 41 | return 0; 42 | } 43 | 44 | v8::Local hessian_encode_int(const int32_t val, v8::Isolate *isolate) 45 | { 46 | v8::EscapableHandleScope handle_scope(isolate); 47 | if (INT_DIRECT_MIN <= val && val <= INT_DIRECT_MAX) { 48 | v8::Local ret = HessianPool::Get(isolate, 1); 49 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 50 | out[0] = val + INT_ZERO; 51 | return handle_scope.Escape(ret); 52 | } else if (INT_BYTE_MIN <= val && val <= INT_BYTE_MAX) { 53 | v8::Local ret = HessianPool::Get(isolate, 2); 54 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 55 | out[1] = val & 0xff; 56 | out[0] = (val >> 8) + INT_BYTE_ZERO; 57 | return handle_scope.Escape(ret); 58 | } else if (INT_SHORT_MIN <= val && val <= INT_SHORT_MAX) { 59 | v8::Local ret = HessianPool::Get(isolate, 3); 60 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 61 | out[0] = (val >> 16) + INT_SHORT_ZERO; 62 | *(uint16_t *)(out + 1) = htons(val & 0xffff); 63 | return handle_scope.Escape(ret); 64 | } else { 65 | v8::Local ret = HessianPool::Get(isolate, 5); 66 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 67 | out[0] = 0x49; 68 | *(int32_t *)(out+1) = htonl(val); 69 | return handle_scope.Escape(ret); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/hessian_long.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | short hessian_decode_long(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 11 | { 12 | uint8_t code = buf[0]; 13 | if (code >= 0xd8 && code <= 0xef) { 14 | args.GetReturnValue().Set(code - 0xe0); 15 | return 1; 16 | } 17 | if (buf_length >= 2 && code >= 0xf0 && code <= 0xff) { 18 | args.GetReturnValue().Set(((code - 0xf8) << 8) + buf[1]); 19 | return 1; 20 | } 21 | if (buf_length >= 3 && code >= 0x38 && code <= 0x3f) { 22 | args.GetReturnValue().Set(((code - 0x3c) << 16) + (buf[1] << 8) + buf[2]); 23 | return 1; 24 | } 25 | if (buf_length >= 4 && code == 0x59) { 26 | args.GetReturnValue().Set(static_cast(ntohl(*(int32_t *)(buf+1)))); 27 | return 1; 28 | } 29 | if (buf_length >= 5 && code == 0x4c) { 30 | args.GetReturnValue().Set((double)(ntohll(*(int64_t *)(buf + 1)))); 31 | return 1; 32 | } 33 | return 0; 34 | } 35 | 36 | v8::Local hessian_encode_long(const int64_t val, v8::Isolate *isolate) 37 | { 38 | v8::EscapableHandleScope handle_scope(isolate); 39 | if (val >= -8 && val <= 15) { 40 | v8::Local ret = HessianPool::Get(isolate, 1); 41 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 42 | out[0] = (uint8_t)(val + 0xe0); 43 | return handle_scope.Escape(ret); 44 | } else if (val >= -2048 && val <= 2047) { 45 | v8::Local ret = HessianPool::Get(isolate, 2); 46 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 47 | out[0] = (uint8_t)((val >> 8) + 0xf8); 48 | out[1] = (uint8_t)(val & 0xff); 49 | return handle_scope.Escape(ret); 50 | } else if (val >= -262144 && val <= 262143) { 51 | v8::Local ret = HessianPool::Get(isolate, 3); 52 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 53 | out[0] = (uint8_t)((val >> 16) + 0x3c); 54 | *(uint16_t *)(out + 1) = htons(val & 0xffff); 55 | return handle_scope.Escape(ret); 56 | } else if (val >= -0x80000000LL && val <= 0x7fffffffLL) { 57 | v8::Local ret = HessianPool::Get(isolate, 5); 58 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 59 | out[0] = 0x59; 60 | *(int32_t *)(out + 1) = htons((int32_t)val); 61 | return handle_scope.Escape(ret); 62 | } else { 63 | v8::Local ret = HessianPool::Get(isolate, 9); 64 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 65 | out[0] = 0x4c; 66 | *(int64_t *)(out + 1) = htonll(val); 67 | return handle_scope.Escape(ret); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /benchmark/README.md: -------------------------------------------------------------------------------- 1 | benchmark result 2 | ---------- 3 | 4 | ``` 5 | node benchmark/encode.js 6 | 7 | Hessian Encode Benchmark 8 | node version: v0.11.12, date: Tue May 27 2014 11:30:03 GMT+0800 (CST) 9 | Starting... 10 | 16 tests completed. 11 | 12 | hessian1 encode: number x 1,669,884 ops/sec ±1.38% (93 runs sampled) 13 | hessian2 encode: number x 1,893,674 ops/sec ±0.74% (96 runs sampled) 14 | hessian1 encode: date x 834,286 ops/sec ±1.40% (91 runs sampled) 15 | hessian2 encode: date x 789,740 ops/sec ±1.06% (95 runs sampled) 16 | hessian1 encode: long x 646,034 ops/sec ±0.89% (95 runs sampled) 17 | hessian2 encode: long x 643,354 ops/sec ±1.60% (88 runs sampled) 18 | hessian1 encode: string x 955,180 ops/sec ±1.19% (96 runs sampled) 19 | hessian2 encode: string x 1,006,919 ops/sec ±1.22% (93 runs sampled) 20 | hessian1 encode: [1, 2, 3] x 536,860 ops/sec ±0.85% (94 runs sampled) 21 | hessian2 encode: [1, 2, 3] x 615,294 ops/sec ±0.93% (95 runs sampled) 22 | hessian1 encode array x 377,167 ops/sec ±0.85% (95 runs sampled) 23 | hessian2 encode array x 403,383 ops/sec ±0.94% (91 runs sampled) 24 | hessian1 encode: simple object x 146,367 ops/sec ±1.67% (93 runs sampled) 25 | hessian2 encode: simple object x 147,188 ops/sec ±1.81% (94 runs sampled) 26 | hessian1 encode: complex object x 95,309 ops/sec ±1.40% (91 runs sampled) 27 | hessian2 encode: complex object x 95,851 ops/sec ±1.20% (96 runs sampled) 28 | 29 | 30 | Hessian Decode Benchmark 31 | node version: v0.11.12, date: Tue May 27 2014 11:31:30 GMT+0800 (CST) 32 | Starting... 33 | 16 tests completed. 34 | 35 | hessian1 decode: number x 5,915,496 ops/sec ±0.73% (98 runs sampled) 36 | hessian2 decode: number x 5,838,371 ops/sec ±2.66% (90 runs sampled) 37 | hessian1 decode: date x 2,958,136 ops/sec ±1.87% (91 runs sampled) 38 | hessian2 decode: date x 2,721,653 ops/sec ±0.81% (97 runs sampled) 39 | hessian1 decode: long x 4,076,127 ops/sec ±0.83% (93 runs sampled) 40 | hessian2 decode: long x 5,400,659 ops/sec ±1.26% (93 runs sampled) 41 | hessian1 decode: string x 1,067,996 ops/sec ±2.20% (91 runs sampled) 42 | hessian2 decode: string x 1,133,082 ops/sec ±1.04% (93 runs sampled) 43 | hessian1 decode: [1, 2, 3] x 1,201,908 ops/sec ±1.26% (91 runs sampled) 44 | hessian2 decode: [1, 2, 3] x 1,915,498 ops/sec ±1.66% (95 runs sampled) 45 | hessian1 decode array x 505,896 ops/sec ±1.13% (93 runs sampled) 46 | hessian2 decode array x 616,792 ops/sec ±0.79% (98 runs sampled) 47 | hessian1 decode: simple object x 194,474 ops/sec ±0.87% (97 runs sampled) 48 | hessian2 decode: simple object x 177,599 ops/sec ±0.97% (96 runs sampled) 49 | hessian1 decode: complex object x 139,387 ops/sec ±0.83% (97 runs sampled) 50 | hessian2 decode: complex object x 139,213 ops/sec ±0.58% (99 runs sampled) 51 | ``` 52 | -------------------------------------------------------------------------------- /lib/object.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hessian.js - lib/object.js 3 | * Copyright(c) 4 | * MIT Licensed 5 | * 6 | * Authors: 7 | * dead_horse (http://deadhorse.me) 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | 'use strict'; 12 | 13 | var util = require('util'); 14 | 15 | exports.DEFAULT_CLASSNAME = { 16 | boolean: 'boolean', 17 | int: 'int', 18 | long: 'long', 19 | double: 'double', 20 | date: 'java.util.Date', 21 | string: 'java.lang.String', 22 | byteArray: '[B', 23 | list: 'java.util.ArrayList', 24 | // iList: 'java.util.List', 25 | map: 'java.util.HashMap', 26 | iMap: 'java.util.Map', 27 | exception: 'java.lang.RuntimeException' 28 | }; 29 | 30 | exports.Object = 'java.lang.Object'; 31 | 32 | var SERIALIZER_MAP = exports.SERIALIZER_MAP = {}; 33 | 34 | [ 35 | 'boolean', 36 | 'java.lang.Boolean', 37 | 'bool', 38 | ].forEach(function (t) { 39 | SERIALIZER_MAP[t] = 'Bool'; 40 | }); 41 | 42 | [ 43 | 'double', 44 | 'java.lang.Double', 45 | 'float', 46 | 'java.lang.Float', 47 | ].forEach(function (t) { 48 | SERIALIZER_MAP[t] = 'Double'; 49 | }); 50 | 51 | [ 52 | 'java.lang.Long', 53 | 'long', 54 | ].forEach(function (t) { 55 | SERIALIZER_MAP[t] = 'Long'; 56 | }); 57 | 58 | [ 59 | 'short', 60 | 'java.lang.Short', 61 | 'int', 62 | 'java.lang.Integer', 63 | 'byte', 64 | 'java.lang.Byte', 65 | ].forEach(function (t) { 66 | SERIALIZER_MAP[t] = 'Int'; 67 | }); 68 | 69 | [ 70 | 'java.lang.String', 71 | 'String', 72 | 'string', 73 | 'char', 74 | 'char[]', 75 | 'java.lang.Character', 76 | ].forEach(function (t) { 77 | SERIALIZER_MAP[t] = 'String'; 78 | }); 79 | 80 | [ 81 | 'java.util.Date' 82 | ].forEach(function (t) { 83 | SERIALIZER_MAP[t] = 'Date'; 84 | }); 85 | 86 | // http://www.devthought.com/2011/12/22/a-string-is-not-an-error/ 87 | function JavaExceptionError(obj, withType) { 88 | Error.call(this); 89 | Error.captureStackTrace(this, JavaExceptionError); 90 | 91 | // $: { detailMessage: 'this is a java IOException instance', 92 | // cause: [Circular], 93 | // stackTrace: 94 | // [ { declaringClass: 'hessian.Main', 95 | // methodName: 'main', 96 | // fileName: 'Main.java', 97 | // lineNumber: 1282 } ] } 98 | var undeclaredThrowable = obj.$.undeclaredThrowable; 99 | if (undeclaredThrowable && withType) { 100 | undeclaredThrowable = undeclaredThrowable.$; 101 | } 102 | var detailMessage = obj.$.detailMessage; 103 | if (detailMessage && withType) { 104 | detailMessage = detailMessage.$; 105 | } 106 | 107 | var cause = obj.$.cause; 108 | if (cause && cause.$ && withType) { 109 | cause = cause.$; 110 | } 111 | 112 | if (undeclaredThrowable && undeclaredThrowable instanceof Error) { 113 | if (!obj.$.detailMessage) { 114 | return undeclaredThrowable; 115 | } 116 | this.name = undeclaredThrowable.name; 117 | if (withType) { 118 | this.message = obj.$.detailMessage.$ + '; ' + undeclaredThrowable.message; 119 | } else { 120 | this.message = obj.$.detailMessage + '; ' + undeclaredThrowable.message; 121 | } 122 | } else if (!detailMessage && cause && cause !== obj.$) { 123 | return cause; 124 | } else { 125 | if (withType) { 126 | this.message = obj.$.detailMessage && obj.$.detailMessage.$ || obj.$class; 127 | if (obj.$.reasonAndSolution) { 128 | this.message += '; reasonAndSolution: ' + obj.$.reasonAndSolution.$; 129 | } 130 | } else { 131 | this.message = obj.$.detailMessage || obj.$class; 132 | if (obj.$.reasonAndSolution) { 133 | this.message += '; reasonAndSolution: ' + obj.$.reasonAndSolution; 134 | } 135 | } 136 | this.name = obj.$class; 137 | } 138 | 139 | this.cause = obj.$.cause; 140 | 141 | var stack = this.name + ': ' + this.message; 142 | if (withType) { 143 | var stackTraces = obj.$.stackTrace && obj.$.stackTrace.$ || []; 144 | for (var i = 0; i < stackTraces.length; i++) { 145 | var trace = stackTraces[i].$; 146 | stack += '\n at ' + (trace.declaringClass && trace.declaringClass.$) 147 | + '.' + (trace.methodName && trace.methodName.$) 148 | + ' (' + (trace.fileName && trace.fileName.$) 149 | + ':' + (trace.lineNumber && trace.lineNumber.$) + ')'; 150 | } 151 | } else { 152 | var stackTraces = obj.$.stackTrace || []; 153 | for (var i = 0; i < stackTraces.length; i++) { 154 | var trace = stackTraces[i]; 155 | stack += '\n at ' + trace.declaringClass + '.' + trace.methodName 156 | + ' (' + trace.fileName + ':' + trace.lineNumber + ')'; 157 | } 158 | } 159 | 160 | this.stack = stack; 161 | } 162 | 163 | util.inherits(JavaExceptionError, Error); 164 | 165 | exports.JavaExceptionError = JavaExceptionError; 166 | -------------------------------------------------------------------------------- /src/hessian_string.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | v8::Local hessian_encode_string(const v8::Local &str, v8::Isolate *isolate) 11 | { 12 | v8::EscapableHandleScope handle_scope(isolate); 13 | size_t index = 0; 14 | int length = str->Length(); 15 | int capacity = 3 * length + 10; // TODO 10? 16 | v8::Local ret = HessianPool::Get(isolate, capacity); 17 | uint8_t* out = static_cast(ret->Buffer()->GetContents().Data()) + ret->ByteOffset(); 18 | 19 | // TODO 20 | assert(length <= 0x8000); 21 | 22 | if (length <= 31) { 23 | out[index++] = (uint8_t)(length); 24 | } else if (length <= 1023) { 25 | out[index++] = (uint8_t)(48 + (length >> 8)); 26 | // Integer overflow and wrapping assumed 27 | out[index++] = (uint8_t)(length); 28 | } else { 29 | out[index++] = 'S'; 30 | out[index++] = (uint8_t)((length >> 8)); 31 | // Integer overflow and wrapping assumed 32 | out[index++] = (uint8_t)(length); 33 | } 34 | 35 | // TODO encoded as CESU-8 36 | int flags = v8::String::HINT_MANY_WRITES_EXPECTED | v8::String::NO_NULL_TERMINATION | v8::String::REPLACE_INVALID_UTF8; 37 | int nbytes = str->WriteUtf8(reinterpret_cast(out + index), capacity, NULL, flags); 38 | 39 | assert(index + nbytes <= capacity); 40 | return handle_scope.Escape(v8::Uint8Array::New(ret->Buffer(), ret->ByteOffset(), index + nbytes)); 41 | } 42 | 43 | static short internal_decode_string(uint8_t * const buf, const size_t buf_length, uint8_t *out_str, size_t *out_length, short *is_last_chunk) 44 | { 45 | uint8_t code = buf[0]; 46 | size_t delta_length; 47 | short result; 48 | 49 | switch (code) { 50 | case 0x00: case 0x01: case 0x02: case 0x03: 51 | case 0x04: case 0x05: case 0x06: case 0x07: 52 | case 0x08: case 0x09: case 0x0a: case 0x0b: 53 | case 0x0c: case 0x0d: case 0x0e: case 0x0f: 54 | 55 | case 0x10: case 0x11: case 0x12: case 0x13: 56 | case 0x14: case 0x15: case 0x16: case 0x17: 57 | case 0x18: case 0x19: case 0x1a: case 0x1b: 58 | case 0x1c: case 0x1d: case 0x1e: case 0x1f: 59 | *is_last_chunk = 1; 60 | delta_length = code - 0x00; 61 | if (buf_length < 1 + delta_length) { 62 | return 0; 63 | } 64 | memcpy(out_str + *out_length, buf + 1, delta_length); 65 | *out_length = *out_length + delta_length; 66 | return 1; 67 | 68 | case 0x30: case 0x31: case 0x32: case 0x33: 69 | *is_last_chunk = 1; 70 | if (buf_length < 2) { 71 | return 0; 72 | } 73 | delta_length = (code - 0x30) * 256 + buf[1]; 74 | if (buf_length < 2 + delta_length) { 75 | return 0; 76 | } 77 | memcpy(out_str + *out_length, buf + 2, delta_length); 78 | *out_length = *out_length + delta_length; 79 | return 1; 80 | 81 | case 0x53: 82 | *is_last_chunk = 1; 83 | if (buf_length < 3) { 84 | return 0; 85 | } 86 | delta_length = ntohs(*(uint16_t *)(buf + 1)); 87 | if (buf_length < 3 + delta_length) { 88 | return 0; 89 | } 90 | memcpy(out_str + *out_length, buf + 3, delta_length); 91 | *out_length = *out_length + delta_length; 92 | return 1; 93 | 94 | case 0x52: 95 | *is_last_chunk = 0; 96 | if (buf_length < 3) { 97 | return 0; 98 | } 99 | delta_length = ntohs(*(uint16_t *)(buf + 1)); 100 | if (buf_length < 3 + delta_length) { 101 | return 0; 102 | } 103 | memcpy(out_str + *out_length, buf + 3, delta_length); 104 | *out_length = *out_length + delta_length; 105 | while (!*is_last_chunk) { 106 | result = internal_decode_string(buf, buf_length, out_str, out_length, is_last_chunk); 107 | if (!result) { 108 | return 0; 109 | } 110 | } 111 | break; 112 | } 113 | return 0; 114 | } 115 | 116 | class HessianExternalOneByteStringResource : public v8::String::ExternalOneByteStringResource 117 | { 118 | public: 119 | HessianExternalOneByteStringResource(uint8_t *out_str, size_t out_length) 120 | : out_str_(out_str), out_length_(out_length) {} 121 | ~HessianExternalOneByteStringResource() { free(out_str_); } 122 | 123 | const char* data() const { return (const char*)out_str_; } 124 | size_t length() const { return out_length_; } 125 | private: 126 | uint8_t *out_str_; 127 | size_t out_length_; 128 | }; 129 | 130 | short hessian_decode_string(uint8_t * const buf, const size_t buf_length, const v8::FunctionCallbackInfo& args) 131 | { 132 | node::Environment* env = node::Environment::GetCurrent(args); 133 | v8::EscapableHandleScope scope(env->isolate()); 134 | v8::Local string; 135 | short is_last_chunk = 0; 136 | size_t out_length = 0; 137 | uint8_t *out_str = (uint8_t *)malloc(buf_length); 138 | if (NULL == out_str) { 139 | return 0; 140 | } 141 | if (internal_decode_string(buf, buf_length, out_str, &out_length, &is_last_chunk)) { 142 | uint8_t *new_out = (uint8_t*)realloc(out_str, out_length); 143 | if (NULL != new_out) { 144 | out_str = new_out; 145 | } 146 | string = v8::String::NewExternalOneByte(env->isolate(), 147 | new HessianExternalOneByteStringResource(out_str, out_length)).ToLocalChecked(); 148 | scope.Escape(string); 149 | args.GetReturnValue().Set(string); 150 | return 1; 151 | } else { 152 | free(out_str); 153 | return 0; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /test/date.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hessian.js - test/date.test.js 3 | * 4 | * Copyright(c) 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | /* global describe, it */ 12 | 13 | 'use strict'; 14 | 15 | /** 16 | * Module dependencies. 17 | */ 18 | 19 | var should = require('should'); 20 | var hessian = require('../'); 21 | var utils = require('./utils'); 22 | 23 | describe('date.test.js', function () { 24 | var dateBuffer = new Buffer(['d'.charCodeAt(0), 0x00, 0x00, 0x00, 0xd0, 0x4b, 0x92, 0x84, 0xb8]); 25 | 26 | it('should read date 2:51:31 May 8, 1998', function () { 27 | var d = hessian.decode(dateBuffer); 28 | d.should.be.a.Date; 29 | d.getFullYear().should.equal(1998); 30 | d.getTime().should.equal(894621091000); 31 | d.toUTCString().should.equal('Fri, 08 May 1998 09:51:31 GMT'); 32 | d.toISOString().should.equal('1998-05-08T09:51:31.000Z'); 33 | }); 34 | 35 | it('should write date 2:51:31 May 8, 1998', function () { 36 | hessian.encode(new Date(894621091000)).should.eql(dateBuffer); 37 | }); 38 | 39 | it('should write date 0 and read', function () { 40 | hessian.encode(new Date(0)).should.eql(new Buffer(['d'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0])); 41 | }); 42 | 43 | it('should read date 09:51:31 May 8, 1998 UTC', function () { 44 | var d = hessian.decode(utils.bytes('v1/date/894621091000'), '1.0'); 45 | d.should.be.a.Date; 46 | d.getFullYear().should.equal(1998); 47 | d.getTime().should.equal(894621091000); 48 | d.toUTCString().should.equal('Fri, 08 May 1998 09:51:31 GMT'); 49 | d.toISOString().should.equal('1998-05-08T09:51:31.000Z'); 50 | }); 51 | 52 | it('should read date 09:51:00 May 8, 1998 UTC', function () { 53 | var d = hessian.decode(utils.bytes('v1/date/894621060000'), '1.0'); 54 | d.should.be.a.Date; 55 | d.getFullYear().should.equal(1998); 56 | d.getTime().should.equal(894621060000); 57 | d.toUTCString().should.equal('Fri, 08 May 1998 09:51:00 GMT'); 58 | d.toISOString().should.equal('1998-05-08T09:51:00.000Z'); 59 | }); 60 | 61 | it('should write date', function () { 62 | var now = new Date(1398280514000); 63 | hessian.encode(now, '1.0').should.eql(utils.bytes('v1/date/now')); 64 | // read it 65 | hessian.decode(utils.bytes('v1/date/now'), '1.0').should.eql(now); 66 | }); 67 | 68 | describe('hessian 2.0', function () { 69 | it('should read date 09:51:31 May 8, 1998 UTC', function () { 70 | var d = hessian.decode(utils.bytes('v2/date/894621091000'), '2.0'); 71 | d.should.be.a.Date; 72 | d.getFullYear().should.equal(1998); 73 | d.getTime().should.equal(894621091000); 74 | d.toUTCString().should.equal('Fri, 08 May 1998 09:51:31 GMT'); 75 | d.toISOString().should.equal('1998-05-08T09:51:31.000Z'); 76 | }); 77 | 78 | it('should read Compact: date in minutes, 09:51:00 May 8, 1998 UTC', function () { 79 | var d = hessian.decode(utils.bytes('v2/date/894621060000'), '2.0'); 80 | d.should.be.a.Date; 81 | d.getFullYear().should.equal(1998); 82 | d.getTime().should.equal(894621060000); 83 | d.toUTCString().should.equal('Fri, 08 May 1998 09:51:00 GMT'); 84 | d.toISOString().should.equal('1998-05-08T09:51:00.000Z'); 85 | }); 86 | 87 | it('should write and read date, Thu, 23 Jan 6053 02:08:00 GMT', function () { 88 | // Maximum of 32-bit integer 89 | var overflow32BitInt = Math.pow(2, 31); 90 | var milliseconds = overflow32BitInt * 60000; 91 | var date = new Date(); 92 | date.setTime(milliseconds); 93 | 94 | var bytes = utils.bytes('v2/date/' + milliseconds.toString()); 95 | 96 | hessian.encode(date, '2.0').should.eql(bytes); 97 | hessian.decode(bytes, '2.0').should.eql(date); 98 | }); 99 | 100 | it('should write and read date, Wed, 08 Dec -2114 21:53:00 GMT (2115 B.C.)', function () { 101 | // Minimum of 32-bit integer 102 | var overflow32BitInt = -1 * (Math.pow(2, 31) + 1); 103 | var milliseconds = overflow32BitInt * 60000; 104 | var date = new Date(); 105 | date.setTime(milliseconds); 106 | 107 | var bytes = utils.bytes('v2/date/' + milliseconds.toString()); 108 | 109 | hessian.encode(date, '2.0').should.eql(bytes); 110 | hessian.decode(bytes, '2.0').should.eql(date); 111 | }); 112 | 113 | 114 | it('should write and read date', function () { 115 | var now = new Date(1398280514000); 116 | hessian.encode(now, '2.0').should.eql(utils.bytes('v2/date/now')); 117 | // read it 118 | hessian.decode(utils.bytes('v2/date/now'), '2.0').should.eql(now); 119 | }); 120 | 121 | it('should write and read Wed Jan 04 1950 00:00:00 GMT+0800 (CST)', function () { 122 | var date = new Date('Wed Jan 04 1950 00:00:00 GMT+0800 (CST)'); 123 | var bin = new Buffer('4bff5f8c60', 'hex'); 124 | hessian.encode(date, '2.0').should.eql(bin); 125 | hessian.decode(bin, '2.0').should.eql(date); 126 | }); 127 | 128 | // it('should read 1.0 format', function () { 129 | // hessian.decode(utils.bytes('v1/date/894621091000'), '2.0').getTime() 130 | // .should.equal(894621091000); 131 | // hessian.decode(utils.bytes('v1/date/894621060000'), '2.0').getTime() 132 | // .should.equal(894621060000); 133 | // hessian.decode(utils.bytes('v1/date/now'), '2.0').getTime() 134 | // .should.equal(1398280514000); 135 | // }); 136 | }); 137 | }); 138 | -------------------------------------------------------------------------------- /test/v2.list.encode.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'); 4 | var path = require('path'); 5 | var should = require('should'); 6 | var hessian = require('../'); 7 | var utils = require('../lib/utils'); 8 | var java = require('js-to-java'); 9 | 10 | describe('hessian v2', function () { 11 | 12 | it('v2 list encode should ok', function() { 13 | 14 | var arg = { 15 | "$class": "com.x.Site", 16 | "$": { 17 | "id": { 18 | "$class": "long", 19 | "$": 1637 20 | }, 21 | "groupId": { 22 | "$class": "long", 23 | "$": 2 24 | }, 25 | "description": { 26 | "$class": "java.lang.String", 27 | "$": "" 28 | }, 29 | "name": { 30 | "$class": "java.lang.String", 31 | "$": "acltimeout1" 32 | }, 33 | "url": { 34 | "$class": "java.lang.String", 35 | "$": "https://pages.x.com" 36 | }, 37 | "spma": { 38 | "$class": "java.lang.String", 39 | "$": "a2279" 40 | }, 41 | "extendFields": { 42 | "$class": "java.util.List", 43 | "$": [ 44 | { 45 | "$class": "com.x.ExtendField", 46 | "$": { 47 | "fieldKey": { 48 | "$class": "java.lang.String", 49 | "$": "site-tmc" 50 | }, 51 | "bizId": { 52 | "$class": "long", 53 | "$": 1637 54 | }, 55 | "fieldValue": { 56 | "$class": "java.lang.String", 57 | "$": "1" 58 | }, 59 | "id": { 60 | "$class": "long", 61 | "$": 0 62 | }, 63 | "type": { 64 | "$class": "int", 65 | "$": 0 66 | }, 67 | "status": { 68 | "$class": "int", 69 | "$": 0 70 | }, 71 | "metaId": { 72 | "$class": "long", 73 | "$": 0 74 | }, 75 | "valueType": null, 76 | "gmtCreate": null, 77 | "gmtModified": null 78 | } 79 | }, 80 | { 81 | "$class": "com.x.ExtendField", 82 | "$": { 83 | "fieldKey": { 84 | "$class": "java.lang.String", 85 | "$": "site-solution" 86 | }, 87 | "bizId": { 88 | "$class": "long", 89 | "$": 1637 90 | }, 91 | "fieldValue": { 92 | "$class": "java.lang.String", 93 | "$": "base" 94 | }, 95 | "id": { 96 | "$class": "long", 97 | "$": 0 98 | }, 99 | "type": { 100 | "$class": "int", 101 | "$": 0 102 | }, 103 | "status": { 104 | "$class": "int", 105 | "$": 0 106 | }, 107 | "metaId": { 108 | "$class": "long", 109 | "$": 0 110 | }, 111 | "valueType": null, 112 | "gmtCreate": null, 113 | "gmtModified": null 114 | } 115 | }, 116 | { 117 | "$class": "com.x.ExtendField", 118 | "$": { 119 | "bizId": { 120 | "$class": "long", 121 | "$": 1637 122 | }, 123 | "fieldKey": { 124 | "$class": "java.lang.String", 125 | "$": "site-template-whitelist" 126 | }, 127 | "fieldValue": { 128 | "$class": "java.lang.String", 129 | "$": "julu" 130 | }, 131 | "id": { 132 | "$class": "long", 133 | "$": 0 134 | }, 135 | "type": { 136 | "$class": "int", 137 | "$": 0 138 | }, 139 | "status": { 140 | "$class": "int", 141 | "$": 0 142 | }, 143 | "metaId": { 144 | "$class": "long", 145 | "$": 0 146 | }, 147 | "valueType": null, 148 | "gmtCreate": null, 149 | "gmtModified": null 150 | } 151 | }, 152 | { 153 | "$class": "com.x.ExtendField", 154 | "$": { 155 | "bizId": { 156 | "$class": "long", 157 | "$": 1637 158 | }, 159 | "fieldKey": { 160 | "$class": "java.lang.String", 161 | "$": "site-owner" 162 | }, 163 | "fieldValue": { 164 | "$class": "java.lang.String", 165 | "$": "julu" 166 | }, 167 | "id": { 168 | "$class": "long", 169 | "$": 0 170 | }, 171 | "type": { 172 | "$class": "int", 173 | "$": 0 174 | }, 175 | "status": { 176 | "$class": "int", 177 | "$": 0 178 | }, 179 | "metaId": { 180 | "$class": "long", 181 | "$": 0 182 | }, 183 | "valueType": null, 184 | "gmtCreate": null, 185 | "gmtModified": null 186 | } 187 | } 188 | ] 189 | }, 190 | "engName": null, 191 | "ownerWorkIds": null, 192 | "status": { 193 | "$class": "int", 194 | "$": 0 195 | }, 196 | "creator": null, 197 | "mobileUrl": null, 198 | "groupName": null, 199 | "gmtCreate": null, 200 | "gmtModified": null 201 | } 202 | }; 203 | 204 | var bytes = hessian.encode(arg, '2.0'); 205 | var rs = hessian.decode(bytes, '2.0'); 206 | java.revert(arg).should.eql(rs); 207 | 208 | }); 209 | 210 | }); 211 | -------------------------------------------------------------------------------- /test/exception.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hessian.js - test/exception.test.js 3 | * 4 | * Copyright(c) 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var should = require('should'); 18 | var hessian = require('../'); 19 | var utils = require('./utils'); 20 | 21 | describe('exception.test.js', function () { 22 | describe('v1.0', function () { 23 | it('should read java exception as js error', function () { 24 | var ioe = hessian.decode(utils.bytes('v1/exception/IOException')); 25 | ioe.should.be.an.Error; 26 | ioe.name.should.equal('java.io.IOException'); 27 | ioe.message.should.equal('this is a java IOException instance'); 28 | ioe.stack.should.equal('java.io.IOException: this is a java IOException instance\n at hessian.Main.main (Main.java:1283)'); 29 | 30 | var ioe = hessian.decode(utils.bytes('v1/exception/IOException'), true); 31 | ioe.$.should.be.an.Error; 32 | ioe.$.name.should.equal('java.io.IOException'); 33 | ioe.$.message.should.equal('this is a java IOException instance'); 34 | ioe.$.stack.should.equal('java.io.IOException: this is a java IOException instance\n at hessian.Main.main (Main.java:1283)'); 35 | 36 | var e = hessian.decode(utils.bytes('v1/exception/UndeclaredThrowableException')); 37 | e.should.be.an.Error; 38 | should.ok((e instanceof Error) === true); 39 | e.name.should.equal('java.io.IOException'); 40 | e.message.should.equal('this is a java IOException instance'); 41 | e.stack.should.equal('java.io.IOException: this is a java IOException instance\n at hessian.Main.main (Main.java:1283)'); 42 | should.exist(e.cause); 43 | e.cause.detailMessage.should.equal('this is a java IOException instance'); 44 | 45 | var e = hessian.decode(utils.bytes('v1/exception/UndeclaredThrowableException'), true); 46 | e.$.should.be.an.Error; 47 | e.$.name.should.equal('java.io.IOException'); 48 | e.$.message.should.equal('this is a java IOException instance'); 49 | e.$.stack.should.equal('java.io.IOException: this is a java IOException instance\n at hessian.Main.main (Main.java:1283)'); 50 | should.exist(e.$.cause); 51 | e.$.cause.$class.should.equal('java.io.IOException'); 52 | e.$.cause.$.should.be.an.Error; 53 | e.$.cause.$.name.should.equal('java.io.IOException'); 54 | 55 | var e = hessian.decode(utils.bytes('v1/exception/UndeclaredThrowableException2')); 56 | e.should.be.an.Error; 57 | should.ok((e instanceof Error) === true); 58 | e.name.should.equal('java.io.IOException'); 59 | e.message.should.equal('模拟测试异常; this is a java IOException instance'); 60 | e.stack.should.equal('java.io.IOException: 模拟测试异常; this is a java IOException instance\n at hessian.Main.main (Main.java:1303)'); 61 | 62 | var e = hessian.decode(utils.bytes('v1/exception/UndeclaredThrowableException2'), true); 63 | e.$.should.be.an.Error; 64 | e.$.name.should.equal('java.io.IOException'); 65 | e.$.message.should.equal('模拟测试异常; this is a java IOException instance'); 66 | e.$.stack.should.equal('java.io.IOException: 模拟测试异常; this is a java IOException instance\n at hessian.Main.main (Main.java:1303)'); 67 | }); 68 | }); 69 | 70 | describe('v2.0', function () { 71 | it('should read java exception as js error', function () { 72 | var ioe = hessian.decode(utils.bytes('v2/exception/IOException'), '2.0'); 73 | ioe.should.be.an.Error; 74 | should.ok((ioe instanceof Error) === true); 75 | ioe.name.should.equal('java.io.IOException'); 76 | ioe.message.should.equal('this is a java IOException instance'); 77 | ioe.stack.should.equal('java.io.IOException: this is a java IOException instance\n at hessian.Main.main (Main.java:1283)'); 78 | 79 | var e = hessian.decode(utils.bytes('v2/exception/UndeclaredThrowableException'), '2.0'); 80 | e.should.be.an.Error; 81 | should.ok((e instanceof Error) === true); 82 | e.name.should.equal('java.io.IOException'); 83 | e.message.should.equal('this is a java IOException instance'); 84 | e.stack.should.equal('java.io.IOException: this is a java IOException instance\n at hessian.Main.main (Main.java:1283)'); 85 | 86 | var e = hessian.decode(utils.bytes('v2/exception/UndeclaredThrowableException2'), '2.0'); 87 | e.should.be.an.Error; 88 | should.ok((e instanceof Error) === true); 89 | e.name.should.equal('java.io.IOException'); 90 | e.message.should.equal('模拟测试异常; this is a java IOException instance'); 91 | e.stack.should.equal('java.io.IOException: 模拟测试异常; this is a java IOException instance\n at hessian.Main.main (Main.java:1303)'); 92 | 93 | var e = hessian.decode(utils.bytes('v2/exception/UndeclaredThrowableException3'), '2.0'); 94 | e.should.be.an.Error; 95 | should.ok((e instanceof Error) === true); 96 | e.name.should.equal('com.taobao.hsf.exception.HSFServiceAddressNotFoundException'); 97 | e.message.should.equal('HSFServiceAddressNotFoundException-'); 98 | e.cause.stackTrace.length.should.equal(56); 99 | }); 100 | 101 | // it('should read hessian 1.0 exception', function () { 102 | // var ioe = hessian.decode(utils.bytes('v1/exception/IOException'), '2.0'); 103 | // ioe.should.be.an.Error; 104 | // should.ok((ioe instanceof Error) === true); 105 | // ioe.name.should.equal('java.io.IOException'); 106 | // ioe.message.should.equal('this is a java IOException instance'); 107 | // ioe.stack.should.equal('java.io.IOException: this is a java IOException instance\n at hessian.Main.main (Main.java:1283)'); 108 | 109 | // var e = hessian.decode(utils.bytes('v1/exception/UndeclaredThrowableException'), '2.0'); 110 | // e.should.be.an.Error; 111 | // should.ok((e instanceof Error) === true); 112 | // e.name.should.equal('java.io.IOException'); 113 | // e.message.should.equal('this is a java IOException instance'); 114 | // e.stack.should.equal('java.io.IOException: this is a java IOException instance\n at hessian.Main.main (Main.java:1283)'); 115 | 116 | // var e = hessian.decode(utils.bytes('v1/exception/UndeclaredThrowableException2'), '2.0'); 117 | // e.should.be.an.Error; 118 | // should.ok((e instanceof Error) === true); 119 | // e.name.should.equal('java.io.IOException'); 120 | // e.message.should.equal('模拟测试异常; this is a java IOException instance'); 121 | // e.stack.should.equal('java.io.IOException: 模拟测试异常; this is a java IOException instance\n at hessian.Main.main (Main.java:1303)'); 122 | // }); 123 | }); 124 | }); 125 | -------------------------------------------------------------------------------- /src/hessian.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Minqi Pan 3 | * 4 | * This file is part of fast-hessian, distributed under the MIT License 5 | * For full terms see the included LICENSE file 6 | */ 7 | 8 | #include "hessian.h" 9 | 10 | void hessian_encode(const v8::FunctionCallbackInfo& args) 11 | { 12 | node::Environment* env = node::Environment::GetCurrent(args); 13 | v8::Local ret; 14 | 15 | if (args[0]->IsNullOrUndefined()) { 16 | ret = hessian_encode_null(env->isolate()); 17 | } else if (args[0]->IsNumber()) { 18 | int64_t x = args[0]->IntegerValue(); 19 | if (x >= LONG_MAX || x < LONG_MIN) { 20 | ret = hessian_encode_long(x, env->isolate()); 21 | } else { 22 | ret = hessian_encode_int((int32_t)x, env->isolate()); 23 | } 24 | } else if (args[0]->IsDate()) { 25 | double x = args[0].As()->ValueOf(); 26 | ret = hessian_encode_date((uint64_t)x, env->isolate()); 27 | } else if (args[0]->IsString()) { 28 | v8::Local string = args[0].As(); 29 | ret = hessian_encode_string(string, env->isolate()); 30 | } else { 31 | // TODO throw unsupported type to encode 32 | return; 33 | } 34 | if (ret.IsEmpty()) { 35 | // TODO throw encoding failed somehow 36 | return; 37 | } 38 | v8::Maybe mb = ret->SetPrototype(env->context(), env->buffer_prototype_object()); 39 | if (mb.FromMaybe(false)) { 40 | args.GetReturnValue().Set(ret); 41 | return; 42 | } else { 43 | // TODO throw Object failed to be created 44 | return; 45 | } 46 | } 47 | 48 | void hessian_decode(const v8::FunctionCallbackInfo& args) 49 | { 50 | SPREAD_BUFFER_ARG(args[0], buf); 51 | short success; 52 | switch (*((uint8_t*)buf_data)) { 53 | case 0: 54 | case 1: 55 | case 2: 56 | case 3: 57 | case 4: 58 | case 5: 59 | case 6: 60 | case 7: 61 | case 8: 62 | case 9: 63 | case 10: 64 | case 11: 65 | case 12: 66 | case 13: 67 | case 14: 68 | case 15: 69 | case 16: 70 | case 17: 71 | case 18: 72 | case 19: 73 | case 20: 74 | case 21: 75 | case 22: 76 | case 23: 77 | case 24: 78 | case 25: 79 | case 26: 80 | case 27: 81 | case 28: 82 | case 29: 83 | case 30: 84 | case 31: 85 | case 48: 86 | case 49: 87 | case 50: 88 | case 51: 89 | case 82: 90 | case 83: 91 | success = hessian_decode_string((uint8_t *)buf_data, buf_length, args); 92 | break; 93 | case 32: 94 | case 33: 95 | case 34: 96 | case 35: 97 | case 36: 98 | case 37: 99 | case 38: 100 | case 39: 101 | case 40: 102 | case 41: 103 | case 42: 104 | case 43: 105 | case 44: 106 | case 45: 107 | case 46: 108 | case 47: 109 | case 52: 110 | case 53: 111 | case 54: 112 | case 55: 113 | case 65: 114 | case 66: 115 | success = hessian_decode_bytes((uint8_t *)buf_data, buf_length, args); 116 | break; 117 | case 56: 118 | case 57: 119 | case 58: 120 | case 59: 121 | case 60: 122 | case 61: 123 | case 62: 124 | case 63: 125 | case 76: 126 | case 89: 127 | case 216: 128 | case 217: 129 | case 218: 130 | case 219: 131 | case 220: 132 | case 221: 133 | case 222: 134 | case 223: 135 | case 224: 136 | case 225: 137 | case 226: 138 | case 227: 139 | case 228: 140 | case 229: 141 | case 230: 142 | case 231: 143 | case 232: 144 | case 233: 145 | case 234: 146 | case 235: 147 | case 236: 148 | case 237: 149 | case 238: 150 | case 239: 151 | case 240: 152 | case 241: 153 | case 242: 154 | case 243: 155 | case 244: 156 | case 245: 157 | case 246: 158 | case 247: 159 | case 248: 160 | case 249: 161 | case 250: 162 | case 251: 163 | case 252: 164 | case 253: 165 | case 254: 166 | case 255: 167 | success = hessian_decode_long((uint8_t *)buf_data, buf_length, args); 168 | break; 169 | case 67: 170 | case 79: 171 | case 91: 172 | case 92: 173 | case 93: 174 | case 94: 175 | case 95: 176 | case 96: 177 | case 97: 178 | case 98: 179 | case 99: 180 | case 100: 181 | case 101: 182 | case 102: 183 | case 103: 184 | case 104: 185 | case 105: 186 | case 106: 187 | case 107: 188 | case 108: 189 | case 109: 190 | case 110: 191 | case 111: 192 | success = hessian_decode_object((uint8_t *)buf_data, buf_length, args); 193 | break; 194 | case 68: 195 | success = hessian_decode_double((uint8_t *)buf_data, buf_length, args); 196 | break; 197 | case 70: 198 | case 84: 199 | success = hessian_decode_bool((uint8_t *)buf_data, buf_length, args); 200 | break; 201 | case 72: 202 | success = hessian_decode_hash_map((uint8_t *)buf_data, buf_length, args); 203 | break; 204 | case 73: 205 | case 128: 206 | case 129: 207 | case 130: 208 | case 131: 209 | case 132: 210 | case 133: 211 | case 134: 212 | case 135: 213 | case 136: 214 | case 137: 215 | case 138: 216 | case 139: 217 | case 140: 218 | case 141: 219 | case 142: 220 | case 143: 221 | case 144: 222 | case 145: 223 | case 146: 224 | case 147: 225 | case 148: 226 | case 149: 227 | case 150: 228 | case 151: 229 | case 152: 230 | case 153: 231 | case 154: 232 | case 155: 233 | case 156: 234 | case 157: 235 | case 158: 236 | case 159: 237 | case 160: 238 | case 161: 239 | case 162: 240 | case 163: 241 | case 164: 242 | case 165: 243 | case 166: 244 | case 167: 245 | case 168: 246 | case 169: 247 | case 170: 248 | case 171: 249 | case 172: 250 | case 173: 251 | case 174: 252 | case 175: 253 | case 176: 254 | case 177: 255 | case 178: 256 | case 179: 257 | case 180: 258 | case 181: 259 | case 182: 260 | case 183: 261 | case 184: 262 | case 185: 263 | case 186: 264 | case 187: 265 | case 188: 266 | case 189: 267 | case 190: 268 | case 191: 269 | case 192: 270 | case 193: 271 | case 194: 272 | case 195: 273 | case 196: 274 | case 197: 275 | case 198: 276 | case 199: 277 | case 200: 278 | case 201: 279 | case 202: 280 | case 203: 281 | case 204: 282 | case 205: 283 | case 206: 284 | case 207: 285 | case 208: 286 | case 209: 287 | case 210: 288 | case 211: 289 | case 212: 290 | case 213: 291 | case 214: 292 | case 215: 293 | success = hessian_decode_int((uint8_t *)buf_data, buf_length, args); 294 | break; 295 | case 74: 296 | case 75: 297 | success = hessian_decode_date((uint8_t *)buf_data, buf_length, args); 298 | break; 299 | case 77: 300 | success = hessian_decode_map((uint8_t *)buf_data, buf_length, args); 301 | break; 302 | case 78: 303 | success = hessian_decode_null((uint8_t *)buf_data, buf_length, args); 304 | break; 305 | case 81: 306 | success = hessian_decode_ref((uint8_t *)buf_data, buf_length, args); 307 | break; 308 | case 86: 309 | case 88: 310 | case 112: 311 | case 113: 312 | case 114: 313 | case 115: 314 | case 116: 315 | case 117: 316 | case 118: 317 | case 119: 318 | case 120: 319 | case 121: 320 | case 122: 321 | case 123: 322 | case 124: 323 | case 125: 324 | case 126: 325 | case 127: 326 | success = hessian_decode_array((uint8_t *)buf_data, buf_length, args); 327 | break; 328 | default: 329 | // TODO raise error 330 | success = 0; 331 | } 332 | if (!success) { 333 | // TODO throw error 334 | } 335 | } 336 | -------------------------------------------------------------------------------- /benchmark/encode.js: -------------------------------------------------------------------------------- 1 | /**! 2 | * hessian.js - benchmark/encode.js 3 | * 4 | * Copyright(c) fengmk2 and other contributors. 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | 'use strict'; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var ByteBuffer = require('byte'); 18 | var Benchmark = require('benchmark'); 19 | var benchmarks = require('beautify-benchmark'); 20 | var java = require('js-to-java'); 21 | var hessian = require('../'); 22 | 23 | var suite = new Benchmark.Suite(); 24 | 25 | var simpleObject = { 26 | $class: 'com.hessiantest.org.MockRequest', 27 | $: { 28 | id: 123, 29 | name: 'getData', 30 | args: [1, "name", "xxx1231231231231xxx123"] 31 | } 32 | }; 33 | 34 | var complexObject = { 35 | $class: 'com.hessiantest.org.MockRequest', 36 | $: { 37 | id: 123, 38 | name: 'getData', 39 | args: [1, "name", "xxx1231231231231xxx123"], 40 | conn: { 41 | $class: 'com.hessiantest.org.MockRequestConnection', 42 | $: { 43 | ctx: java.long(1024) 44 | } 45 | } 46 | } 47 | }; 48 | 49 | suite 50 | 51 | .add('Fast hessian2 encode: number', function() { 52 | hessian.encode(1, '2.0'); 53 | }) 54 | 55 | .add('Fast hessian2 encode: date', function() { 56 | hessian.encode(new Date(), '2.0'); 57 | }) 58 | 59 | // .add('Fast hessian2 encode: long', function() { 60 | // hessian.encode(java.long(300), '2.0'); 61 | // }) 62 | 63 | .add('Fast hessian2 encode: string', function() { 64 | hessian.encode('xxx1231231231231xxx123', '2.0'); 65 | }) 66 | 67 | // // .add('hessian1 encode: [1, 2, 3]', function() { 68 | // // hessian.encode([1, 2, 3], '1.0'); 69 | // // }) 70 | // .add('Fast hessian2 encode: [1, 2, 3]', function() { 71 | // hessian.encode([1, 2, 3], '2.0'); 72 | // }) 73 | // // .add('hessian1 encode array', function() { 74 | // // hessian.encode([1, "name", "xxx1231231231231xxx123"], '1.0'); 75 | // // }) 76 | // .add('Fast hessian2 encode array', function() { 77 | // hessian.encode([1, "name", "xxx1231231231231xxx123"], '2.0'); 78 | // }) 79 | // 80 | // // .add('hessian1 encode: simple object', function() { 81 | // // hessian.encode(simpleObject, '1.0'); 82 | // // }) 83 | // .add('Fast hessian2 encode: simple object', function() { 84 | // hessian.encode(simpleObject, '2.0'); 85 | // }) 86 | // 87 | // // .add('hessian1 encode: complex object', function() { 88 | // // hessian.encode(complexObject, '1.0'); 89 | // // }) 90 | // .add('Fast hessian2 encode: complex object', function() { 91 | // hessian.encode(complexObject, '2.0'); 92 | // }) 93 | 94 | .on('cycle', function(event) { 95 | benchmarks.add(event.target); 96 | }) 97 | .on('start', function(event) { 98 | console.log('\n Hessian Encode Benchmark\n node version: %s, date: %s\n Starting...', 99 | process.version, Date()); 100 | }) 101 | .on('complete', function done() { 102 | benchmarks.log(); 103 | }) 104 | .run({ 'async': false }); 105 | 106 | // node version: v0.11.12, date: Tue May 13 2014 10:30:18 GMT+0800 (CST) 107 | // Starting... 108 | // 16 tests completed. 109 | // 110 | // hessian1 encode: number x 1,262,878 ops/sec ±10.80% (74 runs sampled) 111 | // Fast hessian2 encode: number x 1,816,722 ops/sec ±2.34% (92 runs sampled) 112 | // hessian1 encode: date x 766,202 ops/sec ±3.90% (90 runs sampled) 113 | // Fast hessian2 encode: date x 673,284 ops/sec ±4.78% (83 runs sampled) 114 | // hessian1 encode: long x 650,132 ops/sec ±1.48% (96 runs sampled) 115 | // Fast hessian2 encode: long x 636,692 ops/sec ±3.49% (88 runs sampled) 116 | // hessian1 encode: string x 804,401 ops/sec ±6.48% (79 runs sampled) 117 | // Fast hessian2 encode: string x 967,111 ops/sec ±3.15% (88 runs sampled) 118 | // hessian1 encode: [1, 2, 3] x 525,540 ops/sec ±2.36% (92 runs sampled) 119 | // Fast hessian2 encode: [1, 2, 3] x 623,072 ops/sec ±2.27% (97 runs sampled) 120 | // hessian1 encode array x 318,811 ops/sec ±8.70% (82 runs sampled) 121 | // Fast hessian2 encode array x 396,659 ops/sec ±3.12% (92 runs sampled) 122 | // hessian1 encode: simple object x 101,458 ops/sec ±9.30% (67 runs sampled) 123 | // Fast hessian2 encode: simple object x 132,938 ops/sec ±3.23% (89 runs sampled) 124 | // hessian1 encode: complex object x 90,243 ops/sec ±2.08% (93 runs sampled) 125 | // Fast hessian2 encode: complex object x 80,702 ops/sec ±5.94% (86 runs sampled) 126 | 127 | // node version: v0.11.12, date: Wed May 14 2014 18:47:59 GMT+0800 (CST) 128 | // Starting... 129 | // 16 tests completed. 130 | // 131 | // hessian1 encode: number x 1,601,925 ops/sec ±2.57% (89 runs sampled) 132 | // Fast hessian2 encode: number x 1,800,237 ops/sec ±1.90% (93 runs sampled) 133 | // hessian1 encode: date x 773,461 ops/sec ±2.22% (88 runs sampled) 134 | // Fast hessian2 encode: date x 703,063 ops/sec ±4.90% (86 runs sampled) 135 | // hessian1 encode: long x 555,507 ops/sec ±4.36% (87 runs sampled) 136 | // Fast hessian2 encode: long x 598,983 ops/sec ±3.26% (86 runs sampled) 137 | // hessian1 encode: string x 911,037 ops/sec ±2.50% (95 runs sampled) 138 | // Fast hessian2 encode: string x 1,013,393 ops/sec ±1.75% (92 runs sampled) 139 | // hessian1 encode: [1, 2, 3] x 520,715 ops/sec ±1.55% (91 runs sampled) 140 | // Fast hessian2 encode: [1, 2, 3] x 552,279 ops/sec ±3.97% (86 runs sampled) 141 | // hessian1 encode array x 377,503 ops/sec ±1.40% (94 runs sampled) 142 | // Fast hessian2 encode array x 403,264 ops/sec ±3.10% (93 runs sampled) 143 | // hessian1 encode: simple object x 132,363 ops/sec ±5.80% (83 runs sampled) 144 | // Fast hessian2 encode: simple object x 138,711 ops/sec ±3.52% (89 runs sampled) 145 | // hessian1 encode: complex object x 94,401 ops/sec ±1.15% (90 runs sampled) 146 | // Fast hessian2 encode: complex object x 90,484 ops/sec ±1.33% (97 runs sampled) 147 | 148 | // node version: v0.11.12, date: Thu May 15 2014 18:13:05 GMT+0800 (CST) 149 | // Starting... 150 | // 16 tests completed. 151 | // 152 | // hessian1 encode: number x 1,553,553 ops/sec ±3.58% (92 runs sampled) 153 | // Fast hessian2 encode: number x 1,895,587 ops/sec ±0.63% (97 runs sampled) 154 | // hessian1 encode: date x 599,048 ops/sec ±0.58% (98 runs sampled) 155 | // Fast hessian2 encode: date x 562,479 ops/sec ±1.76% (93 runs sampled) 156 | // hessian1 encode: long x 498,383 ops/sec ±0.69% (98 runs sampled) 157 | // Fast hessian2 encode: long x 672,058 ops/sec ±1.20% (96 runs sampled) 158 | // hessian1 encode: string x 980,671 ops/sec ±2.19% (97 runs sampled) 159 | // Fast hessian2 encode: string x 1,041,627 ops/sec ±0.70% (93 runs sampled) 160 | // hessian1 encode: [1, 2, 3] x 538,953 ops/sec ±2.54% (92 runs sampled) 161 | // Fast hessian2 encode: [1, 2, 3] x 631,285 ops/sec ±0.36% (99 runs sampled) 162 | // hessian1 encode array x 389,785 ops/sec ±0.51% (98 runs sampled) 163 | // Fast hessian2 encode array x 408,655 ops/sec ±2.37% (97 runs sampled) 164 | // hessian1 encode: simple object x 161,088 ops/sec ±0.84% (97 runs sampled) 165 | // Fast hessian2 encode: simple object x 155,580 ops/sec ±0.82% (98 runs sampled) 166 | // hessian1 encode: complex object x 103,974 ops/sec ±1.34% (96 runs sampled) 167 | // Fast hessian2 encode: complex object x 100,160 ops/sec ±1.18% (101 runs sampled) 168 | -------------------------------------------------------------------------------- /test/binary.test.js: -------------------------------------------------------------------------------- 1 | /* 2 | * hessian.js - test/binary.test.js 3 | * 4 | * Copyright(c) 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var should = require('should'); 18 | var hessian = require('../'); 19 | var utils = require('./utils'); 20 | 21 | describe('binary.test.js', function () { 22 | it('should read "foo" binary', function () { 23 | hessian.decode(Buffer.concat([new Buffer(['B'.charCodeAt(0), 0x00, 0x03]), new Buffer('foo')])); 24 | }); 25 | 26 | it('should write "foo"', function () { 27 | hessian.encode(new Buffer('foo')).should.eql( 28 | Buffer.concat([new Buffer(['B'.charCodeAt(0), 0x00, 0x03]), new Buffer('foo')])); 29 | }); 30 | 31 | it('should read and write empty binary', function () { 32 | var empty = hessian.decode(new Buffer(['B'.charCodeAt(0), 0x00, 0x00])); 33 | empty.should.be.a.Buffer; 34 | empty.should.length(0); 35 | 36 | hessian.encode(new Buffer('')).should.eql(new Buffer(['B'.charCodeAt(0), 0x00, 0x00])); 37 | }); 38 | 39 | it('should write and read as java impl', function () { 40 | var bytes = new Buffer(65535); 41 | bytes.fill(0x41); 42 | var buf = hessian.encode(bytes, '1.0'); 43 | buf.should.length(utils.bytes('v1/bytes/65535').length); 44 | buf.should.eql(utils.bytes('v1/bytes/65535')); 45 | hessian.decode(utils.bytes('v1/bytes/65535'), '1.0').should.eql(bytes); 46 | 47 | var bytes = new Buffer(32768); 48 | bytes.fill(0x41); 49 | var buf = hessian.encode(bytes, '1.0'); 50 | buf.should.length(utils.bytes('v1/bytes/32768').length); 51 | buf.should.eql(utils.bytes('v1/bytes/32768')); 52 | hessian.decode(utils.bytes('v1/bytes/32768'), '1.0').should.eql(bytes); 53 | 54 | var bytes = new Buffer(32769); 55 | bytes.fill(0x41); 56 | var buf = hessian.encode(bytes, '1.0'); 57 | buf.should.length(utils.bytes('v1/bytes/32769').length); 58 | buf.should.eql(utils.bytes('v1/bytes/32769')); 59 | hessian.decode(utils.bytes('v1/bytes/32769'), '1.0').should.eql(bytes); 60 | 61 | var bytes = new Buffer(32767); 62 | bytes.fill(0x41); 63 | var buf = hessian.encode(bytes, '1.0'); 64 | buf.should.length(utils.bytes('v1/bytes/32767').length); 65 | buf.should.eql(utils.bytes('v1/bytes/32767')); 66 | hessian.decode(utils.bytes('v1/bytes/32767'), '1.0').should.eql(bytes); 67 | 68 | var bytes = new Buffer(32769); 69 | bytes.fill(0x41); 70 | var buf = hessian.encode(bytes, '1.0'); 71 | buf.should.length(utils.bytes('v1/bytes/32769').length); 72 | buf.should.eql(utils.bytes('v1/bytes/32769')); 73 | hessian.decode(utils.bytes('v1/bytes/32769'), '1.0').should.eql(bytes); 74 | 75 | var bytes = new Buffer(42769); 76 | bytes.fill(0x41); 77 | var buf = hessian.encode(bytes, '1.0'); 78 | buf.should.length(utils.bytes('v1/bytes/42769').length); 79 | buf.should.eql(utils.bytes('v1/bytes/42769')); 80 | hessian.decode(utils.bytes('v1/bytes/42769'), '1.0').should.eql(bytes); 81 | 82 | var bytes = new Buffer(82769); 83 | bytes.fill(0x41); 84 | var buf = hessian.encode(bytes, '1.0'); 85 | buf.should.length(utils.bytes('v1/bytes/82769').length); 86 | buf.should.eql(utils.bytes('v1/bytes/82769')); 87 | hessian.decode(utils.bytes('v1/bytes/82769'), '1.0').should.eql(bytes); 88 | }); 89 | 90 | describe('v2.0', function () { 91 | it('should read zero length binary data', function () { 92 | var buf = hessian.decode(new Buffer([0x20]), '2.0'); 93 | buf.should.length(0); 94 | buf.should.eql(new Buffer(0)); 95 | }); 96 | 97 | it('should read short datas', function () { 98 | var decoder = new hessian.DecoderV2(new Buffer([0x20, 0x23, 0x23, 0x02, 0x03, 0x20])); 99 | var buf = decoder.read(); 100 | buf.should.length(0); 101 | buf.should.eql(new Buffer(0)); 102 | 103 | buf = decoder.read(); 104 | buf.should.length(3); 105 | buf.should.eql(new Buffer([0x23, 2, 3])); 106 | 107 | buf = decoder.read(); 108 | buf.should.length(0); 109 | buf.should.eql(new Buffer(0)); 110 | decoder.clean(); 111 | }); 112 | 113 | it('should read max length short datas', function () { 114 | var input = new Buffer(16); 115 | input.fill(0x2f); 116 | input[0] = 0x2f; 117 | var buf = hessian.decode(input, '2.0'); 118 | buf.should.length(15); 119 | var output = new Buffer(15); 120 | output.fill(0x2f); 121 | buf.should.eql(output); 122 | 123 | var buf15 = new Buffer(15); 124 | buf15.fill(0x41); 125 | hessian.encode(buf15, '2.0').should.eql(utils.bytes('v2/bytes/15')); 126 | hessian.decode(utils.bytes('v2/bytes/15'), '2.0').should.eql(buf15); 127 | 128 | var buf16 = new Buffer(16); 129 | buf16.fill(0x41); 130 | hessian.encode(buf16, '2.0').should.eql(utils.bytes('v2/bytes/16')); 131 | hessian.decode(utils.bytes('v2/bytes/16'), '2.0').should.eql(buf16); 132 | }); 133 | 134 | it('should read long binary', function () { 135 | var buf = hessian.encode(new Buffer(65535), '2.0'); 136 | buf[0].should.equal(0x41); 137 | hessian.decode(buf, '2.0'); 138 | 139 | buf = hessian.encode(new Buffer(65536), '2.0'); 140 | hessian.decode(buf, '2.0'); 141 | 142 | buf = hessian.encode(new Buffer(65535 * 2 - 10), '2.0'); 143 | hessian.decode(buf, '2.0'); 144 | }); 145 | 146 | it('should write short binary', function () { 147 | hessian.encode(new Buffer(''), '2.0').should.eql(new Buffer([0x20])); 148 | }); 149 | 150 | it('should write and read as java impl', function () { 151 | var bytes = new Buffer(65535); 152 | bytes.fill(0x41); 153 | var buf = hessian.encode(bytes, '2.0'); 154 | buf.should.length(utils.bytes('v2/bytes/65535').length); 155 | buf.should.eql(utils.bytes('v2/bytes/65535')); 156 | hessian.decode(utils.bytes('v2/bytes/65535'), '2.0').should.eql(bytes); 157 | 158 | var bytes = new Buffer(32768); 159 | bytes.fill(0x41); 160 | var buf = hessian.encode(bytes, '2.0'); 161 | buf.should.length(utils.bytes('v2/bytes/32768').length); 162 | buf.should.eql(utils.bytes('v2/bytes/32768')); 163 | hessian.decode(utils.bytes('v2/bytes/32768'), '2.0').should.eql(bytes); 164 | 165 | var bytes = new Buffer(32769); 166 | bytes.fill(0x41); 167 | var buf = hessian.encode(bytes, '2.0'); 168 | buf.should.length(utils.bytes('v2/bytes/32769').length); 169 | buf.should.eql(utils.bytes('v2/bytes/32769')); 170 | hessian.decode(utils.bytes('v2/bytes/32769'), '2.0').should.eql(bytes); 171 | 172 | var bytes = new Buffer(32767); 173 | bytes.fill(0x41); 174 | var buf = hessian.encode(bytes, '2.0'); 175 | buf.should.length(utils.bytes('v2/bytes/32767').length); 176 | buf.should.eql(utils.bytes('v2/bytes/32767')); 177 | hessian.decode(utils.bytes('v2/bytes/32767'), '2.0').should.eql(bytes); 178 | 179 | var bytes = new Buffer(32769); 180 | bytes.fill(0x41); 181 | var buf = hessian.encode(bytes, '2.0'); 182 | buf.should.length(utils.bytes('v2/bytes/32769').length); 183 | buf.should.eql(utils.bytes('v2/bytes/32769')); 184 | hessian.decode(utils.bytes('v2/bytes/32769'), '2.0').should.eql(bytes); 185 | 186 | var bytes = new Buffer(42769); 187 | bytes.fill(0x41); 188 | var buf = hessian.encode(bytes, '2.0'); 189 | buf.should.length(utils.bytes('v2/bytes/42769').length); 190 | buf.should.eql(utils.bytes('v2/bytes/42769')); 191 | hessian.decode(utils.bytes('v2/bytes/42769'), '2.0').should.eql(bytes); 192 | 193 | var bytes = new Buffer(82769); 194 | bytes.fill(0x41); 195 | var buf = hessian.encode(bytes, '2.0'); 196 | buf.should.length(utils.bytes('v2/bytes/82769').length); 197 | buf.should.eql(utils.bytes('v2/bytes/82769')); 198 | hessian.decode(utils.bytes('v2/bytes/82769'), '2.0').should.eql(bytes); 199 | }); 200 | 201 | // it('should read java hessian 1.0 bin format', function () { 202 | // var bytes = new Buffer(65535); 203 | // bytes.fill(0x41); 204 | // hessian.decode(utils.bytes('v1/bytes/65535'), '2.0').should.eql(bytes); 205 | 206 | // var bytes = new Buffer(32767); 207 | // bytes.fill(0x41); 208 | // hessian.decode(utils.bytes('v1/bytes/32767'), '2.0').should.eql(bytes); 209 | 210 | // var bytes = new Buffer(32768); 211 | // bytes.fill(0x41); 212 | // hessian.decode(utils.bytes('v1/bytes/32768'), '2.0').should.eql(bytes); 213 | 214 | // var bytes = new Buffer(32769); 215 | // bytes.fill(0x41); 216 | // hessian.decode(utils.bytes('v1/bytes/32769'), '2.0').should.eql(bytes); 217 | 218 | // var bytes = new Buffer(32767); 219 | // bytes.fill(0x41); 220 | // hessian.decode(utils.bytes('v1/bytes/32767'), '2.0').should.eql(bytes); 221 | 222 | // var bytes = new Buffer(32769); 223 | // bytes.fill(0x41); 224 | // hessian.decode(utils.bytes('v1/bytes/32769'), '2.0').should.eql(bytes); 225 | 226 | // var bytes = new Buffer(42769); 227 | // bytes.fill(0x41); 228 | // hessian.decode(utils.bytes('v1/bytes/42769'), '2.0').should.eql(bytes); 229 | 230 | // var bytes = new Buffer(82769); 231 | // bytes.fill(0x41); 232 | // hessian.decode(utils.bytes('v1/bytes/82769'), '2.0').should.eql(bytes); 233 | // }); 234 | }); 235 | }); 236 | -------------------------------------------------------------------------------- /test/list.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hessian.js - test/list.test.js 3 | * 4 | * Copyright(c) 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var should = require('should'); 18 | var java = require('js-to-java'); 19 | var hessian = require('../'); 20 | var utils = require('./utils'); 21 | 22 | describe('list.test.js', function () { 23 | var intListBuffer = Buffer.concat([ 24 | new Buffer([ 25 | 'V'.charCodeAt(0), 26 | 't'.charCodeAt(0), 0x00, 0x04 27 | ]), 28 | new Buffer('[int'), 29 | new Buffer([ 30 | 'l'.charCodeAt(0), 0, 0, 0, 0x02, 31 | 'I'.charCodeAt(0), 0, 0, 0, 0x00, 32 | 'I'.charCodeAt(0), 0, 0, 0, 0x01, 33 | 'z'.charCodeAt(0) 34 | ]) 35 | ]); 36 | 37 | it('should read int[] = {0, 1}', function () { 38 | hessian.decode(intListBuffer).should.eql([0, 1]); 39 | hessian.decode(intListBuffer, true).should.eql({ 40 | '$class': '[int', 41 | '$': [ { '$class': 'int', '$': 0 }, { '$class': 'int', '$': 1 } ] 42 | }); 43 | }); 44 | 45 | it('should write int[] = {0, 1}', function () { 46 | var buf = hessian.encode(java.array.int([0, 1])); 47 | buf.should.be.a.Buffer; 48 | buf.should.length(intListBuffer.length); 49 | buf.should.eql(intListBuffer); 50 | 51 | hessian.encode({ 52 | $class: '[int', 53 | $: [0, 1] 54 | }).should.eql(intListBuffer); 55 | 56 | // empty list 57 | var empty = Buffer.concat([ 58 | new Buffer([ 59 | 'V'.charCodeAt(0), 60 | 't'.charCodeAt(0), 0x00, 0x04 61 | ]), 62 | new Buffer('[int'), 63 | new Buffer([ 64 | 'l'.charCodeAt(0), 0, 0, 0, 0x00, 65 | 'z'.charCodeAt(0) 66 | ]) 67 | ]); 68 | hessian.decode(empty).should.eql([]); 69 | }); 70 | 71 | it('should read write anonymous variable-length list = {0, null, "foobar"}', function () { 72 | var anonymousList = Buffer.concat([ 73 | new Buffer('V'), 74 | new Buffer([ 75 | 'I'.charCodeAt(0), 0, 0, 0, 0x00, 76 | 'N'.charCodeAt(0), 77 | 'S'.charCodeAt(0), 0, 0x06, 78 | ]), 79 | new Buffer('foobar'), 80 | new Buffer('z'), 81 | ]); 82 | 83 | hessian.decode(anonymousList).should.eql([0, null, 'foobar']); 84 | 85 | // empty 86 | var emptyList = Buffer.concat([ 87 | new Buffer('V'), 88 | new Buffer('z'), 89 | ]); 90 | hessian.decode(emptyList).should.eql([]); 91 | }); 92 | 93 | it('should write and read untyped list', function () { 94 | hessian.encode([1, 2, 'foo'], '1.0').should.eql(utils.bytes('v1/list/untyped_list')); 95 | hessian.encode([], '1.0').should.eql(utils.bytes('v1/list/untyped_[]')); 96 | 97 | hessian.decode(utils.bytes('v1/list/untyped_list'), '1.0').should.eql([1, 2, 'foo']); 98 | hessian.decode(utils.bytes('v1/list/untyped_list'), '1.0', true).should.eql({ 99 | $class: 'java.util.ArrayList', 100 | $: [ 101 | { '$class': 'int', '$': 1 }, 102 | { '$class': 'int', '$': 2 }, 103 | { '$class': 'java.lang.String', '$': 'foo' } 104 | ] 105 | }); 106 | hessian.decode(utils.bytes('v1/list/untyped_[]'), '1.0').should.eql([]); 107 | hessian.decode(utils.bytes('v1/list/untyped_[foo,bar]'), '1.0', true).should.eql( { 108 | $class: 'java.util.ArrayList', 109 | $: [ 110 | { '$class': 'java.lang.String', '$': 'foo' }, 111 | { '$class': 'java.lang.String', '$': 'bar' } 112 | ] 113 | }); 114 | 115 | // java.util.ArrayList as simple 116 | hessian.encode({ 117 | $class: 'java.util.ArrayList', 118 | $: [1, 2, 'foo'] 119 | }, '1.0').should.eql(utils.bytes('v1/list/untyped_list')); 120 | }); 121 | 122 | it('should write and read typed fixed-length list', function () { 123 | hessian.encode({ 124 | $class: 'hessian.demo.SomeArrayList', 125 | $: ['ok', 'some list'] 126 | }, '1.0').should.eql(utils.bytes('v1/list/typed_list')); 127 | hessian.decode(utils.bytes('v1/list/typed_list'), '1.0', true) 128 | .should.eql({ 129 | '$class': 'hessian.demo.SomeArrayList', 130 | '$': [ 131 | { '$class': 'java.lang.String', '$': 'ok' }, 132 | { '$class': 'java.lang.String', '$': 'some list' } 133 | ] 134 | }); 135 | 136 | hessian.decode(utils.bytes('v1/list/typed_list'), '1.0') 137 | .should.eql([ 'ok', 'some list' ]); 138 | 139 | var list = { 140 | $class: '[int', 141 | $: [1, 2, 3] 142 | }; 143 | hessian.encode(list, '1.0').should.eql(utils.bytes('v1/list/[int')); 144 | hessian.decode(utils.bytes('v1/list/[int'), '1.0').should.eql([1, 2, 3]); 145 | hessian.decode(utils.bytes('v1/list/[int'), '1.0', true).should.eql({ 146 | '$class': '[int', 147 | '$': [ 148 | { '$class': 'int', '$': 1 }, 149 | { '$class': 'int', '$': 2 }, 150 | { '$class': 'int', '$': 3 } 151 | ] 152 | }); 153 | 154 | var strs = { 155 | $class: '[string', 156 | $: ['1', '@', '3'] 157 | }; 158 | hessian.encode(strs, '1.0').should.eql(utils.bytes('v1/list/[string')); 159 | hessian.decode(utils.bytes('v1/list/[string'), '1.0', true).should.eql({ 160 | '$class': '[string', 161 | '$': [ 162 | { '$class': 'java.lang.String', '$': '1' }, 163 | { '$class': 'java.lang.String', '$': '@' }, 164 | { '$class': 'java.lang.String', '$': '3' } 165 | ] 166 | }); 167 | }); 168 | 169 | describe('v2.0', function () { 170 | it('should write and read untyped list', function () { 171 | hessian.encode([1, 2, 'foo'], '2.0').should.eql(utils.bytes('v2/list/untyped_list')); 172 | hessian.encode([], '2.0').should.eql(utils.bytes('v2/list/untyped_[]')); 173 | 174 | hessian.decode(utils.bytes('v2/list/untyped_list'), '2.0').should.eql([1, 2, 'foo']); 175 | hessian.decode(utils.bytes('v2/list/untyped_list'), '2.0', true).should.eql([1, 2, 'foo']); 176 | hessian.decode(utils.bytes('v2/list/untyped_list_8'), '2.0').should.eql(['1', '2', '3', '4', '5', '6', '7', '8']); 177 | hessian.decode(utils.bytes('v2/list/untyped_list_8'), '2.0', true).should.eql(['1', '2', '3', '4', '5', '6', '7', '8']); 178 | hessian.decode(utils.bytes('v2/list/untyped_[]'), '2.0').should.eql([]); 179 | hessian.decode(utils.bytes('v2/list/untyped_[foo,bar]'), '2.0', true).should.eql(['foo', 'bar']); 180 | 181 | // java.util.ArrayList as simple 182 | hessian.encode({ 183 | $class: 'java.util.ArrayList', 184 | $: [1, 2, 'foo'] 185 | }, '2.0').should.eql(utils.bytes('v2/list/untyped_list')); 186 | // encode again should cache class 187 | hessian.encode({ 188 | $class: 'java.util.ArrayList', 189 | $: [1, 2, 'foo'] 190 | }, '2.0').should.eql(utils.bytes('v2/list/untyped_list')); 191 | 192 | // java.util.ArrayList length larger than 7 193 | hessian.encode({ 194 | $class: 'java.util.ArrayList', 195 | $: ['1', '2', '3', '4', '5', '6', '7', '8'] 196 | }, '2.0').should.eql(utils.bytes('v2/list/untyped_list_8')); 197 | hessian.encode({ 198 | $class: 'java.util.ArrayList', 199 | $: ['1', '2', '3', '4', '5', '6', '7', '8'] 200 | }, '2.0').should.eql(utils.bytes('v2/list/untyped_list_8')); 201 | }); 202 | 203 | it('should write and read typed fixed-length list', function () { 204 | hessian.encode({ 205 | $class: 'hessian.demo.SomeArrayList', 206 | $: ['ok', 'some list'] 207 | }, '2.0').should.eql(utils.bytes('v2/list/typed_list')); 208 | // encode again should use type cache 209 | hessian.encode({ 210 | $class: 'hessian.demo.SomeArrayList', 211 | $: ['ok', 'some list'] 212 | }, '2.0').should.eql(utils.bytes('v2/list/typed_list')); 213 | hessian.encode({ 214 | $class: 'hessian.demo.SomeArrayList', 215 | $: ['1', '2', '3', '4', '5', '6', '7', '8'] 216 | }, '2.0').should.eql(utils.bytes('v2/list/typed_list_8')); 217 | 218 | hessian.decode(utils.bytes('v2/list/typed_list'), '2.0', true) 219 | .should.eql({ 220 | '$class': 'hessian.demo.SomeArrayList', 221 | '$': [ 'ok', 'some list' ] 222 | }); 223 | hessian.decode(utils.bytes('v2/list/typed_list_8'), '2.0', true) 224 | .should.eql({ 225 | '$class': 'hessian.demo.SomeArrayList', 226 | '$': ['1', '2', '3', '4', '5', '6', '7', '8'] 227 | }); 228 | 229 | hessian.decode(utils.bytes('v2/list/typed_list_8'), '2.0') 230 | .should.eql(['1', '2', '3', '4', '5', '6', '7', '8']); 231 | 232 | var list = { 233 | $class: '[int', 234 | $: [1, 2, 3] 235 | }; 236 | hessian.encode(list, '2.0').should.eql(utils.bytes('v2/list/[int')); 237 | hessian.encode(list, '2.0').should.eql(utils.bytes('v2/list/[int')); 238 | 239 | hessian.decode(utils.bytes('v2/list/[int'), '2.0').should.eql([1, 2, 3]); 240 | // encode again should use type cache 241 | hessian.decode(utils.bytes('v2/list/[int'), '2.0', true).should.eql(list); 242 | 243 | var strs = { 244 | $class: '[string', 245 | $: ['1', '@', '3'] 246 | }; 247 | hessian.encode(strs, '2.0').should.eql(utils.bytes('v2/list/[string')); 248 | hessian.decode(utils.bytes('v2/list/[string'), '2.0', true).should.eql(strs); 249 | }); 250 | 251 | // it('should read hessian 1.0 untyped list', function () { 252 | // hessian.decode(utils.bytes('v1/list/untyped_list'), '2.0').should.eql([1, 2, 'foo']); 253 | // hessian.decode(utils.bytes('v1/list/untyped_list'), '2.0', true).should.eql([1, 2, 'foo']); 254 | // hessian.decode(utils.bytes('v1/list/untyped_[]'), '2.0').should.eql([]); 255 | // hessian.decode(utils.bytes('v1/list/untyped_[foo,bar]'), '2.0', true).should.eql(['foo', 'bar']); 256 | // }); 257 | }); 258 | }); 259 | -------------------------------------------------------------------------------- /benchmark/decode.js: -------------------------------------------------------------------------------- 1 | /**! 2 | * hessian.js - benchmark/decode.js 3 | * 4 | * Copyright(c) fengmk2 and other contributors. 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | 'use strict'; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var ByteBuffer = require('byte'); 18 | var Benchmark = require('benchmark'); 19 | var benchmarks = require('beautify-benchmark'); 20 | var java = require('js-to-java'); 21 | var hessian = require('../'); 22 | 23 | var suite = new Benchmark.Suite(); 24 | 25 | // var simpleObject = { 26 | // $class: 'com.hessiantest.org.MockRequest', 27 | // $: { 28 | // id: 123, 29 | // name: 'getData', 30 | // args: [1, "name", "xxx1231231231231xxx123"] 31 | // } 32 | // }; 33 | // 34 | // // var simpleObjectBuf1 = hessian.encode(simpleObject, '1.0'); 35 | // var simpleObjectBuf2 = hessian.encode(simpleObject, '2.0'); 36 | // 37 | // var complexObject = { 38 | // $class: 'com.hessiantest.org.MockRequest', 39 | // $: { 40 | // id: 123, 41 | // name: 'getData', 42 | // args: [1, "name", "xxx1231231231231xxx123"], 43 | // conn: { 44 | // $class: 'com.hessiantest.org.MockRequestConnection', 45 | // $: { 46 | // ctx: java.long(1024) 47 | // } 48 | // } 49 | // } 50 | // }; 51 | // 52 | // // var complexObjectBuf1 = hessian.encode(complexObject, '1.0'); 53 | // var complexObjectBuf2 = hessian.encode(complexObject, '2.0'); 54 | 55 | // var number1Buf1 = hessian.encode(1, '1.0'); 56 | var number1Buf2 = hessian.encode(1, '2.0'); 57 | 58 | // var dateBuf1 = hessian.encode(new Date(), '1.0'); 59 | var dateBuf2 = hessian.encode(new Date(), '2.0'); 60 | 61 | // // var longBuf1 = hessian.encode(java.long(300), '1.0'); 62 | // var longBuf2 = hessian.encode(java.long(300), '2.0'); 63 | // 64 | // // var stringBuf1 = hessian.encode('xxx1231231231231xxx123', '1.0'); 65 | var stringBuf2 = hessian.encode('xxx1231231231231xxx123', '2.0'); 66 | // 67 | // // var arrBuf1 = hessian.encode([1, 2, 3], '1.0'); 68 | // var arrBuf2 = hessian.encode([1, 2, 3], '2.0'); 69 | // 70 | // // var arrObjectBuf1 = hessian.encode([1, "name", "xxx1231231231231xxx123"], '1.0'); 71 | // var arrObjectBuf2 = hessian.encode([1, "name", "xxx1231231231231xxx123"], '2.0'); 72 | 73 | suite 74 | 75 | // .add('hessian1 decode: number', function() { 76 | // hessian.decode(number1Buf1, '1.0'); 77 | // }) 78 | .add('Fast hessian2 decode: number', function() { 79 | hessian.decode(number1Buf2, '2.0'); 80 | }) 81 | 82 | // .add('hessian1 decode: date', function() { 83 | // hessian.decode(dateBuf1, '1.0'); 84 | // }) 85 | .add('Fast hessian2 decode: date', function() { 86 | hessian.decode(dateBuf2, '2.0'); 87 | }) 88 | 89 | // .add('hessian1 decode: long', function() { 90 | // hessian.decode(longBuf1, '1.0'); 91 | // }) 92 | // .add('Fast hessian2 decode: long', function() { 93 | // hessian.decode(longBuf2, '2.0'); 94 | // }) 95 | 96 | // .add('hessian1 decode: string', function() { 97 | // hessian.decode(stringBuf1, '1.0'); 98 | // }) 99 | .add('Fast hessian2 decode: string', function() { 100 | hessian.decode(stringBuf2, '2.0'); 101 | }) 102 | // 103 | // // .add('hessian1 decode: [1, 2, 3]', function() { 104 | // // hessian.decode(arrBuf1, '1.0'); 105 | // // }) 106 | // .add('Fast hessian2 decode: [1, 2, 3]', function() { 107 | // hessian.decode(arrBuf2, '2.0'); 108 | // }) 109 | // // .add('hessian1 decode array', function() { 110 | // // hessian.decode(arrObjectBuf1, '1.0'); 111 | // // }) 112 | // .add('Fast hessian2 decode array', function() { 113 | // hessian.decode(arrObjectBuf2, '2.0'); 114 | // }) 115 | // 116 | // // .add('hessian1 decode: simple object', function() { 117 | // // hessian.decode(simpleObjectBuf1, '1.0'); 118 | // // }) 119 | // .add('Fast hessian2 decode: simple object', function() { 120 | // hessian.decode(simpleObjectBuf2, '2.0'); 121 | // }) 122 | // 123 | // // .add('hessian1 decode: complex object', function() { 124 | // // hessian.decode(complexObjectBuf1, '1.0'); 125 | // // }) 126 | // .add('Fast hessian2 decode: complex object', function() { 127 | // hessian.decode(complexObjectBuf2, '2.0'); 128 | // }) 129 | // // .add('hessian1 decode with type: number', function() { 130 | // // hessian.decode(number1Buf1, '1.0', true); 131 | // // }) 132 | // .add('Fast hessian2 decode with type: number', function() { 133 | // hessian.decode(number1Buf2, '2.0', true); 134 | // }) 135 | // 136 | // // .add('hessian1 decode with type: date', function() { 137 | // // hessian.decode(dateBuf1, '1.0', true); 138 | // // }) 139 | // .add('Fast hessian2 decode with type: date', function() { 140 | // hessian.decode(dateBuf2, '2.0', true); 141 | // }) 142 | // 143 | // // .add('hessian1 decode with type: long', function() { 144 | // // hessian.decode(longBuf1, '1.0', true); 145 | // // }) 146 | // .add('Fast hessian2 decode with type: long', function() { 147 | // hessian.decode(longBuf2, '2.0', true); 148 | // }) 149 | // 150 | // // .add('hessian1 decode with type: string', function() { 151 | // // hessian.decode(stringBuf1, '1.0', true); 152 | // // }) 153 | // .add('Fast hessian2 decode with type: string', function() { 154 | // hessian.decode(stringBuf2, '2.0', true); 155 | // }) 156 | // 157 | // // .add('hessian1 decode with type: [1, 2, 3]', function() { 158 | // // hessian.decode(arrBuf1, '1.0', true); 159 | // // }) 160 | // .add('Fast hessian2 decode with type: [1, 2, 3]', function() { 161 | // hessian.decode(arrBuf2, '2.0', true); 162 | // }) 163 | // // .add('hessian1 decode with type array', function() { 164 | // // hessian.decode(arrObjectBuf1, '1.0', true); 165 | // // }) 166 | // .add('Fast hessian2 decode with type array', function() { 167 | // hessian.decode(arrObjectBuf2, '2.0', true); 168 | // }) 169 | // 170 | // // .add('hessian1 decode with type: simple object', function() { 171 | // // hessian.decode(simpleObjectBuf1, '1.0', true); 172 | // // }) 173 | // .add('Fast hessian2 decode with type: simple object', function() { 174 | // hessian.decode(simpleObjectBuf2, '2.0', true); 175 | // }) 176 | // 177 | // // .add('hessian1 decode with type: complex object', function() { 178 | // // hessian.decode(complexObjectBuf1, '1.0', true); 179 | // // }) 180 | // .add('Fast hessian2 decode with type: complex object', function() { 181 | // hessian.decode(complexObjectBuf2, '2.0', true); 182 | // }) 183 | 184 | .on('cycle', function(event) { 185 | benchmarks.add(event.target); 186 | }) 187 | .on('start', function(event) { 188 | console.log('\n Hessian Decode Benchmark\n node version: %s, date: %s\n Starting...', 189 | process.version, Date()); 190 | }) 191 | .on('complete', function done() { 192 | benchmarks.log(); 193 | }) 194 | .run({ 'async': false }); 195 | // 196 | // // Hessian Decode Benchmark 197 | // // node version: v0.11.12, date: Wed Jun 25 2014 10:46:26 GMT+0800 (CST) 198 | // // Starting... 199 | // // 32 tests completed. 200 | // 201 | // // hessian1 decode: number x 5,983,374 ops/sec ±1.57% (94 runs sampled) 202 | // // Fast hessian2 decode: number x 5,713,562 ops/sec ±2.22% (91 runs sampled) 203 | // // hessian1 decode: date x 2,959,698 ops/sec ±1.19% (92 runs sampled) 204 | // // Fast hessian2 decode: date x 2,548,345 ops/sec ±1.32% (91 runs sampled) 205 | // // hessian1 decode: long x 3,880,734 ops/sec ±1.66% (93 runs sampled) 206 | // // Fast hessian2 decode: long x 5,221,659 ops/sec ±2.30% (90 runs sampled) 207 | // // hessian1 decode: string x 1,109,890 ops/sec ±1.59% (94 runs sampled) 208 | // // Fast hessian2 decode: string x 1,075,246 ops/sec ±1.43% (92 runs sampled) 209 | // // hessian1 decode: [1, 2, 3] x 1,186,054 ops/sec ±1.24% (92 runs sampled) 210 | // // Fast hessian2 decode: [1, 2, 3] x 2,049,867 ops/sec ±1.75% (98 runs sampled) 211 | // // hessian1 decode array x 511,250 ops/sec ±0.92% (95 runs sampled) 212 | // // Fast hessian2 decode array x 600,564 ops/sec ±1.27% (90 runs sampled) 213 | // // hessian1 decode: simple object x 186,875 ops/sec ±0.81% (93 runs sampled) 214 | // // Fast hessian2 decode: simple object x 174,768 ops/sec ±0.74% (94 runs sampled) 215 | // // hessian1 decode: complex object x 133,573 ops/sec ±1.31% (97 runs sampled) 216 | // // Fast hessian2 decode: complex object x 131,234 ops/sec ±1.45% (95 runs sampled) 217 | // // hessian1 decode with type: number x 5,014,602 ops/sec ±1.97% (91 runs sampled) 218 | // // Fast hessian2 decode with type: number x 5,890,098 ops/sec ±1.81% (89 runs sampled) 219 | // // hessian1 decode with type: date x 2,797,789 ops/sec ±1.82% (91 runs sampled) 220 | // // Fast hessian2 decode with type: date x 2,541,107 ops/sec ±2.40% (92 runs sampled) 221 | // // hessian1 decode with type: long x 3,869,288 ops/sec ±1.31% (93 runs sampled) 222 | // // Fast hessian2 decode with type: long x 5,598,654 ops/sec ±1.20% (95 runs sampled) 223 | // // hessian1 decode with type: string x 1,068,879 ops/sec ±1.89% (92 runs sampled) 224 | // // Fast hessian2 decode with type: string x 1,110,680 ops/sec ±0.89% (94 runs sampled) 225 | // // hessian1 decode with type: [1, 2, 3] x 1,150,027 ops/sec ±0.94% (94 runs sampled) 226 | // // Fast hessian2 decode with type: [1, 2, 3] x 1,834,472 ops/sec ±0.90% (94 runs sampled) 227 | // // hessian1 decode with type array x 508,028 ops/sec ±0.99% (96 runs sampled) 228 | // // Fast hessian2 decode with type array x 605,446 ops/sec ±1.10% (96 runs sampled) 229 | // // hessian1 decode with type: simple object x 190,014 ops/sec ±0.92% (97 runs sampled) 230 | // // Fast hessian2 decode with type: simple object x 176,337 ops/sec ±1.16% (96 runs sampled) 231 | // // hessian1 decode with type: complex object x 133,815 ops/sec ±1.21% (90 runs sampled) 232 | // // Fast hessian2 decode with type: complex object x 134,814 ops/sec ±0.96% (96 runs sampled) 233 | -------------------------------------------------------------------------------- /test/fixtures/4k.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | * hessian.js - test/double.test.js 3 | * 4 | * Copyright(c) 2014 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var should = require('should'); 18 | var java = require('js-to-java'); 19 | var hessian = require('../'); 20 | 21 | describe('double.test.js', function () { 22 | var doubleBuffer = new Buffer(['D'.charCodeAt(0), 23 | 0x40, 0x28, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00]); 24 | 25 | it('should read double 12.25', function () { 26 | hessian.decode(doubleBuffer).should.equal(12.25); 27 | }); 28 | 29 | it('should write double 12.25', function () { 30 | hessian.encode(12.25).should.eql(doubleBuffer); 31 | hessian.encode(java.double(12.25)).should.eql(doubleBuffer); 32 | hessian.encode({ 33 | $class: 'double', 34 | $: 12.25 35 | }).should.eql(doubleBuffer); 36 | }); 37 | 38 | it('should write double 100', function () { 39 | hessian.encode(java.double(100)).should.eql( 40 | new Buffer(['D'.charCodeAt(0), 0x40, 0x59, 0, 0, 0, 0, 0, 0])); 41 | }); 42 | 43 | it('should write double 0', function () { 44 | hessian.encode(java.double(0)).should.eql( 45 | new Buffer(['D'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0])); 46 | }); 47 | 48 | describe('v2.0', function () { 49 | it('should read 0.0 and 1.0', function () { 50 | hessian.decode(new Buffer([0x5b]), '2.0').should.equal(0.0); 51 | hessian.decode(new Buffer([0x5c]), '2.0').should.equal(1.0); 52 | }); 53 | 54 | it('should read 8 bits double', function () { 55 | hessian.decode(new Buffer([0x5d, 0x00]), '2.0').should.equal(0.0); 56 | hessian.decode(new Buffer([0x5d, 0x01]), '2.0').should.equal(1.0); 57 | hessian.decode(new Buffer([0x5d, 0x80]), '2.0').should.equal(-128.0); 58 | hessian.decode(new Buffer([0x5d, 0x7f]), '2.0').should.equal(127.0); 59 | }); 60 | 61 | it('should read 16 bits double', function () { 62 | hessian.decode(new Buffer([0x5e, 0x00, 0x00]), '2.0').should.equal(0.0); 63 | hessian.decode(new Buffer([0x5e, 0x00, 0x01]), '2.0').should.equal(1.0); 64 | hessian.decode(new Buffer([0x5e, 0x00, 0x80]), '2.0').should.equal(128.0); 65 | hessian.decode(new Buffer([0x5e, 0x00, 0x7f]), '2.0').should.equal(127.0); 66 | hessian.decode(new Buffer([0x5e, 0x80, 0x00]), '2.0').should.equal(-32768.0); 67 | hessian.decode(new Buffer([0x5e, 0x7f, 0xff]), '2.0').should.equal(32767.0); 68 | }); 69 | 70 | it('should read 32 bits float double', function () { 71 | hessian.decode(new Buffer([0x5f, 0x00, 0x00, 0x00, 0x00]), '2.0').should.equal(0.0); 72 | hessian.decode(new Buffer([0x5f, 0x41, 0x44, 0x00, 0x00]), '2.0').should.equal(12.25); 73 | }); 74 | 75 | it('should read normal double', function () { 76 | hessian.decode(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0]), '2.0').should.equal(10.0); 77 | }); 78 | 79 | it('should write 0.0 and 1.0', function () { 80 | hessian.encode(java.double(0), '2.0').should.eql(new Buffer([0x5b])); 81 | hessian.encode(java.double(0.0), '2.0').should.eql(new Buffer([0x5b])); 82 | 83 | hessian.encode(java.double(1), '2.0').should.eql(new Buffer([0x5c])); 84 | hessian.encode(java.double(1.0), '2.0').should.eql(new Buffer([0x5c])); 85 | }); 86 | 87 | it('should write big double', function () { 88 | hessian.encode(java.double(10), '2.0') 89 | .should.eql(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0])); 90 | }); 91 | }); 92 | }); 93 | /*! 94 | * hessian.js - test/double.test.js 95 | * 96 | * Copyright(c) 2014 97 | * MIT Licensed 98 | * 99 | * Authors: 100 | * fengmk2 (http://fengmk2.github.com) 101 | */ 102 | 103 | "use strict"; 104 | 105 | /** 106 | * Module dependencies. 107 | */ 108 | 109 | var should = require('should'); 110 | var java = require('js-to-java'); 111 | var hessian = require('../'); 112 | 113 | describe('double.test.js', function () { 114 | var doubleBuffer = new Buffer(['D'.charCodeAt(0), 115 | 0x40, 0x28, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00]); 116 | 117 | it('should read double 12.25', function () { 118 | hessian.decode(doubleBuffer).should.equal(12.25); 119 | }); 120 | 121 | it('should write double 12.25', function () { 122 | hessian.encode(12.25).should.eql(doubleBuffer); 123 | hessian.encode(java.double(12.25)).should.eql(doubleBuffer); 124 | hessian.encode({ 125 | $class: 'double', 126 | $: 12.25 127 | }).should.eql(doubleBuffer); 128 | }); 129 | 130 | it('should write double 100', function () { 131 | hessian.encode(java.double(100)).should.eql( 132 | new Buffer(['D'.charCodeAt(0), 0x40, 0x59, 0, 0, 0, 0, 0, 0])); 133 | }); 134 | 135 | it('should write double 0', function () { 136 | hessian.encode(java.double(0)).should.eql( 137 | new Buffer(['D'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0])); 138 | }); 139 | 140 | describe('v2.0', function () { 141 | it('should read 0.0 and 1.0', function () { 142 | hessian.decode(new Buffer([0x5b]), '2.0').should.equal(0.0); 143 | hessian.decode(new Buffer([0x5c]), '2.0').should.equal(1.0); 144 | }); 145 | 146 | it('should read 8 bits double', function () { 147 | hessian.decode(new Buffer([0x5d, 0x00]), '2.0').should.equal(0.0); 148 | hessian.decode(new Buffer([0x5d, 0x01]), '2.0').should.equal(1.0); 149 | hessian.decode(new Buffer([0x5d, 0x80]), '2.0').should.equal(-128.0); 150 | hessian.decode(new Buffer([0x5d, 0x7f]), '2.0').should.equal(127.0); 151 | }); 152 | 153 | it('should read 16 bits double', function () { 154 | hessian.decode(new Buffer([0x5e, 0x00, 0x00]), '2.0').should.equal(0.0); 155 | hessian.decode(new Buffer([0x5e, 0x00, 0x01]), '2.0').should.equal(1.0); 156 | hessian.decode(new Buffer([0x5e, 0x00, 0x80]), '2.0').should.equal(128.0); 157 | hessian.decode(new Buffer([0x5e, 0x00, 0x7f]), '2.0').should.equal(127.0); 158 | hessian.decode(new Buffer([0x5e, 0x80, 0x00]), '2.0').should.equal(-32768.0); 159 | hessian.decode(new Buffer([0x5e, 0x7f, 0xff]), '2.0').should.equal(32767.0); 160 | }); 161 | 162 | it('should read 32 bits float double', function () { 163 | hessian.decode(new Buffer([0x5f, 0x00, 0x00, 0x00, 0x00]), '2.0').should.equal(0.0); 164 | hessian.decode(new Buffer([0x5f, 0x41, 0x44, 0x00, 0x00]), '2.0').should.equal(12.25); 165 | }); 166 | 167 | it('should read normal double', function () { 168 | hessian.decode(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0]), '2.0').should.equal(10.0); 169 | }); 170 | 171 | it('should write 0.0 and 1.0', function () { 172 | hessian.encode(java.double(0), '2.0').should.eql(new Buffer([0x5b])); 173 | hessian.encode(java.double(0.0), '2.0').should.eql(new Buffer([0x5b])); 174 | 175 | hessian.encode(java.double(1), '2.0').should.eql(new Buffer([0x5c])); 176 | hessian.encode(java.double(1.0), '2.0').should.eql(new Buffer([0x5c])); 177 | }); 178 | 179 | it('should write big double', function () { 180 | hessian.encode(java.double(10), '2.0') 181 | .should.eql(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0])); 182 | }); 183 | }); 184 | }); 185 | /*! 186 | * hessian.js - test/double.test.js 187 | * 188 | * Copyright(c) 2014 189 | * MIT Licensed 190 | * 191 | * Authors: 192 | * fengmk2 (http://fengmk2.github.com) 193 | */ 194 | 195 | "use strict"; 196 | 197 | /** 198 | * Module dependencies. 199 | */ 200 | 201 | var should = require('should'); 202 | var java = require('js-to-java'); 203 | var hessian = require('../'); 204 | 205 | describe('double.test.js', function () { 206 | var doubleBuffer = new Buffer(['D'.charCodeAt(0), 207 | 0x40, 0x28, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00]); 208 | 209 | it('should read double 12.25', function () { 210 | hessian.decode(doubleBuffer).should.equal(12.25); 211 | }); 212 | 213 | it('should write double 12.25', function () { 214 | hessian.encode(12.25).should.eql(doubleBuffer); 215 | hessian.encode(java.double(12.25)).should.eql(doubleBuffer); 216 | hessian.encode({ 217 | $class: 'double', 218 | $: 12.25 219 | }).should.eql(doubleBuffer); 220 | }); 221 | 222 | it('should write double 100', function () { 223 | hessian.encode(java.double(100)).should.eql( 224 | new Buffer(['D'.charCodeAt(0), 0x40, 0x59, 0, 0, 0, 0, 0, 0])); 225 | }); 226 | 227 | it('should write double 0', function () { 228 | hessian.encode(java.double(0)).should.eql( 229 | new Buffer(['D'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0])); 230 | }); 231 | 232 | describe('v2.0', function () { 233 | it('should read 0.0 and 1.0', function () { 234 | hessian.decode(new Buffer([0x5b]), '2.0').should.equal(0.0); 235 | hessian.decode(new Buffer([0x5c]), '2.0').should.equal(1.0); 236 | }); 237 | 238 | it('should read 8 bits double', function () { 239 | hessian.decode(new Buffer([0x5d, 0x00]), '2.0').should.equal(0.0); 240 | hessian.decode(new Buffer([0x5d, 0x01]), '2.0').should.equal(1.0); 241 | hessian.decode(new Buffer([0x5d, 0x80]), '2.0').should.equal(-128.0); 242 | hessian.decode(new Buffer([0x5d, 0x7f]), '2.0').should.equal(127.0); 243 | }); 244 | 245 | it('should read 16 bits double', function () { 246 | hessian.decode(new Buffer([0x5e, 0x00, 0x00]), '2.0').should.equal(0.0); 247 | hessian.decode(new Buffer([0x5e, 0x00, 0x01]), '2.0').should.equal(1.0); 248 | hessian.decode(new Buffer([0x5e, 0x00, 0x80]), '2.0').should.equal(128.0); 249 | hessian.decode(new Buffer([0x5e, 0x00, 0x7f]), '2.0').should.equal(127.0); 250 | hessian.decode(new Buffer([0x5e, 0x80, 0x00]), '2.0').should.equal(-32768.0); 251 | hessian.decode(new Buffer([0x5e, 0x7f, 0xff]), '2.0').should.equal(32767.0); 252 | }); 253 | 254 | it('should read 32 bits float double', function () { 255 | hessian.decode(new Buffer([0x5f, 0x00, 0x00, 0x00, 0x00]), '2.0').should.equal(0.0); 256 | hessian.decode(new Buffer([0x5f, 0x41, 0x44, 0x00, 0x00]), '2.0').should.equal(12.25); 257 | }); 258 | 259 | it('should read normal double', function () { 260 | hessian.decode(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0]), '2.0').should.equal(10.0); 261 | }); 262 | 263 | it('should write 0.0 and 1.0', function () { 264 | hessian.encode(java.double(0), '2.0').should.eql(new Buffer([0x5b])); 265 | hessian.encode(java.double(0.0), '2.0').should.eql(new Buffer([0x5b])); 266 | 267 | hessian.encode(java.double(1), '2.0').should.eql(new Buffer([0x5c])); 268 | hessian.encode(java.double(1.0), '2.0').should.eql(new Buffer([0x5c])); 269 | }); 270 | 271 | it('should write big double', function () { 272 | hessian.encode(java.double(10), '2.0') 273 | .should.eql(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0])); 274 | }); 275 | }); 276 | }); 277 | -------------------------------------------------------------------------------- /test/fixtures/v1/string/text4k.bin: -------------------------------------------------------------------------------- 1 | S&/*! 2 | * hessian.js - test/double.test.js 3 | * 4 | * Copyright(c) 2014 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var should = require('should'); 18 | var java = require('js-to-java'); 19 | var hessian = require('../'); 20 | 21 | describe('double.test.js', function () { 22 | var doubleBuffer = new Buffer(['D'.charCodeAt(0), 23 | 0x40, 0x28, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00]); 24 | 25 | it('should read double 12.25', function () { 26 | hessian.decode(doubleBuffer).should.equal(12.25); 27 | }); 28 | 29 | it('should write double 12.25', function () { 30 | hessian.encode(12.25).should.eql(doubleBuffer); 31 | hessian.encode(java.double(12.25)).should.eql(doubleBuffer); 32 | hessian.encode({ 33 | $class: 'double', 34 | $: 12.25 35 | }).should.eql(doubleBuffer); 36 | }); 37 | 38 | it('should write double 100', function () { 39 | hessian.encode(java.double(100)).should.eql( 40 | new Buffer(['D'.charCodeAt(0), 0x40, 0x59, 0, 0, 0, 0, 0, 0])); 41 | }); 42 | 43 | it('should write double 0', function () { 44 | hessian.encode(java.double(0)).should.eql( 45 | new Buffer(['D'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0])); 46 | }); 47 | 48 | describe('v2.0', function () { 49 | it('should read 0.0 and 1.0', function () { 50 | hessian.decode(new Buffer([0x5b]), '2.0').should.equal(0.0); 51 | hessian.decode(new Buffer([0x5c]), '2.0').should.equal(1.0); 52 | }); 53 | 54 | it('should read 8 bits double', function () { 55 | hessian.decode(new Buffer([0x5d, 0x00]), '2.0').should.equal(0.0); 56 | hessian.decode(new Buffer([0x5d, 0x01]), '2.0').should.equal(1.0); 57 | hessian.decode(new Buffer([0x5d, 0x80]), '2.0').should.equal(-128.0); 58 | hessian.decode(new Buffer([0x5d, 0x7f]), '2.0').should.equal(127.0); 59 | }); 60 | 61 | it('should read 16 bits double', function () { 62 | hessian.decode(new Buffer([0x5e, 0x00, 0x00]), '2.0').should.equal(0.0); 63 | hessian.decode(new Buffer([0x5e, 0x00, 0x01]), '2.0').should.equal(1.0); 64 | hessian.decode(new Buffer([0x5e, 0x00, 0x80]), '2.0').should.equal(128.0); 65 | hessian.decode(new Buffer([0x5e, 0x00, 0x7f]), '2.0').should.equal(127.0); 66 | hessian.decode(new Buffer([0x5e, 0x80, 0x00]), '2.0').should.equal(-32768.0); 67 | hessian.decode(new Buffer([0x5e, 0x7f, 0xff]), '2.0').should.equal(32767.0); 68 | }); 69 | 70 | it('should read 32 bits float double', function () { 71 | hessian.decode(new Buffer([0x5f, 0x00, 0x00, 0x00, 0x00]), '2.0').should.equal(0.0); 72 | hessian.decode(new Buffer([0x5f, 0x41, 0x44, 0x00, 0x00]), '2.0').should.equal(12.25); 73 | }); 74 | 75 | it('should read normal double', function () { 76 | hessian.decode(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0]), '2.0').should.equal(10.0); 77 | }); 78 | 79 | it('should write 0.0 and 1.0', function () { 80 | hessian.encode(java.double(0), '2.0').should.eql(new Buffer([0x5b])); 81 | hessian.encode(java.double(0.0), '2.0').should.eql(new Buffer([0x5b])); 82 | 83 | hessian.encode(java.double(1), '2.0').should.eql(new Buffer([0x5c])); 84 | hessian.encode(java.double(1.0), '2.0').should.eql(new Buffer([0x5c])); 85 | }); 86 | 87 | it('should write big double', function () { 88 | hessian.encode(java.double(10), '2.0') 89 | .should.eql(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0])); 90 | }); 91 | }); 92 | }); 93 | /*! 94 | * hessian.js - test/double.test.js 95 | * 96 | * Copyright(c) 2014 97 | * MIT Licensed 98 | * 99 | * Authors: 100 | * fengmk2 (http://fengmk2.github.com) 101 | */ 102 | 103 | "use strict"; 104 | 105 | /** 106 | * Module dependencies. 107 | */ 108 | 109 | var should = require('should'); 110 | var java = require('js-to-java'); 111 | var hessian = require('../'); 112 | 113 | describe('double.test.js', function () { 114 | var doubleBuffer = new Buffer(['D'.charCodeAt(0), 115 | 0x40, 0x28, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00]); 116 | 117 | it('should read double 12.25', function () { 118 | hessian.decode(doubleBuffer).should.equal(12.25); 119 | }); 120 | 121 | it('should write double 12.25', function () { 122 | hessian.encode(12.25).should.eql(doubleBuffer); 123 | hessian.encode(java.double(12.25)).should.eql(doubleBuffer); 124 | hessian.encode({ 125 | $class: 'double', 126 | $: 12.25 127 | }).should.eql(doubleBuffer); 128 | }); 129 | 130 | it('should write double 100', function () { 131 | hessian.encode(java.double(100)).should.eql( 132 | new Buffer(['D'.charCodeAt(0), 0x40, 0x59, 0, 0, 0, 0, 0, 0])); 133 | }); 134 | 135 | it('should write double 0', function () { 136 | hessian.encode(java.double(0)).should.eql( 137 | new Buffer(['D'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0])); 138 | }); 139 | 140 | describe('v2.0', function () { 141 | it('should read 0.0 and 1.0', function () { 142 | hessian.decode(new Buffer([0x5b]), '2.0').should.equal(0.0); 143 | hessian.decode(new Buffer([0x5c]), '2.0').should.equal(1.0); 144 | }); 145 | 146 | it('should read 8 bits double', function () { 147 | hessian.decode(new Buffer([0x5d, 0x00]), '2.0').should.equal(0.0); 148 | hessian.decode(new Buffer([0x5d, 0x01]), '2.0').should.equal(1.0); 149 | hessian.decode(new Buffer([0x5d, 0x80]), '2.0').should.equal(-128.0); 150 | hessian.decode(new Buffer([0x5d, 0x7f]), '2.0').should.equal(127.0); 151 | }); 152 | 153 | it('should read 16 bits double', function () { 154 | hessian.decode(new Buffer([0x5e, 0x00, 0x00]), '2.0').should.equal(0.0); 155 | hessian.decode(new Buffer([0x5e, 0x00, 0x01]), '2.0').should.equal(1.0); 156 | hessian.decode(new Buffer([0x5e, 0x00, 0x80]), '2.0').should.equal(128.0); 157 | hessian.decode(new Buffer([0x5e, 0x00, 0x7f]), '2.0').should.equal(127.0); 158 | hessian.decode(new Buffer([0x5e, 0x80, 0x00]), '2.0').should.equal(-32768.0); 159 | hessian.decode(new Buffer([0x5e, 0x7f, 0xff]), '2.0').should.equal(32767.0); 160 | }); 161 | 162 | it('should read 32 bits float double', function () { 163 | hessian.decode(new Buffer([0x5f, 0x00, 0x00, 0x00, 0x00]), '2.0').should.equal(0.0); 164 | hessian.decode(new Buffer([0x5f, 0x41, 0x44, 0x00, 0x00]), '2.0').should.equal(12.25); 165 | }); 166 | 167 | it('should read normal double', function () { 168 | hessian.decode(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0]), '2.0').should.equal(10.0); 169 | }); 170 | 171 | it('should write 0.0 and 1.0', function () { 172 | hessian.encode(java.double(0), '2.0').should.eql(new Buffer([0x5b])); 173 | hessian.encode(java.double(0.0), '2.0').should.eql(new Buffer([0x5b])); 174 | 175 | hessian.encode(java.double(1), '2.0').should.eql(new Buffer([0x5c])); 176 | hessian.encode(java.double(1.0), '2.0').should.eql(new Buffer([0x5c])); 177 | }); 178 | 179 | it('should write big double', function () { 180 | hessian.encode(java.double(10), '2.0') 181 | .should.eql(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0])); 182 | }); 183 | }); 184 | }); 185 | /*! 186 | * hessian.js - test/double.test.js 187 | * 188 | * Copyright(c) 2014 189 | * MIT Licensed 190 | * 191 | * Authors: 192 | * fengmk2 (http://fengmk2.github.com) 193 | */ 194 | 195 | "use strict"; 196 | 197 | /** 198 | * Module dependencies. 199 | */ 200 | 201 | var should = require('should'); 202 | var java = require('js-to-java'); 203 | var hessian = require('../'); 204 | 205 | describe('double.test.js', function () { 206 | var doubleBuffer = new Buffer(['D'.charCodeAt(0), 207 | 0x40, 0x28, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00]); 208 | 209 | it('should read double 12.25', function () { 210 | hessian.decode(doubleBuffer).should.equal(12.25); 211 | }); 212 | 213 | it('should write double 12.25', function () { 214 | hessian.encode(12.25).should.eql(doubleBuffer); 215 | hessian.encode(java.double(12.25)).should.eql(doubleBuffer); 216 | hessian.encode({ 217 | $class: 'double', 218 | $: 12.25 219 | }).should.eql(doubleBuffer); 220 | }); 221 | 222 | it('should write double 100', function () { 223 | hessian.encode(java.double(100)).should.eql( 224 | new Buffer(['D'.charCodeAt(0), 0x40, 0x59, 0, 0, 0, 0, 0, 0])); 225 | }); 226 | 227 | it('should write double 0', function () { 228 | hessian.encode(java.double(0)).should.eql( 229 | new Buffer(['D'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0])); 230 | }); 231 | 232 | describe('v2.0', function () { 233 | it('should read 0.0 and 1.0', function () { 234 | hessian.decode(new Buffer([0x5b]), '2.0').should.equal(0.0); 235 | hessian.decode(new Buffer([0x5c]), '2.0').should.equal(1.0); 236 | }); 237 | 238 | it('should read 8 bits double', function () { 239 | hessian.decode(new Buffer([0x5d, 0x00]), '2.0').should.equal(0.0); 240 | hessian.decode(new Buffer([0x5d, 0x01]), '2.0').should.equal(1.0); 241 | hessian.decode(new Buffer([0x5d, 0x80]), '2.0').should.equal(-128.0); 242 | hessian.decode(new Buffer([0x5d, 0x7f]), '2.0').should.equal(127.0); 243 | }); 244 | 245 | it('should read 16 bits double', function () { 246 | hessian.decode(new Buffer([0x5e, 0x00, 0x00]), '2.0').should.equal(0.0); 247 | hessian.decode(new Buffer([0x5e, 0x00, 0x01]), '2.0').should.equal(1.0); 248 | hessian.decode(new Buffer([0x5e, 0x00, 0x80]), '2.0').should.equal(128.0); 249 | hessian.decode(new Buffer([0x5e, 0x00, 0x7f]), '2.0').should.equal(127.0); 250 | hessian.decode(new Buffer([0x5e, 0x80, 0x00]), '2.0').should.equal(-32768.0); 251 | hessian.decode(new Buffer([0x5e, 0x7f, 0xff]), '2.0').should.equal(32767.0); 252 | }); 253 | 254 | it('should read 32 bits float double', function () { 255 | hessian.decode(new Buffer([0x5f, 0x00, 0x00, 0x00, 0x00]), '2.0').should.equal(0.0); 256 | hessian.decode(new Buffer([0x5f, 0x41, 0x44, 0x00, 0x00]), '2.0').should.equal(12.25); 257 | }); 258 | 259 | it('should read normal double', function () { 260 | hessian.decode(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0]), '2.0').should.equal(10.0); 261 | }); 262 | 263 | it('should write 0.0 and 1.0', function () { 264 | hessian.encode(java.double(0), '2.0').should.eql(new Buffer([0x5b])); 265 | hessian.encode(java.double(0.0), '2.0').should.eql(new Buffer([0x5b])); 266 | 267 | hessian.encode(java.double(1), '2.0').should.eql(new Buffer([0x5c])); 268 | hessian.encode(java.double(1.0), '2.0').should.eql(new Buffer([0x5c])); 269 | }); 270 | 271 | it('should write big double', function () { 272 | hessian.encode(java.double(10), '2.0') 273 | .should.eql(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0])); 274 | }); 275 | }); 276 | }); 277 | -------------------------------------------------------------------------------- /test/fixtures/v2/string/text4k.bin: -------------------------------------------------------------------------------- 1 | S&/*! 2 | * hessian.js - test/double.test.js 3 | * 4 | * Copyright(c) 2014 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var should = require('should'); 18 | var java = require('js-to-java'); 19 | var hessian = require('../'); 20 | 21 | describe('double.test.js', function () { 22 | var doubleBuffer = new Buffer(['D'.charCodeAt(0), 23 | 0x40, 0x28, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00]); 24 | 25 | it('should read double 12.25', function () { 26 | hessian.decode(doubleBuffer).should.equal(12.25); 27 | }); 28 | 29 | it('should write double 12.25', function () { 30 | hessian.encode(12.25).should.eql(doubleBuffer); 31 | hessian.encode(java.double(12.25)).should.eql(doubleBuffer); 32 | hessian.encode({ 33 | $class: 'double', 34 | $: 12.25 35 | }).should.eql(doubleBuffer); 36 | }); 37 | 38 | it('should write double 100', function () { 39 | hessian.encode(java.double(100)).should.eql( 40 | new Buffer(['D'.charCodeAt(0), 0x40, 0x59, 0, 0, 0, 0, 0, 0])); 41 | }); 42 | 43 | it('should write double 0', function () { 44 | hessian.encode(java.double(0)).should.eql( 45 | new Buffer(['D'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0])); 46 | }); 47 | 48 | describe('v2.0', function () { 49 | it('should read 0.0 and 1.0', function () { 50 | hessian.decode(new Buffer([0x5b]), '2.0').should.equal(0.0); 51 | hessian.decode(new Buffer([0x5c]), '2.0').should.equal(1.0); 52 | }); 53 | 54 | it('should read 8 bits double', function () { 55 | hessian.decode(new Buffer([0x5d, 0x00]), '2.0').should.equal(0.0); 56 | hessian.decode(new Buffer([0x5d, 0x01]), '2.0').should.equal(1.0); 57 | hessian.decode(new Buffer([0x5d, 0x80]), '2.0').should.equal(-128.0); 58 | hessian.decode(new Buffer([0x5d, 0x7f]), '2.0').should.equal(127.0); 59 | }); 60 | 61 | it('should read 16 bits double', function () { 62 | hessian.decode(new Buffer([0x5e, 0x00, 0x00]), '2.0').should.equal(0.0); 63 | hessian.decode(new Buffer([0x5e, 0x00, 0x01]), '2.0').should.equal(1.0); 64 | hessian.decode(new Buffer([0x5e, 0x00, 0x80]), '2.0').should.equal(128.0); 65 | hessian.decode(new Buffer([0x5e, 0x00, 0x7f]), '2.0').should.equal(127.0); 66 | hessian.decode(new Buffer([0x5e, 0x80, 0x00]), '2.0').should.equal(-32768.0); 67 | hessian.decode(new Buffer([0x5e, 0x7f, 0xff]), '2.0').should.equal(32767.0); 68 | }); 69 | 70 | it('should read 32 bits float double', function () { 71 | hessian.decode(new Buffer([0x5f, 0x00, 0x00, 0x00, 0x00]), '2.0').should.equal(0.0); 72 | hessian.decode(new Buffer([0x5f, 0x41, 0x44, 0x00, 0x00]), '2.0').should.equal(12.25); 73 | }); 74 | 75 | it('should read normal double', function () { 76 | hessian.decode(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0]), '2.0').should.equal(10.0); 77 | }); 78 | 79 | it('should write 0.0 and 1.0', function () { 80 | hessian.encode(java.double(0), '2.0').should.eql(new Buffer([0x5b])); 81 | hessian.encode(java.double(0.0), '2.0').should.eql(new Buffer([0x5b])); 82 | 83 | hessian.encode(java.double(1), '2.0').should.eql(new Buffer([0x5c])); 84 | hessian.encode(java.double(1.0), '2.0').should.eql(new Buffer([0x5c])); 85 | }); 86 | 87 | it('should write big double', function () { 88 | hessian.encode(java.double(10), '2.0') 89 | .should.eql(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0])); 90 | }); 91 | }); 92 | }); 93 | /*! 94 | * hessian.js - test/double.test.js 95 | * 96 | * Copyright(c) 2014 97 | * MIT Licensed 98 | * 99 | * Authors: 100 | * fengmk2 (http://fengmk2.github.com) 101 | */ 102 | 103 | "use strict"; 104 | 105 | /** 106 | * Module dependencies. 107 | */ 108 | 109 | var should = require('should'); 110 | var java = require('js-to-java'); 111 | var hessian = require('../'); 112 | 113 | describe('double.test.js', function () { 114 | var doubleBuffer = new Buffer(['D'.charCodeAt(0), 115 | 0x40, 0x28, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00]); 116 | 117 | it('should read double 12.25', function () { 118 | hessian.decode(doubleBuffer).should.equal(12.25); 119 | }); 120 | 121 | it('should write double 12.25', function () { 122 | hessian.encode(12.25).should.eql(doubleBuffer); 123 | hessian.encode(java.double(12.25)).should.eql(doubleBuffer); 124 | hessian.encode({ 125 | $class: 'double', 126 | $: 12.25 127 | }).should.eql(doubleBuffer); 128 | }); 129 | 130 | it('should write double 100', function () { 131 | hessian.encode(java.double(100)).should.eql( 132 | new Buffer(['D'.charCodeAt(0), 0x40, 0x59, 0, 0, 0, 0, 0, 0])); 133 | }); 134 | 135 | it('should write double 0', function () { 136 | hessian.encode(java.double(0)).should.eql( 137 | new Buffer(['D'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0])); 138 | }); 139 | 140 | describe('v2.0', function () { 141 | it('should read 0.0 and 1.0', function () { 142 | hessian.decode(new Buffer([0x5b]), '2.0').should.equal(0.0); 143 | hessian.decode(new Buffer([0x5c]), '2.0').should.equal(1.0); 144 | }); 145 | 146 | it('should read 8 bits double', function () { 147 | hessian.decode(new Buffer([0x5d, 0x00]), '2.0').should.equal(0.0); 148 | hessian.decode(new Buffer([0x5d, 0x01]), '2.0').should.equal(1.0); 149 | hessian.decode(new Buffer([0x5d, 0x80]), '2.0').should.equal(-128.0); 150 | hessian.decode(new Buffer([0x5d, 0x7f]), '2.0').should.equal(127.0); 151 | }); 152 | 153 | it('should read 16 bits double', function () { 154 | hessian.decode(new Buffer([0x5e, 0x00, 0x00]), '2.0').should.equal(0.0); 155 | hessian.decode(new Buffer([0x5e, 0x00, 0x01]), '2.0').should.equal(1.0); 156 | hessian.decode(new Buffer([0x5e, 0x00, 0x80]), '2.0').should.equal(128.0); 157 | hessian.decode(new Buffer([0x5e, 0x00, 0x7f]), '2.0').should.equal(127.0); 158 | hessian.decode(new Buffer([0x5e, 0x80, 0x00]), '2.0').should.equal(-32768.0); 159 | hessian.decode(new Buffer([0x5e, 0x7f, 0xff]), '2.0').should.equal(32767.0); 160 | }); 161 | 162 | it('should read 32 bits float double', function () { 163 | hessian.decode(new Buffer([0x5f, 0x00, 0x00, 0x00, 0x00]), '2.0').should.equal(0.0); 164 | hessian.decode(new Buffer([0x5f, 0x41, 0x44, 0x00, 0x00]), '2.0').should.equal(12.25); 165 | }); 166 | 167 | it('should read normal double', function () { 168 | hessian.decode(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0]), '2.0').should.equal(10.0); 169 | }); 170 | 171 | it('should write 0.0 and 1.0', function () { 172 | hessian.encode(java.double(0), '2.0').should.eql(new Buffer([0x5b])); 173 | hessian.encode(java.double(0.0), '2.0').should.eql(new Buffer([0x5b])); 174 | 175 | hessian.encode(java.double(1), '2.0').should.eql(new Buffer([0x5c])); 176 | hessian.encode(java.double(1.0), '2.0').should.eql(new Buffer([0x5c])); 177 | }); 178 | 179 | it('should write big double', function () { 180 | hessian.encode(java.double(10), '2.0') 181 | .should.eql(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0])); 182 | }); 183 | }); 184 | }); 185 | /*! 186 | * hessian.js - test/double.test.js 187 | * 188 | * Copyright(c) 2014 189 | * MIT Licensed 190 | * 191 | * Authors: 192 | * fengmk2 (http://fengmk2.github.com) 193 | */ 194 | 195 | "use strict"; 196 | 197 | /** 198 | * Module dependencies. 199 | */ 200 | 201 | var should = require('should'); 202 | var java = require('js-to-java'); 203 | var hessian = require('../'); 204 | 205 | describe('double.test.js', function () { 206 | var doubleBuffer = new Buffer(['D'.charCodeAt(0), 207 | 0x40, 0x28, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00]); 208 | 209 | it('should read double 12.25', function () { 210 | hessian.decode(doubleBuffer).should.equal(12.25); 211 | }); 212 | 213 | it('should write double 12.25', function () { 214 | hessian.encode(12.25).should.eql(doubleBuffer); 215 | hessian.encode(java.double(12.25)).should.eql(doubleBuffer); 216 | hessian.encode({ 217 | $class: 'double', 218 | $: 12.25 219 | }).should.eql(doubleBuffer); 220 | }); 221 | 222 | it('should write double 100', function () { 223 | hessian.encode(java.double(100)).should.eql( 224 | new Buffer(['D'.charCodeAt(0), 0x40, 0x59, 0, 0, 0, 0, 0, 0])); 225 | }); 226 | 227 | it('should write double 0', function () { 228 | hessian.encode(java.double(0)).should.eql( 229 | new Buffer(['D'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0])); 230 | }); 231 | 232 | describe('v2.0', function () { 233 | it('should read 0.0 and 1.0', function () { 234 | hessian.decode(new Buffer([0x5b]), '2.0').should.equal(0.0); 235 | hessian.decode(new Buffer([0x5c]), '2.0').should.equal(1.0); 236 | }); 237 | 238 | it('should read 8 bits double', function () { 239 | hessian.decode(new Buffer([0x5d, 0x00]), '2.0').should.equal(0.0); 240 | hessian.decode(new Buffer([0x5d, 0x01]), '2.0').should.equal(1.0); 241 | hessian.decode(new Buffer([0x5d, 0x80]), '2.0').should.equal(-128.0); 242 | hessian.decode(new Buffer([0x5d, 0x7f]), '2.0').should.equal(127.0); 243 | }); 244 | 245 | it('should read 16 bits double', function () { 246 | hessian.decode(new Buffer([0x5e, 0x00, 0x00]), '2.0').should.equal(0.0); 247 | hessian.decode(new Buffer([0x5e, 0x00, 0x01]), '2.0').should.equal(1.0); 248 | hessian.decode(new Buffer([0x5e, 0x00, 0x80]), '2.0').should.equal(128.0); 249 | hessian.decode(new Buffer([0x5e, 0x00, 0x7f]), '2.0').should.equal(127.0); 250 | hessian.decode(new Buffer([0x5e, 0x80, 0x00]), '2.0').should.equal(-32768.0); 251 | hessian.decode(new Buffer([0x5e, 0x7f, 0xff]), '2.0').should.equal(32767.0); 252 | }); 253 | 254 | it('should read 32 bits float double', function () { 255 | hessian.decode(new Buffer([0x5f, 0x00, 0x00, 0x00, 0x00]), '2.0').should.equal(0.0); 256 | hessian.decode(new Buffer([0x5f, 0x41, 0x44, 0x00, 0x00]), '2.0').should.equal(12.25); 257 | }); 258 | 259 | it('should read normal double', function () { 260 | hessian.decode(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0]), '2.0').should.equal(10.0); 261 | }); 262 | 263 | it('should write 0.0 and 1.0', function () { 264 | hessian.encode(java.double(0), '2.0').should.eql(new Buffer([0x5b])); 265 | hessian.encode(java.double(0.0), '2.0').should.eql(new Buffer([0x5b])); 266 | 267 | hessian.encode(java.double(1), '2.0').should.eql(new Buffer([0x5c])); 268 | hessian.encode(java.double(1.0), '2.0').should.eql(new Buffer([0x5c])); 269 | }); 270 | 271 | it('should write big double', function () { 272 | hessian.encode(java.double(10), '2.0') 273 | .should.eql(new Buffer([0x44, 0x40, 0x24, 0, 0, 0, 0, 0, 0])); 274 | }); 275 | }); 276 | }); 277 | -------------------------------------------------------------------------------- /test/int.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * hessian.js - test/int.test.js 3 | * 4 | * Copyright(c) 5 | * MIT Licensed 6 | * 7 | * Authors: 8 | * fengmk2 (http://fengmk2.github.com) 9 | */ 10 | 11 | "use strict"; 12 | 13 | /** 14 | * Module dependencies. 15 | */ 16 | 17 | var should = require('should'); 18 | var hessian = require('../'); 19 | var utils = require('./utils'); 20 | 21 | describe('int.test.js', function () { 22 | it('should read integer 300', function () { 23 | hessian.decode(new Buffer(['I'.charCodeAt(0), 0x00, 0x00, 0x01, 0x2c])).should.equal(300); 24 | }); 25 | 26 | it('should write integer 300', function () { 27 | hessian.encode(300).should.eql(new Buffer(['I'.charCodeAt(0), 0x00, 0x00, 0x01, 0x2c])); 28 | }); 29 | 30 | it('should write integer 0', function () { 31 | hessian.encode(0).should.eql(new Buffer(['I'.charCodeAt(0), 0, 0, 0, 0])); 32 | }); 33 | 34 | it('should write number as java write', function () { 35 | hessian.encode(0, '1.0').should.eql(utils.bytes('v1/number/0')); 36 | hessian.encode(1).should.eql(utils.bytes('v1/number/1')); 37 | hessian.encode(10).should.eql(utils.bytes('v1/number/10')); 38 | hessian.encode(16).should.eql(utils.bytes('v1/number/16')); 39 | hessian.encode(2047).should.eql(utils.bytes('v1/number/2047')); 40 | hessian.encode(255, '1.0').should.eql(utils.bytes('v1/number/255')); 41 | hessian.encode(256, '1.0').should.eql(utils.bytes('v1/number/256')); 42 | hessian.encode(262143, '1.0').should.eql(utils.bytes('v1/number/262143')); 43 | hessian.encode(262144, '1.0').should.eql(utils.bytes('v1/number/262144')); 44 | hessian.encode(46, '1.0').should.eql(utils.bytes('v1/number/46')); 45 | hessian.encode(47, '1.0').should.eql(utils.bytes('v1/number/47')); 46 | 47 | hessian.encode(-16, '1.0').should.eql(utils.bytes('v1/number/-16')); 48 | hessian.encode(-2048, '1.0').should.eql(utils.bytes('v1/number/-2048')); 49 | hessian.encode(-256).should.eql(utils.bytes('v1/number/-256')); 50 | hessian.encode(-262144, '1.0').should.eql(utils.bytes('v1/number/-262144')); 51 | hessian.encode(-262145, '1.0').should.eql(utils.bytes('v1/number/-262145')); 52 | }); 53 | 54 | it('should read java number bin', function () { 55 | hessian.decode(utils.bytes('v1/number/0'), '1.0').should.equal(0); 56 | hessian.decode(utils.bytes('v1/number/1'), '1.0').should.equal(1); 57 | hessian.decode(utils.bytes('v1/number/10'), '1.0').should.equal(10); 58 | hessian.decode(utils.bytes('v1/number/16'), '1.0').should.equal(16); 59 | hessian.decode(utils.bytes('v1/number/2047'), '1.0').should.equal(2047); 60 | hessian.decode(utils.bytes('v1/number/255'), '1.0').should.equal(255); 61 | hessian.decode(utils.bytes('v1/number/256'), '1.0').should.equal(256); 62 | hessian.decode(utils.bytes('v1/number/262143'), '1.0').should.equal(262143); 63 | hessian.decode(utils.bytes('v1/number/262144'), '1.0').should.equal(262144); 64 | hessian.decode(utils.bytes('v1/number/46'), '1.0').should.equal(46); 65 | hessian.decode(utils.bytes('v1/number/47'), '1.0').should.equal(47); 66 | hessian.decode(utils.bytes('v1/number/-16'), '1.0').should.equal(-16); 67 | hessian.decode(utils.bytes('v1/number/-2048'), '1.0').should.equal(-2048); 68 | hessian.decode(utils.bytes('v1/number/-256'), '1.0').should.equal(-256); 69 | hessian.decode(utils.bytes('v1/number/-262144'), '1.0').should.equal(-262144); 70 | hessian.decode(utils.bytes('v1/number/-262145'), '1.0').should.equal(-262145); 71 | }); 72 | 73 | describe('v2.0', function () { 74 | it('should read compact integers', function () { 75 | hessian.decode(new Buffer([0x90]), '2.0').should.equal(0); 76 | hessian.decode(new Buffer([0x80]), '2.0').should.equal(-16); 77 | hessian.decode(new Buffer([0xbf]), '2.0').should.equal(47); 78 | 79 | hessian.decode(new Buffer([0xc8, 0x00]), '2.0').should.equal(0); 80 | hessian.decode(new Buffer([0xc0, 0x00]), '2.0').should.equal(-2048); 81 | hessian.decode(new Buffer([0xc7, 0x00]), '2.0').should.equal(-256); 82 | hessian.decode(new Buffer([0xcf, 0xff]), '2.0').should.equal(2047); 83 | 84 | hessian.decode(new Buffer([0xd4, 0x00, 0x00]), '2.0').should.equal(0); 85 | hessian.decode(new Buffer([0xd0, 0x00, 0x00]), '2.0').should.equal(-262144); 86 | hessian.decode(new Buffer([0xd7, 0xff, 0xff]), '2.0').should.equal(262143); 87 | 88 | hessian.decode(new Buffer(['I'.charCodeAt(0), 0x00, 0x00, 0x00, 0x00]), '2.0').should.equal(0); 89 | hessian.decode(new Buffer(['I'.charCodeAt(0), 0x00, 0x00, 0x01, 0x2c]), '2.0').should.equal(300); 90 | }); 91 | 92 | it('should write number as java write', function () { 93 | hessian.encode(0, '2.0').should.eql(utils.bytes('v2/number/0')); 94 | hessian.encode(1, '2.0').should.eql(utils.bytes('v2/number/1')); 95 | hessian.encode(10, '2.0').should.eql(utils.bytes('v2/number/10')); 96 | hessian.encode(16, '2.0').should.eql(utils.bytes('v2/number/16')); 97 | hessian.encode(2047, '2.0').should.eql(utils.bytes('v2/number/2047')); 98 | hessian.encode(255, '2.0').should.eql(utils.bytes('v2/number/255')); 99 | hessian.encode(256, '2.0').should.eql(utils.bytes('v2/number/256')); 100 | hessian.encode(262143, '2.0').should.eql(utils.bytes('v2/number/262143')); 101 | hessian.encode(262144, '2.0').should.eql(utils.bytes('v2/number/262144')); 102 | hessian.encode(46, '2.0').should.eql(utils.bytes('v2/number/46')); 103 | hessian.encode(47, '2.0').should.eql(utils.bytes('v2/number/47')); 104 | hessian.encode(-16, '2.0').should.eql(utils.bytes('v2/number/-16')); 105 | hessian.encode(-2048, '2.0').should.eql(utils.bytes('v2/number/-2048')); 106 | hessian.encode(-256, '2.0').should.eql(utils.bytes('v2/number/-256')); 107 | hessian.encode(-262144, '2.0').should.eql(utils.bytes('v2/number/-262144')); 108 | hessian.encode(-262145, '2.0').should.eql(utils.bytes('v2/number/-262145')); 109 | }); 110 | 111 | it('should read java number bin', function () { 112 | hessian.decode(utils.bytes('v2/number/0'), '2.0').should.equal(0); 113 | hessian.decode(utils.bytes('v2/number/1'), '2.0').should.equal(1); 114 | hessian.decode(utils.bytes('v2/number/10'), '2.0').should.equal(10); 115 | hessian.decode(utils.bytes('v2/number/16'), '2.0').should.equal(16); 116 | hessian.decode(utils.bytes('v2/number/2047'), '2.0').should.equal(2047); 117 | hessian.decode(utils.bytes('v2/number/255'), '2.0').should.equal(255); 118 | hessian.decode(utils.bytes('v2/number/256'), '2.0').should.equal(256); 119 | hessian.decode(utils.bytes('v2/number/262143'), '2.0').should.equal(262143); 120 | hessian.decode(utils.bytes('v2/number/262144'), '2.0').should.equal(262144); 121 | hessian.decode(utils.bytes('v2/number/46'), '2.0').should.equal(46); 122 | hessian.decode(utils.bytes('v2/number/47'), '2.0').should.equal(47); 123 | hessian.decode(utils.bytes('v2/number/-16'), '2.0').should.equal(-16); 124 | hessian.decode(utils.bytes('v2/number/-2048'), '2.0').should.equal(-2048); 125 | hessian.decode(utils.bytes('v2/number/-256'), '2.0').should.equal(-256); 126 | hessian.decode(utils.bytes('v2/number/-262144'), '2.0').should.equal(-262144); 127 | hessian.decode(utils.bytes('v2/number/-262145'), '2.0').should.equal(-262145); 128 | }); 129 | 130 | it('should read hessian 1.0 number bin', function () { 131 | hessian.decode(utils.bytes('v1/number/0'), '2.0').should.equal(0); 132 | hessian.decode(utils.bytes('v1/number/1'), '2.0').should.equal(1); 133 | hessian.decode(utils.bytes('v1/number/10'), '2.0').should.equal(10); 134 | hessian.decode(utils.bytes('v1/number/16'), '2.0').should.equal(16); 135 | hessian.decode(utils.bytes('v1/number/2047'), '2.0').should.equal(2047); 136 | hessian.decode(utils.bytes('v1/number/255'), '2.0').should.equal(255); 137 | hessian.decode(utils.bytes('v1/number/256'), '2.0').should.equal(256); 138 | hessian.decode(utils.bytes('v1/number/262143'), '2.0').should.equal(262143); 139 | hessian.decode(utils.bytes('v1/number/262144'), '2.0').should.equal(262144); 140 | hessian.decode(utils.bytes('v1/number/46'), '2.0').should.equal(46); 141 | hessian.decode(utils.bytes('v1/number/47'), '2.0').should.equal(47); 142 | hessian.decode(utils.bytes('v1/number/-16'), '2.0').should.equal(-16); 143 | hessian.decode(utils.bytes('v1/number/-2048'), '2.0').should.equal(-2048); 144 | hessian.decode(utils.bytes('v1/number/-256'), '2.0').should.equal(-256); 145 | hessian.decode(utils.bytes('v1/number/-262144'), '2.0').should.equal(-262144); 146 | hessian.decode(utils.bytes('v1/number/-262145'), '2.0').should.equal(-262145); 147 | }); 148 | 149 | it('should write compact integers', function () { 150 | // -16 ~ 47 151 | var buf = hessian.encode(0, '2.0'); 152 | buf.should.length(1); 153 | buf[0].should.equal(0x90); 154 | buf.should.eql(new Buffer([0x90])); 155 | 156 | buf = hessian.encode(1, '2.0'); 157 | buf.should.length(1); 158 | buf[0].should.equal(0x91); 159 | buf.should.eql(new Buffer([0x91])); 160 | 161 | buf = hessian.encode(-16, '2.0'); 162 | buf.should.length(1); 163 | buf[0].should.equal(0x80); 164 | buf.should.eql(new Buffer([0x80])); 165 | 166 | buf = hessian.encode(46, '2.0'); 167 | buf.should.length(1); 168 | buf[0].should.equal(0xbe); 169 | buf.should.eql(new Buffer([0xbe])); 170 | 171 | buf = hessian.encode(47, '2.0'); 172 | buf.should.length(1); 173 | buf[0].should.equal(0xbf); 174 | buf.should.eql(new Buffer([0xbf])); 175 | 176 | // -2048 ~ 2047 177 | buf = hessian.encode(-2048, '2.0'); 178 | buf.should.length(2); 179 | buf[0].should.equal(0xc0); 180 | buf[1].should.equal(0x00); 181 | buf.should.eql(new Buffer([0xc0, 0x00])); 182 | 183 | buf = hessian.encode(-256, '2.0'); 184 | buf.should.length(2); 185 | buf[0].should.equal(0xc7); 186 | buf[1].should.equal(0x00); 187 | buf.should.eql(new Buffer([0xc7, 0x00])); 188 | 189 | buf = hessian.encode(255, '2.0'); 190 | buf.should.length(2); 191 | buf[0].should.equal(0xc8); 192 | buf[1].should.equal(0xff); 193 | buf.should.eql(new Buffer([0xc8, 0xff])); 194 | 195 | buf = hessian.encode(256, '2.0'); 196 | buf.should.length(2); 197 | buf[0].should.equal(0xc9); 198 | buf[1].should.equal(0x00); 199 | buf.should.eql(new Buffer([0xc9, 0x00])); 200 | 201 | buf = hessian.encode(2047, '2.0'); 202 | buf.should.length(2); 203 | buf[0].should.equal(0xcf); 204 | buf[1].should.equal(0xff); 205 | buf.should.eql(new Buffer([0xcf, 0xff])); 206 | 207 | // -262144 ~ 262143 208 | buf = hessian.encode(-262144, '2.0'); 209 | buf.should.length(3); 210 | buf[0].should.equal(0xd0); 211 | buf[1].should.equal(0x00); 212 | buf[2].should.equal(0x00); 213 | buf.should.eql(new Buffer([0xd0, 0x00, 0x00])); 214 | 215 | buf = hessian.encode(262143, '2.0'); 216 | buf.should.length(3); 217 | buf[0].should.equal(0xd7); 218 | buf[1].should.equal(0xff); 219 | buf[2].should.equal(0xff); 220 | buf.should.eql(new Buffer([0xd7, 0xff, 0xff])); 221 | 222 | // 262144 223 | buf = hessian.encode(262144, '2.0'); 224 | buf.should.length(5); 225 | buf[0].should.equal('I'.charCodeAt(0)); 226 | buf[1].should.equal(0x00); 227 | buf[2].should.equal(0x04); 228 | buf[3].should.equal(0x00); 229 | buf[4].should.equal(0x00); 230 | buf.should.eql(new Buffer(['I'.charCodeAt(0), 0x00, 0x04, 0x00, 0x00])); 231 | 232 | buf = hessian.encode(-262145, '2.0'); 233 | buf.should.length(5); 234 | buf[0].should.equal('I'.charCodeAt(0)); 235 | buf[1].should.equal(0xff); 236 | buf[2].should.equal(0xfb); 237 | buf[3].should.equal(0xff); 238 | buf[4].should.equal(0xff); 239 | buf.should.eql(new Buffer(['I'.charCodeAt(0), 0xff, 0xfb, 0xff, 0xff])); 240 | }); 241 | }); 242 | }); 243 | --------------------------------------------------------------------------------