1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
//! Common Bluetooth Mesh Objects/Structures.
use crate::bytes::ToFromBytesEndian;
use core::convert::{TryFrom, TryInto};
use core::fmt::{Display, Error, Formatter};
use core::str::FromStr;
use core::time;
use std::ops::{Add, Sub};

#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct IVI(pub bool);
impl From<IVI> for bool {
    #[must_use]
    fn from(i: IVI) -> Self {
        i.0
    }
}
impl From<bool> for IVI {
    #[must_use]
    fn from(b: bool) -> Self {
        IVI(b)
    }
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
pub struct CTL(pub bool);
impl From<CTL> for bool {
    #[must_use]
    fn from(c: CTL) -> Self {
        c.0
    }
}
impl From<bool> for CTL {
    #[must_use]
    fn from(b: bool) -> Self {
        CTL(b)
    }
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
pub struct KeyRefreshFlag(pub bool);
impl From<KeyRefreshFlag> for bool {
    #[must_use]
    fn from(c: KeyRefreshFlag) -> Self {
        c.0
    }
}
impl From<bool> for KeyRefreshFlag {
    #[must_use]
    fn from(b: bool) -> Self {
        KeyRefreshFlag(b)
    }
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct IVUpdateFlag(pub bool);
impl From<IVUpdateFlag> for bool {
    #[must_use]
    fn from(c: IVUpdateFlag) -> Self {
        c.0
    }
}
impl From<bool> for IVUpdateFlag {
    #[must_use]
    fn from(b: bool) -> Self {
        IVUpdateFlag(b)
    }
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct TTL(u8);

const TTL_MASK: u8 = 127;
const TTL_MAX: u8 = 0xFF;
impl TTL {
    #[must_use]
    pub fn new(v: u8) -> TTL {
        assert!(
            v <= TTL_MASK,
            "TTL {} is bigger than max TTL {}",
            v,
            TTL_MASK
        );
        TTL(v)
    }
    /// Returns u8 with 7 lower bits being TTL and the 1 highest bit being a flag
    #[must_use]
    pub const fn with_flag(self, flag: bool) -> u8 {
        self.0 | ((flag as u8) << 7)
    }
    /// returns 7 bit TTL + 1 bit bool flag from 8bit uint.
    #[must_use]
    pub const fn new_with_flag(v: u8) -> (TTL, bool) {
        (TTL(v & TTL_MASK), v & !TTL_MASK != 0)
    }
    /// Creates a 7 bit TTL by masking out the 8th bit from a u8
    #[must_use]
    pub const fn from_masked_u8(v: u8) -> TTL {
        TTL(v & TTL_MASK)
    }
    #[must_use]
    pub fn should_relay(self) -> bool {
        match self.0 {
            2..=127 => true,
            _ => false,
        }
    }
}
#[derive(Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash, Debug)]
pub struct TTLConversationError(());
impl TryFrom<u8> for TTL {
    type Error = TTLConversationError;

    fn try_from(value: u8) -> Result<Self, Self::Error> {
        if value > TTL_MAX {
            Err(TTLConversationError(()))
        } else {
            Ok(TTL(value))
        }
    }
}
impl From<TTL> for u8 {
    fn from(ttl: TTL) -> Self {
        ttl.0
    }
}

impl Display for TTL {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
        write!(f, "TTL({})", self.0)
    }
}
/// 7-bit `NID` (different than `NetworkID`!!)
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct NID(u8);

impl Display for NID {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
        write!(f, "{}", self.0)
    }
}
const NID_MASK: u8 = 127;

impl NID {
    #[must_use]
    pub fn new(v: u8) -> NID {
        assert!(
            v <= NID_MASK,
            "NID {} is bigger than max NID {}",
            v,
            NID_MASK
        );
        NID(v)
    }
    #[must_use]
    pub const fn with_flag(self, flag: bool) -> u8 {
        self.0 | ((flag as u8) << 7)
    }
    /// Creates a 7 bit NID by masking out the 8th bit from a u8
    #[must_use]
    pub const fn from_masked_u8(v: u8) -> NID {
        NID(v & 0x7F)
    }
    /// returns 7 bit NID + 1 bit bool flag from 8bit uint.
    #[must_use]
    pub const fn new_with_flag(v: u8) -> (NID, bool) {
        (NID(v & 0x7F), v & 0x80 != 0)
    }
}
impl From<NID> for u8 {
    fn from(n: NID) -> Self {
        n.0
    }
}
/// 24-bit Unsigned Integer. Commonly used for other 24-bit Unsigned types (`IVIndex`, `SequenceNumber`, Etc)
#[derive(Default, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct U24(u32);
const U24_MAX: u32 = (1_u32 << 24) - 1; // 2**24 - 1
impl Display for U24 {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
        write!(f, "U24({})", self.0)
    }
}
impl U24 {
    #[must_use]
    pub fn new(v: u32) -> U24 {
        if v > U24_MAX {
            panic!("number {} is bigger than max U24 {}", v, U24_MAX);
        } else {
            U24(v)
        }
    }
    /// Creates a U24 by masking the 4th byte of 'v'
    #[must_use]
    pub const fn new_masked(v: u32) -> U24 {
        U24(v & U24_MAX)
    }
    #[must_use]
    pub const fn value(self) -> u32 {
        self.0
    }
    #[must_use]
    pub const fn max_value() -> U24 {
        U24(U24_MAX)
    }
}
impl core::ops::Add for U24 {
    type Output = U24;

