NEP+ Docs
  • NEP+ middleware documentation
  • Developer Tools
    • NEP CLI
  • User interfaces
    • Install NEP+ App (Windows)
    • Install NEP+ App (macOS)
    • NEP+ App (0.0.4) - Deprecated
  • Concepts for developers
    • Message Format
    • Tutorials for developers
      • Connecting Multiple Scripts on the Same Computer using NEP+ Tools: A Step-by-Step Tutorial
      • Connecting 2 scripts in a local network (e.g., two computers on the same Wifi network)
      • Connecting ROS to non-ROS nodes using NEP+ tools
  • Programming enviroments
    • Python
    • C# (Unity)
    • C# (Visual Studio)
    • Javascript (Node.js)
    • Java/Kotlin (Android Studio)
    • Java (Netbeans)
    • C++ (Visual Studio)
  • Other tutorials
    • Pepper & NAO robots
      • Using Pepper without Pepper in Choregraphe
      • Install Pepper/NAO SDK
  • Code examples
    • Sending images from Python and Opencv
Powered by GitBook
On this page
  • Message serialization and types in NEP+
  • JSON
  • MessagePack:
  • Base64 for Images:
  • ROS Messages Types:
  • No serialization:
  1. Concepts for developers

Message Format

How messages are defined in NEP+?

Message serialization and types in NEP+

NEP+ provide the flexibility of using different message formats to send data between components of a distributed system. Here, we will discuss the pros and cons of using available formats in NEP+.

By default, NEP libraries use JSON as a message format.

JSON

JSON is a lightweight and widely used data interchange format that is easy for both humans and machines to read and write. It is based on a subset of the JavaScript programming language and has become a popular choice for representing structured data in various programming languages and applications. JSON data comprises key-value pairs, arrays, and nested objects, making it suitable for organizing and transmitting complex data structures.

Pros:

  • Easy to work with and widely supported in various programming languages.

  • Human-readable and self-describing data structure.

  • Well-suited for structured data with nested objects.

Cons:

  • Larger message size compared to binary formats due to textual representation.

  • Slower encoding and decoding for large messages.

MessagePack:

MessagePack is a binary serialization format that efficiently encodes data in a compact binary representation. It is designed to be fast, lightweight, and suitable for high-performance data exchange between different systems and programming languages. MessagePack is not human-readable like JSON, but its compactness and speed make it an excellent choice for data serialization, especially in scenarios where low overhead and reduced bandwidth usage are essential.

Pros:

  • Compact binary format with a small message size, leading to reduced network bandwidth and faster transmission.

  • Faster serialization and deserialization compared to JSON.

  • Supports most data types efficiently.

Cons:

  • Not human-readable, which can make debugging more challenging.

  • Limited support in some programming languages compared to JSON.

Base64 for Images:

Base64 is a binary-to-text encoding scheme that converts binary data into an ASCII string representation. It is commonly used to represent binary data, such as images.

Pros:

  • Convenient for transmitting binary data, like images, over text-based protocols.

  • Ensures compatibility with systems that may not support binary data transmission.

  • Useful when working with older systems that lack support for MessagePack or other binary formats.

Cons:

  • Larger message size due to encoding overhead (33% increase in size).

  • Slower encoding and decoding for large images compared to binary formats.

In Python, users can send OpenCV images directly. They are converted sed as Base64 format

ROS Messages Types:

Only recommended for applications requiring integration with the Robot Operating System (ROS).

Pros:

  • ROS messages are a native part of the ROS ecosystem, making them seamless to use within ROS-based applications. They are well-integrated with ROS tools, such as rosbag for data recording and playback.

Cons:

  • ROS messages are designed primarily for communication within the ROS ecosystem. Using them outside of ROS applications may require additional effort or conversion, leading to increased message size and overhead, especially for complex data structures. This can impact communication performance and bandwidth usage.

  • Using ROS messages in non-ROS applications or systems with different serialization formats can introduce compatibility challenges.

ROS Messages Types are implemented as C# classes (more languages can be supported in the future) and not as native ROS messages. They require using the NEP Bridge tool to communicate with the ROS ecosystem.

No serialization:

No serialization requires developers to implement their desired data representation manually.

Pros:

  • It provides developers with the flexibility to choose their desired data representation.

  • It can be suitable for applications with custom data structures or domain-specific requirements.

Cons:

  • This can be more complex and time-consuming compared to using standardized serialization formats.

  • Developers must ensure that both the sender and receiver agree on the data representation to prevent data corruption and maintain compatibility.

MessagePack is implemented in Python and C# and will be implemented in other languages.

The message format choice depends on your application's requirements and the trade-offs you are willing to make between message size, serialization/deserialization speed, human readability, and language support. For efficient data transmission, especially with large datasets or binary data like images, MessagePack is often a good choice. However, if human readability and compatibility with older systems are essential, JSON or Base64 can be considered. Evaluating your system's needs and choosing the most appropriate message format is necessary.

Last updated 1 year ago