This guide helps you quickly set up and start using the Ditto CoT library in your preferred programming language.
Quick Navigation: Building Guide | Testing Guide | Integration Examples | API Reference
Choose the language(s) you want to work with:
- Rust 1.70+: Install Rust
- Git: For cloning the repository
- Java JDK 17+: Download JDK
- Gradle 7.0+: Included via wrapper in repository
- Git: For cloning the repository
- .NET SDK 6.0+: Download .NET
- Git: For cloning the repository
- Make: For unified build commands across languages
- Ditto Account: For testing P2P synchronization features
Rust - Add to your Cargo.toml:
[dependencies]
ditto_cot = { git = "https://github.com/getditto-shared/ditto_cot" }Java - Add to your build.gradle:
dependencies {
implementation 'com.ditto:ditto-cot:1.0.0'
}Maven - Add to your pom.xml:
<dependency>
<groupId>com.ditto</groupId>
<artifactId>ditto-cot</artifactId>
<version>1.0.0</version>
</dependency># Clone the repository
git clone https://github.com/getditto-shared/ditto_cot.git
cd ditto_cot
# Build all languages (requires prerequisites installed)
make all
# Or build specific language
make rust # Build Rust library
make java # Build Java libraryRust:
cd rust
cargo test --libJava:
cd java
./gradlew testRust:
use ditto_cot::{cot_events::CotEvent, ditto::cot_to_document};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a simple location event
let event = CotEvent::builder()
.uid("USER-123")
.event_type("a-f-G-U-C")
.location(34.0522, -118.2437, 100.0)
.callsign("Test User")
.build();
// Convert to Ditto document
let doc = cot_to_document(&event, "peer-123");
println!("Created document: {}", serde_json::to_string_pretty(&doc)?);
Ok(())
}Java:
import com.ditto.cot.CotEvent;
public class FirstExample {
public static void main(String[] args) {
// Create a simple location event
CotEvent event = CotEvent.builder()
.uid("USER-123")
.type("a-f-G-U-C")
.point(34.0522, -118.2437, 100.0)
.callsign("Test User")
.build();
// Convert to XML
String xml = event.toXml();
System.out.println("Created XML: " + xml);
}
}// Rust
let location_event = CotEvent::builder()
.uid("TRACKER-001")
.event_type("a-f-G-U-C") // Friendly ground unit
.location_with_accuracy(34.052235, -118.243683, 100.0, 5.0, 10.0)
.callsign("ALPHA-1")
.team("Blue")
.build();// Java
CotEvent locationEvent = CotEvent.builder()
.uid("TRACKER-001")
.type("a-f-G-U-C")
.point(34.052235, -118.243683, 100.0, 5.0, 10.0)
.detail()
.callsign("ALPHA-1")
.groupName("Blue")
.build()
.build();// Rust
let chat_event = CotEvent::new_chat_message(
"USER-456",
"BRAVO-2",
"Message received, moving to coordinates",
"All Chat Rooms",
"All Chat Rooms"
);// Java
CotEvent chatEvent = CotEvent.builder()
.uid("USER-456")
.type("b-t-f")
.detail()
.chat("All Chat Rooms", "Message received, moving to coordinates")
.callsign("BRAVO-2")
.build()
.build();// Rust
let cot_xml = r#"<event version="2.0" uid="TEST-123" type="a-f-G-U-C"...>"#;
let event = CotEvent::from_xml(cot_xml)?;// Java
String cotXml = "<event version=\"2.0\" uid=\"TEST-123\" type=\"a-f-G-U-C\"...>";
CotEvent event = CotEvent.fromXml(cotXml);// Rust
let xml = event.to_xml()?;// Java
String xml = event.toXml();// Rust
use ditto_cot::ditto::cot_to_document;
let doc = cot_to_document(&event, "my-peer-id");
match doc {
CotDocument::MapItem(map_item) => {
println!("Location: {} at {},{}",
map_item.e, map_item.j.unwrap_or(0.0), map_item.l.unwrap_or(0.0));
},
CotDocument::Chat(chat) => {
println!("Chat: {}", chat.message);
},
_ => println!("Other document type"),
}// Java
import com.ditto.cot.schema.*;
Object doc = converter.convertToDocument(event);
if (doc instanceof MapItemDocument) {
MapItemDocument mapItem = (MapItemDocument) doc;
System.out.println("Location: " + mapItem.getE() +
" at " + mapItem.getJ() + "," + mapItem.getL());
} else if (doc instanceof ChatDocument) {
ChatDocument chat = (ChatDocument) doc;
System.out.println("Chat: " + chat.getMessage());
}CoT XML → Parse → CotEvent → Validate → Process
Builder → CotEvent → Convert → Ditto Document → Store
Local Change → CRDT Update → Differential Sync → Remote Apply
Now that you have the basics working, explore these areas:
- Read the Architecture Guide to understand system design
- Learn about CRDT Optimization for P2P benefits
- Follow the Building Guide for development setup
- Set up Testing for your contribution workflow
- Explore Ditto SDK Integration for real-time sync
- Check language-specific examples:
- Issues: Report bugs on GitHub Issues
- Discussions: Ask questions in GitHub Discussions
- Documentation: Check our comprehensive docs
Rust Build Errors: Ensure you have Rust 1.70+ and all dependencies installed
Java Compilation Issues: Verify JDK 17+ and Gradle wrapper permissions
Missing Dependencies: Run make all to ensure all components are built
Test Failures: Some tests require Ditto credentials - see Testing Guide
- Building Guide - Detailed build procedures for all languages
- Testing Guide - Comprehensive testing strategies and troubleshooting
- Integration Examples - Language-specific usage patterns
- API Reference - Complete API documentation
- Troubleshooting - Common issues and solutions
- Architecture - Understanding the system design