2024-09-06 23:17:53 -05:00
|
|
|
import { lookupProtobufType, ProtoSource } from './lookupProtobufType';
|
2024-06-28 20:08:50 -05:00
|
|
|
|
2024-09-06 23:17:53 -05:00
|
|
|
export function encodeProtobuf(
|
2024-09-03 21:47:06 -05:00
|
|
|
source: ProtoSource,
|
|
|
|
|
type: string,
|
|
|
|
|
data: Record<string, any>,
|
|
|
|
|
) {
|
2024-09-06 23:17:53 -05:00
|
|
|
const message = lookupProtobufType(source, type);
|
2024-09-03 21:47:06 -05:00
|
|
|
const verification = message.verify(data);
|
2024-08-25 18:10:56 -05:00
|
|
|
|
|
|
|
|
if (verification !== null) throw new Error(verification);
|
|
|
|
|
|
2024-09-03 21:47:06 -05:00
|
|
|
return message.encode(message.create(data)).finish();
|
2024-06-28 20:08:50 -05:00
|
|
|
}
|