Liking cljdoc? Tell your friends :D
Clojure only.

protojure.grpc.codec.lpm

Utility functions for GRPC length-prefixed-message encoding.

Utility functions for GRPC [length-prefixed-message](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests) encoding.
raw docstring

decodeclj

(decode f
        input
        output
        {:keys [codecs content-coding tmo]
         :or {codecs compression/builtin-codecs tmo 5000}
         :as options})

Takes a parsing function, a pair of input/output core.async channels, and an optional codec and decodes a stream of length-prefixed-message (LPM).

Parameters

ValueTypeDescription
f(fn [is])A protobuf decoder function with an arity of 1 that accepts an instance of InputStream, such as the pb-> functions produced by the protoc-gen-clojure compiler
inputcore.async/channelA core.async channel that carries LPM encoded bytes, one byte per (take!). Closing the input will shut down the pipeline.
outputcore.async/channelA core.async channel that carries decoded protobuf records. Will be closed when the pipeline shuts down.
optionsmapSee Options
Options

| Value | Type | Default | Description | |--------------------|-----------------------------------------------------------------| | content-coding | string | "identity" | See Content-coding table | | codecs | map | protojure.grpc.codec.compression/builtin-codecs | The dictionary of codecs to utilize | | tmo | unsigned int | 5000ms | A timeout, in ms, for receiving the remaining LPM payload bytes once the header has been received. |

Example
{:content-coding "gzip"
 :codecs mycodecs
 :tmo 1000}
Content-coding

The value for the content-coding option must be one of

ValueComment
nilno compression
"identity"no compression
other stringretrieves the codec from codecs option
Takes a parsing function, a pair of input/output [core.async channels](https://clojuredocs.org/clojure.core.async/chan), and an optional codec and
decodes a stream of [length-prefixed-message](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests) (LPM).

#### Parameters

| Value           | Type                 | Description                                                                  |
|-----------------|----------------------|---------------------------------------------------------------------------|
| **f**           | _(fn [is])_          | A protobuf decoder function with an arity of 1 that accepts an instance of [InputStream](https://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html), such as the pb-> functions produced by the protoc-gen-clojure compiler |
| **input**       | _core.async/channel_ | A core.async channel that carries LPM encoded bytes, one byte per [(take!)](https://clojuredocs.org/clojure.core.async/take!).  Closing the input will shut down the pipeline. |
| **output**      | _core.async/channel_ | A core.async channel that carries decoded protobuf records.  Will be closed when the pipeline shuts down. |
| **options**     | _map_                | See _Options_

##### Options

| Value              | Type             | Default      | Description                                                            |
|--------------------|-----------------------------------------------------------------|
| **content-coding** | _string_         | "identity" | See _Content-coding_ table    |
| **codecs**         | _map_            | [[protojure.grpc.codec.compression/builtin-codecs]] | The dictionary of codecs to utilize |
| **tmo**            | _unsigned int_   | 5000ms       | A timeout, in ms, for receiving the remaining LPM payload bytes once the header has been received. |

###### Example

```
{:content-coding "gzip"
 :codecs mycodecs
 :tmo 1000}
```

##### Content-coding
The value for the **content-coding** option must be one of

| Value          | Comment                                   |
|----------------|-------------------------------------------|
| nil            | no compression                            |
| "identity"   | no compression                            |
| _other string_ | retrieves the codec from _codecs_ option  |
sourceraw docstring

encodeclj

(encode f
        input
        output
        {:keys [codecs content-coding max-frame-size]
         :or {codecs compression/builtin-codecs}
         :as options})

Takes an input and output core.async channel, along with an optional codec and encodes a stream of 0 or more length-prefixed-message messages.

Parameters

ValueTypeDescription
f(fn [init])A protobuf encoder function with an arity of 1 that accepts an init-map, such as the new-XX functions produced by the protoc-gen-clojure compiler
inputcore.async/channelA core.async channel expected to carry maps that will be transformed to protobuf messages based on f
outputcore.async/channelA core.async channel that will carry bytes representing the encoded messages. See max-frame-size. Will be closed when the pipeline shuts down.
optionsmapSee Options
Options

| Value | Type | Default | Description | |--------------------|---------------------------------------------------------------------------------------------------------------| | content-coding | String | "identity" | See the content-coding section of decode | | codecs | map | protojure.grpc.codec.compression/builtin-codecs | The dictionary of codecs to utilize | | max-frame-size | UInt32 | 0 | Maximum frame-size emitted on output channel. See Output channel details below |

Output channel details

The max-frame-size option dictates how bytes are encoded on the output channel:

  • 0: (Default) Indicates 'stream' mode: Bytes are encoded one byte per (put!).
  • >0: Indicates 'framed' mode: The specified value will dictate the upper bound on byte-array based frames emitted to the output channel.
Example
{:content-coding "gzip"
 :codecs mycodecs
 :max-frame-size 16384}
Takes an input and output [core.async channel](https://clojuredocs.org/clojure.core.async/chan), along with an optional codec and
encodes a stream of 0 or more [length-prefixed-message](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests)
messages.

#### Parameters

| Value           | Type                 | Description                                                               |
|-----------------|----------------------|---------------------------------------------------------------------------|
| **f**           | _(fn [init])_        | A protobuf encoder function with an arity of 1 that accepts an init-map, such as the new-XX functions produced by the protoc-gen-clojure compiler |
| **input**       | _core.async/channel_ | A core.async channel expected to carry maps that will be transformed to protobuf messages based on _f_                                            |
| **output**      | _core.async/channel_ | A core.async channel that will carry bytes representing the encoded messages. See _max-frame-size_.  Will be closed when the pipeline shuts down. |
| **options**     | _map_                | See _Options_                                                             |

##### Options

| Value              | Type     | Default      | Description                                                                         |
|--------------------|---------------------------------------------------------------------------------------------------------------|
| **content-coding** | _String_ | "identity" | See the _content-coding_ section of [[decode]]                                      |
| **codecs**         | _map_    | [[protojure.grpc.codec.compression/builtin-codecs]] | The dictionary of codecs to utilize          |
| **max-frame-size** | _UInt32_ | 0            | Maximum frame-size emitted on _output_ channel.  See _Output channel details_ below |

##### Output channel details

The _max-frame-size_ option dictates how bytes are encoded on the _output_ channel:

  - **0**: (Default) Indicates 'stream' mode: Bytes are encoded one byte per [(put!)](https://clojuredocs.org/clojure.core.async/put!).
  - **>0**: Indicates 'framed' mode: The specified value will dictate the upper bound on byte-array based frames emitted to the output channel.

###### Example

```
{:content-coding "gzip"
 :codecs mycodecs
 :max-frame-size 16384}
```
  
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close