303 lines
8.5 KiB

// This file is auto generated by the protocol-buffers compiler
/* eslint-disable quotes */
/* eslint-disable indent */
/* eslint-disable no-redeclare */
/* eslint-disable camelcase */
// Remember to `npm install --save protocol-buffers-encodings`
var encodings = require('protocol-buffers-encodings')
var varint = encodings.varint
var skip = encodings.skip
exports.TYPE = {
QUERY: 1,
UPDATE: 2,
RESPONSE: 3
}
var Holepunch = exports.Holepunch = {
buffer: true,
encodingLength: null,
encode: null,
decode: null
}
var Message = exports.Message = {
buffer: true,
encodingLength: null,
encode: null,
decode: null
}
defineHolepunch()
defineMessage()
function defineHolepunch () {
Holepunch.encodingLength = encodingLength
Holepunch.encode = encode
Holepunch.decode = decode
function encodingLength (obj) {
var length = 0
if (defined(obj.from)) {
var len = encodings.bytes.encodingLength(obj.from)
length += 1 + len
}
if (defined(obj.to)) {
var len = encodings.bytes.encodingLength(obj.to)
length += 1 + len
}
return length
}
function encode (obj, buf, offset) {
if (!offset) offset = 0
if (!buf) buf = Buffer.allocUnsafe(encodingLength(obj))
var oldOffset = offset
if (defined(obj.from)) {
buf[offset++] = 18
encodings.bytes.encode(obj.from, buf, offset)
offset += encodings.bytes.encode.bytes
}
if (defined(obj.to)) {
buf[offset++] = 26
encodings.bytes.encode(obj.to, buf, offset)
offset += encodings.bytes.encode.bytes
}
encode.bytes = offset - oldOffset
return buf
}
function decode (buf, offset, end) {
if (!offset) offset = 0
if (!end) end = buf.length
if (!(end <= buf.length && offset <= buf.length)) throw new Error("Decoded message is not valid")
var oldOffset = offset
var obj = {
from: null,
to: null
}
while (true) {
if (end <= offset) {
decode.bytes = offset - oldOffset
return obj
}
var prefix = varint.decode(buf, offset)
offset += varint.decode.bytes
var tag = prefix >> 3
switch (tag) {
case 2:
obj.from = encodings.bytes.decode(buf, offset)
offset += encodings.bytes.decode.bytes
break
case 3:
obj.to = encodings.bytes.decode(buf, offset)
offset += encodings.bytes.decode.bytes
break
default:
offset = skip(prefix & 7, buf, offset)
}
}
}
}
function defineMessage () {
Message.encodingLength = encodingLength
Message.encode = encode
Message.decode = decode
function encodingLength (obj) {
var length = 0
if (defined(obj.version)) {
var len = encodings.varint.encodingLength(obj.version)
length += 1 + len
}
if (!defined(obj.type)) throw new Error("type is required")
var len = encodings.enum.encodingLength(obj.type)
length += 1 + len
if (!defined(obj.rid)) throw new Error("rid is required")
var len = encodings.varint.encodingLength(obj.rid)
length += 1 + len
if (defined(obj.to)) {
var len = encodings.bytes.encodingLength(obj.to)
length += 1 + len
}
if (defined(obj.id)) {
var len = encodings.bytes.encodingLength(obj.id)
length += 1 + len
}
if (defined(obj.target)) {
var len = encodings.bytes.encodingLength(obj.target)
length += 1 + len
}
if (defined(obj.closerNodes)) {
var len = encodings.bytes.encodingLength(obj.closerNodes)
length += 1 + len
}
if (defined(obj.roundtripToken)) {
var len = encodings.bytes.encodingLength(obj.roundtripToken)
length += 1 + len
}
if (defined(obj.command)) {
var len = encodings.string.encodingLength(obj.command)
length += 1 + len
}
if (defined(obj.error)) {
var len = encodings.string.encodingLength(obj.error)
length += 1 + len
}
if (defined(obj.value)) {
var len = encodings.bytes.encodingLength(obj.value)
length += 1 + len
}
return length
}
function encode (obj, buf, offset) {
if (!offset) offset = 0
if (!buf) buf = Buffer.allocUnsafe(encodingLength(obj))
var oldOffset = offset
if (defined(obj.version)) {
buf[offset++] = 88
encodings.varint.encode(obj.version, buf, offset)
offset += encodings.varint.encode.bytes
}
if (!defined(obj.type)) throw new Error("type is required")
buf[offset++] = 8
encodings.enum.encode(obj.type, buf, offset)
offset += encodings.enum.encode.bytes
if (!defined(obj.rid)) throw new Error("rid is required")
buf[offset++] = 16
encodings.varint.encode(obj.rid, buf, offset)
offset += encodings.varint.encode.bytes
if (defined(obj.to)) {
buf[offset++] = 82
encodings.bytes.encode(obj.to, buf, offset)
offset += encodings.bytes.encode.bytes
}
if (defined(obj.id)) {
buf[offset++] = 26
encodings.bytes.encode(obj.id, buf, offset)
offset += encodings.bytes.encode.bytes
}
if (defined(obj.target)) {
buf[offset++] = 34
encodings.bytes.encode(obj.target, buf, offset)
offset += encodings.bytes.encode.bytes
}
if (defined(obj.closerNodes)) {
buf[offset++] = 42
encodings.bytes.encode(obj.closerNodes, buf, offset)
offset += encodings.bytes.encode.bytes
}
if (defined(obj.roundtripToken)) {
buf[offset++] = 50
encodings.bytes.encode(obj.roundtripToken, buf, offset)
offset += encodings.bytes.encode.bytes
}
if (defined(obj.command)) {
buf[offset++] = 58
encodings.string.encode(obj.command, buf, offset)
offset += encodings.string.encode.bytes
}
if (defined(obj.error)) {
buf[offset++] = 66
encodings.string.encode(obj.error, buf, offset)
offset += encodings.string.encode.bytes
}
if (defined(obj.value)) {
buf[offset++] = 74
encodings.bytes.encode(obj.value, buf, offset)
offset += encodings.bytes.encode.bytes
}
encode.bytes = offset - oldOffset
return buf
}
function decode (buf, offset, end) {
if (!offset) offset = 0
if (!end) end = buf.length
if (!(end <= buf.length && offset <= buf.length)) throw new Error("Decoded message is not valid")
var oldOffset = offset
var obj = {
version: 0,
type: 1,
rid: 0,
to: null,
id: null,
target: null,
closerNodes: null,
roundtripToken: null,
command: "",
error: "",
value: null
}
var found1 = false
var found2 = false
while (true) {
if (end <= offset) {
if (!found1 || !found2) throw new Error("Decoded message is not valid")
decode.bytes = offset - oldOffset
return obj
}
var prefix = varint.decode(buf, offset)
offset += varint.decode.bytes
var tag = prefix >> 3
switch (tag) {
case 11:
obj.version = encodings.varint.decode(buf, offset)
offset += encodings.varint.decode.bytes
break
case 1:
obj.type = encodings.enum.decode(buf, offset)
offset += encodings.enum.decode.bytes
found1 = true
break
case 2:
obj.rid = encodings.varint.decode(buf, offset)
offset += encodings.varint.decode.bytes
found2 = true
break
case 10:
obj.to = encodings.bytes.decode(buf, offset)
offset += encodings.bytes.decode.bytes
break
case 3:
obj.id = encodings.bytes.decode(buf, offset)
offset += encodings.bytes.decode.bytes
break
case 4:
obj.target = encodings.bytes.decode(buf, offset)
offset += encodings.bytes.decode.bytes
break
case 5:
obj.closerNodes = encodings.bytes.decode(buf, offset)
offset += encodings.bytes.decode.bytes
break
case 6:
obj.roundtripToken = encodings.bytes.decode(buf, offset)
offset += encodings.bytes.decode.bytes
break
case 7:
obj.command = encodings.string.decode(buf, offset)
offset += encodings.string.decode.bytes
break
case 8:
obj.error = encodings.string.decode(buf, offset)
offset += encodings.string.decode.bytes
break
case 9:
obj.value = encodings.bytes.decode(buf, offset)
offset += encodings.bytes.decode.bytes
break
default:
offset = skip(prefix & 7, buf, offset)
}
}
}
}
function defined (val) {
return val !== null && val !== undefined && (typeof val !== 'number' || !isNaN(val))
}