https://github.com/eleme/node-thrift-protocol
An implementation of thrift-protocol with node.
https://github.com/eleme/node-thrift-protocol
Last synced: 6 months ago
JSON representation
An implementation of thrift-protocol with node.
- Host: GitHub
- URL: https://github.com/eleme/node-thrift-protocol
- Owner: eleme
- License: mit
- Created: 2016-06-08T00:57:53.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-27T03:20:17.000Z (almost 9 years ago)
- Last Synced: 2025-06-12T04:48:26.940Z (7 months ago)
- Language: JavaScript
- Size: 40 KB
- Stars: 18
- Watchers: 13
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
## node-thrift-protocol
An implementation of thrift-protocol with node.
### Demo
```javascript
let Thrift = require('node-thrift-protocol');
/* Server */
let server = Thrift.createServer(thrift => {
thrift.on('data', message => {
let { name, id, type } = message;
thrift.write({
name,
id,
type: 'REPLY',
fields: [
{ id: 0, type: 'BOOL', value: true }
]
});
});
}).listen(8101);
/* Client */
let thrift = Thrift.connect({
port: 8101,
host: '127.0.0.1'
});
thrift.write({
name: 'ping',
type: 'CALL',
id: 1
});
thrift.on('data', message => {
let { id, name, type, fields } = message;
fields.forEach(item => {
let { id, type, value } = item;
});
});
```
### Usage
#### class Thrift extends stream.Duplex { ... }
This class is used to crate a thrift or local server.
##### Thrift.createServer([options]);
Creates a new server. The connectionListener argument is automatically set as a listener for the 'connection' event.
`options` is an object as net.createServer in net module.
returns `socket`.
##### Thrift.connect(options[, callback]);
Opens the connection for a given socket.
`options` is an object as net.connect in net module.
return `thrift`.
##### new Thrift(socket);
Construct a new `thrift` object with a `socket`.
### Protocol
[thrift-protocol.txt](thrift-protocol.txt)