bluejay icon indicating copy to clipboard operation
bluejay copied to clipboard

Add a simple json schema for adding services to dittojay through json

Open brendanlensink opened this issue 5 years ago • 3 comments
trafficstars

Fixes: #225

Summary of Problem:

We'd like to be able to add and manage services created with Dittojay through JSON instead of having to add them in code.

Proposed Solution:

Created a simple JSON schema that can be parsed to create services from.

A couple questions:

  • I noticed that the CBMutableService constructor calls the UUID param type, is there a reason we should do this as well, or is it clearer to just stick with uuid?
  • Is it helpful to have some sort of user-defined name attribute for keeping track of services once they're loaded?
  • Do we need to require UUIDs be set ahead of the time, or can they be optional and generated at runtime by Dittojay?
  • Does it make sense to have value passed in as a String that we can then convert into Data??

brendanlensink avatar Dec 09 '19 18:12 brendanlensink

I don't think we should merge this to master.

That's totally reasonable, would this end up being version 0.7.2 then?

I think we can allow specifying name and even description

Description is a great idea, added that as well.

Instead of just value ...

Changed value to hold another JSON object, with the intent being that Dittojay will parse the JSON and concat all the values to create the Data to be read.

I think it would be neat to create some sort of framework to separate the value data and the schema, but it might be a more 2.0/next iteration feature if that makes sense?

brendanlensink avatar Dec 09 '19 21:12 brendanlensink

Yes, let's defer any high complexity features that might not be necessary to have right away :)

sakuraehikaru avatar Dec 09 '19 22:12 sakuraehikaru

value being an object might not work (or at least, not work by itself).

The fields are going to be order dependant (except in the trivial case of only one field), but I don't think that ordering is well defined for JSON (like once we have loaded that in, there is no way to say "give me the fields in order", which is pretty essential for creating the binary data to send).

What I think we want is an array that defines things like ordering and byte width:

"value" : [
   { "byteWidth": 2, "value": 700 },
   { "byteWidth": 4, "value": -100 }
]

This is (I believe) the simplest thing that could work. We can get more complicated by adding possible options to the fields ({"byteWidth": 2, "bigEndian": true, "value": 700 }) or by naming the fields so we can do the more seperate-schema-and-data approach later:

"schema" : [
   { "name" : "foo", "byteWidth": 2, "bigEndian": true}.
   { "name" : "bar", "byteWidth": 4, "bigEndian": false}
],
data: {
  "foo": 700,
  "bar": -100
}

nbrooke avatar Jan 03 '20 22:01 nbrooke

@sakuraehikaru Is it worth keeping this PR open, or can we close this and re-open if we want to address this in the future?

brendanlensink avatar Sep 16 '22 21:09 brendanlensink

@brendanlensink I have no preference, other than if we do close this, then let's not delete this branch so we don't lose any work that's already done.

sakuraehikaru avatar Sep 16 '22 21:09 sakuraehikaru