43 lines
1.8 KiB
TypeScript
43 lines
1.8 KiB
TypeScript
//---------------------------------------------------------------------------
|
|
// @syndicate-lang/core, an implementation of Syndicate dataspaces for JS.
|
|
// Copyright (C) 2016-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
//---------------------------------------------------------------------------
|
|
|
|
import * as S from '../gen/sturdy.js';
|
|
import { Oid } from '../gen/protocol.js';
|
|
import { Ref } from '../runtime/actor.js';
|
|
import { Decoder, DecoderState, Encoder, EncoderState, GenericEmbedded, neverEmbeddedType, EmbeddedType, Value } from '@preserves/core';
|
|
|
|
export type WireSymbol = { oid: Oid, ref: Ref, count: number };
|
|
|
|
export const wireRefEmbeddedType: EmbeddedType<S.WireRef> = {
|
|
decode(s: DecoderState): S.WireRef {
|
|
return S.asWireRef(new Decoder<any>(s).next());
|
|
},
|
|
|
|
encode(s: EncoderState, v: S.WireRef): void {
|
|
new Encoder<any>(s, neverEmbeddedType).push(S.fromWireRef(v));
|
|
},
|
|
|
|
fromValue(v: Value<GenericEmbedded>): S.WireRef {
|
|
return S.asWireRef(v as Value<S._embedded>);
|
|
},
|
|
|
|
toValue(v: S.WireRef): Value<GenericEmbedded> {
|
|
return S.fromWireRef(v) as Value<GenericEmbedded>;
|
|
}
|
|
};
|