Skip to content

Dev_Serializers

Berkay Alp Cakal edited this page Mar 30, 2020 · 1 revision

RosBridgeClient Serializers

The rosbridge protocol is a specification for sending JSON based commands to ROS.

In ROS# there are some options that you can choose to make (de-)serialization between the message packages and JSON based byte chunks. .NET and Newtonsoft are available JSON (de-)serialization tools in RosBridgeClient.

RosBridgeClient is designed to keep the serialization generic. New serializers can be added by implementing the ISerializer interface:

internal interface ISerializer
{
    byte[] Serialize<T>(T obj);
    DeserializedObject Deserialize(byte[] rawData);
    T Deserialize<T>(string JsonString);
}
internal abstract class DeserializedObject
{
    internal abstract string GetProperty(string property);
}

Note that the received byte array is first deserialized to DeserializedObject via Deserialize(byte[] rawData), then the properties of this JSON object are extracted. Referring to rosbridge protocol, the "msg" property contains a JSON object, which is deserialized into C# classes via T Deserialize<T>(string JsonString);.

Different JSON (de-)serialization libraries have their own type definitions for a JSON object, and fucntion definitions to extract properties from a JSON object. One should also implement the abstract class DeserializedObject accordingly.

You can see NewtonsoftJsonSerializer.cs and MicrosoftSerializer.cs as examples for implementations.

A RosSocket is instantiated by passing in the ISerializer implementation that you want to use.

Example:

// ...
RosSocket rosSocket = new RosSocket(IProtocol protocol, ISerializer serializer);

Currently existing ISerializer interface implementations:

  • .NET Framework 4.7.2 and later versions, find more info on its documentation.
  • See the .NET dependencies here
  • An open source external library, see its documentation here
  • For platform compatibilities, please see the issues.

© Siemens AG, 2020 Author: Berkay Alp Cakal ([email protected])

Clone this wiki locally