    fn add(self, rhs: Self) -> Self::Output {
        U24::new_masked(self.0 + rhs.0)
    }
}
impl core::ops::Sub for U24 {
    type Output = U24;

    fn sub(self, rhs: Self) -> Self::Output {
        U24::new_masked(self.0 - rhs.0)
    }
}
#[derive(Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash, Debug)]
pub struct U24ConversionError(());
impl TryFrom<u32> for U24 {
    type Error = U24ConversionError;

    fn try_from(value: u32) -> Result<Self, Self::Error> {
        if value > U24_MAX {
            Err(U24ConversionError(()))
        } else {
            Ok(U24(value))
        }
    }
}
impl From<u16> for U24 {
    fn from(v: u16) -> Self {
        U24(v.into())
    }
}
impl FromStr for U24 {
    type Err = U24ConversionError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let v = u32::from_str(s).map_err(|_| U24ConversionError(()))?;
        v.try_into()
    }
}
impl ToFromBytesEndian for U24 {
    type AsBytesType = [u8; 3];

    #[must_use]
    fn to_bytes_le(&self) -> Self::AsBytesType {
        let b = self.0.to_le_bytes();
        [b[0], b[1], b[2]]
    }

    #[must_use]
    fn to_bytes_be(&self) -> Self::AsBytesType {
        let b = self.0.to_be_bytes();
        [b[2], b[1], b[0]]
    }

    #[must_use]
    fn from_bytes_le(bytes: &[u8]) -> Option<Self> {
        if bytes.len() == 3 {
            Some(U24(u32::from_le_bytes([bytes[0], bytes[1], bytes[2], 0])))
        } else {
            None
        }
    }

    #[must_use]
    fn from_bytes_be(bytes: &[u8]) -> Option<Self> {
        if bytes.len() == 3 {
            Some(U24(u32::from_be_bytes([0, bytes[2], bytes[1], bytes[0]])))
        } else {
            None
        }
    }
}
impl From<U24> for u32 {
    fn from(u: U24) -> Self {
        u.0
    }
}
#[derive(Copy, Clone, Eq, Ord, PartialOrd, PartialEq, Debug, Default, Hash)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct IVIndex(pub u32);
impl IVIndex {
    pub fn ivi(&self) -> IVI {
        IVI(self.0 & 1 == 1)
    }
    pub fn next(&self) -> Option<IVIndex> {
        self.0.checked_add(1).map(IVIndex)
    }
    pub fn prev(&self) -> Option<IVIndex> {
        self.0.checked_sub(1).map(IVIndex)
    }
    /// Returns an IVIndex matching `IVI` and `IVUpdateFlag`. Will return `None` if there is no
    /// `self.next()` or `self.prev()`.
    /// # Example
    /// ```
    /// use bluetooth_mesh::mesh::{IVIndex, IVI, IVUpdateFlag};
    /// assert!(IVIndex(0).matching_flags(IVI(true), IVUpdateFlag(false)).is_none());
    /// assert!(IVIndex(u32::max_value()).matching_flags(IVI(false), IVUpdateFlag(true)).is_none());
    /// assert_eq!(IVIndex(2).matching_flags(IVI(true), IVUpdateFlag(false)), Some(IVIndex(1)));
    /// ```
    pub fn matching_flags(&self, ivi: IVI, update: IVUpdateFlag) -> Option<IVIndex> {
        if self.ivi() == ivi {
            Some(*self)
        } else {
            if bool::from(update) {
                self.next()
            } else {
                self.prev()
            }
        }
    }
}

