mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: transition to protobug
This commit is contained in:
1 parent
45dc99e1ce
commit
370ef2df65
16 files changed
+105
-387
No files matched your search
@@ -1,9 +0,0 @@
|
||||
import { lookupProtobufType, ProtoSource } from './lookupProtobufType';
|
||||
|
||||
export function decodeProtobuf<Type>(
|
||||
source: ProtoSource,
|
||||
type: string,
|
||||
data: Uint8Array,
|
||||
) {
|
||||
return lookupProtobufType(source, type).decode(data).toJSON() as Type;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { lookupProtobufType, ProtoSource } from './lookupProtobufType';
|
||||
|
||||
export function encodeProtobuf(
|
||||
source: ProtoSource,
|
||||
type: string,
|
||||
data: Record<string, any>,
|
||||
) {
|
||||
const message = lookupProtobufType(source, type);
|
||||
const verification = message.verify(data);
|
||||
|
||||
if (verification !== null) throw new Error(verification);
|
||||
|
||||
return message.encode(message.create(data)).finish();
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { encodeProtobuf } from './encodeProtobuf';
|
||||
import { ProtoSource } from './lookupProtobufType';
|
||||
|
||||
export async function encodeProtobufToBase64(
|
||||
source: ProtoSource,
|
||||
type: string,
|
||||
data: any,
|
||||
) {
|
||||
const array = encodeProtobuf(source, type, data);
|
||||
return Buffer.from(array).toString('base64');
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
export * from './decodeProtobuf';
|
||||
export * from './encodeProtobuf';
|
||||
export * from './encodeProtobufToBase64';
|
||||
export * from './lookupProtobufType';
|
||||
@@ -1,12 +0,0 @@
|
||||
import protobuf from 'protobufjs';
|
||||
import average_definitions from '../../protos/average_definitions.proto';
|
||||
import reviews from '../../protos/reviews.proto';
|
||||
import tank_definitions from '../../protos/tank_definitions.proto';
|
||||
|
||||
export type ProtoSource = keyof typeof protos;
|
||||
|
||||
const protos = { reviews, average_definitions, tank_definitions };
|
||||
|
||||
export function lookupProtobufType(source: ProtoSource, type: string) {
|
||||
return protobuf.parse(protos[source]).root.lookupType(type);
|
||||
}
|
||||
Reference in new issue
Block a user