VarIntDecode.mjs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @author GCHQ Contributor [3]
  3. * @copyright Crown Copyright 2019
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation";
  7. import OperationError from "../errors/OperationError";
  8. import Protobuf from "../lib/Protobuf";
  9. /**
  10. * VarInt Decode operation
  11. */
  12. class VarIntDecode extends Operation {
  13. /**
  14. * VarIntDecode constructor
  15. */
  16. constructor() {
  17. super();
  18. this.name = "VarInt Decode";
  19. this.module = "Default";
  20. this.description = "Decodes a VarInt encoded integer. VarInt is an efficient way of encoding variable length integers and is commonly used with Protobuf.";
  21. this.infoURL = "https://developers.google.com/protocol-buffers/docs/encoding#varints";
  22. this.inputType = "byteArray";
  23. this.outputType = "number";
  24. this.args = [];
  25. }
  26. /**
  27. * @param {byteArray} input
  28. * @param {Object[]} args
  29. * @returns {number}
  30. */
  31. run(input, args) {
  32. try {
  33. return Protobuf.varIntDecode(input);
  34. } catch (err) {
  35. throw new OperationError(err);
  36. }
  37. }
  38. }
  39. export default VarIntDecode;