1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #![allow(non_snake_case)]
16 #![allow(non_camel_case_types)]
17 #![allow(warnings, missing_docs)]
18 #![allow(clippy::all)]
19 // this is now stable
20 #![feature(mixed_integer_ops)]
21 
22 include!(concat!(env!("OUT_DIR"), "/_packets.rs"));
23 
hex_to_word(hex: u8) -> u824 fn hex_to_word(hex: u8) -> u8 {
25     if b'0' <= hex && hex <= b'9' {
26         hex - b'0'
27     } else if b'A' <= hex && hex <= b'F' {
28         hex - b'A' + 0xa
29     } else {
30         hex - b'a' + 0xa
31     }
32 }
33 
hex_str_to_byte_vector(hex: &str) -> Vec<u8>34 fn hex_str_to_byte_vector(hex: &str) -> Vec<u8> {
35     hex.as_bytes()
36         .chunks_exact(2)
37         .map(|chunk| hex_to_word(chunk[1]) + (hex_to_word(chunk[0]) << 4))
38         .collect()
39 }
40