View Source GRPC.Codec.JSON (grpc v0.9.0)

JSON Codec for gRPC communication.

This module implements the GRPC.Codec behaviour, providing encoding and decoding functions for JSON serialization in the context of gRPC communication.

Behavior Functions

  • name/0: Returns the name of the codec, which is "json".
  • encode/1: Encodes a struct using the Protobuf.JSON.encode!/1 function.
  • decode/2: Decodes binary data into a map using the Jason library.

This module requires the Jason dependency.

Summary

Functions

Decodes binary data into a map using the Jason library. Parameters

Encodes a struct using the Protobuf.JSON.encode!/1 function.

Callback implementation for GRPC.Codec.name/0.

Functions

Decodes binary data into a map using the Jason library. Parameters:

binary - The binary data to be decoded.
module - Module to be created.

Returns:

A map representing the decoded data.

Raises:

Raises an error if the Jason library is not loaded.

Example:

binary_data |> GRPC.Codec.JSON.decode(__MODULE__)

Encodes a struct using the Protobuf.JSON.encode!/1 function.

Parameters:

  • struct - The struct to be encoded.

Returns:

The encoded binary data.

Example:

%MyStruct{id: 1, name: "John"} |> GRPC.Codec.JSON.encode()

Callback implementation for GRPC.Codec.name/0.