impl Display for IVIndex {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
        write!(f, "IVIndex({})", self.0)
    }
}
impl ToFromBytesEndian for IVIndex {
    type AsBytesType = [u8; 4];

    #[must_use]
    fn to_bytes_le(&self) -> Self::AsBytesType {
        (self.0).to_bytes_le()
    }

    #[must_use]
    fn to_bytes_be(&self) -> Self::AsBytesType {
        (self.0).to_bytes_be()
    }

    #[must_use]
    fn from_bytes_le(bytes: &[u8]) -> Option<Self> {
        Some(Self(u32::from_bytes_le(bytes)?))
    }

    #[must_use]
    fn from_bytes_be(bytes: &[u8]) -> Option<Self> {
        Some(Self(u32::from_bytes_be(bytes)?))
    }
}
/// 24-bit Sequence number. Sent with each Network PDU. Each element has their own Sequence Number.
#[derive(Copy, Clone, Eq, Ord, PartialOrd, PartialEq, Debug, Default, Hash)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct SequenceNumber(pub U24);
impl SequenceNumber {
    pub fn next(&self) -> SequenceNumber {
        assert!(self.0.value() <= U24_MAX);
        SequenceNumber(U24((self.0).0 + 1))
    }
}
impl Add<SequenceNumber> for SequenceNumber {
    type Output = u32;

    fn add(self, rhs: SequenceNumber) -> Self::Output {
        u32::from(self.0 + rhs.0)
    }
}
impl Sub<SequenceNumber> for SequenceNumber {
    type Output = u32;

    fn sub(self, rhs: SequenceNumber) -> Self::Output {
        u32::from(self.0 - rhs.0)
    }
}
impl Display for SequenceNumber {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
        write!(f, "SequenceNumber({})", (self.0).value())
    }
}
impl ToFromBytesEndian for SequenceNumber {
    type AsBytesType = [u8; 3];

    #[must_use]
    fn to_bytes_le(&self) -> Self::AsBytesType {
        (self.0).to_bytes_le()
    }

    #[must_use]
    fn to_bytes_be(&self) -> Self::AsBytesType {
        (self.0).to_bytes_be()
    }

    #[must_use]
    fn from_bytes_le(bytes: &[u8]) -> Option<Self> {
        Some(SequenceNumber(U24::from_bytes_le(bytes)?))
    }

    #[must_use]
    fn from_bytes_be(bytes: &[u8]) -> Option<Self> {
        Some(SequenceNumber(U24::from_bytes_be(bytes)?))
    }
}

/// 16-bit Bluetooth Company Identifier. Companies are assigned unique Company Identifiers to
/// Bluetooth SIG members requesting them. [See here for more](https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers/)
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct CompanyID(pub u16);
impl CompanyID {
    /// Return the length in bytes of `CompanyID` (2-bytes, 16-bits)
    pub const fn byte_len() -> usize {
        2
    }
}
impl ToFromBytesEndian for CompanyID {
    type AsBytesType = [u8; 2];

    #[must_use]
    fn to_bytes_le(&self) -> Self::AsBytesType {
        (self.0).to_bytes_le()
    }

    #[must_use]
    fn to_bytes_be(&self) -> Self::AsBytesType {
        (self.0).to_bytes_be()
    }

    #[must_use]
    fn from_bytes_le(bytes: &[u8]) -> Option<Self> {
        Some(CompanyID(u16::from_bytes_le(bytes)?))
    }

    #[must_use]
    fn from_bytes_be(bytes: &[u8]) -> Option<Self> {
        Some(CompanyID(u16::from_bytes_be(bytes)?))
    }
}
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash, Ord, PartialOrd)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct ModelID(pub u16);
impl ModelID {
    pub const fn byte_len() -> usize {
        2
    }
}
impl ToFromBytesEndian for ModelID {
    type AsBytesType = [u8; 2];

    #[must_use]
    fn to_bytes_le(&self) -> Self::AsBytesType {
        (self.0).to_bytes_le()
    }

    #[must_use]
    fn to_bytes_be(&self) -> Self::AsBytesType {
        (self.0).to_bytes_be()
    }

    #[must_use]
    fn from_bytes_le(bytes: &[u8]) -> Option<Self> {
        Some(ModelID(u16::from_bytes_le(bytes)?))
    }

