xamarin/Monkey.Robotics — pull request #12 by dtaylorus (2014-10-19 05:21:46+00:00)
Title: Messaging enhancements

Hi!

I've implemented the following for the Monkey.Robotics messaging protocol:

- Support for messaging extensibility with forward and backward protocol compatibility using PBON encoding (pbon.info).
- Support for unsigned and byte[] variable types and larger message sizes.

I tried to maintain the overall structure of the client and server and added strongly-typed message classes that have a more robust serialization model under the covers.

The message header still contains only the ControlOp value, but it is now extensible without breaking compatibility with older clients/servers.

Each message now has a JSON-style begin and end marker { and } respectively, which will allow for backward compatible message reading even when new fields are added to the message.

Each message field now has a 1-byte identifier, which replaces the type-identifier byte when the type is already known (the strongly-typed message field values). This identifier can grow larger than 1 byte as necessary.

Field values are represented in a compact binary form per http://pbon.info, and support all of the primitive .NET types.

Unknown message fields are skipped during reading, enabling backward compatibility.

Variable (object) values are encoded as a PBON array of [type-prefix, value]. I used the same type-prefix byte values as originally coded. Encoding these values as a PBON type ensures that unknown values can be correctly skipped in a stream (i.e., the total length is known).

This basic protocol has plenty of room for enhancements, such as digital signatures and authentication tokens, which I've implemented in other projects. I kept this first implementation fairly simple to give it the best shot at running on NetDuino.

Unfortunately, I don't have the hardware to test and I don't see any mocks, so this code is largely untested (except for the Serialization folder, which comes from the Serialize.NET repo and is fully unit tested) and will probably require some more work to finalize.

I'm in Seattle and attend the Mobile .NET Developers group, and I'm happy to collaborate to test and make any necessary fixes if anyone is interested.