1use std::ops::Deref;
2
3use skia_bindings::SkFourByteTag;
4
5use crate::prelude::*;
6
7#[derive(Copy, Clone, PartialEq, Eq, Hash, Default, Debug)]
8#[repr(transparent)]
9pub struct FourByteTag(SkFourByteTag);
10
11native_transmutable!(SkFourByteTag, FourByteTag, four_byte_tag_layout);
12
13impl Deref for FourByteTag {
14 type Target = u32;
15 fn deref(&self) -> &Self::Target {
16 &self.0
17 }
18}
19
20impl From<(char, char, char, char)> for FourByteTag {
21 fn from((a: char, b: char, c: char, d: char): (char, char, char, char)) -> Self {
22 Self::from_chars(a, b, c, d)
23 }
24}
25
26impl From<u32> for FourByteTag {
27 fn from(v: u32) -> Self {
28 Self::new(v)
29 }
30}
31
32impl FourByteTag {
33 pub const fn from_chars(a: char, b: char, c: char, d: char) -> Self {
34 Self(
35 ((a as u8 as u32) << 24)
36 | ((b as u8 as u32) << 16)
37 | ((c as u8 as u32) << 8)
38 | (d as u8 as u32),
39 )
40 }
41
42 pub const fn new(v: u32) -> Self {
43 Self(v)
44 }
45
46 pub fn a(self) -> u8 {
47 (self.into_native() >> 24) as u8
48 }
49
50 pub fn b(self) -> u8 {
51 (self.into_native() >> 16) as u8
52 }
53
54 pub fn c(self) -> u8 {
55 (self.into_native() >> 8) as u8
56 }
57
58 pub fn d(self) -> u8 {
59 self.into_native() as u8
60 }
61}
62