react-api-adts
Version:
Helpful algebraic data types for API handling in React apps.
18 lines (17 loc) • 670 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.protoDecoder = exports.protoEncoder = void 0;
const api_1 = require("./api");
function serialize(writer) {
const bin = writer.finish();
return bin.buffer.slice(bin.byteOffset, bin.byteOffset + bin.byteLength);
}
const protobufContentType = "application/protobuf";
function protoEncoder(enc) {
return new api_1.Encoder(protobufContentType, (t) => serialize(enc.encode(t)));
}
exports.protoEncoder = protoEncoder;
function protoDecoder(dec) {
return new api_1.Decoder(protobufContentType, (buf) => dec.decode(new Uint8Array(buf)));
}
exports.protoDecoder = protoDecoder;