---
description: How messages are defined in NEP+?
---

# Message Format

## Message serialization and types in NEP+&#x20;

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+.

{% hint style="success" %}
By default, NEP libraries use JSON as a message format.&#x20;
{% endhint %}

### **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.

{% hint style="info" %}
In Python, users can send OpenCV images directly. They are converted sed as Base64 format
{% endhint %}

### **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.&#x20;

{% hint style="info" %}
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.
{% endhint %}

### **No serialization:**

No serialization requires developers to implement their desired data representation manually.&#x20;

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.&#x20;

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.

{% hint style="info" %}
MessagePack is implemented in Python and C# and will be implemented in other languages.
{% endhint %}

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.

