bt_common/company_id.rs
1// Copyright 2023 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/// A Bluetooth Company ID, which is assigned by the Bluetotoh SIG.
6/// Company identifiers are unique numbers assigned by the Bluetooth SIG to
7/// member companies requesting one. Referenced in the Bluetooth Core Spec in
8/// many commands and formats. See the Assigned Number Document for a reference.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10pub struct CompanyId(u16);
11
12impl CompanyId {
13 pub fn to_le_bytes(&self) -> [u8; 2] {
14 self.0.to_le_bytes()
15 }
16}
17
18impl From<u16> for CompanyId {
19 fn from(value: u16) -> Self {
20 Self(value)
21 }
22}
23
24impl From<CompanyId> for u16 {
25 fn from(value: CompanyId) -> Self {
26 value.0
27 }
28}
29
30impl core::fmt::Display for CompanyId {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 write!(f, "Company (ID {:02x})", self.0)
33 }
34}