NativeFromBinary should give error instead of giving empty slice in case of failure in decoding.
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.1k
- Forks
- 232
- PR merge metrics
- No merged PRs in 30d
Description
Hi there,
Consider below struct: [struct1]
`type Personal struct {
Addresses []Address `json:"addresses"`
}`
`type Address struct {
StreetName string `json:"streetName" validate:"min=6,max=100,noLeadingTrailingSpace" pact:"example=123456,regex=^\\d{6}$"`
}`
Consider below avro codec for the same: [struct1]
`{
"name": "Personal",
"type": "record",
"fields": [
{
"name": "addresses",
"type": {
"type": "array",
"items": {
"type": "record",
"name": "Address",
"fields": [{
"name": "streetName",
"type": "string"
}
]
}
}
}
]
}`
Now consider another struct & it's avro schema: [struct2]
`{
"name": "Personal",
"type": "record",
"fields": [
{
"name": "addresses",
"type": {
"type": "array",
"items": {
"type": "record",
"name": "Address",
"fields": [{
"name": "state",
"type": "string"
}
]
}
}
}
]
}`
`type Personal struct {
Addresses []Address `json:"addresses"`
}`
`type Address struct {
State string `json:"state" validate:"min=6,max=100,noLeadingTrailingSpace" pact:"example=123456,regex=^\\d{6}$"`
}`
Now I'm trying to encode my message using struct2 and decode in struct1 using NativeFromBinary() method i.e.
`val, newBuf, err := ac.NativeFromBinary(msg)`
Ideal assumption would be to get a decoding error, but instead of getting error I'm getting a Personal(struct1) containing empty Addresses slice into val & newBuf containing other remaining bytes(undecoded) and err is nil.
I think this is shouldn't be the case. Please see!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the NativeFromBinary method and reproduce the case using the two incompatible Personal schemas described in the issue. Trace how decoding handles the unexpected field and remaining bytes. Done means the mismatch is reported as an error instead of returning a partial value with nil error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- data-engineering
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100