Date/Time: Mon, 15 Oct 2018 20:41:19 +0000
Post From: DTC Protocol
|User783015 - Posts: 7|
Thanks a lot for your replies!
I understand that the binary encoding is just a serialization format for sending the message over the wire. The challenge is how do I create a data structure in Python which will result in a binary data stream identical to the one produced by the C++ structure defined in the DTC protocol - in other words the binary data stream which the DTC server is expecting.
Python is a dynamically typed scripting language - you do not define a data type when you declare/define a variable. Consider the following python code:
var = 5
print( sys.getsizeof( var ) )
The output I get is "24" (on a 64-bit Win7 machine). So my tiny integer number is stored in a 24 byte big int memory space.
My point is that every language may use totally different binary encoding of its data and high level scripting languages like Perl or Python handle this in the background and don't even "bother" the user with these internals. Trying to make two different languages talk to each other in a binary format may be problematic. After some googling around I found https://docs.python.org/3.0/library/struct.html which should probably do what I'm looking for. But the question is how many other languages have something like that.
I would suggest to reconsider using the binary format as the default encoding for DTC. While you can construct a JSON file using any language you want - even as primitive as a batch file - constructing a binary message may be significantly more difficult. I guess that's also why the RESTful APIs became so popular - they allow very simple and limitless interoperability between different languages and even platforms. Using such a platform independent (yet less efficient, I agree) encoding by default, you may significantly increase the chances of wider adoption of the DTC protocol.
And thanks, SC Support, for the offer to add the encoding selection to the Sierra Chart DTC Server! I'll play with the Python struct module above but I will gladly use that new feature.