all files / src/cbor/ Types.js

56.82% Statements 25/44
19.05% Branches 4/21
90.91% Functions 20/22
56.82% Lines 25/44
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124                                                              48×     18×     19×     16×     28×     22×     22×     187×     66×     57×     40×     85×     67×     58×     54×     16×     14×         46×                     22× 12×                                            
/*
 * Wire
 * Copyright (C) 2016 Wire Swiss GmbH
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 *
 */
 
'use strict';
 
/**
 * @class Types
 * @throws Error
 */
class Types {
  constructor() {
    throw new Error('Can\'t create instance of singleton');
  }
 
  /** @type {number} */
  static get ARRAY() { return 1; }
 
  /** @type {number} */
  static get BOOL() { return 2; }
 
  /** @type {number} */
  static get BREAK() { return 3; }
 
  /** @type {number} */
  static get BYTES() {return 4; }
 
  /** @type {number} */
  static get FLOAT16() { return 5; }
 
  /** @type {number} */
  static get FLOAT32() { return 6; }
 
  /** @type {number} */
  static get FLOAT64() { return 7; }
 
  /** @type {number} */
  static get UINT8() { return 8; }
 
  /** @type {number} */
  static get UINT16() { return 9; }
 
  /** @type {number} */
  static get UINT32() { return 10; }
 
  /** @type {number} */
  static get UINT64() { return 11; }
 
  /** @type {number} */
  static get INT8() { return 12; }
 
  /** @type {number} */
  static get INT16() { return 13; }
 
  /** @type {number} */
  static get INT32() { return 14; }
 
  /** @type {number} */
  static get INT64() { return 15; }
 
  /** @type {number} */
  static get NULL() { return 16; }
 
  /** @type {number} */
  static get OBJECT() { return 17; }
 
  /** @type {number} */
  static get TAGGED() { return 18; }
 
  /** @type {number} */
  static get TEXT() { return 19; }
 
  /** @type {number} */
  static get UNDEFINED() { return 20; }
 
  /**
   * @param {!Types} t
   * @returns {number}
   * @throws TypeError
   */
  static major(t) {
    switch (t) {
      case this.ARRAY: return 4;
      case this.BOOL: return 7;
      case this.BREAK: return 7;
      case this.BYTES: return 2;
      case this.FLOAT16: return 7;
      case this.FLOAT32: return 7;
      case this.FLOAT64: return 7;
      case this.UINT8: return 0;
      case this.UINT16: return 0;
      case this.UINT32: return 0;
      case this.UINT64: return 0;
      case this.INT8: return 1;
      case this.INT16: return 1;
      case this.INT32: return 1;
      case this.INT64: return 1;
      case this.NULL: return 7;
      case this.OBJECT: return 5;
      case this.TAGGED: return 6;
      case this.TEXT: return 3;
      case this.UNDEFINED: return 7;
      default: throw new TypeError('Invalid CBOR type');
    }
  }
}
 
module.exports = Types;