Gathering detailed insights and metrics for hessian.js-1
Gathering detailed insights and metrics for hessian.js-1
npm install hessian.js-1
Typescript
Module System
Min. Node Version
Node Version
NPM Version
74.4
Supply Chain
97.8
Quality
83.4
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
48,008
Last Day
14
Last Week
89
Last Month
503
Last Year
8,947
185 Stars
234 Commits
29 Forks
20 Watching
18 Branches
25 Contributors
Minified
Minified + Gzipped
Latest Version
1.12.2
Package Id
hessian.js-1@1.12.2
Unpacked Size
175.28 kB
Size
42.12 kB
File Count
24
NPM Version
8.19.4
Node Version
16.20.2
Publised On
05 Aug 2024
Cumulative downloads
Total Downloads
Last day
-26.3%
14
Compared to previous day
Last week
-24.6%
89
Compared to previous week
Last month
5%
503
Compared to previous month
Last year
70.2%
8,947
Compared to previous year
Hessian Serialization 1.0 and 2.0 (base on version com.caucho/hessian/3.1.3) written by pure JavaScript. Support all kind of types in Java, with high performance.
1$ npm install hessian.js-1 --save
8 primitive types:
3 recursive types:
list
for lists and arraysmap
for maps and dictionariesobject
for objectsone special contruct:
Hessian 2.0 has 3 internal reference maps:
Tips: you can use with js-to-java to help you write java class in js.
1var hessian = require('hessian.js-1'); 2var java = require('js-to-java'); 3var encoder = new hessian.Encoder(); 4 5encoder.write(1); // int 6encoder.write(1.1); // double 7encoder.write(1e100); // double 8encoder.write(Math.pow(2, 18)); // long 9encoder.write(true); // boolean 10encoder.write(null); // null 11encoder.write('test'); // string 12 13// java base types 14encoder.write(java.long(3001010320)); // 3001010320L 15encoder.write(java.double(100)); // double 16encoder.write(java.array.int([0, 1, 2])); // int[] = {0, 1, 2} 17 18var object = {}; 19object.prop1 = [1, 2, 3]; 20object.prop2 = 'string'; 21object.prop3 = {key: 'value'}; 22object.prop4 = object; // circular 23encoder.write(object); // object
1var hessian = require('hessian.js-1'); 2var encoder = new hessian.Encoder(); 3 4var long = { 5 $class: 'java.lang.Long', 6 $: 1 7} 8encoder.write(long); // long type 9 10var testObject = { 11 $class: 'com.hessian.TestObject', 12 $: { 13 a: 1, 14 b: 'test', 15 c: {$class: 'java.lang.Long', $: 123} 16 } 17}; 18encoder.write(testObject);
If a type of Class contains a plurality of data, you must ensure that the number of attributes, and each instance of the order is the same!
1// Wrong 2[ 3 {$class: 'com.X', $: {a: 1, b: 2}}, 4 {$class: 'com.X', $: {b: 22, a: 11}}, 5 {$class: 'com.X', $: {a: 1, b: 2, c: 3}}] 6 7// Right 8[ 9 {$class: 'com.X', $: {a: 1, b: 2, c: 0}}, 10 {$class: 'com.X', $: {a: 11, b: 22, c: 0}}, 11 {$class: 'com.X', $: {a: 1, b: 2, c: 3}}, 12]
You need to declare a custom Map type with isMap property
1var hessian = require('hessian.js-1'); 2var encoder = new hessian.Encoder(); 3 4var document = { 5 $class: 'org.bson.Document', 6 $: { 7 _id: { 8 $class: 'org.bson.Document', 9 $: { 10 $in: [ 11 '5bd6a201c816e527d97cb1ad', 12 ], 13 }, 14 isMap: true, // mark it as a Map 15 }, 16 }, 17 isMap: true, // mark it as a Map 18}; 19 20encoder.write(document);
1var hessian = require('hessian.js-1'); 2var decoder = new hessian.Decoder(buf); 3 4decoder.read(); //return what it is 5decoder.readNull(); 6decoder.readBool(); 7decoder.readInt(); 8decoder.readLong(); 9decoder.readDouble(); 10decoder.readDate(); 11decoder.readObect(); 12decoder.readMap(); 13decoder.readArray(); 14decoder.readList(); 15decoder.readRef();
hessian 1.0:
1var hessian = require('hessian.js-1'); 2 3var testObject = { 4 a: 1, 5 b: 'string', 6 c: true, 7 d: 1.1, 8 e: Math.pow(2, 40), 9 f: [1, 2, 3, '4', true, 5], 10 g: {a: 1, b: true, c: 'string'} 11}; 12 13var buf; 14try { 15 buf = hessian.encode(testObject); 16} catch (err) { 17 console.log('encode error: ', err.message); 18 process.exit(1); 19} 20 21try { 22 var res = hessian.decode(buf); 23 // res.should.eql(testObject); 24} catch (err) { 25 console.log('decode error: ', err.message); 26}
hessian 2.0:
1var hessian = require('hessian.js-1'); 2 3var testObject = { 4 a: 1, 5 b: 'string', 6 c: true, 7 d: 1.1, 8 e: Math.pow(2, 40), 9 f: [1, 2, 3, '4', true, 5], 10 g: {a: 1, b: true, c: 'string'} 11}; 12 13var buf; 14try { 15 buf = hessian.encode(testObject, '2.0'); 16} catch (err) { 17 console.log('encode error: ', err.message); 18 process.exit(1); 19} 20 21try { 22 var res = hessian.decode(buf, '2.0'); 23 // res.should.eql(testObject); 24} catch (err) { 25 console.log('decode error: ', err.message); 26}
R
meaning ref
on 1.0, but x52 ('R')
represents any non-final string chunk on 2.0 # starting production
top ::= value
# 8-bit binary data split into 64k chunks
binary ::= x41 b1 b0 <binary-data> binary # non-final chunk
::= 'B' b1 b0 <binary-data> # final chunk
::= [x20-x2f] <binary-data> # binary data of
# length 0-15
::= [x34-x37] <binary-data> # binary data of
# length 0-1023
# boolean true/false
boolean ::= 'T'
::= 'F'
# definition for an object (compact map)
class-def ::= 'C' string int string*
# time in UTC encoded as 64-bit long milliseconds since
# epoch
date ::= x4a b7 b6 b5 b4 b3 b2 b1 b0
::= x4b b3 b2 b1 b0 # minutes since epoch
# 64-bit IEEE double
double ::= 'D' b7 b6 b5 b4 b3 b2 b1 b0
::= x5b # 0.0
::= x5c # 1.0
::= x5d b0 # byte cast to double
# (-128.0 to 127.0)
::= x5e b1 b0 # short cast to double
::= x5f b3 b2 b1 b0 # 32-bit float cast to double
# 32-bit signed integer
int ::= 'I' b3 b2 b1 b0
::= [x80-xbf] # -x10 to x3f
::= [xc0-xcf] b0 # -x800 to x7ff
::= [xd0-xd7] b1 b0 # -x40000 to x3ffff
# list/vector
list ::= x55 type value* 'Z' # variable-length list
::= 'V' type int value* # fixed-length list
::= x57 value* 'Z' # variable-length untyped list
::= x58 int value* # fixed-length untyped list
::= [x70-77] type value* # fixed-length typed list
::= [x78-7f] value* # fixed-length untyped list
# 64-bit signed long integer
long ::= 'L' b7 b6 b5 b4 b3 b2 b1 b0
::= [xd8-xef] # -x08 to x0f
::= [xf0-xff] b0 # -x800 to x7ff
::= [x38-x3f] b1 b0 # -x40000 to x3ffff
::= x59 b3 b2 b1 b0 # 32-bit integer cast to long
# map/object
map ::= 'M' type (value value)* 'Z' # key, value map pairs
::= 'H' (value value)* 'Z' # untyped key, value
# null value
null ::= 'N'
# Object instance
object ::= 'O' int value*
::= [x60-x6f] value*
# value reference (e.g. circular trees and graphs)
ref ::= x51 int # reference to nth map/list/object
# UTF-8 encoded character string split into 64k chunks
string ::= x52 b1 b0 <utf8-data> string # non-final chunk
::= 'S' b1 b0 <utf8-data> # string of length
# 0-65535
::= [x00-x1f] <utf8-data> # string of length
# 0-31
::= [x30-x34] <utf8-data> # string of length
# 0-1023
# map/list types for OO languages
type ::= string # type name
::= int # type reference
# main production
value ::= null
::= binary
::= boolean
::= class-def value
::= date
::= double
::= int
::= list
::= long
::= map
::= object
::= ref
::= string
Hessian 2.0 is organized as a bytecode protocol. A Hessian reader is essentially a switch statement on the initial octet.
x00 - x1f # utf-8 string length 0-32
x20 - x2f # binary data length 0-16
x30 - x33 # utf-8 string length 0-1023
x34 - x37 # binary data length 0-1023
x38 - x3f # three-octet compact long (-x40000 to x3ffff)
x40 # reserved (expansion/escape)
x41 # 8-bit binary data non-final chunk ('A')
x42 # 8-bit binary data final chunk ('B')
x43 # object type definition ('C')
x44 # 64-bit IEEE encoded double ('D')
x45 # reserved
x46 # boolean false ('F')
x47 # reserved
x48 # untyped map ('H')
x49 # 32-bit signed integer ('I')
x4a # 64-bit UTC millisecond date
x4b # 32-bit UTC minute date
x4c # 64-bit signed long integer ('L')
x4d # map with type ('M')
x4e # null ('N')
x4f # object instance ('O')
x50 # reserved
x51 # reference to map/list/object - integer ('Q')
x52 # utf-8 string non-final chunk ('R')
x53 # utf-8 string final chunk ('S')
x54 # boolean true ('T')
x55 # variable-length list/vector ('U')
x56 # fixed-length list/vector ('V')
x57 # variable-length untyped list/vector ('W')
x58 # fixed-length untyped list/vector ('X')
x59 # long encoded as 32-bit int ('Y')
x5a # list/map terminator ('Z')
x5b # double 0.0
x5c # double 1.0
x5d # double represented as byte (-128.0 to 127.0)
x5e # double represented as short (-32768.0 to 327676.0)
x5f # double represented as float
x60 - x6f # object with direct type (` ... n, o)
x70 - x77 # fixed list with direct length (p, q, r, s, t, u, v, w)
x78 - x7f # fixed untyped list with direct length (x, y, z, {, |, }, ~, .....)
x80 - xbf # one-octet compact int (-x10 to x3f, x90 is 0)
xc0 - xcf # two-octet compact int (-x800 to x7ff)
xd0 - xd7 # three-octet compact int (-x40000 to x3ffff)
xd8 - xef # one-octet compact long (-x8 to xf, xe0 is 0)
xf0 - xff # two-octet compact long (-x800 to x7ff, xf8 is 0)
fengmk2 | shaoshuai0102 | leoner | gxcsoccer |
---|
This project follows the git-contributor spec, auto updated at Fri May 24 2024 14:10:28 GMT+0800
.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
Found 9/30 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More