Files
blitzkit/packages/core/src/protobuf/encodeProtobuf.ts
T
2024-09-06 23:17:53 -05:00

15 lines
394 B
TypeScript

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();
}