Hi!
I have created a protocol called CBOT (Character Based Object Transport) which is a direct JSON replacement especially for web development. Basically, it is a better and more robust protocol for transporting data while not being a binary protocol. The protocol already has full support in Java and TypeScript/JavaScript.
However, I have wanted to expand the language support and Python was a natural next choice for that. I am not really a Python expert but I have been able to get the implementation to a point where most of the protocol’s capabilities actually work. And I would really appreciate any feedback or live testing for the implementation.
So far I have:
- Implementation that supports most of the protocol capabilities
But I am not sure about:
- Whether I am using Python’s different datatypes correctly
- If the code is done in a pythonic way
- And many other things as well…
Here is a simple example of how the library usage looks in Python and JavaScript when it is used as a pure JSON replacement without schema:
from sisujs_cbot import Cbot, CbotOptions
# Create a CBot instance
cbot = Cbot(CbotOptions())
# Data
data = {
"name": "John Smith",
"age": 41.0,
"address": {
"street": "Second Avenue",
"postalCode": "1356-A",
"city": "Yorkistan"
},
"isNiceGuy": True,
"hobbies": [
"Playing cards",
"Shopping",
"Asking odd questions"
]
}
# Serialize
message = cbot.serialize(data)
# Deserialize
deserialized = cbot.deserialize(message)
Alternatively, the same in JavaScript:
import { Cbot } from "@sisujs/meta-cbot";
// Create a Cbot instance
const cbot = Cbot.getInstance();
// Data
data = {
name: "John Smith",
age: 41.0,
address: {
street: "Second Avenue",
postalCode: "1356-A",
city: "Yorkistan"
},
isNiceGuy: true,
hobbies: [
"Playing cards",
"Shopping",
"Asking odd questions"
]
};
// Serialize
const message = cbot.serialize(data);
// Deserialize
const deserialized = cbot.deserialize(message);
The protocol also has support for using schema (or typed model in my terminology), which creates a protocol-level contract between parties. And one feature that differentiates this protocol from others is that it has well-established support for polymorphic types.
Relevant links for the project and the implementation itself:
- Homepage: https://cbot.sisujs.fi
- Current implementation: python · 14-python-support · Sisujs / Sisujs · GitLab
If you are interested in the typed model examples, there are ongoing validation tests for all three languages to demonstrate how they match models with each other:
- Java: java/cbot/src/test/java/fi/sisujstest/cbot/typedmodel/TypedModelTest.java · 14-python-support · Sisujs / Sisujs · GitLab
- TypeScript: js/meta-cbot/src/test/cbot/typedmodel/typedmodel.test.ts · 14-python-support · Sisujs / Sisujs · GitLab
- Python: python/tests/test_model.py · 14-python-support · Sisujs / Sisujs · GitLab
Thank you for your help.