An implementation of CBOR in C

Overview

CBOR

This is a simple, small decoder for CBOR, the Concise Binary Object Representation. CBOR is defined by IETF RFC 8949, and Wikipedia has a good description.

Simplicity and code size are considered first.

The decoder takes 702 bytes for ARM Cortex-M0, using arm-none-eabi-gcc 10-2020-q4-major with optimization for code size -Os.

Stack usage per the major type function:

Major type Bytes
0: unsigned integer 16
1: negative integer 40
2: byte string 24
3: text string 24
4: array 8
5: map 8
6: tag(not implemented yet) 0
7: floating-point numbers, simple values and break 8

Features

  • C99
  • No dynamic allocations
  • Small memory footprint

Usage

  • CBOR_BIG_ENDIAN
  • CBOR_RECURSION_MAX_LEVEL

Decoder

struct {
	uint8_t u8_1;
	char txt[3];
	uint8_t u8_2;
} fmt;

uint8_t msg[] = { 0x83,0x01,0x63,0x61,0x62,0x63,0x03 };
cbor_decode(&fmt, sizeof(fmt), msg, sizeof(msg));

Encoder

Limitation

  • The maximum item length is size_t because the interface return type is size_t. The argument's value in the specification can go up to uint64_t though
  • A negative integer ranges down to -2^63-1 other than -2^64 in the specification
  • Tag item is not implemented yet
  • Encoder is not implemented yet
You might also like...
WireGuard implementation for ESP32 Arduino

WireGuard Implementation for ESP32 Arduino This is an implementation of the WireGuard® for ESP32 Arduino. Almost all of this code is based on the Wire

An implementation of the Mobile Adapter GB protocol, to connect to custom game servers.

libmobile Library that implements the Mobile Adapter GB protocol, in a way that should be easy to integrate into a plethora of different emulators/har

The implementation of the Domino Network protocol based program.

spacex The implementation of the Domino distributed storage network protocol for the Smart Ecology. With a fully featured and well documented that pro

Simple HTTP protocol implementation in C

C-SimpleHTTP A simple HTTP protocol implementation in C How do i run it? First of all, this project is made in c, then you will need GCC Compiler. The

LAppS - Lua Application Server for micro-services with default communication over WebSockets. The fastest and most vertically scalable WebSockets server implementation ever. Low latency C++ - Lua stack roundtrip.

LAppS - Lua Application Server This is an attempt to provide very easy to use Lua Application Server working over WebSockets protocol (RFC 6455). LApp

This project is implementation of TFTP protocol from scratch

TFTP This project is implementation of TFTP protocol from scratch

A language server protocol implementation

A barebone LSP implementation Starting point for server implementations of the LSP protocol. Provides the infrastructure to easily hook in functionali

A Tcp/Ip stack implementation on top of Solarflare ef_vi, and a C++ headers only framework for tcp multiplexing client/server.

Efvitcp Efvitcp is a tcp library using Solarflare ef_vi interface on linux, and also a tcp multiplexing framework for both C++ client and server progr

mvfst is a client and server implementation of IETF QUIC protocol in C++ by Facebook.
mvfst is a client and server implementation of IETF QUIC protocol in C++ by Facebook.

mvfst (Pronounced move fast) is a client and server implementation of IETF QUIC protocol in C++ by Facebook.

Comments
  • Excessive Recursion - Indefinite Containers

    Excessive Recursion - Indefinite Containers

    I have tested the lib functionality using several arrays and maps with indefinite lengths. Upon parsing the created buffer, the parser gives a CBOR_EXCESSIVE error.

    During my investigation, I have found that both parse() and go_get_item_length() functions are dealing with size_t variables, whereas the indefinite length is -1. I have not found any other functions or methods to parse indefinite length containers so far.

    Please give me guidance on how to overcome this issue. Thanks!

    bug 
    opened by RidanBulwark 6
  • new cbor_encode_text_string() incompatible with C99

    new cbor_encode_text_string() incompatible with C99

    The new cbor_encode_text_string() function uses strnlen() which is a C11 function. Also, the new function no longer takes text length as a parameter. I find the old function more useful. I suggest that the library has one function takes in length as parameter and one does not. The one using strnlen() can be compiled out when C99 compiler is used.

    opened by CaryChu 1
  • Added introductory paragraph to README.

    Added introductory paragraph to README.

    As discussed on Reddit, here's a short introductory paragraph that gives context for the project.

    https://www.reddit.com/r/C_Programming/comments/ohf8tz/an_implementation_of_cbor_in_c/

    opened by kbob 1
