Skip to content

Communication Protocol

Dilpreet Chana edited this page Mar 6, 2020 · 13 revisions

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:

Request JSON

{
    "id": <id>,
    "command": <command>,
    "payload": <payload>
}

ID

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.

Payload

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.

Commands

insert (Needs Value)

Store a new key value pair

get

Get value at specified key

delete

Delete value at specified key

find

Check if specified key exists

update (Needs Value)

Update the value of existing key

upsert (Needs Value)

Update the value of key if it exists, create a new entry in the store if key does not exist

clear

Remove all key value pairs

count

Get number of key value pairs stored

Serialization

Primitive Types

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"

Response JSON

{
    "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
}

ID

The ID is the id of the request this is a response to

Return

A list of return objects where the i-th return object corresponds to the i-th request object for request with matching ID

Status

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

Value

The return is a list of values returned by the request command

The following are the expected return types for specified commands:

get

String serialized object stored at the specified key

count

Number of elements stored in data structure