aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 39e7cb9ac1d4363f8bafe8dbef3fe271a78e2e84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Protocol Buffers for Nim

A pure Nim library for dealing with protobuf serialization and deserialization. A `protoc` plugin is also included which can be used for generating Nim code, usable by the library, from `.proto` files.

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;
}
```

The `protoc` plugin will basically generate the following code:

```nim
const
    Test1Desc = MessageDesc(
        name: "Test1",
        fields: @[
            FieldDesc(
                name: "a",
                number: 1,
                ftype: FieldType.Int32,
                label: FieldLabel.Optional,
                typeName: "",
                packed: false
            )
        ]
    )

generateMessageType(Test1Desc)
generateMessageProcs(Test1Desc)
```

And you can use it like this:

```nim
let message = newTest1()
setA(message, 150)
let pbso = newProtobufStream(newFileStream(stdout))
writeTest1(pbso, message)
```