Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An issue with encoding #23

Closed
przemekd opened this issue Aug 9, 2019 · 4 comments
Closed

An issue with encoding #23

przemekd opened this issue Aug 9, 2019 · 4 comments

Comments

@przemekd
Copy link

przemekd commented Aug 9, 2019

I don't know if it is by design or not, but when not specifying all tags I get a badly encoded byte array. For example:

package main

import (
	"encoding/hex"
	"fmt"
	"log"
	"github.com/hamba/avro"
)

type SimpleRecord struct {
	A string  `avro:"a"`
	C *string `avro:"c"`
}

func main() {
	schema, _ := avro.Parse(`{
    "type": "record",
    "name": "simple",
    "namespace": "org.hamba.avro",
    "fields" : [
        {"name": "a", "type": "string"},
        {"name": "b", "type": ["null", "string"], "default": null},
        {"name": "c", "type": ["null", "string"], "default": null}
    ]}`)

	in := SimpleRecord{A: "test", C: nil}
	data, _ := avro.Marshal(schema, in)
	fmt.Println(hex.Dump(data))
}

The output is:
00000000 08 74 65 73 74 00 |.test.| (it misses 00 and it's not correctly binary serialized avro object)

I would expect having default values encoded, even if they are not specified in a struct.

@nrwiersma
Copy link
Member

Yeah, that is wrong. Will add a test for this case and see what is going on.

Thanks for reporting.

@nrwiersma
Copy link
Member

This should be fixed in v0.5.3. Please let me know if this fixes things for you?

Thanks again.

@przemekd
Copy link
Author

przemekd commented Aug 9, 2019

Yay, it works! Thanks for fixing it so quick!

@nrwiersma
Copy link
Member

No worries. Thanks again for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants