Skip to content

Commit

Permalink
msg-ext library separated
Browse files Browse the repository at this point in the history
  • Loading branch information
kawanet committed Oct 18, 2018
1 parent 2ac5e41 commit f4b2a3f
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 579 deletions.
3 changes: 1 addition & 2 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*~
node_modules
test/[123]*.js
test/95.*.js
test/10.*.js
60 changes: 0 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,66 +41,6 @@ declare function msgToBuffer(msg: MsgInterface): Buffer;

- `Msg` is the abstract class for msgpack container classes.

### `MsgExt` class

- `MsgExt` is the base class for msgpack's ext formats.

`MsgExt` in ES6:

```js
import {MsgExt, msgToBuffer} from "msg-interface";

class MsgExtDate extends MsgExt {
static from(date) {
const payload = Buffer.alloc(8);
payload.writeDoubleBE(+date, 0);
return new MsgExtDate(payload);
}

toDate() {
return new Date(this.buffer.readDoubleBE(0));
}
}

MsgExtDate.prototype.type = 0x0D;

const now = Date.UTC(2018, 0, 2, 3, 4, 5);
const msg = MsgExtDate.from(now);
const buffer = msgToBuffer(msg); // => <Buffer d7 01 42 76 15 28 a3 60 80 00>
const dt = msg.toDate(); // => 2018-01-02T03:04:05.000Z
```

`MsgExt` in ES5:

```js
var MsgInterface = require("msg-interface");
var MsgExt = MsgInterface.MsgExt;
var msgToBuffer = MsgInterface.msgToBuffer;

function MsgExtDate(payload) {
MsgExt.call(this, payload);
}

MsgExtDate.from = function(date) {
var payload = Buffer.alloc(8);
payload.writeDoubleBE(+date, 0);
return new MsgExtDate(payload);
};

MsgExtDate.prototype = Object.create(MsgExt.prototype);

MsgExtDate.prototype.type = 0x0D;

MsgExtDate.prototype.toDate = function() {
return new Date(this.buffer.readDoubleBE(0));
};

var now = Date.UTC(2018, 0, 2, 3, 4, 5);
var msg = MsgExtDate.from(now);
var buffer = msgToBuffer(msg); // => <Buffer d7 01 42 76 15 28 a3 60 80 00>
var dt = msg.toDate(); // => 2018-01-02T03:04:05.000Z
```

### GitHub

- [https://github.com/kawanet/msg-interface](https://github.com/kawanet/msg-interface)
Expand Down
111 changes: 0 additions & 111 deletions lib/msg-ext.js

This file was deleted.

24 changes: 0 additions & 24 deletions lib/msg.js

This file was deleted.

15 changes: 0 additions & 15 deletions typings/msg-interface.d.ts → msg-interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,3 @@ export declare abstract class Msg implements MsgInterface {
*/
writeMsgpackTo(buffer: Buffer, offset?: number): number;
}

export declare class MsgExt extends Msg {
constructor(payload: Buffer, type?: number);
constructor(type: number, payload: Buffer);

/**
* payload
*/
buffer: Buffer;

/**
* msgpack extension type number: -128 to +127
*/
type: number;
}
24 changes: 22 additions & 2 deletions lib/msg-interface.js → msg-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@

exports.isMsg = isMsg;
exports.msgToBuffer = gen(Buffer.alloc);
exports.Msg = require("./msg").Msg;
exports.MsgExt = require("./msg-ext").MsgExt;
exports.Msg = Msg;

/**
* a msgpack representation container
*/

function Msg() {
// do nothing
}

(function(P) {

P.msgpackLength = void 0;

P.writeMsgpackTo = writeMsgpackTo;

})(Msg.prototype);

function writeMsgpackTo(buffer, offset) {
/*jshint unused:false*/
throw new Error("Method not implemented: writeMsgpackTo");
}

/**
* @return {boolean} true when the argument has the MsgInterface implemented
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"msgpack"
],
"license": "MIT",
"main": "./lib/msg-interface.js",
"main": "./msg-interface.js",
"repository": {
"type": "git",
"url": "git+https://github.com/kawanet/msg-interface.git"
Expand All @@ -40,10 +40,10 @@
"fixpack": "fixpack",
"jshint": "./node_modules/.bin/jshint .",
"mocha": "./node_modules/.bin/mocha test/*.js",
"test": "npm run tsc && npm run jshint && npm run mocha",
"test": "npm run jshint && npm run mocha",
"tsc": "./node_modules/.bin/tsc",
"tsc-watch": "./node_modules/.bin/tsc --watch",
"zuul-local": "./node_modules/.bin/zuul --local 4000 --ui mocha-bdd test/*.js"
},
"typings": "typings/msg-interface.d.ts"
"typings": "./msg-interface.d.ts"
}
95 changes: 0 additions & 95 deletions test/20.msg-ext.js

This file was deleted.

Loading

0 comments on commit f4b2a3f

Please sign in to comment.