pashto-inflector/src/lib/protobuf.ts

30 lines
992 B
TypeScript
Raw Normal View History

2021-03-10 11:37:35 +00:00
import * as T from "../types";
// @ts-ignore
import * as protoModels from "./dictionary-models.js";
import Pbf from "pbf";
2021-06-17 18:16:11 +00:00
export function writeDictionary(dictionary: T.Dictionary): ArrayBuffer {
2021-03-10 11:37:35 +00:00
const pbfDict = new Pbf();
protoModels.Dictionary.write(dictionary, pbfDict);
const buffer = pbfDict.finish();
return buffer;
}
export function readDictionary(buffer: Uint8Array): T.Dictionary {
const pbf = new Pbf(buffer);
const dictionary = protoModels.Dictionary.read(pbf) as T.Dictionary;
return dictionary;
}
2021-06-17 18:16:11 +00:00
export function writeDictionaryInfo(dictionary: T.DictionaryInfo): ArrayBuffer {
2021-03-10 11:37:35 +00:00
const pbfDict = new Pbf();
protoModels.DictionaryInfo.write(dictionary, pbfDict);
const buffer = pbfDict.finish();
return buffer;
}
export function readDictionaryInfo(buffer: Uint8Array): T.DictionaryInfo {
const pbf = new Pbf(buffer);
const dictionaryInfo = protoModels.DictionaryInfo.read(pbf) as T.DictionaryInfo;
return dictionaryInfo;
}