avrora v0.11.0 Avrora.Encoder View Source
Encode and decode binary Avro messages.
Link to this section Summary
Functions
Decode binary Avro message, loading schema from Schema Registry or Object Container Files.
Decode binary Avro message, loading schema from local file or Schema Registry.
Encode message map in Avro format, loading schema from local file or Schema Registry.
Link to this section Functions
Decode binary Avro message, loading schema from Schema Registry or Object Container Files.
Examples
...> payload = <<0, 0, 0, 0, 8, 72, 48, 48, 48, 48, 48, 48, 48, 48, 45, 48,
48, 48, 48, 45, 48, 48, 48, 48, 45, 48, 48, 48, 48, 45, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 123, 20, 174, 71, 225, 250, 47, 64>>
...> Avrora.Encoder.decode(payload)
{:ok, %{"id" => "00000000-0000-0000-0000-000000000000", "amount" => 15.99}}
Decode binary Avro message, loading schema from local file or Schema Registry.
Examples
...> payload = <<72, 48, 48, 48, 48, 48, 48, 48, 48, 45, 48, 48, 48, 48, 45,
48, 48, 48, 48, 45, 48, 48, 48, 48, 45, 48, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 123, 20, 174, 71, 225, 250, 47, 64>>
...> Avrora.Encoder.decode(payload, schema_name: "io.confluent.Payment")
{:ok, %{"id" => "00000000-0000-0000-0000-000000000000", "amount" => 15.99}}
Encode message map in Avro format, loading schema from local file or Schema Registry.
The :format
argument controls output format:
:plain
- Just return Avro binary data, with no header or embedded schema:ocf
- Use [Object Container File]https://avro.apache.org/docs/1.8.1/spec.html#Object+Container+Files) format, embedding the full schema with the data:registry
- Write data with Confluent Schema Registry Wire Format, which prefixes the data with the schema id:guess
- Use:registry
if possible, otherwise use:ocf
(default)
Examples
...> payload = %{"id" => "00000000-0000-0000-0000-000000000000", "amount" => 15.99}
...> Avrora.Encoder.encode(payload, schema_name: "io.confluent.Payment", format: :plain)
{:ok, <<72, 48, 48, 48, 48, 48, 48, 48, 48, 45, 48, 48, 48, 48, 45,
48, 48, 48, 48, 45, 48, 48, 48, 48, 45, 48, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 123, 20, 174, 71, 225, 250, 47, 64>>}