iotds: create generic JSON encode, decode entity functions

Issue #300 closed
Trek Hopton created an issue

Each of our datastore entities has its own Encode and Decode methods. They are generally tab separated lists encoded to bytes. Instead we should switch to using JSON so that they can be used in web APIs and are compatible with many front end libraries. The site entity already does this, see iotds/site.go.

We should make generic iotds EncodeEntity() and DecodeEntity() functions which simply wrap the json.Marshal and json.Unmarshal functions. Then we can get rid of individual entity Encode and Decode functions for our datastore objects.

Comments (4)

  1. Trek Hopton reporter

    @Alan Noble Do you think we should get rid of Encode and Decode methods per entity? Or keep them and wrap a generic EncodeEntity DecodeEntity function?

  2. Alan Noble

    We can provide default implementations based on JSON marshalling but we should still keep the Encode and Decode methods to give clients complete flexibility as to how they wish to encode/decode. For example, JSON is very inefficient for encoding binary data types.

    There is already this issue on openfish/datastore: https://github.com/ausocean/openfish/issues/3

  3. Trek Hopton reporter

    Got it, so openfish/datastore can provide generic entity Encode and Decode functions that can be used in implementations of the Entity interface’s Encode and Decode methods, unless a different encoding is desired. This will simplify initial functional Entity implementations.

    I’ll close this issue and link this discussion in the openfish issue.

  4. Log in to comment