-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added wire format, changes to implement it
- Loading branch information
1 parent
f3da249
commit 0200df1
Showing
8 changed files
with
91 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import json | ||
|
||
from google.protobuf import json_format | ||
|
||
|
||
from serde.serde import Serde | ||
from serde.wire import Wire | ||
|
||
|
||
class JsonSerde(Serde, Wire): | ||
def serialise(self, event): | ||
return bytes(json.dumps(event), "utf-8") | ||
|
||
def get_content_type(self): | ||
return "application/json" | ||
|
||
def marshal(self, event): | ||
return json_format.MessageToJson(event) | ||
|
||
def unmarshal(self, data, template): | ||
return json_format.Parse(data, template) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
class Serde: | ||
def serialise(self, event): | ||
raise NotImplementedError() | ||
|
||
def deserialise(self, data, template): | ||
raise NotImplementedError() | ||
|
||
def get_content_type(self): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
from serde.enum import ContentType | ||
from serde.enum import Serialiser, WireType | ||
from serde.json_serde import JsonSerde | ||
from serde.serde import Serde | ||
from serde.wire import Wire | ||
|
||
|
||
def get_serde(content_type): | ||
if content_type == ContentType.JSON: | ||
def get_serde(serialiser) -> Serde: | ||
if serialiser == Serialiser.JSON: | ||
return JsonSerde() | ||
else: | ||
return NotImplementedError() | ||
raise NotImplementedError() | ||
|
||
def get_wire_type(wire_type) -> Wire: | ||
if wire_type == WireType.JSON: | ||
return JsonSerde() | ||
else: | ||
raise NotImplementedError() | ||
|
||
|
||
CONTENT_TYPE_HEADER_KEY = "Content-Type" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Wire: | ||
def marshal(self, obj): | ||
raise NotImplementedError("not implemented") | ||
|
||
def unmarshal(self, obj, template): | ||
raise NotImplementedError("not implemented") | ||
|
||
def get_content_type(self): | ||
raise NotImplementedError("not implemented") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters