novy-syndicate/src/gen/box-protocol.ts

80 lines
2.8 KiB
TypeScript
Raw Normal View History

2021-03-11 17:00:45 +00:00
import * as _ from "@preserves/core";
import * as _i_Actor from "../actor";
2021-03-11 17:00:45 +00:00
export const $BoxState = Symbol.for("BoxState");
export const $SetBox = Symbol.for("SetBox");
export const BoxState = _.Record.makeConstructor<{"_field0": number}, _ptr>()($BoxState, ["_field0"]);
export type BoxState = _.Record<(typeof $BoxState), [number], _ptr>;
export const SetBox = _.Record.makeConstructor<{"_field0": number}, _ptr>()($SetBox, ["_field0"]);
export type SetBox = _.Record<(typeof $SetBox), [number], _ptr>;
export type _ptr = _i_Actor.Ref;
2021-03-11 17:00:45 +00:00
export type _val = _.Value<_ptr>;
export function isBoxState(v: any): v is BoxState {
return (
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.is(v.label, $BoxState) &&
((v.length === 1) && typeof v[0] === 'number')
);
}
export function asBoxState(v: any): BoxState {
if (!isBoxState(v)) {throw new TypeError(`Invalid BoxState: ${_.stringify(v)}`);} else {return v;};
}
2021-03-12 19:49:18 +00:00
export function decodeBoxState(d: _.TypedDecoder<_ptr>): BoxState | undefined {
return ((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $BoxState);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = d.nextSignedInteger(); if (v0 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0] as [number];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $BoxState), [number]>(L, Fs);
})());
}
2021-03-11 17:00:45 +00:00
export function isSetBox(v: any): v is SetBox {
return (
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
_.is(v.label, $SetBox) &&
((v.length === 1) && typeof v[0] === 'number')
);
}
export function asSetBox(v: any): SetBox {
if (!isSetBox(v)) {throw new TypeError(`Invalid SetBox: ${_.stringify(v)}`);} else {return v;};
}
2021-03-12 19:49:18 +00:00
export function decodeSetBox(d: _.TypedDecoder<_ptr>): SetBox | undefined {
return ((() => {
const M = d.mark();
if (!d.openRecord()) return void 0;
const L = _.checkIs(d.nextSymbol(), $SetBox);
if (L === void 0) { d.restoreMark(M); return void 0; };
const Fs = (((() => {
const M = d.mark();
const v0 = d.nextSignedInteger(); if (v0 === void 0) { d.restoreMark(M); return void 0; };
if (!d.closeCompound()) { d.restoreMark(M); return void 0; };
return [v0] as [number];
})())) as any;
if (Fs === void 0) { d.restoreMark(M); return void 0; };
return _.Record<(typeof $SetBox), [number]>(L, Fs);
})());
}
export const _decodePtr = (d: _.TypedDecoder<_ptr>) => _i_Actor.decodeRef(d);