From 7dadb5adc9b7cfd80834b7fa941158ebfdb91889 Mon Sep 17 00:00:00 2001 From: Martin Heidegger Date: Wed, 23 Mar 2022 19:14:48 +0900 Subject: [PATCH] chore: update dependencies (#85) --- bench/index.js | 22 ++++---- bin.js | 18 +++---- compile-to-js.js | 14 ++--- compile.js | 108 +++++++++++++++++++-------------------- example.js | 12 ++--- index.js | 16 +++--- package.json | 6 +-- test/basic.js | 22 ++++---- test/corrupted.js | 16 +++--- test/defaults.js | 10 ++-- test/enums.js | 12 ++--- test/float.js | 12 ++--- test/helpers/messages.js | 4 +- test/integers.js | 12 ++--- test/map.js | 16 +++--- test/nan.js | 20 ++++---- test/nested.js | 16 +++--- test/notpacked.js | 18 +++---- test/oneof.js | 24 ++++----- test/packed.js | 28 +++++----- test/repeated.js | 16 +++--- test/utf-8.js | 8 +-- 22 files changed, 215 insertions(+), 215 deletions(-) diff --git a/bench/index.js b/bench/index.js index 47b5149..8085f14 100644 --- a/bench/index.js +++ b/bench/index.js @@ -1,15 +1,15 @@ -var protobuf = require('../') -var fs = require('fs') -var path = require('path') -var messages = protobuf(fs.readFileSync(path.join(__dirname, 'bench.proto'))) +const protobuf = require('../') +const fs = require('fs') +const path = require('path') +const messages = protobuf(fs.readFileSync(path.join(__dirname, 'bench.proto'))) -var TIMES = 1000000 +const TIMES = 1000000 -var then = 0 -var diff = 0 +let then = 0 +let diff = 0 -var run = function (name, encode, decode) { - var EXAMPLE = { +const run = function (name, encode, decode) { + const EXAMPLE = { foo: 'hello', hello: 42, payload: Buffer.from('a'), @@ -23,8 +23,8 @@ var run = function (name, encode, decode) { } } - var EXAMPLE_BUFFER = encode(EXAMPLE) - var i + const EXAMPLE_BUFFER = encode(EXAMPLE) + let i console.log('Benchmarking %s', name) console.log(' Running object encoding benchmark...') diff --git a/bin.js b/bin.js index 260cdcd..f5574e4 100755 --- a/bin.js +++ b/bin.js @@ -1,17 +1,17 @@ #!/usr/bin/env node -var protobuf = require('./') -var fs = require('fs') +const protobuf = require('./') +const fs = require('fs') -var filename = null -var output = null -var watch = false -var encodings = null +let filename = null +let output = null +let watch = false +let encodings = null // handrolled parser to not introduce minimist as this is used a bunch of prod places // TODO: if this becomes more complicated / has bugs, move to minimist -for (var i = 2; i < process.argv.length; i++) { - var v = process.argv[i] - var n = v.split('=')[0] +for (let i = 2; i < process.argv.length; i++) { + const v = process.argv[i] + const n = v.split('=')[0] if (v[0] !== '-') { filename = v } else if (n === '--output' || n === '-o' || n === '-wo') { diff --git a/compile-to-js.js b/compile-to-js.js index c14ab7b..b888659 100644 --- a/compile-to-js.js +++ b/compile-to-js.js @@ -1,6 +1,6 @@ -var os = require('os') +const os = require('os') -var RESERVED = { +const RESERVED = { type: true, message: true, name: true, @@ -16,8 +16,8 @@ function isEncoder (m) { } function compile (messages, opts) { - var out = '' - var encodings = opts && opts.encodings + let out = '' + const encodings = opts && opts.encodings out += '// This file is auto generated by the protocol-buffers compiler' + os.EOL out += os.EOL @@ -43,7 +43,7 @@ function compile (messages, opts) { if (!safe) return JSON.stringify(map, null, 2).replace(/\n/g, os.EOL) + os.EOL - var out = '{' + os.EOL + let out = '{' + os.EOL keys.forEach(function (k, i) { out += spaces + ' ' + k + ': ' + map[k] + (i < keys.length - 1 ? ',' : '') + os.EOL @@ -53,12 +53,12 @@ function compile (messages, opts) { } function visit (messages, exports, spaces) { - var encoders = Object.keys(messages).filter(function (name) { + const encoders = Object.keys(messages).filter(function (name) { if (RESERVED[name]) return false return isEncoder(messages[name]) }) - var enums = Object.keys(messages).filter(function (name) { + const enums = Object.keys(messages).filter(function (name) { if (RESERVED[name]) return false return !isEncoder(messages[name]) }) diff --git a/compile.js b/compile.js index aaadc51..1cdad22 100644 --- a/compile.js +++ b/compile.js @@ -1,26 +1,26 @@ -/* eslint-disable no-spaced-func */ /* eslint-disable no-unexpected-multiline */ /* eslint-disable func-call-spacing */ +/* eslint-disable indent */ -var encodings = require('protocol-buffers-encodings') -var varint = require('varint') -var genobj = require('generate-object-property') -var genfun = require('generate-function') +const encodings = require('protocol-buffers-encodings') +const varint = require('varint') +const genobj = require('generate-object-property') +const genfun = require('generate-function') -var flatten = function (values) { +const flatten = function (values) { if (!values) return null - var result = {} + const result = {} Object.keys(values).forEach(function (k) { result[k] = values[k].value }) return result } -var defined = function defined (val) { +const defined = function defined (val) { return val !== null && val !== undefined && (typeof val !== 'number' || !isNaN(val)) } -var isString = function (def) { +const isString = function (def) { try { return !!def && typeof JSON.parse(def) === 'string' } catch (err) { @@ -28,7 +28,7 @@ var isString = function (def) { } } -var defaultValue = function (f, def) { +const defaultValue = function (f, def) { if (f.map) return '{}' if (f.repeated) return '[]' @@ -59,17 +59,17 @@ var defaultValue = function (f, def) { } } -var unique = function () { - var seen = {} +const unique = function () { + const seen = {} return function (key) { - if (seen.hasOwnProperty(key)) return false + if (Object.prototype.hasOwnProperty.call(seen, key)) return false seen[key] = true return true } } -var encName = function (e) { - var name = encodings.name(e) +const encName = function (e) { + let name = encodings.name(e) if (name) name = 'encodings.' + name else if (!e.name) name = 'encodings.enum' else name = e.name @@ -77,15 +77,15 @@ var encName = function (e) { } module.exports = function (schema, extraEncodings, inlineEnc) { - var messages = {} - var enums = {} - var cache = {} + const messages = {} + const enums = {} + const cache = {} - var encString = function (idx, encs) { + const encString = function (idx, encs) { return inlineEnc ? encName(encs[idx]) : 'enc[' + idx + ']' } - var visit = function (schema, prefix) { + const visit = function (schema, prefix) { if (schema.enums) { schema.enums.forEach(function (e) { e.id = prefix + (prefix ? '.' : '') + e.name @@ -100,8 +100,8 @@ module.exports = function (schema, extraEncodings, inlineEnc) { m.fields.forEach(function (f) { if (!f.map) return - var name = 'Map_' + f.map.from + '_' + f.map.to - var map = { + const name = 'Map_' + f.map.from + '_' + f.map.to + const map = { name: name, enums: [], messages: [], @@ -136,8 +136,8 @@ module.exports = function (schema, extraEncodings, inlineEnc) { visit(schema, '') - var compileEnum = function (e) { - var conditions = Object.keys(e.values) + const compileEnum = function (e) { + let conditions = Object.keys(e.values) .map(function (k) { return 'val !== ' + parseInt(e.values[k].value, 10) }) @@ -145,7 +145,7 @@ module.exports = function (schema, extraEncodings, inlineEnc) { if (!conditions) conditions = 'true' - var encode = genfun() + const encode = genfun() ('function encode (val, buf, offset) {') ('if (%s) throw new Error("Invalid enum value: "+val)', conditions) ('varint.encode(val, buf, offset)') @@ -156,7 +156,7 @@ module.exports = function (schema, extraEncodings, inlineEnc) { varint: varint }) - var decode = genfun() + const decode = genfun() ('function decode (buf, offset) {') ('var val = varint.decode(buf, offset)') ('if (%s) throw new Error("Invalid enum value: "+val)', conditions) @@ -170,7 +170,7 @@ module.exports = function (schema, extraEncodings, inlineEnc) { return encodings.make(0, encode, decode, varint.encodingLength) } - var compileMessage = function (m, exports) { + const compileMessage = function (m, exports) { m.messages.forEach(function (nested) { exports[nested.name] = resolve(nested.name, m.id) }) @@ -183,7 +183,7 @@ module.exports = function (schema, extraEncodings, inlineEnc) { exports.message = true exports.name = m.name - var oneofs = {} + const oneofs = {} m.fields.forEach(function (f) { if (!f.oneof) return @@ -191,31 +191,31 @@ module.exports = function (schema, extraEncodings, inlineEnc) { oneofs[f.oneof].push(f.name) }) - var enc = m.fields.map(function (f) { + const enc = m.fields.map(function (f) { return resolve(f.type, m.id) }) - var dedupEnc = enc.filter(function (e, i) { + const dedupEnc = enc.filter(function (e, i) { return enc.indexOf(e) === i }) - var dedupIndex = enc.map(function (e) { + const dedupIndex = enc.map(function (e) { return dedupEnc.indexOf(e) }) - var forEach = function (fn) { - for (var i = 0; i < enc.length; i++) fn(enc[i], m.fields[i], genobj('obj', m.fields[i].name), i) + const forEach = function (fn) { + for (let i = 0; i < enc.length; i++) fn(enc[i], m.fields[i], genobj('obj', m.fields[i].name), i) } // compile encodingLength - var encodingLength = genfun() + let encodingLength = genfun() ('function encodingLength (obj) {') ('var length = 0') Object.keys(oneofs).forEach(function (name) { - var msg = JSON.stringify('only one of the properties defined in oneof ' + name + ' can be set') - var cnt = oneofs[name] + const msg = JSON.stringify('only one of the properties defined in oneof ' + name + ' can be set') + const cnt = oneofs[name] .map(function (prop) { return '+defined(' + genobj('obj', prop) + ')' }) @@ -225,8 +225,8 @@ module.exports = function (schema, extraEncodings, inlineEnc) { }) forEach(function (e, f, val, i) { - var packed = f.repeated && f.options && f.options.packed && f.options.packed !== 'false' - var hl = varint.encodingLength(f.tag << 3 | e.type) + const packed = f.repeated && f.options && f.options.packed && f.options.packed !== 'false' + const hl = varint.encodingLength(f.tag << 3 | e.type) if (f.required) encodingLength('if (!defined(%s)) throw new Error(%s)', val, JSON.stringify(f.name + ' is required')) else encodingLength('if (defined(%s)) {', val) @@ -282,15 +282,15 @@ module.exports = function (schema, extraEncodings, inlineEnc) { // compile encode - var encode = genfun() + let encode = genfun() ('function encode (obj, buf, offset) {') ('if (!offset) offset = 0') ('if (!buf) buf = Buffer.allocUnsafe(encodingLength(obj))') ('var oldOffset = offset') Object.keys(oneofs).forEach(function (name) { - var msg = JSON.stringify('only one of the properties defined in oneof ' + name + ' can be set') - var cnt = oneofs[name] + const msg = JSON.stringify('only one of the properties defined in oneof ' + name + ' can be set') + const cnt = oneofs[name] .map(function (prop) { return '+defined(' + genobj('obj', prop) + ')' }) @@ -303,10 +303,10 @@ module.exports = function (schema, extraEncodings, inlineEnc) { if (f.required) encode('if (!defined(%s)) throw new Error(%s)', val, JSON.stringify(f.name + ' is required')) else encode('if (defined(%s)) {', val) - var packed = f.repeated && f.options && f.options.packed && f.options.packed !== 'false' - var p = varint.encode(f.tag << 3 | 2) - var h = varint.encode(f.tag << 3 | e.type) - var j + const packed = f.repeated && f.options && f.options.packed && f.options.packed !== 'false' + const p = varint.encode(f.tag << 3 | 2) + const h = varint.encode(f.tag << 3 | e.type) + let j if (f.map) { encode() @@ -367,7 +367,7 @@ module.exports = function (schema, extraEncodings, inlineEnc) { // compile decode - var invalid = m.fields + const invalid = m.fields .map(function (f, i) { return f.required && '!found' + i }) @@ -376,14 +376,14 @@ module.exports = function (schema, extraEncodings, inlineEnc) { }) .join(' || ') - var decode = genfun() + let decode = genfun() - var objectKeys = [] + let objectKeys = [] forEach(function (e, f) { - var def = f.options && f.options.default - var resolved = resolve(f.type, m.id, false) - var vals = resolved && resolved.values + let def = f.options && f.options.default + const resolved = resolve(f.type, m.id, false) + const vals = resolved && resolved.values if (vals) { // is enum if (f.repeated) { @@ -430,7 +430,7 @@ module.exports = function (schema, extraEncodings, inlineEnc) { ('switch (tag) {') forEach(function (e, f, val, i) { - var packed = f.repeated && f.options && f.options.packed && f.options.packed !== 'false' + const packed = f.repeated && f.options && f.options.packed && f.options.packed !== 'false' decode('case %d:', f.tag) @@ -502,11 +502,11 @@ module.exports = function (schema, extraEncodings, inlineEnc) { return exports } - var resolve = function (name, from, compile) { + const resolve = function (name, from, compile) { if (extraEncodings && extraEncodings[name]) return extraEncodings[name] if (encodings[name]) return encodings[name] - var m = (from ? from + '.' + name : name).split('.') + const m = (from ? from + '.' + name : name).split('.') .map(function (part, i, list) { return list.slice(0, i).concat(name).join('.') }) diff --git a/example.js b/example.js index 829e4b0..899ef5f 100644 --- a/example.js +++ b/example.js @@ -1,15 +1,15 @@ -var protobuf = require('./') -var fs = require('fs') -var path = require('path') +const protobuf = require('./') +const fs = require('fs') +const path = require('path') -var messages = protobuf(fs.readFileSync(path.join(__dirname, 'example.proto'))) +const messages = protobuf(fs.readFileSync(path.join(__dirname, 'example.proto'))) -var ex = { +const ex = { foo: 'hello world', num: 42 } -var buf = messages.Test.encode(ex) +const buf = messages.Test.encode(ex) console.log('test message', ex) console.log('encoded test message', buf) diff --git a/index.js b/index.js index 4454f31..4a0bc1f 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,10 @@ -var schema = require('protocol-buffers-schema') -var compile = require('./compile') -var compileToJS = require('./compile-to-js') +const schema = require('protocol-buffers-schema') +const compile = require('./compile') +const compileToJS = require('./compile-to-js') -var flatten = function (values) { +const flatten = function (values) { if (!values) return null - var result = {} + const result = {} Object.keys(values).forEach(function (k) { result[k] = values[k].value }) @@ -15,11 +15,11 @@ module.exports = function (proto, opts) { if (!opts) opts = {} if (!proto) throw new Error('Pass in a .proto string or a protobuf-schema parsed object') - var sch = (typeof proto === 'object' && !Buffer.isBuffer(proto)) ? proto : schema.parse(proto) + const sch = (typeof proto === 'object' && !Buffer.isBuffer(proto)) ? proto : schema.parse(proto) // to not make toString,toJSON enumarable we make a fire-and-forget prototype - var Messages = function () { - var self = this + const Messages = function () { + const self = this compile(sch, opts.encodings || {}, opts.inlineEnc).forEach(function (m) { self[m.name] = flatten(m.values) || m diff --git a/package.json b/package.json index c1c725a..0c5f41b 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,11 @@ "protocol-buffers-encodings": "^1.1.0", "protocol-buffers-schema": "^3.1.1", "signed-varint": "^2.0.0", - "varint": "^5.0.0" + "varint": "^6.0.0" }, "devDependencies": { - "standard": "^10.0.3", - "tape": "^4.8.0" + "standard": "^16.0.4", + "tape": "^5.5.2" }, "bin": { "protocol-buffers": "./bin.js" diff --git a/test/basic.js b/test/basic.js index 5b51270..9c00925 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,19 +1,19 @@ -var tape = require('tape') -var Basic = require('./helpers/messages').Basic +const tape = require('tape') +const Basic = require('./helpers/messages').Basic tape('basic encode', function (t) { - var b1 = Basic.encode({ + const b1 = Basic.encode({ num: 1, payload: Buffer.from('lol') }) - var b2 = Basic.encode({ + const b2 = Basic.encode({ num: 1, payload: Buffer.from('lol'), meeeh: 42 }) - var b3 = Basic.encode({ + const b3 = Basic.encode({ num: 1, payload: 'lol', meeeh: 42 @@ -25,35 +25,35 @@ tape('basic encode', function (t) { }) tape('basic encode + decode', function (t) { - var b1 = Basic.encode({ + const b1 = Basic.encode({ num: 1, payload: Buffer.from('lol') }) - var o1 = Basic.decode(b1) + const o1 = Basic.decode(b1) t.same(o1.num, 1) t.same(o1.payload, Buffer.from('lol')) - var b2 = Basic.encode({ + const b2 = Basic.encode({ num: 1, payload: Buffer.from('lol'), meeeh: 42 }) - var o2 = Basic.decode(b2) + const o2 = Basic.decode(b2) t.same(o2, o1) t.end() }) tape('basic encode + decode floats', function (t) { - var b1 = Basic.encode({ + const b1 = Basic.encode({ num: 1.1, payload: Buffer.from('lol') }) - var o1 = Basic.decode(b1) + const o1 = Basic.decode(b1) t.same(o1.num, 1.1) t.same(o1.payload, Buffer.from('lol')) diff --git a/test/corrupted.js b/test/corrupted.js index 0fc568a..48216e0 100644 --- a/test/corrupted.js +++ b/test/corrupted.js @@ -1,7 +1,7 @@ -var tape = require('tape') -var protobuf = require('../') +const tape = require('tape') +const protobuf = require('../') -var protoStr = 'enum AbcType {\n' + +const protoStr = 'enum AbcType {\n' + ' IGNORE = 0;\n' + ' ACK_CONFIRMATION_TOKEN = 1;\n' + '}\n' + @@ -20,10 +20,10 @@ var protoStr = 'enum AbcType {\n' + ' required bytes nonce = 2;\n' + '}' -var messages = protobuf(protoStr) +const messages = protobuf(protoStr) tape('invalid message decode', function (t) { - var didFail = false + let didFail = false try { messages.ABC.decode(Buffer.from([8, 182, 168, 235, 144, 178, 41])) } catch (e) { @@ -34,7 +34,7 @@ tape('invalid message decode', function (t) { }) tape('non buffers should fail', function (t) { - var didFail = false + let didFail = false try { messages.ABC.decode({}) } catch (e) { @@ -45,8 +45,8 @@ tape('non buffers should fail', function (t) { }) tape('protocol parser test case', function (t) { - var didFail = false - var buf = Buffer.from('cec1', 'hex') + let didFail = false + const buf = Buffer.from('cec1', 'hex') try { messages.Open.decode(buf) } catch (err) { diff --git a/test/defaults.js b/test/defaults.js index 358b887..659628b 100644 --- a/test/defaults.js +++ b/test/defaults.js @@ -1,15 +1,15 @@ -var tape = require('tape') -var Defaults = require('./helpers/messages').Defaults +const tape = require('tape') +const Defaults = require('./helpers/messages').Defaults tape('defaults decode', function (t) { - var o1 = Defaults.decode(Buffer.alloc(0)) // everything default + const o1 = Defaults.decode(Buffer.alloc(0)) // everything default - var b2 = Defaults.encode({ + const b2 = Defaults.encode({ num: 10, foos: [1] }) - var b3 = Defaults.encode({ + const b3 = Defaults.encode({ num: 10, foo2: 2 }) diff --git a/test/enums.js b/test/enums.js index 7aaf1fc..69d6081 100644 --- a/test/enums.js +++ b/test/enums.js @@ -1,16 +1,16 @@ -var tape = require('tape') -var messages = require('./helpers/messages') +const tape = require('tape') +const messages = require('./helpers/messages') tape('enums', function (t) { - var e = messages.FOO + const e = messages.FOO - t.same(e, {A: 1, B: 2}, 'enum is defined') + t.same(e, { A: 1, B: 2 }, 'enum is defined') t.end() }) tape('hex enums', function (t) { - var e = messages.FOO_HEX + const e = messages.FOO_HEX - t.same(e, {A: 1, B: 2}, 'enum is defined using hex') + t.same(e, { A: 1, B: 2 }, 'enum is defined using hex') t.end() }) diff --git a/test/float.js b/test/float.js index 01869bf..80724ea 100644 --- a/test/float.js +++ b/test/float.js @@ -1,21 +1,21 @@ -var tape = require('tape') -var Float = require('./helpers/messages').Float +const tape = require('tape') +const Float = require('./helpers/messages').Float tape('float encode + decode', function (t) { - var arr = new Float32Array(3) + const arr = new Float32Array(3) arr[0] = 1.1 arr[1] = 0 arr[2] = -2.3 - var obj = { + const obj = { float1: arr[0], float2: arr[1], float3: arr[2] } - var b1 = Float.encode(obj) + const b1 = Float.encode(obj) - var o1 = Float.decode(b1) + const o1 = Float.decode(b1) t.same(o1, obj) diff --git a/test/helpers/messages.js b/test/helpers/messages.js index e35942b..c917954 100644 --- a/test/helpers/messages.js +++ b/test/helpers/messages.js @@ -1,5 +1,5 @@ -var path = require('path') -var fs = require('fs') +const path = require('path') +const fs = require('fs') if (process.env.COMPILED) module.exports = require('./compiled.js') else module.exports = require('../../')(fs.readFileSync(path.join(__dirname, '../test.proto'))) diff --git a/test/integers.js b/test/integers.js index f1dedd7..a617f58 100644 --- a/test/integers.js +++ b/test/integers.js @@ -1,8 +1,8 @@ -var tape = require('tape') -var Integers = require('./helpers/messages').Integers +const tape = require('tape') +const Integers = require('./helpers/messages').Integers tape('integers encode + decode', function (t) { - var b1 = Integers.encode({ + const b1 = Integers.encode({ sint32: 1, sint64: 2, int32: 3, @@ -10,7 +10,7 @@ tape('integers encode + decode', function (t) { int64: 5 }) - var o1 = Integers.decode(b1) + const o1 = Integers.decode(b1) t.same(o1, { sint32: 1, @@ -24,7 +24,7 @@ tape('integers encode + decode', function (t) { }) tape('integers encode + decode + negative', function (t) { - var b1 = Integers.encode({ + const b1 = Integers.encode({ sint32: -1, sint64: -2, int32: -3, @@ -32,7 +32,7 @@ tape('integers encode + decode + negative', function (t) { int64: -1 * Math.pow(2, 52) - 5 }) - var o1 = Integers.decode(b1) + const o1 = Integers.decode(b1) t.same(o1, { sint32: -1, diff --git a/test/map.js b/test/map.js index a52c851..17d33f0 100644 --- a/test/map.js +++ b/test/map.js @@ -1,26 +1,26 @@ -var tape = require('tape') -var Map = require('./helpers/messages').Map +const tape = require('tape') +const Map = require('./helpers/messages').Map tape('map encode + decode', function (t) { - var b1 = Map.encode({ + const b1 = Map.encode({ foo: { hello: 'world' } }) - var o1 = Map.decode(b1) + const o1 = Map.decode(b1) - t.same(o1.foo, {hello: 'world'}) + t.same(o1.foo, { hello: 'world' }) - var doc = { + const doc = { foo: { hello: 'world', hi: 'verden' } } - var b2 = Map.encode(doc) - var o2 = Map.decode(b2) + const b2 = Map.encode(doc) + const o2 = Map.decode(b2) t.same(o2, doc) t.end() diff --git a/test/nan.js b/test/nan.js index 4a178ad..3724368 100644 --- a/test/nan.js +++ b/test/nan.js @@ -1,20 +1,20 @@ -var tape = require('tape') -var protobuf = require('../') +const tape = require('tape') +const protobuf = require('../') -var protoStr = 'message MyMessage {\n' + +const protoStr = 'message MyMessage {\n' + ' optional uint32 my_number = 1;\n' + ' required string my_other = 2;\n' + '}' -var messages = protobuf(protoStr) +const messages = protobuf(protoStr) tape('NaN considered not defined', function (t) { - var didFail = false - var error - var encoded - var decoded - var testString = 'hello!' - var properResult = Buffer.from([0x12, 0x06, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x21]) + let didFail = false + let error + let encoded + let decoded + const testString = 'hello!' + const properResult = Buffer.from([0x12, 0x06, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x21]) try { encoded = messages.MyMessage.encode({ my_number: NaN, my_other: testString }) decoded = messages.MyMessage.decode(encoded) diff --git a/test/nested.js b/test/nested.js index 3fdea45..6f4de0d 100644 --- a/test/nested.js +++ b/test/nested.js @@ -1,8 +1,8 @@ -var tape = require('tape') -var Nested = require('./helpers/messages').Nested +const tape = require('tape') +const Nested = require('./helpers/messages').Nested tape('nested encode', function (t) { - var b1 = Nested.encode({ + const b1 = Nested.encode({ num: 1, payload: Buffer.from('lol'), meh: { @@ -11,7 +11,7 @@ tape('nested encode', function (t) { } }) - var b2 = Nested.encode({ + const b2 = Nested.encode({ num: 1, payload: Buffer.from('lol'), meeeh: 42, @@ -26,7 +26,7 @@ tape('nested encode', function (t) { }) tape('nested encode + decode', function (t) { - var b1 = Nested.encode({ + const b1 = Nested.encode({ num: 1, payload: Buffer.from('lol'), meh: { @@ -35,7 +35,7 @@ tape('nested encode + decode', function (t) { } }) - var o1 = Nested.decode(b1) + const o1 = Nested.decode(b1) t.same(o1.num, 1) t.same(o1.payload, Buffer.from('lol')) @@ -43,7 +43,7 @@ tape('nested encode + decode', function (t) { t.same(o1.meh.num, 2) t.same(o1.meh.payload, Buffer.from('bar')) - var b2 = Nested.encode({ + const b2 = Nested.encode({ num: 1, payload: Buffer.from('lol'), meeeh: 42, @@ -53,7 +53,7 @@ tape('nested encode + decode', function (t) { } }) - var o2 = Nested.decode(b2) + const o2 = Nested.decode(b2) t.same(o2, o1) t.end() diff --git a/test/notpacked.js b/test/notpacked.js index 7768994..18220f6 100644 --- a/test/notpacked.js +++ b/test/notpacked.js @@ -1,14 +1,14 @@ -var tape = require('tape') -var NotPacked = require('./helpers/messages').NotPacked -var FalsePacked = require('./helpers/messages').FalsePacked +const tape = require('tape') +const NotPacked = require('./helpers/messages').NotPacked +const FalsePacked = require('./helpers/messages').FalsePacked tape('NotPacked encode + FalsePacked decode', function (t) { - var b1 = NotPacked.encode({ - id: [ 9847136125 ], + const b1 = NotPacked.encode({ + id: [9847136125], value: 10000 }) - var o1 = FalsePacked.decode(b1) + const o1 = FalsePacked.decode(b1) t.same(o1.id.length, 1) t.same(o1.id[0], 9847136125) @@ -17,12 +17,12 @@ tape('NotPacked encode + FalsePacked decode', function (t) { }) tape('FalsePacked encode + NotPacked decode', function (t) { - var b1 = FalsePacked.encode({ - id: [ 9847136125 ], + const b1 = FalsePacked.encode({ + id: [9847136125], value: 10000 }) - var o1 = NotPacked.decode(b1) + const o1 = NotPacked.decode(b1) t.same(o1.id.length, 1) t.same(o1.id[0], 9847136125) diff --git a/test/oneof.js b/test/oneof.js index 29f499c..6cd0bfe 100644 --- a/test/oneof.js +++ b/test/oneof.js @@ -1,9 +1,9 @@ -var tape = require('tape') -var proto = require('./helpers/messages') -var Property = proto.Property -var PropertyNoOneof = proto.PropertyNoOneof +const tape = require('tape') +const proto = require('./helpers/messages') +const Property = proto.Property +const PropertyNoOneof = proto.PropertyNoOneof -var data = { +const data = { name: 'Foo', desc: 'optional description', int_value: 12345 @@ -15,14 +15,14 @@ tape('oneof encode', function (t) { }) tape('oneof encode + decode', function (t) { - var buf = Property.encode(data) - var out = Property.decode(buf) + const buf = Property.encode(data) + const out = Property.decode(buf) t.deepEqual(data, out) t.end() }) tape('oneof encode of overloaded json throws', function (t) { - var invalidData = { + const invalidData = { name: 'Foo', desc: 'optional description', string_value: 'Bar', // ignored @@ -38,21 +38,21 @@ tape('oneof encode of overloaded json throws', function (t) { }) tape('oneof encode + decode of overloaded oneof buffer', function (t) { - var invalidData = { + const invalidData = { name: 'Foo', desc: 'optional description', string_value: 'Bar', // retained, has highest tag number bool_value: true, // ignored int_value: 12345 // ignored } - var validData = { + const validData = { name: 'Foo', desc: 'optional description', string_value: 'Bar' } - var buf = PropertyNoOneof.encode(invalidData) - var out = Property.decode(buf) + const buf = PropertyNoOneof.encode(invalidData) + const out = Property.decode(buf) t.deepEqual(validData, out) t.end() }) diff --git a/test/packed.js b/test/packed.js index d8c48b6..32b496e 100644 --- a/test/packed.js +++ b/test/packed.js @@ -1,8 +1,8 @@ -var tape = require('tape') -var Packed = require('./helpers/messages').Packed +const tape = require('tape') +const Packed = require('./helpers/messages').Packed tape('Packed encode', function (t) { - var b1 = Packed.encode({ + const b1 = Packed.encode({ packed: [ 10, 42, @@ -10,7 +10,7 @@ tape('Packed encode', function (t) { ] }) - var b2 = Packed.encode({ + const b2 = Packed.encode({ packed: [ 10, 42, @@ -24,7 +24,7 @@ tape('Packed encode', function (t) { }) tape('Packed encode + decode', function (t) { - var b1 = Packed.encode({ + const b1 = Packed.encode({ packed: [ 10, 42, @@ -32,14 +32,14 @@ tape('Packed encode + decode', function (t) { ] }) - var o1 = Packed.decode(b1) + const o1 = Packed.decode(b1) t.same(o1.packed.length, 3) t.same(o1.packed[0], 10) t.same(o1.packed[1], 42) t.same(o1.packed[2], 52) - var b2 = Packed.encode({ + const b2 = Packed.encode({ packed: [ 10, 42, @@ -48,14 +48,14 @@ tape('Packed encode + decode', function (t) { meeh: 42 }) - var o2 = Packed.decode(b2) + const o2 = Packed.decode(b2) t.same(o2, o1) t.end() }) tape('packed message encode', function (t) { - var b1 = Packed.encode({ + const b1 = Packed.encode({ list: [{ num: 1, payload: Buffer.from('lol') @@ -65,7 +65,7 @@ tape('packed message encode', function (t) { }] }) - var b2 = Packed.encode({ + const b2 = Packed.encode({ list: [{ num: 1, payload: Buffer.from('lol') @@ -82,7 +82,7 @@ tape('packed message encode', function (t) { }) tape('packed message encode + decode', function (t) { - var b1 = Packed.encode({ + const b1 = Packed.encode({ list: [{ num: 1, payload: Buffer.from('lol') @@ -92,7 +92,7 @@ tape('packed message encode + decode', function (t) { }] }) - var o1 = Packed.decode(b1) + const o1 = Packed.decode(b1) t.same(o1.list.length, 2) t.same(o1.list[0].num, 1) @@ -100,7 +100,7 @@ tape('packed message encode + decode', function (t) { t.same(o1.list[1].num, 2) t.same(o1.list[1].payload, Buffer.from('lol1')) - var b2 = Packed.encode({ + const b2 = Packed.encode({ list: [{ num: 1, payload: Buffer.from('lol') @@ -112,7 +112,7 @@ tape('packed message encode + decode', function (t) { meeh: 42 }) - var o2 = Packed.decode(b2) + const o2 = Packed.decode(b2) t.same(o2, o1) t.end() diff --git a/test/repeated.js b/test/repeated.js index b9723db..afd2854 100644 --- a/test/repeated.js +++ b/test/repeated.js @@ -1,8 +1,8 @@ -var tape = require('tape') -var Repeated = require('./helpers/messages').Repeated +const tape = require('tape') +const Repeated = require('./helpers/messages').Repeated tape('repeated encode', function (t) { - var b1 = Repeated.encode({ + const b1 = Repeated.encode({ list: [{ num: 1, payload: Buffer.from('lol') @@ -12,7 +12,7 @@ tape('repeated encode', function (t) { }] }) - var b2 = Repeated.encode({ + const b2 = Repeated.encode({ list: [{ num: 1, payload: Buffer.from('lol') @@ -29,7 +29,7 @@ tape('repeated encode', function (t) { }) tape('repeated encode + decode', function (t) { - var b1 = Repeated.encode({ + const b1 = Repeated.encode({ list: [{ num: 1, payload: Buffer.from('lol') @@ -39,7 +39,7 @@ tape('repeated encode + decode', function (t) { }] }) - var o1 = Repeated.decode(b1) + const o1 = Repeated.decode(b1) t.same(o1.list.length, 2) t.same(o1.list[0].num, 1) @@ -47,7 +47,7 @@ tape('repeated encode + decode', function (t) { t.same(o1.list[1].num, 2) t.same(o1.list[1].payload, Buffer.from('lol1')) - var b2 = Repeated.encode({ + const b2 = Repeated.encode({ list: [{ num: 1, payload: Buffer.from('lol') @@ -59,7 +59,7 @@ tape('repeated encode + decode', function (t) { meeh: 42 }) - var o2 = Repeated.decode(b2) + const o2 = Repeated.decode(b2) t.same(o2, o1) t.end() diff --git a/test/utf-8.js b/test/utf-8.js index f4d6352..dc730bd 100644 --- a/test/utf-8.js +++ b/test/utf-8.js @@ -1,12 +1,12 @@ -var tape = require('tape') -var UTF8 = require('./helpers/messages').UTF8 +const tape = require('tape') +const UTF8 = require('./helpers/messages').UTF8 tape('strings can be utf-8', function (t) { - var ex = { + const ex = { foo: 'ビッグデータ「人間の解釈が必要」「量の問題ではない」論と、もう一つのビッグデータ「人間の解釈が必要」「量の問題ではない」論と、もう一つの', bar: 42 } - var b1 = UTF8.encode(ex) + const b1 = UTF8.encode(ex) t.same(UTF8.decode(b1), ex) t.end()