Skip to content

Dev_Serializers

Mehmet Emre Çakal edited this page Oct 10, 2024 · 2 revisions

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.6.2 / .NET Standard 2.0 / .NET Core 6.0 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, 2017-2024

Clone this wiki locally