All files types.ts

100% Statements 23/23
100% Branches 2/2
100% Functions 3/3
100% Lines 22/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 671x     13x     11x 13x 4x   13x     1x 1x     1x 1x 1x   1x 1x 1x     1x 1x     1x     1x     1x     1x         1x                                         1x  
import { $$types } from './proto';
 
function isInitialize(map: any): map is Map<string, string> {
    return typeof map !== 'undefined';
}
 
const at = (type: string) => (o: any, fieldName: string | symbol): void => {
    if(!isInitialize(o[$$types])) {
        o[$$types] = new Map<string, string>();
    }
    o[$$types].set(fieldName, type);
}
 
export const DYNAMIC_SIZE_TYPE = 'UInt32BE';
export const BINARY            = 'binary';
 
// Integer
export const uint8   = at('UInt8');
export const uint16  = at('UInt16BE');
export const uint32  = at('UInt32BE');
 
export const int8    = at('Int8');
export const int16   = at('Int16BE');
export const int32   = at('Int32BE');
 
// Float & Double
export const float   = at('FloatBE');
export const double  = at('DoubleBE');
 
// Boolean
export const boolean = uint8;
 
// BSON
export const bson    = at('BSON');
 
// String
export const string  = at('String');
 
// Binary
export const binary  = at('Binary');
 
/**
 * Map of known types and sizes in bytes.
 */
export const byteMap = new Map<string, number>([
/* +-----------+--------------+
 * | Type      | Size (bytes) |
 * +-----------+--------------+ */
    ['UInt8',       1],
    ['UInt16BE',    2],
    ['UInt32BE',    4],
 
    ['Int8',        1],
    ['Int16BE',     2],
    ['Int32BE',     4],
 
    ['FloatBE',     4],
    ['DoubleBE',    8],
]);
 
/**
 * Static Types
 * - types with fixed memory space, e.g. 
 * UInt8, Int8, UInt16, etc.
 */
export const staticTypes = new Set(byteMap.keys());