Releases(v0.3.1)
  • v0.3.1(Dec 9, 2022)

    v0.3.1

    Features

    • Add CMake scaffolding
    • Separate base.h from cbor.h to use cbor.h as single header file with all the necessary includes
    • Add unmarshal functionality for map

    Bug Fixes

    • Fix garbage data in the uninitialized buffer when decoding
    • Fix not working break stop code on indefinite array
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Sep 23, 2022)

    v0.3.0

    Changes

    • Breaking Change: Revert cbor_encode_text_string() to its original version
    • Add cbor_encode_null_terminated_string()
    • Fix to conform to C99 standard removing strnlen()
    • Increase the maximum recursion level from 4 to 8
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Aug 24, 2022)

    v0.2.0

    Changes

    • Breaking Change: Change the reader and the parser initializer prototypes
      • cbor_reader_init() and cbor_parse()
      • Now a reader can be reusable to different messages
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Aug 24, 2022)

Owner
Kyunghwan Kwon
Kyunghwan Kwon
C++11 implementation of Socket.IO client

By virtue of being written in C++, this client works in several different platforms. The examples folder contains an iPhone, QT and Console example chat client! It depends on websocket++ and is inspired by socket.io-clientpp.

Socket.IO 2k Jan 3, 2023
hessian2-codec it is a complete C++ implementation of hessian2 spec

hessian2-codec is a C++ library from Alibaba for hessian2 codec. It is a complete C++ implementation of hessian2 spec. Because it was originally intended to implement the Dubbo Filter of Envoy, it did not provide good support for serialization of user-defined types (there is only one way to implement user-defined types using ADL, but it is not very complete and does not support nested types well). At the moment it is simply deserializing content into some C++ intermediate types.

Alibaba 16 Nov 15, 2022
FreeModbus is a Modbus ASCII/RTU and Modbus TCP implementation for embedded systems

FreeModbus is a Modbus ASCII/RTU and Modbus TCP implementation for embedded systems. It provides an implementation of the Modbus Application Protocol

Mahmood Hosseini 22 Oct 11, 2022
WireGuard Implementation for lwIP

WireGuard Implementation for lwIP This project is a C implementation of the WireGuard® protocol intended to be used with the lwIP IP stack Motivation

Daniel 121 Dec 31, 2022
Custom WebSocket implementation in C for educational and recreational purposes.

C WebSockets WARNING! The library is in an active development state and is not even alpha yet. Use it at your own risk. Nothing is documented, anythin

Tsoding 17 May 25, 2022
Backroll is a pure Rust implementation of GGPO rollback networking library.

backroll-rs Backroll is a pure Rust implementation of GGPO rollback networking library. Development Status This is still in an early beta stage. At ti

Hourai Teahouse 276 Jan 2, 2023
STARTTLS implementation for mail servers that don't have it.

smtpd-starttls-proxy - a STARTTLS implementation for mail servers ----------------------------------------------------------------- smtpd-starttls-p

Laurent Bercot 6 Dec 21, 2021
An Ace of Spades server implementation done in C

SpadesX What is SpadesX and why ? TL;DR Ace of Spades server written in C (Currently in full on development and thus early Alpha) Now if you would lik

null 38 Jan 5, 2023
High performance in-kernel WireGuard implementation for Windows

WireGuard for the NT Kernel High performance in-kernel WireGuard implementation for Windows WireGuardNT is an implementation of WireGuard, for the NT

WireGuard 60 Dec 2, 2022
eBPF implementation that runs on top of Windows

eBPF for Windows eBPF is a well-known technology for providing programmability and agility, especially for extending an OS kernel, for use cases such

Microsoft 1.7k Jan 9, 2023