Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/naokikimura/msgpack-rpc-lite
Implementation of MessagePack-RPC with msgpack-lite
https://github.com/naokikimura/msgpack-rpc-lite
messagepack messagepack-rpc msgpack msgpack-lite msgpack-rpc msgpackrpc
Last synced: 5 days ago
JSON representation
Implementation of MessagePack-RPC with msgpack-lite
- Host: GitHub
- URL: https://github.com/naokikimura/msgpack-rpc-lite
- Owner: naokikimura
- License: mit
- Created: 2018-02-10T04:10:05.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T17:52:37.000Z (about 2 years ago)
- Last Synced: 2024-11-29T01:19:22.100Z (24 days ago)
- Topics: messagepack, messagepack-rpc, msgpack, msgpack-lite, msgpack-rpc, msgpackrpc
- Language: TypeScript
- Homepage:
- Size: 236 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# msgpack-rpc-lite
[![npm version](https://badge.fury.io/js/msgpack-rpc-lite.svg)](https://badge.fury.io/js/msgpack-rpc-lite)
[![Build Status](https://travis-ci.org/naokikimura/msgpack-rpc-lite.svg?branch=master)](https://travis-ci.org/naokikimura/msgpack-rpc-lite)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/85c5e44e31da475ebcaae8f1b79de7c8)](https://app.codacy.com/app/n.kimura.cap/msgpack-rpc-lite?utm_source=github.com&utm_medium=referral&utm_content=naokikimura/msgpack-rpc-lite&utm_campaign=badger)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/5a32022009694006ab61191e243e569f)](https://www.codacy.com/app/n.kimura.cap/msgpack-rpc-lite?utm_source=github.com&utm_medium=referral&utm_content=naokikimura/msgpack-rpc-lite&utm_campaign=Badge_Coverage)
[![codecov](https://codecov.io/gh/naokikimura/msgpack-rpc-lite/branch/master/graph/badge.svg)](https://codecov.io/gh/naokikimura/msgpack-rpc-lite)
[![Known Vulnerabilities](https://snyk.io/test/github/naokikimura/msgpack-rpc-lite/badge.svg?targetFile=package.json)](https://snyk.io/test/github/naokikimura/msgpack-rpc-lite?targetFile=package.json)Implementation of MessagePack-RPC with msgpack-lite
## Usage ##
- __createServer([*serverOptions*][, *codecOptions*])__
Creates a new MessagePack-RPC server.
- `serverOptions` <Object> See [net.createServer([options][, connectionListener])](https://nodejs.org/api/net.html#net_net_createserver_options_connectionlistener)
- `codecOptions` <Object>
- `encode` See [Custom Codec Options][1]
- `decode` See [Custom Codec Options][1]
- Returns: <net.Server>- __Server event: *method*__
Emitted when a new connection is made.
- <Array> request parameters.
- <Function> If a request is received, a callback function is passed.
- To return the results to the client, pass `null` as the first argument and response parameters as the second argument.
- If an error occurs, pass it to the first argument.- __createClient(*port*[, *host*][, *timeout*][, *codecOptions*])__
Initiates a MessagePack-RPC client.
- `port` <number> Port the socket should connect to.
- `host` <string> Host the socket should connect to. Default: `'localhost'`
- `timeout` <number> Sets the socket to timeout after timeout milliseconds of inactivity on the socket. If timeout is 0, then the existing idle timeout is disabled. Default: `0`
- `codecOptions` <Object>
- `encode` See [Custom Codec Options][1]
- `decode` See [Custom Codec Options][1]
- Return: <Client>- __client.request(*method*[, *...args*])__
- `method` <string>
- Return: <Promise>- __client.notify(*method*[, *...args*])__
- `method` <string>
- Return: <Promise>[1]: https://github.com/kawanet/msgpack-lite#custom-codec-options
## Examples ##
- Server
```js
const rpc = require('msgpack-rpc-lite');
const server = rpc.createServer().on('say', (params, callback) => {
const [ message ] = params;
callback(null, `hello ${ message }`);
});
server.listen(9199);
```- Client
```js
const rpc = require('msgpack-rpc-lite');const client = rpc.createClient(9199, 'localhost');
client.request('say', [ 'world' ]).then(([ response ]) => {
console.log(response); // hello world
})
```## Compatibility Mode ##
Set `true` to `useraw` of `encode`/`decode` of Codec-options.
- Client
```js
const codecOptions = { encode: { useraw: true }, decode: { useraw: true } };const client = rpc.createClient(9199, 'localhost', 0, codecOptions);
```See also:
- https://github.com/kawanet/msgpack-lite#compatibility-mode
- https://github.com/msgpack/msgpack/blob/master/spec.md#upgrading-messagepack-specification## See also ##
- [MessagePack-RPC Specification](https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md)
- http://frsyuki.hatenablog.com/entry/20100406/p1
- [MessagePack specification](https://github.com/msgpack/msgpack/blob/master/spec.md)
- [msgpack-lite](https://github.com/kawanet/msgpack-lite)