mini-syndicate-py/syndicate/mini/protocol.py

45 lines
1.5 KiB
Python
Raw Normal View History

2018-11-20 19:45:27 +00:00
import preserves
from preserves import Record, Symbol
2019-05-16 11:46:22 +00:00
## Enrolment
Connect = Record.makeConstructor('Connect', 'scope')
Peer = Record.makeConstructor('Peer', 'scope')
2019-05-30 21:35:56 +00:00
## Bidirectional
Commit = Record.makeConstructor('Commit', '')
2019-05-16 11:46:22 +00:00
## Client -> Server
2018-11-20 19:45:27 +00:00
Assert = Record.makeConstructor('Assert', 'endpointName assertion')
Clear = Record.makeConstructor('Clear', 'endpointName')
Message = Record.makeConstructor('Message', 'body')
2019-05-16 11:46:22 +00:00
## Server -> Client
2018-11-20 19:45:27 +00:00
Add = Record.makeConstructor('Add', 'endpointName captures')
Del = Record.makeConstructor('Del', 'endpointName captures')
Msg = Record.makeConstructor('Msg', 'endpointName captures')
2019-05-16 13:59:23 +00:00
Err = Record.makeConstructor('Err', 'detail')
2018-11-20 19:45:27 +00:00
2019-03-22 12:52:25 +00:00
## Bidirectional
Ping = Record.makeConstructor('Ping', '')
Pong = Record.makeConstructor('Pong', '')
2018-11-20 19:45:27 +00:00
## Standard Syndicate constructors
Observe = Record.makeConstructor('observe', 'specification')
Capture = Record.makeConstructor('capture', 'specification')
Discard = Record.makeConstructor('discard', '')
class Decoder(preserves.Decoder):
def __init__(self, *args, **kwargs):
super(Decoder, self).__init__(*args, **kwargs)
_init_shortforms(self)
class Encoder(preserves.Encoder):
def __init__(self, *args, **kwargs):
super(Encoder, self).__init__(*args, **kwargs)
_init_shortforms(self)
def _init_shortforms(c):
c.set_shortform(0, Discard.constructorInfo.key)
c.set_shortform(1, Capture.constructorInfo.key)
c.set_shortform(2, Observe.constructorInfo.key)