Skip to content

LiYulin-s/zig-cbor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zig-CBOR: Yet another CBOR library for Zig

A CBOR library for Zig. It is designed to be simple, efficient, and easy to use.

const cbor = @import("zig-cbor");

pub fn main() !void {
    const gpa = std.testing.allocator;
    const Point = struct { x: u8, y: u8 };
    // A2 61 78 01 61 79 02 = map(2) { "x": 1, "y": 2 }
    const r = try cbor.parseFromSlice(Point, gpa, &.{ 0xA2, 0x61, 'x', 0x01, 0x61, 'y', 0x02 }, .{});
    defer r.deinit();
    try std.testing.expectEqual(@as(u8, 1), r.value.x);
    try std.testing.expectEqual(@as(u8, 2), r.value.y);
}

Installation

Developers tend to either use

  • The latest tagged release of Zig
  • The latest build of Zigs master branch

Depending on which developer you are, you need to run different zig fetch commands:

# Version of mecha that works with a tagged release of Zig
# Replace `<REPLACE ME>` with the version of mecha that you want to use
# See: https://github.com/LiYulin-s/zig-cbor/releases
zig fetch --save https://github.com/LiYulin-s/zig-cbor/archive/refs/tags/<REPLACE ME>.tar.gz

# Version of mecha that works with latest build of Zigs master branch
zig fetch --save git+https://github.com/LiYulin-s/zig-cbor.git

Then add the following to build.zig:

const zig_cbor = b.dependency("zig-cbor", .{});
exe.root_module.addImport("zig-cbor", zig_cbor.module("zig_cbor"));

Packages

 
 
 

Contributors

Languages