The JSON protocol provides the same features as XML protocol version 2.0 but in JSON format, offering better integration with modern web applications and JavaScript clients.
Protocol Version: 512 (equivalent to XML 2.0)
| Feature | XML Protocol | JSON Protocol |
|---|---|---|
| Version number | “2.0” (string) | 512 (number) |
| Switch values | “On”/”Off” (strings) | true/false (booleans) |
| Number values | Strings | JSON numbers |
| BLOB data | BASE64 inline or URL | URL only |
| Message structure | XML tags/attributes | JSON objects |
| Array representation | Repeated elements | JSON arrays with items key |
Important: JSON protocol only supports URL-referenced BLOBs. No inline BASE64 data support.
BLOBs are referenced by URL paths:
{
"setBLOBVector": {
"device": "CCD Imager Simulator",
"name": "CCD_IMAGE",
"state": "Ok",
"items": [
{
"name": "IMAGE",
"value": "/blob/0x10381d798.fits"
}
]
}
}
{
"getProperties": {
"version": 512,
"client": "My Client",
"device": "Server",
"name": "LOAD"
}
}
{
"defTextVector": {
"version": 512,
"device": "Server",
"name": "LOAD",
"group": "Main",
"label": "Load driver",
"perm": "rw",
"state": "Idle",
"items": [
{
"name": "DRIVER",
"label": "Load driver",
"value": ""
}
]
}
}
{
"defSwitchVector": {
"version": 512,
"device": "Server",
"name": "RESTART",
"group": "Main",
"label": "Restart",
"perm": "rw",
"state": "Idle",
"rule": "AnyOfMany",
"hints": "order: 10; widget: button",
"items": [
{
"name": "RESTART",
"label": "Restart server",
"value": false
}
]
}
}
{
"setSwitchVector": {
"device": "CCD Imager Simulator",
"name": "CONNECTION",
"state": "Ok",
"items": [
{
"name": "CONNECTED",
"value": true
},
{
"name": "DISCONNECTED",
"value": false
}
]
}
}
{
"newNumberVector": {
"device": "CCD Imager Simulator",
"name": "CCD_EXPOSURE",
"token": "FA0012",
"items": [
{
"name": "EXPOSURE",
"value": 1
}
]
}
}
{
"deleteProperty": {
"device": "Mount IEQ (guider)"
}
}
use libindigo::strategies::rs::protocol_json::JsonProtocolParser;
let json = r#"{"getProperties": {"version": 512, "device": "Server"}}"#;
let message = JsonProtocolParser::parse_message(json)?;
match message {
ProtocolMessage::GetProperties(gp) => {
println!("Device: {:?}", gp.device);
}
_ => {}
}
use libindigo::strategies::rs::protocol_json::JsonProtocolSerializer;
use libindigo::strategies::rs::protocol::{GetProperties, ProtocolMessage};
let msg = ProtocolMessage::GetProperties(GetProperties {
version: Some("2.0".to_string()),
device: Some("Server".to_string()),
name: Some("LOAD".to_string()),
});
let json = JsonProtocolSerializer::serialize(&msg)?;
// Output: {"getProperties":{"version":512,"device":"Server","name":"LOAD"}}
defTextVector - Text property definitionsdefNumberVector - Number property definitionsdefSwitchVector - Switch property definitionsdefLightVector - Light property definitionsdefBLOBVector - BLOB property definitionssetTextVector - Text property updatessetNumberVector - Number property updatessetSwitchVector - Switch property updatessetLightVector - Light property updatessetBLOBVector - BLOB property updatesnewTextVector - Text property commandsnewNumberVector - Number property commandsnewSwitchVector - Switch property commandsnewBLOBVector - BLOB property commandsgetProperties - Request property definitionsenableBLOB - Control BLOB transfermessage - Status messagesdeleteProperty - Property deletionLocation: src/strategies/rs/protocol_json.rs
Components:
JsonProtocolParser - Parses JSON strings into ProtocolMessage enumsJsonProtocolSerializer - Serializes ProtocolMessage enums to JSON stringsShared Types: Reuses all message type structs from protocol.rs for consistency between XML and JSON protocols.
Comprehensive unit tests are included:
Run tests:
cargo test --features rs protocol_json --lib
This implementation follows the INDIGO JSON protocol specification: