syndicate-js/packages/server/src/protocol.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

"use strict";
2019-09-11 14:11:15 +00:00
import { Map, Decoder, Encoder, Discard, Capture, Observe } from "@syndicate-lang/core";
2019-05-12 22:26:01 +00:00
message type Connect(scope);
message type Turn(items);
message type Assert(endpointName, assertion);
message type Clear(endpointName);
message type Message(body);
message type Add(endpointName, captures);
message type Del(endpointName, captures);
message type Msg(endpointName, captures);
message type End(endpointName);
2019-06-11 23:22:53 +00:00
message type Err(detail, context);
2019-03-18 23:29:43 +00:00
message type Ping();
message type Pong();
2019-09-11 14:11:15 +00:00
const _decode_placeholders =
(Map()
.set(0, Discard.constructorInfo.label)
.set(1, Capture.constructorInfo.label)
.set(2, Observe.constructorInfo.label));
const _encode_placeholders = _decode_placeholders.mapEntries((e) => [e[1], e[0]]);
function makeDecoder(initialBuffer) {
2019-09-11 14:11:15 +00:00
return new Decoder(initialBuffer, {placeholders: _decode_placeholders});
}
function makeEncoder() {
return new Encoder({placeholders: _encode_placeholders});
}
2019-06-20 12:35:04 +00:00
function shouldDebugPrint(m) {
// return !(Ping.isClassOf(m) || Pong.isClassOf(m));
return true;
}
Object.assign(module.exports, {
2019-06-08 20:14:00 +00:00
Connect,
Turn,
Assert, Clear, Message,
Add, Del, Msg, Err, End,
2019-03-18 23:29:43 +00:00
Ping, Pong,
2019-09-11 14:11:15 +00:00
makeDecoder, makeEncoder,
2019-06-20 12:35:04 +00:00
shouldDebugPrint,
});