-
Notifications
You must be signed in to change notification settings - Fork 6
Communication Protocol
This page outlines the standard for sending messages between different implementations of DDB. Messages are case sensitive and should be sent as a JSON string with the form:
{
"id": <id>,
"command": <command>,
"payload": <payload>
}
The ID is the id assigned to the device to identify data stored by that device. The id should be a random base64 string of length 100. This id will be stored in the config file. The generation and setup of this id will be outlined in the Network Discovery Protocol document.
The payload is an array of valid objects. An array of objects imply the command is to be executed, independently, on each valid object in the array
The payload object will take the form
{
...
"payload": [
{
"key": <key of value>
"value": <object to store serialized to a string>
},
...
]
...
}
Note: Not all commands will need a "value" entry, only commands marked "Needs Value" should check if the payload has "value".
See the section on serialization for information on how to serialize and de-serialize data.
Store a new key value pair
Get value at specified key
Delete value at specified key
Check if specified key exists
Update the value of existing key
Update the value of key if it exists, create a new entry in the store if key does not exist
Remove all key value pairs
Get number of key value pairs stored
Primitive types include int
, float
, char
, string
, etc. These types should be serialized as a simple string.
Ex.
(int) 12 -> "12"
(float) 3.14 -> "3.14"
{
"id": <id>,
"return": [
{
"status": <return status 1>,
"value": <return value 1>
},
{
"status": <return status 2>,
"value": <return value 2>
},
...
]
}
If the request JSON is not valid according to this document, the response JSON will look like the following:
{
"id": <id if available>,
"status": 400
}
The ID is the id of the request this is a response to
A list of return objects where the i-th return object corresponds to the i-th request object for request with matching ID
The status is a list of numbers indicating the outcome of the request
The following status codes implemented:
-
200 OK
-
204 OK with no return
-
404 Not found
-
408 Request timeout
The return is a list of values returned by the request command
The following are the expected return types for specified commands:
String serialized object stored at the specified key
Number of elements stored in data structure