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

Non JSON method payload #59

Open
floriaanpost opened this issue Apr 5, 2022 · 1 comment
Open

Non JSON method payload #59

floriaanpost opened this issue Apr 5, 2022 · 1 comment

Comments

@floriaanpost
Copy link

Thank you for creating this library :)

I am using method payloads (and responses) that are not in JSON form, but base64 strings (strictly speaking still valid json) as my connected devices use cellular data, so I want to keep data usage to an absolute minimum. However, the MethodCall.Payload in this library is a map[string]interface{}. I forked your library to change it into just an interface{}.

Are you interested in a pull request? (and if so, would you prefer a new method (to keep it backwards compatible) or a change to MethodCall and MethodResponse?)

@amenzhinsky
Copy link
Owner

Hi,

IIRC when I was writing the code IoTHub accepted json only and now as understand this correctly it can be anything []byte, plus the library itself doesn't guarantee API changes yet. So I think it's worth changing it, but I'd prefer that RegisterMethod method signature remain the same and I'd like it to call the new one internally (say HandleMethod):

return c.HandleMethod(ctx, name, func(b []byte error {
  var m map[string]interface{}
  if err := json.Unmarshall(b, &m); err != nil {
    return err
  }
  return fn(m)
})

link #24

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

2 participants