BVB Source Codes

reactide Show api.js Source code

Return Download reactide: download api.js Source code - Download reactide Source code - Type:.js
  1. var asn1 = require('../asn1');
  2. var inherits = require('inherits');
  3.  
  4. var api = exports;
  5.  
  6. api.define = function define(name, body) {
  7.   return new Entity(name, body);
  8. };
  9.  
  10. function Entity(name, body) {
  11.   this.name = name;
  12.   this.body = body;
  13.  
  14.   this.decoders = {};
  15.   this.encoders = {};
  16. };
  17.  
  18. Entity.prototype._createNamed = function createNamed(base) {
  19.   var named;
  20.   try {
  21.     named = require('vm').runInThisContext(
  22.       '(function ' + this.name + '(entity) {\n' +
  23.       '  this._initNamed(entity);\n' +
  24.       '})'
  25.     );
  26.   } catch (e) {
  27.     named = function (entity) {
  28.       this._initNamed(entity);
  29.     };
  30.   }
  31.   inherits(named, base);
  32.   named.prototype._initNamed = function initnamed(entity) {
  33.     base.call(this, entity);
  34.   };
  35.  
  36.   return new named(this);
  37. };
  38.  
  39. Entity.prototype._getDecoder = function _getDecoder(enc) {
  40.   enc = enc || 'der';
  41.   // Lazily create decoder
  42.   if (!this.decoders.hasOwnProperty(enc))
  43.     this.decoders[enc] = this._createNamed(asn1.decoders[enc]);
  44.   return this.decoders[enc];
  45. };
  46.  
  47. Entity.prototype.decode = function decode(data, enc, options) {
  48.   return this._getDecoder(enc).decode(data, options);
  49. };
  50.  
  51. Entity.prototype._getEncoder = function _getEncoder(enc) {
  52.   enc = enc || 'der';
  53.   // Lazily create encoder
  54.   if (!this.encoders.hasOwnProperty(enc))
  55.     this.encoders[enc] = this._createNamed(asn1.encoders[enc]);
  56.   return this.encoders[enc];
  57. };
  58.  
  59. Entity.prototype.encode = function encode(data, enc, /* internal */ reporter) {
  60.   return this._getEncoder(enc).encode(data, reporter);
  61. };
  62.  
downloadapi.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top