Split protobuf of tripod-id
This commit is contained in:
parent
97a3f86ef9
commit
6256c61a45
9 changed files with 85 additions and 30 deletions
|
|
@ -1,7 +1,11 @@
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
#[cfg(feature="prost")]
|
#[cfg(feature="prost")]
|
||||||
prost_build::compile_protos(
|
prost_build::compile_protos(
|
||||||
&["proto/tripod_id.proto"],
|
&[
|
||||||
|
"proto/tripod_id/single.proto",
|
||||||
|
"proto/tripod_id/double.proto",
|
||||||
|
"proto/tripod_id/triple.proto"
|
||||||
|
],
|
||||||
&["proto/"]
|
&["proto/"]
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
syntax = "proto3";
|
|
||||||
package tripod_id;
|
|
||||||
|
|
||||||
// Single size tripod id message
|
|
||||||
message Single {
|
|
||||||
uint32 id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Double size tripod id message
|
|
||||||
message Double {
|
|
||||||
uint32 id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Triple size tripod id message
|
|
||||||
message Triple {
|
|
||||||
uint64 id = 1;
|
|
||||||
}
|
|
||||||
7
tripod-id/proto/tripod_id/double.proto
Normal file
7
tripod-id/proto/tripod_id/double.proto
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package tripod_id;
|
||||||
|
|
||||||
|
// Double size tripod id message
|
||||||
|
message Double {
|
||||||
|
uint32 id = 1;
|
||||||
|
}
|
||||||
7
tripod-id/proto/tripod_id/single.proto
Normal file
7
tripod-id/proto/tripod_id/single.proto
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package tripod_id;
|
||||||
|
|
||||||
|
// Single size tripod id message
|
||||||
|
message Single {
|
||||||
|
uint32 id = 1;
|
||||||
|
}
|
||||||
7
tripod-id/proto/tripod_id/triple.proto
Normal file
7
tripod-id/proto/tripod_id/triple.proto
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package tripod_id;
|
||||||
|
|
||||||
|
// Triple size tripod id message
|
||||||
|
message Triple {
|
||||||
|
uint64 id = 1;
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use prost::Name;
|
use prost::Name;
|
||||||
|
|
||||||
use crate::{prost::{Double, TripodIdMessage}, Error, TripodId};
|
use crate::{prost::{Double, TripodIdMessage}, Error};
|
||||||
|
|
||||||
impl Name for Double {
|
impl Name for Double {
|
||||||
const NAME: &'static str = "Double";
|
const NAME: &'static str = "Double";
|
||||||
|
|
@ -27,3 +27,27 @@ impl TryFrom<Double> for crate::Double {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::{Double, DoubleMessage, TripodId};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn nil() {
|
||||||
|
let nil = DoubleMessage{id: 0};
|
||||||
|
assert_eq!(Double::NIL, Double::try_from(nil).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn max() {
|
||||||
|
let max = DoubleMessage{id: u32::from(Double::CAPACITY)-1};
|
||||||
|
assert_eq!(Double::MAX, Double::try_from(max).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn oversized () {
|
||||||
|
let oversized = DoubleMessage{id: u32::from(Double::CAPACITY)};
|
||||||
|
let _ = Double::try_from(oversized).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,17 +1,20 @@
|
||||||
pub mod generated {
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/tripod_id.rs"));
|
|
||||||
}
|
|
||||||
|
|
||||||
mod single;
|
mod single;
|
||||||
mod double;
|
mod double;
|
||||||
mod triple;
|
mod triple;
|
||||||
|
|
||||||
pub use generated::*;
|
|
||||||
|
|
||||||
use crate::TripodId;
|
use crate::TripodId;
|
||||||
|
|
||||||
const PACKAGE_NAME: &'static str = "tripod_id";
|
const PACKAGE_NAME: &'static str = "tripod_id";
|
||||||
|
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/tripod_id.rs"));
|
||||||
|
|
||||||
|
/// Alias of single tripod-id message
|
||||||
pub type SingleMessage = Single;
|
pub type SingleMessage = Single;
|
||||||
|
|
||||||
|
/// Alias of double tripod-id message
|
||||||
pub type DoubleMessage = Double;
|
pub type DoubleMessage = Double;
|
||||||
|
|
||||||
|
/// Alias of triple tripod-id message
|
||||||
pub type TripleMessage = Triple;
|
pub type TripleMessage = Triple;
|
||||||
|
|
||||||
pub trait TripodIdMessage: From<Self::TripodId> {
|
pub trait TripodIdMessage: From<Self::TripodId> {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use prost::Name;
|
use prost::Name;
|
||||||
|
|
||||||
use crate::{prost::{Triple, TripodIdMessage}, Error, TripodId};
|
use crate::{prost::{Triple, TripodIdMessage}, Error};
|
||||||
|
|
||||||
impl Name for Triple {
|
impl Name for Triple {
|
||||||
const NAME: &'static str = "Triple";
|
const NAME: &'static str = "Triple";
|
||||||
|
|
@ -27,3 +27,27 @@ impl TryFrom<Triple> for crate::Triple {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::{Triple, TripleMessage, TripodId};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn nil() {
|
||||||
|
let nil = TripleMessage{id: 0};
|
||||||
|
assert_eq!(Triple::NIL, Triple::try_from(nil).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn max() {
|
||||||
|
let max = TripleMessage{id: u64::from(Triple::CAPACITY)-1};
|
||||||
|
assert_eq!(Triple::MAX, Triple::try_from(max).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn oversized () {
|
||||||
|
let oversized = TripleMessage{id: u64::from(Triple::CAPACITY)};
|
||||||
|
let _ = Triple::try_from(oversized).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,3 @@
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use crate::Single;
|
|
||||||
|
|
||||||
/// Test if the character is valid delimiter.
|
/// Test if the character is valid delimiter.
|
||||||
pub fn is_delimiter(c: char) -> bool {
|
pub fn is_delimiter(c: char) -> bool {
|
||||||
match c {
|
match c {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue