No description
Find a file
Oskari Timperi 67e38c9fb7 Fix #19
2021-08-29 12:22:51 +03:00
examples Update examples 2018-04-25 18:23:56 +03:00
nimpb Fix #19 2021-08-29 12:22:51 +03:00
tests Fixes for Nim 1.0 2019-09-24 23:43:09 +03:00
.gitignore Add .gitignore 2018-04-01 12:03:47 +03:00
.travis.yml Fix travis build 2019-06-24 21:20:04 +03:00
LICENSE Add LICENSE 2018-03-26 20:57:33 +03:00
nimpb.nimble bump version 2018-10-10 00:14:15 -07:00
README.md Add travis build badge to README.md 2018-04-25 19:22:17 +03:00
TODO.md Rename TODO to TODO.md 2018-05-08 13:59:40 -07:00

Protocol Buffers for Nim

Build Status

A Nim library to serialize/deserialize Protocol Buffers.

To actually generate Nim code from protobuf definitions, you need the protoc tool. To make things simple, nimpb depends on nimpb_protoc, which bundles protoc binaries for the most common platforms (Windows, Linux, macOS).

NOTE At the moment this is at a very rough state. Do not use for any kind of production use. Anything can change at any time. You've been warned.

Example

Given the following file:

syntax = "proto3";

message Test1 {
    int32 a = 1;

    enum MyEnum {
        Foo = 0;
        Bar = 1;
    }

    MyEnum e = 2;
}

You can use nimpb_build (a tool that comes with nimpb) to generate code like this (procs not included in the example):

type
    Test1_MyEnum* {.pure.} = enum
        Foo = 0
        Bar = 1

    Test1* = ref Test1Obj
    Test1Obj* = object of RootObj
        a: int32
        e: MyEnum

And you can use the generated code like this:

let message = newTest1()
message.a = 150
message.e = Test1_MyEnum.Bar

let data = serialize(message)

let message2 = newTest1(data)

assert message2.a == 150
assert message2.e == Test1_MyEnum.Bar

Other libraries

If you do not want to depend on the protoc compiler, check Peter Munch-Ellingsen's protobuf library. It handles parsing of the protobuf files in compile time which can make building simpler.

Services

For an example about how to generate services, see nimtwirp.