    #[must_use]
    fn from_bytes_be(bytes: &[u8]) -> Option<Self> {
        Some(ModelID(u16::from_bytes_be(bytes)?))
    }
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Hash)]
pub struct KeyIndexConversationError(());
const KEY_INDEX_MAX: u16 = (1 << 12) - 1;
/// 12-bit KeyIndex
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct KeyIndex(u16);
impl KeyIndex {
    /// # Panics
    /// Panics if `key > KEY_INDEX_MAX`.
    pub fn new(key_index: u16) -> Self {
        match Self::try_from(key_index) {
            Ok(i) => i,
            Err(_) => panic!("key index too high"),
        }
    }
    pub fn new_masked(key_index: u16) -> Self {
        KeyIndex(key_index & KEY_INDEX_MAX)
    }
}
impl TryFrom<u16> for KeyIndex {
    type Error = KeyIndexConversationError;

    fn try_from(value: u16) -> Result<Self, Self::Error> {
        if value > KEY_INDEX_MAX {
            Err(KeyIndexConversationError(()))
        } else {
            Ok(KeyIndex(value))
        }
    }
}
impl From<KeyIndex> for u16 {
    fn from(i: KeyIndex) -> Self {
        i.0
    }
}
/// 12-bit NetKeyIndex
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct NetKeyIndex(pub KeyIndex);
/// 12-bit AppKeyIndex
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct AppKeyIndex(pub KeyIndex);

#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct ElementIndex(pub u8);
impl ElementIndex {
    #[must_use]
    pub fn is_primary(&self) -> bool {
        self.0 == 0
    }
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct ElementCount(pub u8);
const TRANSMIT_COUNT_MAX: u8 = 0b111;
/// 3-bit Transit Count,
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct TransmitCount(u8);

impl TransmitCount {
    /// # Panics
    /// Panics if `count > COUNT_MAX`,
    pub fn new(count: u8) -> Self {
        assert!(count <= TRANSMIT_COUNT_MAX);
        Self(count)
    }
}
impl From<TransmitCount> for u8 {
    fn from(count: TransmitCount) -> Self {
        count.0
    }
}
const STEPS_MAX: u8 = (1u8 << 5) - 1;
/// 5-bit Transmit Interval Steps
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct TransmitSteps(u8);

impl TransmitSteps {
    /// # Panics
    /// Panics if `steps > STEPS_MAX`.
    pub fn new(steps: u8) -> Self {
        assert!(steps <= STEPS_MAX);
        Self(steps)
    }
    pub fn to_milliseconds(&self) -> u32 {
        (u32::from(self.0) + 1) * 50
    }
    pub fn to_duration(&self) -> time::Duration {
        time::Duration::from_millis(self.to_milliseconds().into())
    }
}

impl From<TransmitSteps> for u8 {
    fn from(steps: TransmitSteps) -> Self {
        steps.0
    }
}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Hash)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
pub struct TransmitInterval {
    pub count: TransmitCount,
    pub steps: TransmitSteps,
}
impl TransmitInterval {
    pub fn new(count: TransmitCount, steps: TransmitSteps) -> Self {
        Self { count, steps }
    }
}
impl From<TransmitInterval> for u8 {
    fn from(interval: TransmitInterval) -> Self {
        u8::from(interval.count) | (u8::from(interval.steps) << 3)
    }
}
impl From<u8> for TransmitInterval {
    fn from(b: u8) -> Self {
        Self::new(
            TransmitCount::new(b & TRANSMIT_COUNT_MAX),
            TransmitSteps::new(b >> 3),
        )
    }
}

pub fn bytes_str_to_buf<T: Default + AsMut<[u8]>>(s: &str) -> Option<T> {
    let mut out = T::default();
    let buf = out.as_mut();
    if buf.len() == 0 || buf.len() * 2 != s.len() {
        return None;
    }
    for (i, c) in s.chars().enumerate() {
        let v = u8::try_from(c.to_digit(16)?).expect("only returns [0..=15]");
        buf[i / 2] |= v << u8::try_from(((i + 1) % 2) * 4).expect("only returns 0 or 4");
    }
    Some(out)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_ttl() {
        assert!(!TTL::new(0).should_relay());
        assert!(!TTL::new(1).should_relay());
        assert!(TTL::new(2).should_relay());
        assert!(TTL::new(65).should_relay());
        assert!(TTL::new(126).should_relay());
        assert!(TTL::new(127).should_relay())
    }
    #[test]
    #[should_panic]
    fn test_ttl_out_of_range() {
        let _ = TTL::new(128);
    }
}