dht-flood/dist/messages.js

145 lines
5.1 KiB
JavaScript

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Packet = exports.protobufPackage = void 0;
/* eslint-disable */
const _m0 = __importStar(require("protobufjs/minimal"));
exports.protobufPackage = "";
function createBasePacket() {
return { originId: new Uint8Array(), messageNumber: 0, ttl: 0, data: new Uint8Array() };
}
exports.Packet = {
encode(message, writer = _m0.Writer.create()) {
if (message.originId.length !== 0) {
writer.uint32(10).bytes(message.originId);
}
if (message.messageNumber !== 0) {
writer.uint32(16).uint32(message.messageNumber);
}
if (message.ttl !== 0) {
writer.uint32(24).uint32(message.ttl);
}
if (message.data.length !== 0) {
writer.uint32(34).bytes(message.data);
}
return writer;
},
decode(input, length) {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBasePacket();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.originId = reader.bytes();
break;
case 2:
message.messageNumber = reader.uint32();
break;
case 3:
message.ttl = reader.uint32();
break;
case 4:
message.data = reader.bytes();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object) {
return {
originId: isSet(object.originId) ? bytesFromBase64(object.originId) : new Uint8Array(),
messageNumber: isSet(object.messageNumber) ? Number(object.messageNumber) : 0,
ttl: isSet(object.ttl) ? Number(object.ttl) : 0,
data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(),
};
},
toJSON(message) {
const obj = {};
message.originId !== undefined &&
(obj.originId = base64FromBytes(message.originId !== undefined ? message.originId : new Uint8Array()));
message.messageNumber !== undefined && (obj.messageNumber = Math.round(message.messageNumber));
message.ttl !== undefined && (obj.ttl = Math.round(message.ttl));
message.data !== undefined &&
(obj.data = base64FromBytes(message.data !== undefined ? message.data : new Uint8Array()));
return obj;
},
fromPartial(object) {
const message = createBasePacket();
message.originId = object.originId ?? new Uint8Array();
message.messageNumber = object.messageNumber ?? 0;
message.ttl = object.ttl ?? 0;
message.data = object.data ?? new Uint8Array();
return message;
},
};
var globalThis = (() => {
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw "Unable to locate global object";
})();
function bytesFromBase64(b64) {
if (globalThis.Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
}
else {
const bin = globalThis.atob(b64);
const arr = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; ++i) {
arr[i] = bin.charCodeAt(i);
}
return arr;
}
}
function base64FromBytes(arr) {
if (globalThis.Buffer) {
return globalThis.Buffer.from(arr).toString("base64");
}
else {
const bin = [];
arr.forEach((byte) => {
bin.push(String.fromCharCode(byte));
});
return globalThis.btoa(bin.join(""));
}
}
function isSet(value) {
return value !== null && value !== undefined;
}