iothub icon indicating copy to clipboard operation
iothub copied to clipboard

Non JSON method payload

Open floriaanpost opened this issue 3 years ago • 1 comments

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?)

floriaanpost avatar Apr 05 '22 12:04 floriaanpost

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

amenzhinsky avatar Apr 05 '22 13:04 amenzhinsky