MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / create

Method create

chirpstack/src/api/multicast.rs:28–82  ·  view source on GitHub ↗
(
        &self,
        request: Request<api::CreateMulticastGroupRequest>,
    )

Source from the content-addressed store, hash-verified

26#[tonic::async_trait]
27impl MulticastGroupService for MulticastGroup {
28 async fn create(
29 &self,
30 request: Request<api::CreateMulticastGroupRequest>,
31 ) -> Result<Response<api::CreateMulticastGroupResponse>, Status> {
32 let req_mg = match &request.get_ref().multicast_group {
33 Some(v) => v,
34 None => {
35 return Err(Status::invalid_argument("multicast_group is missing"));
36 }
37 };
38
39 let app_id = Uuid::from_str(&req_mg.application_id).map_err(|e| e.status())?;
40
41 self.validator
42 .validate(
43 request.extensions(),
44 validator::ValidateMulticastGroupsAccess::new(
45 validator::Flag::Create,
46 None,
47 Some(app_id),
48 ),
49 )
50 .await?;
51
52 let mg = multicast::MulticastGroup {
53 application_id: app_id.into(),
54 name: req_mg.name.clone(),
55 region: req_mg.region().from_proto(),
56 mc_addr: DevAddr::from_str(&req_mg.mc_addr).map_err(|e| e.status())?,
57 mc_nwk_s_key: AES128Key::from_str(&req_mg.mc_nwk_s_key).map_err(|e| e.status())?,
58 mc_app_s_key: AES128Key::from_str(&req_mg.mc_app_s_key).map_err(|e| e.status())?,
59 f_cnt: req_mg.f_cnt as i64,
60 group_type: match req_mg.group_type() {
61 api::MulticastGroupType::ClassB => "B",
62 api::MulticastGroupType::ClassC => "C",
63 }
64 .to_string(),
65 dr: req_mg.dr as i16,
66 frequency: req_mg.frequency as i64,
67 class_b_ping_slot_periodicity: req_mg.class_b_ping_slot_periodicity as i16,
68 class_c_scheduling_type: req_mg.class_c_scheduling_type().from_proto(),
69 ..Default::default()
70 };
71 let mg = multicast::create(mg).await.map_err(|e| e.status())?;
72
73 let mut resp = Response::new(api::CreateMulticastGroupResponse {
74 id: mg.id.to_string(),
75 });
76 resp.metadata_mut().insert(
77 "x-log-multicast_group_id",
78 mg.id.to_string().parse().unwrap(),
79 );
80
81 Ok(resp)
82 }
83
84 async fn get(
85 &self,

Callers 1

test_multicast_groupFunction · 0.45

Calls 8

statusMethod · 0.80
from_protoMethod · 0.80
to_stringMethod · 0.80
insertMethod · 0.80
unwrapMethod · 0.80
createFunction · 0.50
validateMethod · 0.45
intoMethod · 0.45

Tested by 1

test_multicast_groupFunction · 0.36