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

NativeFromBinary should give error instead of giving empty slice in case of failure in decoding. #287

Open
sidstillworks opened this issue Sep 5, 2024 · 0 comments

Comments

@sidstillworks
Copy link

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!

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

No branches or pull requests

1 participant