From d7b99fa935224f662da5f5140fffed093e76088f Mon Sep 17 00:00:00 2001 From: AlexejStukov Date: Thu, 21 Jul 2016 09:29:44 +0200 Subject: [PATCH] added encode to Binding --- channels/binding/base.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/channels/binding/base.py b/channels/binding/base.py index c7b4ba0..f7a8984 100644 --- a/channels/binding/base.py +++ b/channels/binding/base.py @@ -88,6 +88,13 @@ class Binding(object): Entry point for triggering the binding from save signals. """ cls.trigger_outbound(instance, "delete") + + @classmethod + def encode(cls, stream, payload): + """ + Encodes stream + payload for outbound sending. + """ + raise NotImplementedError() @classmethod def trigger_outbound(cls, instance, action): @@ -100,7 +107,7 @@ class Binding(object): payload = self.serialize(instance, action) if payload != {}: assert self.stream is not None - message = WebsocketDemultiplexer.encode(self.stream, payload) + message = cls.encode(self.stream, payload) for group_name in self.group_names(instance, action): group = Group(group_name) group.send(message) @@ -115,9 +122,7 @@ class Binding(object): def serialize(self, instance, action): """ Should return a serialized version of the instance to send over the - wire (return value must be a dict suitable for sending over a channel - - e.g., to send JSON as a WebSocket text frame, you must return - {"text": json.dumps(instance_serialized_as_dict)} + wire (e.g. {"pk": 12, "value": 42, "string": "some string"}) """ raise NotImplementedError()