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

46 lines
1.5 KiB
Python
Raw Normal View History

2018-11-20 19:45:27 +00:00
import preserves
2019-09-11 14:00:27 +00:00
from preserves import Record
2018-11-20 19:45:27 +00:00
2019-05-16 11:46:22 +00:00
## Enrolment
Connect = Record.makeConstructor('Connect', 'scope')
2019-05-30 21:35:56 +00:00
## Bidirectional
2019-06-11 23:26:40 +00:00
Turn = Record.makeConstructor('Turn', 'items')
2019-05-30 21:35:56 +00:00
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-06-07 14:06:18 +00:00
End = Record.makeConstructor('End', 'endpointName')
2019-06-11 23:26:40 +00:00
Err = Record.makeConstructor('Err', 'detail context')
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', '')
_decode_placeholders = {
0: Discard.constructorInfo.key,
1: Capture.constructorInfo.key,
2: Observe.constructorInfo.key,
}
_encode_placeholders = dict(((v, k) for (k, v) in _decode_placeholders.items()))
2018-11-20 19:45:27 +00:00
class Decoder(preserves.Decoder):
def __init__(self, *args, **kwargs):
super(Decoder, self).__init__(*args, placeholders=_decode_placeholders, **kwargs)
2018-11-20 19:45:27 +00:00
class Encoder(preserves.Encoder):
def __init__(self, *args, **kwargs):
super(Encoder, self).__init__(*args, placeholders=_encode_placeholders, **kwargs)