<!-- SPDX-FileCopyrightText: Copyright 2023-2026 Jetperch LLC
SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->

<a id="h-meta"></a>

# Metadata handling

### *group* Metadata handling

Handle JSON-formatted metadata. 

### Enums

### enum jsdrv_meta_flag_e

Metadata flag bits (mirrors minibitty’s mb_pubsub_meta_flags_e). 

*Values:*

### enumerator JSDRV_META_FLAG_RO

Topic is read-only; cannot be updated by the host. 

### enumerator JSDRV_META_FLAG_HIDE

Topic should not appear in the user interface. 

### enumerator JSDRV_META_FLAG_DEV

Developer option; not for production use. 

### Functions

### int32_t jsdrv_meta_syntax_check(const char \*meta)

Check the JSON metadata syntax. 

* **Parameters:**
  **meta** – The JSON metadata. 
* **Returns:**
  0 or error code. 

### int32_t jsdrv_meta_dtype(const char \*meta, uint8_t \*dtype)

Get the data type. 

* **Parameters:**
  * **meta** – The JSON metadata. 
  * **dtype** – **[out]** The [jsdrv_union_e](https://docs.joulescope.com/en/software/joulescope_driver/h_union.md#group__jsdrv__union_1ga2a05d885f40b41bfd2c499659678b597) data type. 
* **Returns:**
  0 or error code. 

### int32_t jsdrv_meta_default(const char \*meta, struct [jsdrv_union_s](https://docs.joulescope.com/en/software/joulescope_driver/h_union.md#_CPPv413jsdrv_union_s) \*value)

Get the default value. 

* **Parameters:**
  * **meta** – The JSON metadata. 
  * **value** – **[out]** The parsed default value. 
* **Returns:**
  0 or error code. 

### int32_t jsdrv_meta_value(const char \*meta, struct [jsdrv_union_s](https://docs.joulescope.com/en/software/joulescope_driver/h_union.md#_CPPv413jsdrv_union_s) \*value)

Validate a parameter value using the metadata. 

* **Parameters:**
  * **meta** – The JSON metadata. 
  * **value** – **[inout]** The value, which is modified in place. 
* **Returns:**
  0 or error code. 

### int32_t jsdrv_meta_flags(const char \*meta, uint32_t \*flags)

Get the flags bitmask from the metadata. 

Parses the “flags” key from the JSON metadata, which is a list of string tokens: “ro”, “hide”, “dev”. Returns a bitmask of [jsdrv_meta_flag_e](#group__jsdrv__meta_1ga444d12671864661f302b6712ae76de86). If “flags” is absent, \*flags is set to 0.

* **Parameters:**
  * **meta** – The JSON metadata. 
  * **flags** – **[out]** The resulting bitmask. 
* **Returns:**
  0 or error code. 

## Host-side metadata

The driver defines its own topic metadata, such as JS320 `h/fs` and the
memory buffer `m/` topics, in `jsdrvp_param_s` tables in
`src/**/*_params.c`.  Tables in `src/devices/<model>/` apply to that
device model.  Other tables are global driver topics.  Topics may contain
`{buf}` and `{sig}` placeholders for the buffer and signal ids.

`pyjoulescope_driver.metadata_extract` parses these tables into the
packaged `host_params.json`.  After editing a table, regenerate it with:

```default
python -m pyjoulescope_driver.metadata_extract --write
```

A unit test fails when `host_params.json` is stale.

The `metadata` entry point combines this host-side metadata with the
firmware build’s `pubsub_metadata.json` files to document all topics
without a device:

```default
python -m pyjoulescope_driver metadata --firmware js320.zip --out js320.html
```

With a connected device, `--diff` compares the live metadata against a
saved JSON file to verify the offline output:

```default
python -m pyjoulescope_driver metadata --diff js320.json
```
