https://github.com/oskaritimperi/nimpb
Protocol Buffers for Nim
https://github.com/oskaritimperi/nimpb
library nim nimpb protobuf protocol-buffers serialization
Last synced: 22 days ago
JSON representation
Protocol Buffers for Nim
- Host: GitHub
- URL: https://github.com/oskaritimperi/nimpb
- Owner: oskaritimperi
- License: mit
- Created: 2018-03-26T17:55:06.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-08-29T09:23:16.000Z (over 3 years ago)
- Last Synced: 2025-04-09T16:18:44.213Z (22 days ago)
- Topics: library, nim, nimpb, protobuf, protocol-buffers, serialization
- Language: Nim
- Size: 327 KB
- Stars: 38
- Watchers: 3
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Protocol Buffers for Nim
[](https://travis-ci.org/oswjk/nimpb)
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](https://github.com/oswjk/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):
```nim
type
Test1_MyEnum* {.pure.} = enum
Foo = 0
Bar = 1Test1* = ref Test1Obj
Test1Obj* = object of RootObj
a: int32
e: MyEnum
```And you can use the generated code like this:
```nim
let message = newTest1()
message.a = 150
message.e = Test1_MyEnum.Barlet 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](https://github.com/PMunch/protobuf-nim). 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](https://github.com/oswjk/nimtwirp).