iotds: create generic JSON encode, decode entity functions
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)
-
reporter -
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
-
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.
-
reporter - changed status to closed
Issue is for the datastore package, see here: https://github.com/ausocean/openfish/issues/3 We should keep the Encode and Decode functions that we currently have because they are more efficient for binary encoding.
- Log in to comment
@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?