Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

control.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
  2. var assert = require('assert-plus');
  3. var util = require('util');
  4. var asn1 = require('asn1');
  5. var Protocol = require('../protocol');
  6. ///--- Globals
  7. var Ber = asn1.Ber;
  8. ///--- API
  9. function Control(options) {
  10. assert.optionalObject(options);
  11. options = options || {};
  12. assert.optionalString(options.type);
  13. assert.optionalBool(options.criticality);
  14. if (options.value) {
  15. assert.buffer(options.value);
  16. }
  17. this.type = options.type || '';
  18. this.criticality = options.critical || options.criticality || false;
  19. this.value = options.value || null;
  20. }
  21. Object.defineProperties(Control.prototype, {
  22. json: {
  23. get: function getJson() {
  24. var obj = {
  25. controlType: this.type,
  26. criticality: this.criticality,
  27. controlValue: this.value
  28. };
  29. return (typeof (this._json) === 'function' ? this._json(obj) : obj);
  30. }
  31. }
  32. });
  33. Control.prototype.toBer = function toBer(ber) {
  34. assert.ok(ber);
  35. ber.startSequence();
  36. ber.writeString(this.type || '');
  37. ber.writeBoolean(this.criticality);
  38. if (typeof (this._toBer) === 'function') {
  39. this._toBer(ber);
  40. } else {
  41. if (this.value)
  42. ber.writeString(this.value);
  43. }
  44. ber.endSequence();
  45. return;
  46. };
  47. Control.prototype.toString = function toString() {
  48. return this.json;
  49. };
  50. ///--- Exports
  51. module.exports = Control;