Skip to content

Commit

Permalink
Merge pull request #386 from helium/andymck/sp-str-impls
Browse files Browse the repository at this point in the history
Centralise str impl for service provider enum
  • Loading branch information
andymck authored Jan 12, 2024
2 parents e3258b5 + e3c15a6 commit 585704c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const SERVICES: &[&str] = &[
const MESSAGES: &[&str] = &[
"src/blockchain_txn.proto",
"src/entropy.proto",
"src/service_provider.proto",
"src/data_rate.proto",
"src/region.proto",
"src/mapper.proto",
Expand Down
23 changes: 22 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use prost::{DecodeError, EncodeError, Message};
pub mod services {
use crate::{
BlockchainRegionParamsV1, BlockchainTokenTypeV1, BlockchainTxn, DataRate, EntropyReportV1,
GatewayStakingMode, MapperAttach, Region, RoutingAddress,
GatewayStakingMode, MapperAttach, Region, RoutingAddress, ServiceProvider,
};

pub mod iot_config {
Expand Down Expand Up @@ -98,6 +98,27 @@ pub mod services {
pub use tonic::transport::*;
}

impl std::str::FromStr for ServiceProvider {
type Err = prost::DecodeError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Helium Mobile" => Ok(ServiceProvider::HeliumMobile),
unknown => Err(prost::DecodeError::new(format!(
"unknown service provider: {unknown}"
))),
}
}
}

impl std::fmt::Display for ServiceProvider {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
ServiceProvider::HeliumMobile => f.write_str("Helium Mobile"),
}
}
}

impl std::str::FromStr for DataRate {
type Err = prost::DecodeError;

Expand Down
5 changes: 1 addition & 4 deletions src/service/poc_mobile.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package helium.poc_mobile;

import "mapper.proto";
import "service_provider.proto";

message speedtest_req_v1 {
bytes pub_key = 1;
Expand Down Expand Up @@ -337,10 +338,6 @@ message subscriber_reward {
uint64 discovery_location_amount = 2;
}

enum service_provider {
helium_mobile = 0;
}

message service_provider_reward {
// rewardable entity id of the service provider to which the reward will be
// credited
Expand Down
7 changes: 7 additions & 0 deletions src/service_provider.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

package helium;

enum service_provider {
helium_mobile = 0;
}

0 comments on commit 585704c

Please sign in to comment.