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

46 lines
984 B
JavaScript
Raw Normal View History

"use strict";
import { Decoder, 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();
function makeDecoder(initialBuffer) {
return new Decoder(initialBuffer, {
shortForms: {
0: Discard.constructorInfo.label,
1: Capture.constructorInfo.label,
2: Observe.constructorInfo.label,
}
});
}
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,
makeDecoder,
2019-06-20 12:35:04 +00:00
shouldDebugPrint,
});