Comments (2)
You only need to register types with Register
for a union type, so it knows what the type looks like.
It looks like the issue you are having is that schema does not contain an array. I suggest you read the spec to fully understand schemas.
This is the correct schema and code:
type SimpleRecord struct {
A int64 `avro:"a"`
B string `avro:"b"`
}
schema, err := avro.Parse(`{"type": "array", "items":
{
"type": "record",
"name": "simple",
"namespace": "org.hamba.avro",
"fields" : [
{"name": "a", "type": "long"},
{"name": "b", "type": "string"}
]
}}`)
if err != nil {
log.Fatal(err)
}
in := []SimpleRecord{{A: 27, B: "foo"}}
data, err := avro.Marshal(schema, in)
if err != nil {
log.Fatal(err)
}
fmt.Println(data)
// Outputs: [1 10 54 6 102 111 111 0]
out := []SimpleRecord{}
err = avro.Unmarshal(schema, data, &out)
if err != nil {
log.Fatal(err)
}
fmt.Println(out)
// Outputs: [{27 foo}]
from avro.
I think this is worth to be added on documentation.. Probably many people will work with slices and they will have the same issue.
from avro.
Related Issues (20)
- Example of writing an avro file containing a sequence of records HOT 2
- Can't use comments in schema files. HOT 2
- When comparing record complex types the fields/symbols/unions must be in the same order to be compatible HOT 7
- Ref types error HOT 3
- Is there any way to generate avro schema file using go struct? HOT 10
- Proposal: allow adjusting array/map block header format HOT 1
- Support tinygo HOT 6
- Are cross schema references supported? HOT 2
- PropertySchema properties are not JSON marshalled/unmarshalled HOT 5
- Referencing defined type throw error "unknown type" HOT 5
- Encoding Fixed Type In A Union
- AvroGen: generates duplicate structs due to a name resolution conflict HOT 7
- Schema with duplicate names should throw error
- Encoding to JSON does not reference reused types HOT 1
- Unmarshaling Interface Types in a Union HOT 6
- Reset the schema cache? HOT 4
- AVRO schema refs with Hamba avro HOT 8
- Support original name for structs
- Add protocol original schema string HOT 4
- Infinite loop parsing recursive schema HOT 1
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 avro.