-
-
Notifications
You must be signed in to change notification settings - Fork 576
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use strict"; | ||
|
||
const BaseSerializer = require("./base"); | ||
/** | ||
* JSON serializer for Moleculer | ||
* | ||
* @class JSONSerializer | ||
*/ | ||
class NotepackSerializer extends BaseSerializer { | ||
/** | ||
* Creates an instance of JSONSerializer. | ||
* | ||
* @memberof NotepackSerializer | ||
*/ | ||
constructor() { | ||
super(); | ||
try { | ||
this.codec = require("notepack.io"); | ||
} catch(err) { | ||
/* istanbul ignore next */ | ||
this.broker.fatal("The 'notepack.io' package is missing! Please install it with 'npm install notepack.io --save' command!", err, true); | ||
} | ||
} | ||
|
||
/** | ||
* Serializer a JS object to Buffer | ||
* | ||
* @param {Object} obj | ||
* @param {String} type of packet | ||
* @returns {Buffer} | ||
* | ||
* @memberof Serializer | ||
*/ | ||
serialize(obj) { | ||
return this.codec.encode(obj); | ||
} | ||
|
||
/** | ||
* Deserialize Buffer to JS object | ||
* | ||
* @param {Buffer} buf | ||
* @param {String} type of packet | ||
* @returns {Object} | ||
* | ||
* @memberof Serializer | ||
*/ | ||
deserialize(buf) { | ||
return this.codec.decode(buf); | ||
} | ||
} | ||
|
||
module.exports = NotepackSerializer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters