Comments (5)
Hey @kevinbader sorry for a long response, but I've updated master with updated typespec for Avrora.Encoder.decode/1
and Avrora.Encoder.decode/2
Update: I plan to fix issue #27 and then make a release, so I will hand a while in a master branch
from avrora.
Hi @kevinbader, this is not a bug. When you don't have a schema registry, by default Avrora is using Avro Object Container FIles format, which assumes that you have always a list.
The reason to use OCF is the assumption that your data should be always decodable and since OCF includes schema in a header of a message, you can always decode it.
You can fine that under format
section in the README.
Here is how you can make it plain:
iex(3)> Avrora.encode(%{"baz" => "test"}, schema_name: "foo.Bar")
09:18:14.875 [debug] reading schema `foo.Bar` from the file ./tmp/schemas/foo/Bar.avsc
{:ok,
<<79, 98, 106, 1, 3, 144, 2, 20, 97, 118, 114, 111, 46, 99, 111, 100, 101, 99,
8, 110, 117, 108, 108, 22, 97, 118, 114, 111, 46, 115, 99, 104, 101, 109, 97,
212, 1, 123, 34, 110, 97, 109, 101, 115, 112, 97, 99, 101, ...>>}
iex(4)> Avrora.encode(%{"baz" => "test"}, schema_name: "foo.Bar", format: :plain)
{:ok, "\btest"}
iex(5)> Avrora.decode("\btest", schema_name: "foo.Bar")
{:ok, %{"baz" => "test"}}
:plain
format you see it as a string and not as a charlist, maybe it's an iex
thing but just in case will check
UPD: yes, it's a correct plain display
iex(6)> String.to_charlist("\btest")
'\btest'
from avrora.
Hi @Strech,
thanks for your quick response! From the docs I couldn't really tell that using OCF would always result in a list, even in case there is only a single map in the container. Given what you wrote, however, I propose to change the spec of encode to reflect this; currently Dialyzer thinks it always returns a binary and never a list:
@spec encode(map(), keyword(String.t())) :: {:ok, binary()} | {:error, term()}
from avrora.
Evening @kevinbader,
From the docs I couldn't really tell that using OCF would always result in a list
I re-read the docs and what I can quote from the docs:
Avro includes a simple object container file format. A file has a schema, and all objects stored in the file must be written according to that schema, using binary encoding. Objects are stored in blocks that may be compressed
A file data block consists of:
- A long indicating the count of objects in this block.
- A long indicating the size in bytes of the serialized objects in the current block, after any codec is applied
- The serialized objects. If a codec is specified, this is compressed by that codec.
As you can see, it always plural, as I understand it a block of objects can include just one for sure, but it's considered to be a container of objects and in Elixir/Erlang world it's a List
I propose to change the spec of encode to reflect this; currently Dialyzer thinks it always returns a binary and never a list:
Completely agree, but not encode spec, decode you mean. Because encode always return binary and no List is involved. Will do it for decode 👍
from avrora.
You're completely right - thanks!
from avrora.
Related Issues (20)
- Empty user-agent in header when calling registry
- schema evolution support HOT 7
- hook to skip certain fields. HOT 2
- Rewrite schema registration mix task with new functionality
- Rework Mix task section
- Allow mix task to accept a Client to be used for registration
- Drop unnecessary configuration options
- Remove plain format from decode/2 and encode/2
- Warnings on compilation HOT 4
- Maintain a CHANGELOG? HOT 5
- Dialyzer issues with private clients HOT 2
- "Messages encoded with OCF are wrapped in a List" what for? HOT 1
- Allow 3 named types to be used as root schemas
- Get schema name on decode HOT 3
- Add deprecation warning for encode with plain format
- Private clients hardcode schemas path at compile time HOT 6
- Any way to configure the registry_url at startup? HOT 8
- Option for decoding with tagged union values HOT 7
- unnamed_type error with primary type schema HOT 11
- Add option to enable SSL verification of registry requests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avrora.