# sofa-hessian-node

> An internal improved version of Hessian powered by Ant Financial.

Latest version **2.2.1** (published 2023-07-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install sofa-hessian-node
pnpm add sofa-hessian-node
yarn add sofa-hessian-node
bun add sofa-hessian-node
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2023-07-28 |
| First published | 2018-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 10.0.0 |
| Dependencies | 4 |
| Unpacked size | 67.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | gxcsoccer |
| Maintainers | gxcsoccer, coolme200, popomore, killagu, mansonchor.zzw |
| Keywords | hessian, nodejs, sofa |

## Links

- npm: https://www.npmjs.com/package/sofa-hessian-node
- Repository: https://github.com/alipay/sofa-hessian-node
- Homepage: https://github.com/alipay/sofa-hessian-node#readme
- Issues: https://github.com/alipay/sofa-hessian-node/issues
- npm.io page: https://npm.io/package/sofa-hessian-node

## Dependencies (4)

- [utility](https://npm.io/package/utility.md) ^1.16.3
- [hessian.js](https://npm.io/package/hessian.js.md) ^2.10.0
- [hessian.js-1](https://npm.io/package/hessian.js-1.md) ^1.9.1
- [@protobufjs/codegen](https://npm.io/package/@protobufjs/codegen.md) ^2.0.4

## Recent versions

- 2.2.1 (latest) — 2023-07-28
- 1.9.2 (latest-1) — 2021-12-15
- 1.9.1-beta3 (beta) — 2021-05-19
- 2.2.0 — 2022-03-13
- 1.9.1 — 2021-05-20
- 1.9.1-beta2 — 2021-05-19
- 1.9.1-beta1 — 2021-05-19
- 1.9.0 — 2020-11-12
- 1.8.2 — 2020-10-29
- 1.8.1 — 2020-09-21
- 2.1.0 — 2020-07-01
- 2.0.0 — 2020-06-16
- 1.8.0 — 2020-05-13
- 1.7.1 — 2020-03-30
- 1.7.0 — 2020-02-25
- … 20 more at https://npm.io/package/sofa-hessian-node/versions

## README

# sofa-hessian-node
蚂蚁金服对 Hessian 序列化的定制版本

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/sofa-hessian-node.svg?style=flat-square
[npm-url]: https://npmjs.org/package/sofa-hessian-node
[travis-image]: https://img.shields.io/travis/alipay/sofa-hessian-node.svg?style=flat-square
[travis-url]: https://travis-ci.org/alipay/sofa-hessian-node
[codecov-image]: https://codecov.io/gh/alipay/sofa-hessian-node/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/alipay/sofa-hessian-node
[david-image]: https://img.shields.io/david/alipay/sofa-hessian-node.svg?style=flat-square
[david-url]: https://david-dm.org/alipay/sofa-hessian-node
[snyk-image]: https://snyk.io/test/npm/sofa-hessian-node/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/sofa-hessian-node
[download-image]: https://img.shields.io/npm/dm/sofa-hessian-node.svg?style=flat-square
[download-url]: https://npmjs.org/package/sofa-hessian-node

sofa-hessian-node 对应的 Java Hessian 版本是 v3.1.3。它对 [hessian.js-1](https://www.npmjs.org/package/hessian.js-1) 模块做了进一步封装，通过预编译来提高性能。

## 安装

```bash
$ npm install sofa-hessian-node --save
```

## 示例

```js
'use strict';

// classMap 是要序列化类的定义
const classMap = {
  'com.alipay.test.sub.TestObj2': {
    name: {
      type: 'java.lang.String',
    },
    transientField: {
      type: 'java.lang.String',
      isTransient: true,
    },
    finalField: {
      type: 'java.lang.String',
      defaultValue: 'xxx',
    },
    staticField: {
      type: 'java.lang.String',
      isStatic: true,
    },
  },
};

const encode = require('sofa-hessian-node').encode;

const buf = encode({
  $class: 'com.alipay.test.sub.TestObj2',
  $: { name: 'gxcsoccer' },
}, '2.0', classMap);

console.log(buf.toString('hex'));
// 4fac636f6d2e616c697061792e746573742e7375622e546573744f626a3292046e616d650a66696e616c4669656c646f9009677863736f6363657203787878
```

## hessian 4 支持

```js
const { v4 } = require('sofa-hessian-node');

const buf = v4.encode({
  $class: 'com.alipay.test.sub.TestObj2',
  $: { name: 'gxcsoccer' },
}, '2.0', classMap);

console.log(buf.toString('hex'));
```

## 性能数据

从 [benchmark](benchmark/index.js) 看，相比于直接使用 hessian.js-1，sofa-hessian-node 性能有非常明显的提高（特别是针对复杂对象的场景）

```bash
  node version: v10.0.0, date: Wed Jun 27 2018 23:17:47 GMT+0800 (CST)
  Starting...
  4 tests completed.

  hessian old - 1.0 x  47,719 ops/sec ±2.57% (86 runs sampled)
  hessian new - 1.0 x 246,812 ops/sec ±2.76% (87 runs sampled)
  hessian old - 2.0 x  78,132 ops/sec ±2.49% (84 runs sampled)
  hessian new - 2.0 x 372,090 ops/sec ±2.99% (87 runs sampled)
```

## 如何贡献

请告知我们可以为你做些什么，不过在此之前，请检查一下是否有已经[存在的Bug或者意见](https://github.com/alipay/sofa-hessian-node/issues)。

如果你是一个代码贡献者，请参考[代码贡献规范](https://github.com/eggjs/egg/blob/master/CONTRIBUTING.zh-CN.md)。

## 开源协议

[MIT](LICENSE)

---
_Source: https://npm.io/package/sofa-hessian-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
