| Crates.io | ovsdb-schema |
| lib.rs | ovsdb-schema |
| version | 0.0.1 |
| created_at | 2025-03-08 04:49:45.636935+00 |
| updated_at | 2025-03-08 04:49:45.636935+00 |
| description | Rust types and serialization for the Open vSwitch Database Management Protocol (OVSDB) |
| homepage | |
| repository | https://review.vexxhost.dev/plugins/gitiles/ovsdb |
| max_upload_size | |
| id | 1584077 |
| size | 29,185 |
A Rust implementation of the OVSDB protocol serialization and deserialization types.
This crate provides the core primitives and traits needed to work with the Open vSwitch Database Management Protocol (OVSDB) as defined in RFC7047. It includes:
This crate is designed to be used alongside ovsdb-derive for a complete OVSDB client implementation.
OvsdbAtom and OvsdbValue types representing OVSDB's basic data typesOvsdbSerializable trait for converting between Rust types and OVSDB valuesString, i64, bool, etc.Vec<T> and HashMap<K, V>use ovsdb_schema::{OvsdbSerializable, OvsdbSerializableExt};
use std::collections::HashMap;
use uuid::Uuid;
// Use the trait directly
let my_string = "hello".to_string();
let ovsdb_value = my_string.to_ovsdb();
let json_value = my_string.to_ovsdb_json().unwrap();
// Extract UUIDs from JSON values
let uuid_str = "550e8400-e29b-41d4-a716-446655440000";
let uuid = Uuid::parse_str(uuid_str).unwrap();
let json_value = serde_json::json!(["uuid", uuid_str]);
let extracted_uuid = ovsdb_schema::extract_uuid(&json_value).unwrap();
assert_eq!(uuid, extracted_uuid);
ovsdb-deriveThis crate is designed to work with the companion ovsdb-derive crate:
use ovsdb_derive::ovsdb_object;
use std::collections::HashMap;
#[ovsdb_object]
pub struct NbGlobal {
pub name: Option<String>,
pub nb_cfg: Option<i64>,
pub external_ids: Option<HashMap<String, String>>,
}
// The macro adds _uuid and _version fields and implements
// OvsdbSerializable automatically
| Rust Type | OVSDB Type |
|---|---|
String |
string |
i64 |
integer |
f64 |
real |
bool |
boolean |
Uuid |
uuid |
Vec<T> |
set |
HashMap<K, V> |
map |
Option<T> |
value or empty set |
Implement OvsdbSerializable for your custom types:
use ovsdb_schema::{OvsdbSerializable, OvsdbValue, OvsdbAtom};
struct MyType(String);
impl OvsdbSerializable for MyType {
fn to_ovsdb(&self) -> OvsdbValue {
OvsdbValue::Atom(OvsdbAtom::String(self.0.clone()))
}
fn from_ovsdb(value: &OvsdbValue) -> Option<Self> {
match value {
OvsdbValue::Atom(OvsdbAtom::String(s)) => Some(MyType(s.clone())),
_ => None,
}
}
}
This project is licensed under the Apache License, Version 2.0.