Hi Rajiv,
I'd recommend you this nice tool for generating Rust structs from Avro
schema: https://github.com/lerouxrgd/rsgen-avro
$ cat q.avsc
1 │ {
2 │ "type": "record",
3 │ "name": "Abcd",
4 │ "fields": [
5 │ {"name": "b", "type": ["null", "bytes"], "default": null}
6 │ ]
7 │ }
generates:
cat q.rs
1 │
2 │ #[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize,
serde::Serialize)]
3 │ #[serde(default)]
4 │ pub struct Abcd {
5 │ pub b: Option<Vec<u8>>,
6 │ }
7 │
8 │ #[inline(always)]
9 │ fn default_abcd_b() -> Option<Vec<u8>> { None }
10 │
11 │ impl Default for Abcd {
12 │ fn default() -> Abcd {
13 │ Abcd {
14 │ b: default_abcd_b(),
15 │ }
16 │ }
17 │ }
On Mon, Aug 29, 2022 at 10:05 AM Rajiv M Ranganath <
[email protected]> wrote:
> Hi,
>
> I am new to Avro. When I have an Arvo schema of the form,
>
> ```
> record Abcd {
> union { null, bytes } efgh = null;
> }
> ```
>
> What would be the corresponding Rust struct?
>
> I tried
>
> ```
> #[derive(Debug, Deserialize, PartialEq)]
> struct Abcd {
> efgh: Option<Vec<u8>>,
> }
> ```
>
> But for some reason, `apache_avro::from_value` is giving an
> `Err(DeserializeValue("not an array"))` error.
>
> Best,
> Rajiv
>