-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'artemisbot-features/messagepack'
- Loading branch information
Showing
7 changed files
with
182 additions
and
12 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,47 @@ | ||
/** | ||
* @author Matt C [matt@artemisbot.uk] | ||
* @copyright Crown Copyright 2018 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation"; | ||
import OperationError from "../errors/OperationError"; | ||
import notepack from "notepack.io"; | ||
|
||
/** | ||
* From MessagePack operation | ||
*/ | ||
class FromMessagePack extends Operation { | ||
|
||
/** | ||
* FromMessagePack constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "From MessagePack"; | ||
this.module = "Code"; | ||
this.description = "Converts MessagePack encoded data to JSON. MessagePack is a computer data interchange format. It is a binary form for representing simple data structures like arrays and associative arrays."; | ||
this.infoURL = "https://wikipedia.org/wiki/MessagePack"; | ||
this.inputType = "ArrayBuffer"; | ||
this.outputType = "JSON"; | ||
this.args = []; | ||
} | ||
|
||
/** | ||
* @param {ArrayBuffer} input | ||
* @param {Object[]} args | ||
* @returns {JSON} | ||
*/ | ||
run(input, args) { | ||
try { | ||
const buf = Buffer.from(new Uint8Array(input)); | ||
return notepack.decode(buf); | ||
} catch (err) { | ||
throw new OperationError(`Could not decode MessagePack to JSON: ${err}`); | ||
} | ||
} | ||
|
||
} | ||
|
||
export default FromMessagePack; |
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,50 @@ | ||
/** | ||
* @author Matt C [matt@artemisbot.uk] | ||
* @copyright Crown Copyright 2018 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation"; | ||
import OperationError from "../errors/OperationError.mjs"; | ||
import notepack from "notepack.io"; | ||
|
||
/** | ||
* To MessagePack operation | ||
*/ | ||
class ToMessagePack extends Operation { | ||
|
||
/** | ||
* ToMessagePack constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "To MessagePack"; | ||
this.module = "Code"; | ||
this.description = "Converts JSON to MessagePack encoded byte buffer. MessagePack is a computer data interchange format. It is a binary form for representing simple data structures like arrays and associative arrays."; | ||
this.infoURL = "https://wikipedia.org/wiki/MessagePack"; | ||
this.inputType = "JSON"; | ||
this.outputType = "ArrayBuffer"; | ||
this.args = []; | ||
} | ||
|
||
/** | ||
* @param {JSON} input | ||
* @param {Object[]} args | ||
* @returns {ArrayBuffer} | ||
*/ | ||
run(input, args) { | ||
try { | ||
if (ENVIRONMENT_IS_WORKER()) { | ||
return notepack.encode(input); | ||
} else { | ||
return notepack.encode(input).buffer; | ||
} | ||
} catch (err) { | ||
throw new OperationError(`Could not encode JSON to MessagePack: ${err}`); | ||
} | ||
} | ||
|
||
} | ||
|
||
export default ToMessagePack; |
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