GithubHelp home page GithubHelp logo

Comments (6)

nrwiersma avatar nrwiersma commented on June 10, 2024

You have added a nullable union, so you need an extra pointer to deal with the union.

from avro.

Korzhenevskyi avatar Korzhenevskyi commented on June 10, 2024

@nrwiersma could you give me an example, please?

from avro.

Korzhenevskyi avatar Korzhenevskyi commented on June 10, 2024

should I use a map?

func TestEncoder_FixedRat_Positive(t *testing.T) {
	schema := `["null", {"type":"fixed", "name": "test", "size": 6,"logicalType":"decimal","precision":4,"scale":2}]`
	buf := bytes.NewBuffer([]byte{})
	enc, err := avro.NewEncoder(schema, buf)
	require.NoError(t, err)

	m := map[string]any{
		"test": big.NewRat(1734, 5),
	}

	err = enc.Encode(m)

	require.NoError(t, err)
	assert.Equal(t, []byte{0x02, 0x00, 0x00, 0x00, 0x00, 0x87, 0x78}, buf.Bytes())
}

from avro.

Korzhenevskyi avatar Korzhenevskyi commented on June 10, 2024

I wonder why https://github.com/hamba/avro/blob/main/encoder_union_test.go#L427 -- this works for bytes, but doesn't work for fixed.

from avro.

nrwiersma avatar nrwiersma commented on June 10, 2024

You need to encode the pointer to the value, effectively a **big.Rat.

val := big.NewRat(1734, 5)
err = enc.Encode(&val)

from avro.

Korzhenevskyi avatar Korzhenevskyi commented on June 10, 2024

Thank you @nrwiersma!

from avro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.