dht-data/src/messages.ts

265 lines
11 KiB
TypeScript

// @generated by protobuf-ts 2.8.1
// @generated from protobuf file "messages.proto" (syntax proto2)
// tslint:disable
import type { BinaryWriteOptions } from "@protobuf-ts/runtime";
import type { IBinaryWriter } from "@protobuf-ts/runtime";
import { WireType } from "@protobuf-ts/runtime";
import type { BinaryReadOptions } from "@protobuf-ts/runtime";
import type { IBinaryReader } from "@protobuf-ts/runtime";
import { UnknownFieldHandler } from "@protobuf-ts/runtime";
import type { PartialMessage } from "@protobuf-ts/runtime";
import { reflectionMergePartial } from "@protobuf-ts/runtime";
import { MESSAGE_TYPE } from "@protobuf-ts/runtime";
import { MessageType } from "@protobuf-ts/runtime";
/**
* @generated from protobuf message Message
*/
export interface Message {
/**
* @generated from protobuf field: Type type = 1;
*/
type: Type;
/**
* @generated from protobuf field: map<string, State> bootstrap = 2;
*/
bootstrap: {
[key: string]: State;
}; // For bootstrap events
/**
* @generated from protobuf field: optional bytes data = 3;
*/
data?: Uint8Array; // For state event
/**
* @generated from protobuf field: optional bytes signature = 4;
*/
signature?: Uint8Array;
/**
* @generated from protobuf field: optional int64 timestamp = 5;
*/
timestamp?: bigint;
/**
* @generated from protobuf field: optional bytes id = 6;
*/
id?: Uint8Array; // For connected and disconnected events
}
/**
* @generated from protobuf message State
*/
export interface State {
/**
* @generated from protobuf field: repeated bytes connectedTo = 1;
*/
connectedTo: Uint8Array[];
/**
* @generated from protobuf field: optional bytes data = 2;
*/
data?: Uint8Array;
/**
* @generated from protobuf field: optional bytes signature = 3;
*/
signature?: Uint8Array;
/**
* @generated from protobuf field: optional int64 timestamp = 4;
*/
timestamp?: bigint;
}
/**
* @generated from protobuf enum Type
*/
export enum Type {
/**
* @generated synthetic value - protobuf-ts requires all enums to have a 0 value
*/
UNSPECIFIED$ = 0,
/**
* @generated from protobuf enum value: BOOTSTRAP_REQUEST = 1;
*/
BOOTSTRAP_REQUEST = 1,
/**
* @generated from protobuf enum value: BOOTSTRAP_RESPONSE = 2;
*/
BOOTSTRAP_RESPONSE = 2,
/**
* @generated from protobuf enum value: CONNECTED = 3;
*/
CONNECTED = 3,
/**
* @generated from protobuf enum value: DISCONNECTED = 4;
*/
DISCONNECTED = 4,
/**
* @generated from protobuf enum value: STATE = 5;
*/
STATE = 5
}
// @generated message type with reflection information, may provide speed optimized methods
class Message$Type extends MessageType<Message> {
constructor() {
super("Message", [
{ no: 1, name: "type", kind: "enum", T: () => ["Type", Type] },
{ no: 2, name: "bootstrap", kind: "map", K: 9 /*ScalarType.STRING*/, V: { kind: "message", T: () => State } },
{ no: 3, name: "data", kind: "scalar", opt: true, T: 12 /*ScalarType.BYTES*/ },
{ no: 4, name: "signature", kind: "scalar", opt: true, T: 12 /*ScalarType.BYTES*/ },
{ no: 5, name: "timestamp", kind: "scalar", opt: true, T: 3 /*ScalarType.INT64*/, L: 0 /*LongType.BIGINT*/ },
{ no: 6, name: "id", kind: "scalar", opt: true, T: 12 /*ScalarType.BYTES*/ }
]);
}
create(value?: PartialMessage<Message>): Message {
const message = { type: 0, bootstrap: {} };
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
if (value !== undefined)
reflectionMergePartial<Message>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Message): Message {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* Type type */ 1:
message.type = reader.int32();
break;
case /* map<string, State> bootstrap */ 2:
this.binaryReadMap2(message.bootstrap, reader, options);
break;
case /* optional bytes data */ 3:
message.data = reader.bytes();
break;
case /* optional bytes signature */ 4:
message.signature = reader.bytes();
break;
case /* optional int64 timestamp */ 5:
message.timestamp = reader.int64().toBigInt();
break;
case /* optional bytes id */ 6:
message.id = reader.bytes();
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
private binaryReadMap2(map: Message["bootstrap"], reader: IBinaryReader, options: BinaryReadOptions): void {
let len = reader.uint32(), end = reader.pos + len, key: keyof Message["bootstrap"] | undefined, val: Message["bootstrap"][any] | undefined;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case 1:
key = reader.string();
break;
case 2:
val = State.internalBinaryRead(reader, reader.uint32(), options);
break;
default: throw new globalThis.Error("unknown map entry field for field Message.bootstrap");
}
}
map[key ?? ""] = val ?? State.create();
}
internalBinaryWrite(message: Message, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* Type type = 1; */
if (message.type !== 0)
writer.tag(1, WireType.Varint).int32(message.type);
/* map<string, State> bootstrap = 2; */
for (let k of Object.keys(message.bootstrap)) {
writer.tag(2, WireType.LengthDelimited).fork().tag(1, WireType.LengthDelimited).string(k);
writer.tag(2, WireType.LengthDelimited).fork();
State.internalBinaryWrite(message.bootstrap[k], writer, options);
writer.join().join();
}
/* optional bytes data = 3; */
if (message.data !== undefined)
writer.tag(3, WireType.LengthDelimited).bytes(message.data);
/* optional bytes signature = 4; */
if (message.signature !== undefined)
writer.tag(4, WireType.LengthDelimited).bytes(message.signature);
/* optional int64 timestamp = 5; */
if (message.timestamp !== undefined)
writer.tag(5, WireType.Varint).int64(message.timestamp);
/* optional bytes id = 6; */
if (message.id !== undefined)
writer.tag(6, WireType.LengthDelimited).bytes(message.id);
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message Message
*/
export const Message = new Message$Type();
// @generated message type with reflection information, may provide speed optimized methods
class State$Type extends MessageType<State> {
constructor() {
super("State", [
{ no: 1, name: "connectedTo", kind: "scalar", repeat: 2 /*RepeatType.UNPACKED*/, T: 12 /*ScalarType.BYTES*/ },
{ no: 2, name: "data", kind: "scalar", opt: true, T: 12 /*ScalarType.BYTES*/ },
{ no: 3, name: "signature", kind: "scalar", opt: true, T: 12 /*ScalarType.BYTES*/ },
{ no: 4, name: "timestamp", kind: "scalar", opt: true, T: 3 /*ScalarType.INT64*/, L: 0 /*LongType.BIGINT*/ }
]);
}
create(value?: PartialMessage<State>): State {
const message = { connectedTo: [] };
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
if (value !== undefined)
reflectionMergePartial<State>(this, message, value);
return message;
}
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: State): State {
let message = target ?? this.create(), end = reader.pos + length;
while (reader.pos < end) {
let [fieldNo, wireType] = reader.tag();
switch (fieldNo) {
case /* repeated bytes connectedTo */ 1:
message.connectedTo.push(reader.bytes());
break;
case /* optional bytes data */ 2:
message.data = reader.bytes();
break;
case /* optional bytes signature */ 3:
message.signature = reader.bytes();
break;
case /* optional int64 timestamp */ 4:
message.timestamp = reader.int64().toBigInt();
break;
default:
let u = options.readUnknownField;
if (u === "throw")
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
let d = reader.skip(wireType);
if (u !== false)
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
}
}
return message;
}
internalBinaryWrite(message: State, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter {
/* repeated bytes connectedTo = 1; */
for (let i = 0; i < message.connectedTo.length; i++)
writer.tag(1, WireType.LengthDelimited).bytes(message.connectedTo[i]);
/* optional bytes data = 2; */
if (message.data !== undefined)
writer.tag(2, WireType.LengthDelimited).bytes(message.data);
/* optional bytes signature = 3; */
if (message.signature !== undefined)
writer.tag(3, WireType.LengthDelimited).bytes(message.signature);
/* optional int64 timestamp = 4; */
if (message.timestamp !== undefined)
writer.tag(4, WireType.Varint).int64(message.timestamp);
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
return writer;
}
}
/**
* @generated MessageType for protobuf message State
*/
export const State = new State$Type();