# Starting the protobuf

**URL:** <https://swi-prolog.discourse.group/t/starting-the-protobuf/7513>\
**Category:** Help!\
**Created:** [June 4, 2024, 7:47pm UTC](https://swi-prolog.discourse.group/t/starting-the-protobuf/7513 "2024-06-04T19:47:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ann-zhukova](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ann-zhukova/32/6393_2.png) [@ann-zhukova](https://swi-prolog.discourse.group/u/ann-zhukova)\
**Post date:** [June 4, 2024, 7:47pm UTC](https://swi-prolog.discourse.group/t/starting-the-protobuf/7513/1 "2024-06-04T19:47:01Z")

</div>

Hello!

I am trying to use the Google Protocol Buffer library for SWI-Prolog by following this tutorial: [('packages/protobufs.html')](https://www.swi-prolog.org/pldoc/doc_for?object=(%27packages/protobufs.html')).

At first, I was doing everything wrong and installed the protocol for Windows and tried to compile the proto file with the built-in SWI-Prolog packages. After a few hours of various errors, I checked the developer’s documentation and found out that it could not be processed on Windows.

So, I created a Docker image with this Dockerfile:

```prolog
FROM debian:buster
RUN apt-get update && apt-get install -y \
    swi-prolog
RUN apt-get install -y wget
WORKDIR /tmp
RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protoc-27.0-linux-x86_64.zip
RUN unzip protoc-27.0-linux-x86_64.zip -d protoc
RUN mv protoc/include /usr/local/include && \
    mv protoc/bin/* /usr/local/bin
RUN rm -rf /tmp/*
WORKDIR /app
CMD ["bash"]

```

Then, I ran these commands in my container:

```prolog
1 Add "/usr/lib/swi-prolog/library/protobufs " to path 
2 Create gen_pb directory
3 protoc -I/usr/local/include --swipl_out=gen_pb google/protobuf/descriptor.proto google/protobuf/compiler/plugin.proto

```

I have the plugin.proto file, but this command did not create:

```prolog
gen_pb/google/protobuf/descriptor_pb.pl
gen_pb/google/protobuf/compiler/plugin_pb.pl

```

Now I am not sure about windows. I found addressbook.proto in my swipl files in windows and I read in docs that I need make run\_addressbook. May I run it on Windows? And how?

Therefore, I need some advice from someone who has already gone through the entire process.

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [June 5, 2024, 3:16pm UTC](https://swi-prolog.discourse.group/t/starting-the-protobuf/7513/2 "2024-06-05T15:16:58Z")

</div>

It appears that there are some missing pieces in the documentation – I’ll try to update these soon. (I think that the plugin needs to be specified when using `protoc`, for example)

I’m unable to help with docker or Windows; hopefully when I fix the documentation for using `protoc` it’ll be obvious how to do things with docker.

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [June 7, 2024, 4:27am UTC](https://swi-prolog.discourse.group/t/starting-the-protobuf/7513/3 "2024-06-07T04:27:28Z")

</div>

Here’s a partial answer; the protobuf package seems to have become out of date, so I need to make some changes to it. Also, there are some typos in the documentation. ☹

The following worked on Debian and should also work on Ubuntu (after installing swi-prolog, protobuf-compiler, pkg-config). It is possible that it would also work on Windows; there is a comment with [commit 01e748fa3bac23e15830b978af9fbc14ab191146](https://github.com/SWI-Prolog/contrib-protobufs/commit/01e748fa3bac23e15830b978af9fbc14ab191146) that it has cleaned up float32 and int32 for MSVC.

```prolog
protoc -I/usr/share/doc/protobuf-compiler/examples -I/usr/include --swipl_out=/tmp/ --plugin=protoc-gen-swipl=/usr/lib/swi-prolog/library/protobufs/protoc-gen-swipl /usr/share/doc/protobuf-compiler/examples/addressbook.proto

```

This generated `/tmp/addressbook_pb.pl` … you should change the `--swipl-out=` specification to be the directory you want (e.g., `interop`).

Note that `protoc` requires a `-I` item that encompasses the .proto file, so this also works:

```bash
protoc -I/usr/share/doc/protobuf-compiler/examples -I/usr/include --swipl_out=/tmp/ --plugin=protoc-gen-swipl=/usr/lib/swi-prolog/library/protobufs/protoc-gen-swipl addressbook.proto

```

It’s possible that your installation puts files in a different place; you can find the addressbook example with:

```bash
dpkg -L protobuf-compiler | grep addressbook

```

To test this, I ran the following (there’s a typo in address book.pl for the “decode” command):

```bash
swipl -g test_write -g test_write -g test_read -t halt addressbook.pl # outputs to addressbook.wire
protoc --decode=tutorial.AddressBook addressbook.proto <addressbook.wire 

```

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [June 9, 2024, 5:46pm UTC](https://swi-prolog.discourse.group/t/starting-the-protobuf/7513/4 "2024-06-09T17:46:09Z")

</div>

I’ve updated the documentation: [DOC: examples+tests using updated protobuf-compiler package by kamahen · Pull Request #18 · SWI-Prolog/contrib-protobufs · GitHub](https://github.com/SWI-Prolog/contrib-protobufs/pull/18)

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [June 10, 2024, 8:14am UTC](https://swi-prolog.discourse.group/t/starting-the-protobuf/7513/5 "2024-06-10T08:14:35Z")

</div>

FYI

For others like me finding the GitHub page and expecting more info. The GitHub repository has a few subdirectories with further documentation in them.

Here are the directories with documentation pages AFAIK

[https://github.com/SWI-Prolog/contrib-protobufs](https://github.com/SWI-Prolog/contrib-protobufs)  
[https://github.com/SWI-Prolog/contrib-protobufs/tree/master/bootstrap](https://github.com/SWI-Prolog/contrib-protobufs/tree/master/bootstrap)  
[https://github.com/SWI-Prolog/contrib-protobufs/tree/master/bootstrap/gen\_pb](https://github.com/SWI-Prolog/contrib-protobufs/tree/master/bootstrap/gen_pb)  
[https://github.com/SWI-Prolog/contrib-protobufs/tree/master/demo](https://github.com/SWI-Prolog/contrib-protobufs/tree/master/demo)  
[https://github.com/SWI-Prolog/contrib-protobufs/tree/master/interop](https://github.com/SWI-Prolog/contrib-protobufs/tree/master/interop)

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [June 10, 2024, 12:23pm UTC](https://swi-prolog.discourse.group/t/starting-the-protobuf/7513/6 "2024-06-10T12:23:37Z")

</div>

The SWI-Prolog index is misleading: “protobufs” leads to [SWI-Prolog -- library(protobufs): Google's Protocol Buffers ("protobufs")](https://www.swi-prolog.org/pldoc/man?section=protobufs) but there’s more here (with a rather strange name):  
[section('packages/protobufs.html')](https://www.swi-prolog.org/pldoc/doc_for?object=section(%27packages/protobufs.html%27))

@jan - Can this indexing be fixed, please? (Also, the author’s info and maybe it needs a copyright?).  
The file is `swipl-devel/packages/protobufs/protobufs.doc`.

There ought to be a section describing the various directories, such as `/usr/share/swi-prolog/doc/packages/examples/protobufs` (which includes `demo`, `interop` and `bootstrap`). Where should this be added?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [June 15, 2024, 11:17am UTC](https://swi-prolog.discourse.group/t/starting-the-protobuf/7513/7 "2024-06-15T11:17:57Z")

</div>

> [@peter.ludemann](#):
>
> The [SWI-Prolog](https://www.swi-prolog.org/pldoc/doc_for?object=manual) index is misleading: “protobufs” leads to [SWI-Prolog – library(protobufs): Google’s Protocol Buffers (“protobufs”)](https://www.swi-prolog.org/pldoc/man?section=protobufs)

There are a lot of hits in the search. protobuf is only used for the library name though. The docs talk about Google Protocol Buffers and you find that using “protocol”. I guess we can add a tag “protobufs”. I see the tagging interface is a bit broken after the website migration though ☹

> [@peter.ludemann](#):
>
> Where should this be added?

I don’t know. You’re guess is most likely better than mine 🙂
