Skip to content

Add JSON write support#11

Draft
essioc wants to merge 9 commits intoepics-modules:mainfrom
essioc:feat-json-write-support
Draft

Add JSON write support#11
essioc wants to merge 9 commits intoepics-modules:mainfrom
essioc:feat-json-write-support

Conversation

@essioc
Copy link
Copy Markdown
Contributor

@essioc essioc commented Mar 26, 2026

This changelist replaces existing JSON handling, by using JSON pointer to address components within MQTT JSON message and configuration file to provide templates and alternative write addresses.

List of changes:

  • Remove recursive JSON field discovery with JSON pointer
  • [Optional] add clangd and E3 Makefile to gitignore
  • Add a new IOC shell function that expands existing method with JSON configuration loader
  • Add JSON configuration, removing redundant settings after some configurations are moved to JSON object.
  • Refactor parseDeviceAddress to check first, and create object later.
  • Add JSON composer and replace NotImplemented placeholders with JSON write feature
  • Update README.

essioc added 6 commits March 23, 2026 12:34
Previously, the module recursively looped and checked
key in the iterable. It had a limitation that it could not handle
mixed types, root array, and empty key.

JSON Pointer solves this problem because it can address all points in a
JSON object whether it is an array or a dictionary.

See also: https://datatracker.ietf.org/doc/html/rfc6901

BREAKING CHANGE: Previous json field addressing will no longer work
this does not add anything that actually does anything with the configuration
By using config file, there is no more need to add additional argument
when defining asyn address. Some comparison logic and parsing can now
be simplified.
this additionally has reduced risk of memory leak, as addr is only
allocated after all checks have passed.
@essioc essioc force-pushed the feat-json-write-support branch from fd3054f to d8b9012 Compare March 26, 2026 15:19
essioc added 2 commits March 26, 2026 17:02
Some records prefer to have separate writable field.
I considered implementing topic like

  AbstractTopicName
    ReadAddress
    WriteAddress
    Template
    Fields

However, this is problematic because when a message arrives, its topic
is the only name that is exposed. Therefore the searchable key for finding
the option must be in the same place as AbstractTopicName, not as a field
under it. (otherwise the search will be a bit more expensive)

So keeping the roles like:

  ReadAddressAndAlsoTopicName
    WriteAddress (optional)
    Template (optional)
    Fields

Seems more practical

Then, during config time the program can determine whether the record
ought to be writeable or not (absence of template = not writable)
this simplifies writing records that are supposed to be read-only
without having to write a dummy template just to satisfy the writer,
or having read only records that have ill-defined write behavior.

There are some duplicate code calls for some refactoring, but I don't see
a straightforward way to achieve this because callers for functions like
arrayWrite, integerWrite is not very modifiable, and adding a method that
prints status and returns error code doesn't really make the code shorter
or simpler
@essioc essioc force-pushed the feat-json-write-support branch 2 times, most recently from ed001e1 to 1cf5447 Compare March 26, 2026 16:40
@essioc essioc force-pushed the feat-json-write-support branch from 1cf5447 to 9e00eab Compare March 26, 2026 16:42
@AndreFavotto
Copy link
Copy Markdown
Collaborator

still WIP - but can you submit 25c64e8 (First commit here) in a separate PR, please?

I support the change, but I think it deserves its own attention

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

Successfully merging this pull request may close these issues.

2 participants