-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNullValue.cjs
58 lines (44 loc) · 1.43 KB
/
NullValue.cjs
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
'use strict';
var assert = require('nanoassert');
var types = require('protobuf-codec/encode/types');
var types$1 = require('protobuf-codec/decode/types');
/// autogenerated by protoc-plugin-js
const NULL_VALUE = 0;
const enumValues = new Map([[0, 'NULL_VALUE']]);
const enumNames = new Map([['NULL_VALUE', 0]]);
function encode(value, buf, byteOffset = 0) {
if (typeof value === 'string') return encode(parse(value), buf, byteOffset)
if (value == null) throw new Error('Invalid NullValue value (' + value + ')')
return types.enumerable.encode(value, buf, byteOffset)
}
function decode(varint) {
const int = types$1.enumerable(varint);
return stringify(int) ?? int
}
function encodingLength(value) {
if (typeof value === 'string') return encodingLength(parse(value))
assert(value != null, 'Invalid NullValue value (' + value + ')');
if (0 <= value && value <= 0) return 1
// enumerable max value in case of unknown value
return 5
}
/**
* Convert an enum value to it's human readable name.
* Returns undefined on an unknown value.
*/
function stringify(int) {
return enumValues.get(int)
}
/**
* Convert an enum string names to it's machine integer value.
* Returns undefined on an unknown name.
*/
function parse(str) {
return enumNames.get(str)
}
exports.NULL_VALUE = NULL_VALUE;
exports.decode = decode;
exports.encode = encode;
exports.encodingLength = encodingLength;
exports.parse = parse;
exports.stringify = stringify;