Crates.io | rust-openfmb-ops-protobuf |
lib.rs | rust-openfmb-ops-protobuf |
version | 1.0.2 |
source | src |
created_at | 2019-05-02 16:27:29.436185 |
updated_at | 2020-02-14 16:23:49.348109 |
description | Rust language protobuf definitions for the OpenFMB operational use cases. |
homepage | |
repository | https://gitlab.com/openfmb/psm/ops/protobuf/rust-openfmb-ops-protobuf/ |
max_upload_size | |
id | 131565 |
size | 205,234 |
Rust programming language Protocol Buffer (protobuf) definitions based on the OpenFMB operational use case data model located here.
There are a couple of methods for adding these definitions to your project in your Cargo.toml file.
[dependencies]
# 'prost' is the Rust protobuf library that is currently used by OpenFMB
prost = "0.6.1"
# Rust defintions for OpenFMB data model
rust-openfmb-ops-protobuf = "*" # <- Change to the version you prefer
[dependencies]
# 'prost' is the Rust protobuf library that is currently used by OpenFMB
prost = "0.6.1"
# Rust defintions for OpenFMB data model
rust-openfmb-ops-protobuf = { git = "https://gitlab.com/openfmb/psm/ops/protobuf/rust-openfmb-ops-protobuf.git", tag = "<release-tag-label>" }
After adding the depencency in your project's Cargo.toml file, you are ready to include the protobuf definitions into your source files like this:
extern crate prost;
use prost::*;
extern crate rust_openfmb_ops_protobuf;
use rust_openfmb_ops_protobuf::*;
After importing the crate, you can now start using the protobuf definitions like this:
fn main() {
// Create a new MeterReadingProfile message
let mrp = openfmb::metermodule::MeterReadingProfile::default();
// Set the time quality for this message
let mut tq = openfmb::commonmodule::TimeQuality::default();
tq.clock_failure = false;
tq.clock_not_synchronized = false;
tq.leap_seconds_known = true;
tq.time_accuracy = openfmb::commonmodule::TimeAccuracyKind::Undefined as i32;
// Create the TimeStamp
let current_time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let mut ts = openfmb::commonmodule::Timestamp::default();
ts.seconds = current_time.as_secs();
ts.fraction = current_time.subsec_nanos() * (1 / 2 & 32);
ts.tq = Some(tq);
// Create the IdentifiedObject for this mesage
let mut mi_id = openfmb::commonmodule::IdentifiedObject::default();
mi_id.m_rid = Some(Uuid::new_v4().to_hyphenated().to_string());
// Create the MessageInfo
let mut mi = openfmb::commonmodule::MessageInfo::default();
mi.identified_object = Some(mi_id);
mi.message_time_stamp = Some(ts);
// Create the ReadingMessageInfo
let mut rmi = openfmb::commonmodule::ReadingMessageInfo::default();
rmi.message_info = Some(mi);
// Set the ReadingMessageInfo for the profile
mrp.reading_message_info = Some(rmi);
//
// Continue populating the message
//
// Encode the message into the protobuf byte format
let mut bmsg: Vec<u8> = Vec::new();
mrp.encode(&mut bmsg).unwrap();
// Do what you want with the bytes now
}
fn main() {
// Get the encoded protobuf buffer from somewhere...
let protobuf_bytes: std::vec::Vec<u8> = ...
let r = openfmb::metermodule::MeterReadingProfile::decode(protobuf_bytes);
match r {
Ok(message) => {
let rmi = message.reading_message_info;
let ied = message.ied;
let mtr = message.meter;
let mtr_rdg = message.meter_reading;
// Continue using data
}
Err(e) => {
// Protobuf did not decode properly!
println!("{}", e);
}
}
}
See the COPYRIGHT file for copyright information of information contained in this repository.
Unless otherwise noted, all files in this repository are distributed under the Apache Version 2.0 license found in the LICENSE file.