# @exocet/pandora-protobuf

> Pandora's protobuf message parser

Latest version **0.0.1-alpha.1** (published 2019-04-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @exocet/pandora-protobuf
pnpm add @exocet/pandora-protobuf
yarn add @exocet/pandora-protobuf
bun add @exocet/pandora-protobuf
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-alpha.1 |
| Published | 2019-04-23 |
| First published | 2019-04-19 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 38.6 KB |
| Known vulnerabilities | 0 (+10 in 1 direct dependencies) |
| Install scripts | no |
| Author | Exocet |
| Maintainers | codermarcos, vflopes |
| Keywords | pandora, protobuf, message, parser |

## Links

- npm: https://www.npmjs.com/package/@exocet/pandora-protobuf
- Repository: https://github.com/exocet-engineering/pandora-protobuf
- Homepage: https://github.com/exocet-engineering/pandora-protobuf#readme
- Issues: https://github.com/exocet-engineering/pandora-protobuf/issues
- npm.io page: https://npm.io/package/@exocet/pandora-protobuf

## Dependencies (7)

- [glob](https://npm.io/package/glob.md) ^7.1.3
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.1
- [jsonpath](https://npm.io/package/jsonpath.md) ^1.0.1
- [protobufjs](https://npm.io/package/protobufjs.md) ^6.8.8
- [change-case](https://npm.io/package/change-case.md) ^3.1.0
- [@exocet/value-flagger](https://npm.io/package/@exocet/value-flagger.md) ^1.0.0
- [@exocet/pandora-shared-modules](https://npm.io/package/@exocet/pandora-shared-modules.md) 0.0.1-alpha.2

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.0.1-alpha.1 (latest) — 2019-04-23
- 0.0.1-alpha.0 — 2019-04-19

## README

# Pandora Protobuf

Addon to provide flow and setup functions to encode/decode Protobuf 3 using [protobufjs](https://github.com/protobufjs/protobuf.js).

```
npm install --save @exocet/pandora-protobuf
```

---------------------------

## Concepts

### Message envelope

The message envelope creates a pattern for transposing data between endpoints, this pattern is defined in the file "lib / standard.proto":

```protobuf
syntax = "proto3";

package pandora.standard;

message MessageEnvelope {
	bytes data = 1;
	repeated bytes collection = 2;
	uint32 total = 3;
}
```

---------------------------

## Setup

Available features:

* Generate protos from entity definition
* Multiple protos defined by labels
* Provide encoder/decoder hook
* Flow steps: decodeProtobuf, encodeProtobuf

To add this addon into your project, put the addon spec into your endpoint YAML:

```yaml
kind: Pandora/endpoint
metadata:
  name: myEndpoint
spec:
  addons:
    - name: protobuf
      package: "@exocet/pandora-protobuf"
      flow: true
      setup: true
```

After the setup the following property of the context will be available:

* `.application.protos` - Instance of `protobufjs.Root`

---------------------------

## Hooks

The hooks created by this addon are:

* **protobufEncoder** (`.service.hooks.useHook('protobufEncoder')`) - Synchronous hook to encode data to protobuf
	```javascript
	const [protobufEncoder] = service.hooks.useHook('protobufEncoder');
	const encoded = protobufEncoder('myNamespace.myEntity.myLabel', data);
	```
* **protobufDecoder** (`.service.hooks.useHook('protobufDecoder')`) - Synchronous hook to decode protobuf
	```javascript
	const [protobufDecoder] = service.hooks.useHook('protobufDecoder');
	const data = protobufDecoder('myNamespace.myEntity.myLabel', encoded);
	```

---------------------------

## Flow

The provided flow type and steps are listed bellow:

* **decodeProtobuf** - This flow decodes protobuf:
	```yaml
	kind: Pandora/flowStep
	metadata:
	  name: decodeProtobuf
	spec:
	  type: decodeProtobuf
	  options:
	    inboundFrom: request # JSON Path to acquire protobuf from execution context
		outboundTo: request # JSON path to put the decoded data
		wrappedMessageEnvelope: true # Decode inbound wrapped in message envelope
		collectionAsPayload: true # If the message envelope contains a collection then this flow will put the collection as outbound
		encodingFrom: null # JSON Path to execution value that contains the current encoding of inbound, if it's specified then this flow will only decode the inbound if the value is "proto3"
	    entity: # The entity to parse the proto definition
	      label: default
	      namespace: stock
	      name: product
	```
* **encodeProtobuf** - This flow encodes data to protobuf:
	```yaml
	kind: Pandora/flowStep
	metadata:
	  name: encodeProtobuf
	spec:
	  type: encodeProtobuf
	  options:
	    inboundFrom: response # JSON Path to acquire data from execution context
		outboundTo: response # JSON path to put the encoded data
		wrappedMessageEnvelope: true # Wraps the outbound in message envelope
		encodingFrom: null  # JSON Path to execution value that contains the desired encoding of outbound, if it's specified then this flow will only encode the inbound if the value is "proto3"
	    entity: # The entity to parse the proto definition
	      label: default
	      namespace: stock
	      name: product
	```

---
_Source: https://npm.io/package/@exocet/pandora-protobuf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
