confserver: Standardize and document the handling of hex values

Previously, server always sent back "hex" types as JSON integers but would only accept setting them as a
JSON string of hex digits. This still works, but also possible to use JSON integers in both directions.

Add tests for both representations, add a note in the README about types.
pull/4306/head
Angus Gratton 2020-01-22 17:43:40 +11:00 zatwierdzone przez Angus Gratton
rodzic 2e8a894ea7
commit 89fb104747
3 zmienionych plików z 22 dodań i 0 usunięć

Wyświetl plik

@ -82,6 +82,13 @@ After a request is processed, a response is printed to stdout similar to this:
* `visible` contains any visibility changes, where the visible config symbols have changed.
* `values` contains any value changes, where a config symbol value has changed. This may be due to an explicit change (ie the client `set` this value), or a change caused by some other change in the config system. Note that a change which is set by the client may not be reflected exactly the same in the response, due to restrictions on allowed values which are enforced by the config server. Invalid changes are ignored by the config server.
### KConfig Item Types
* `string` types are represented as JSON strings.
* `bool` and `tristate` types are represented as JSON Booleans, the third `tristate` state is not supported.
* `int` types are represented as JSON integers
* `hex` types are also represented as JSON integers, clients should read the separate metadata file to know if the UI representation is `int` or `hex`. It is possible to set a `hex` item by sending the server a JSON string of hex digits (no prefix) as the value, but the server always sends `hex` values as JSON integers.
### Error Responses
In some cases, a request may lead to an error message. In this case, the error message is printed to stderr but an array of errors is also returned in the `error` key of the response:

Wyświetl plik

@ -224,6 +224,13 @@ def handle_set(config, error, to_set):
sym.set_value(0)
else:
error.append("Boolean symbol %s only accepts true/false values" % sym.name)
elif sym.type == kconfiglib.HEX:
try:
if not isinstance(val, int):
val = int(val, 16) # input can be a decimal JSON value or a string of hex digits
sym.set_value("%x" % val)
except ValueError:
error.append("Hex symbol %s can accept a decimal integer or a string of hex digits, only")
else:
sym.set_value(str(val))
print("Set %s" % sym.name)

Wyświetl plik

@ -45,3 +45,11 @@
* Enabling submenuconfig item re-shows its children
> { "SUBMENU_CONFIG": true }
< { "values" : { "SUBMENU_CONFIG_ITEM": true, "SUBMENU_CONFIG" : true }, "visible": { "SUBMENU_CONFIG_ITEM": true } }
* Read/write hex values as decimal integers
> { "TEST_CONDITIONAL_HEX_RANGES": 140 }
< { "values" : { "TEST_CONDITIONAL_HEX_RANGES" : 140 } }
* Can write hex values as hex strings, but the result is a decimal integer
> { "TEST_CONDITIONAL_HEX_RANGES": "90" }
< { "values" : { "TEST_CONDITIONAL_HEX_RANGES" : 144 } }