docs: add documentation on how to build the protobuf

This commit is contained in:
Tom French 2022-05-16 15:30:42 +01:00 committed by James Long
parent 908def3957
commit fda8127b4e
2 changed files with 19 additions and 4 deletions

View file

@ -1,17 +1,29 @@
# protobuf
We use [protobuf](https://developers.google.com/protocol-buffers/) to encode messages as binary data to send across the network.
## Generating protobuf
We use protobuf to encode messages as binary data to send across the network.
The protobuf is generated by using the [protoc](https://github.com/protocolbuffers/protobuf) compiler.
To generate the protobuf: I forget, will document this soon.
This can be installed by downloading one of the [pre-built binaries](https://github.com/protocolbuffers/protobuf/releases/) and placing it in your `$PATH`. The version used to build the current protobuf is [v3.20.1](https://github.com/protocolbuffers/protobuf/releases/tag/v3.20.1).
Once installed, the protobuf can be generated by running the below commands.
```bash
cd packages/loot-core/src/server/sync
protoc sync.proto --js_out=import_style=commonjs,binary:proto
```
However there is one very important thing to remember! The default output includes this near the top:
```
var global = Function('return this')();
var global = (function() { return this || window || global || self || Function('return this')(); }).call(null);
```
This will not work with our CSP directives. You must manually modify this to this:
```
var global = globalThis;
```
```

View file

@ -2,11 +2,14 @@
/**
* @fileoverview
* @enhanceable
* @suppress {missingRequire} reports error on implicit type usages.
* @suppress {messageConventions} JS Compiler reports an error if a variable or
* field starts with 'MSG_' and isn't a translatable message.
* @public
*/
// GENERATED CODE -- DO NOT EDIT!
/* eslint-disable */
// @ts-nocheck
var jspb = require('google-protobuf');
var goog = jspb;