| 244 | |
| 245 | #[tokio::test] |
| 246 | pub async fn test_decode() { |
| 247 | let recv_time = Utc.with_ymd_and_hms(2014, 7, 8, 9, 10, 11).unwrap(); |
| 248 | |
| 249 | let decoder = r#" |
| 250 | function decodeUplink(input) { |
| 251 | var buff = new Buffer(input.bytes); |
| 252 | |
| 253 | return { |
| 254 | data: { |
| 255 | f_port: input.fPort, |
| 256 | variables: input.variables, |
| 257 | data_hex: buff.toString('hex'), |
| 258 | data: input.bytes, |
| 259 | recv_time: input.recvTime.toString() |
| 260 | } |
| 261 | }; |
| 262 | } |
| 263 | "# |
| 264 | .to_string(); |
| 265 | |
| 266 | let mut vars: HashMap<String, String> = HashMap::new(); |
| 267 | vars.insert("foo".into(), "bar".into()); |
| 268 | |
| 269 | let out = decode(recv_time, 10, &vars, &decoder, &[0x01, 0x02, 0x03]) |
| 270 | .await |
| 271 | .unwrap(); |
| 272 | |
| 273 | let expected = pbjson_types::Struct { |
| 274 | fields: [ |
| 275 | ( |
| 276 | "f_port".to_string(), |
| 277 | pbjson_types::Value { |
| 278 | kind: Some(pbjson_types::value::Kind::NumberValue(10.0)), |
| 279 | }, |
| 280 | ), |
| 281 | ( |
| 282 | "variables".to_string(), |
| 283 | pbjson_types::Value { |
| 284 | kind: Some(pbjson_types::value::Kind::StructValue( |
| 285 | pbjson_types::Struct { |
| 286 | fields: [( |
| 287 | "foo".to_string(), |
| 288 | pbjson_types::Value { |
| 289 | kind: Some(pbjson_types::value::Kind::StringValue( |
| 290 | "bar".to_string(), |
| 291 | )), |
| 292 | }, |
| 293 | )] |
| 294 | .iter() |
| 295 | .cloned() |
| 296 | .collect(), |
| 297 | }, |
| 298 | )), |
| 299 | }, |
| 300 | ), |
| 301 | ( |
| 302 | "data_hex".to_string(), |
| 303 | pbjson_types::Value { |