Code Monkey home page Code Monkey logo

msglite-cpp's Introduction

Introduction

MsgLite is a format designed for reliable data transmission over loss-prone streams such as UART. It has the following features:

  1. MsgLite is protected with a CRC32 checksum and implements a resilient stream unpacker, capable of filtering out corrupted bytes.

  2. MsgLite is designed for microcontrollers, requiring no dynamic memory allocation or C++ STL.

  3. MsgLite implements a subset of MessagePack, ensuring compatibility and simplifying communication with high-end targets like Raspberry Pi that can run Python, Golang, etc.

  4. MsgLite has no external dependencies. Simply pull one header and one source file, and you're good to go.

Demo

#include <cstdio>

#include "msglite.h"

int main()
{
    // A demo message consists of three objects: [String, Bool, Float]
    MsgLite::Message message("helloworld", true, 3.1415926f);

    // A byte array that can hold any MsgLite message
    MsgLite::Buffer buffer;

    // Pack the message into the buffer using Pack()
    bool pack_successful = MsgLite::Pack(message, buffer);
    if (!pack_successful) {
        printf("Failed to pack the message.\n");
        return 1;
    }
    printf("Message packed successfully.\n");

    MsgLite::Unpacker unpacker;

    // Feed bytes to the stream unpacker
    for (int ii = 0; ii < buffer.len; ++ii) {
        bool message_available = unpacker.put(buffer.data[ii]);
        if (message_available) {
            printf("Message unpacked successfully.\n");
            break;
        }
    }

    return 0;
}

Format

MsgLite is MessagePack and can transfer up to 15 objects per message in these formats:

+--------+------------------+-------------------+---------------------+
| Header | Checksum (CRC32) | Number of objects |       Objects       |
+--------+------------------+-------------------+---------------------+
|  0x92  |  0xCE + 4 bytes  |    0x90 to 0x9F   | Same as MessagePack |
+--------+------------------+-------------------+---------------------+

Objects can be:

  • Bool
  • 8/16/32/64-bit unsigned integer
  • 8/16/32/64-bit signed integer
  • 32/64-bit floating point number
  • Strings (up to 15 characters, cannot hold '\0')

The MsgLite format ensures that each valid message, after serialization, is no longer than 247 bytes. Therefore, the unpacker can reject data that is too long, ensuring self-recovery from corrupted data.

msglite-cpp's People

Contributors

jwangac avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.