/src/serenity/AK/ByteReader.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/StdLibExtraDetails.h> |
10 | | #include <AK/Types.h> |
11 | | |
12 | | namespace AK { |
13 | | |
14 | | struct ByteReader { |
15 | | template<typename T> |
16 | | requires(IsTriviallyCopyable<T>) static void store(u8* addr, T value) |
17 | 308 | { |
18 | 308 | __builtin_memcpy(addr, &value, sizeof(T)); |
19 | 308 | } |
20 | | template<typename T> |
21 | | requires(IsTriviallyConstructible<T>) static void load(u8 const* addr, T& value) |
22 | 5.12M | { |
23 | 5.12M | __builtin_memcpy(&value, addr, sizeof(T)); |
24 | 5.12M | } void AK::ByteReader::load<unsigned int>(unsigned char const*, unsigned int&) requires IsTriviallyConstructible<unsigned int> Line | Count | Source | 22 | 2.62M | { | 23 | 2.62M | __builtin_memcpy(&value, addr, sizeof(T)); | 24 | 2.62M | } |
Unexecuted instantiation: void AK::ByteReader::load<unsigned short>(unsigned char const*, unsigned short&) requires IsTriviallyConstructible<unsigned short> void AK::ByteReader::load<unsigned long>(unsigned char const*, unsigned long&) requires IsTriviallyConstructible<unsigned long> Line | Count | Source | 22 | 2.50M | { | 23 | 2.50M | __builtin_memcpy(&value, addr, sizeof(T)); | 24 | 2.50M | } |
Unexecuted instantiation: void AK::ByteReader::load<signed char __vector(8)>(unsigned char const*, signed char __vector(8)&) requires IsTriviallyConstructible<signed char __vector(8)> Unexecuted instantiation: void AK::ByteReader::load<unsigned char __vector(8)>(unsigned char const*, unsigned char __vector(8)&) requires IsTriviallyConstructible<unsigned char __vector(8)> Unexecuted instantiation: void AK::ByteReader::load<short __vector(4)>(unsigned char const*, short __vector(4)&) requires IsTriviallyConstructible<short __vector(4)> Unexecuted instantiation: void AK::ByteReader::load<unsigned short __vector(4)>(unsigned char const*, unsigned short __vector(4)&) requires IsTriviallyConstructible<unsigned short __vector(4)> Unexecuted instantiation: void AK::ByteReader::load<int __vector(2)>(unsigned char const*, int __vector(2)&) requires IsTriviallyConstructible<int __vector(2)> Unexecuted instantiation: void AK::ByteReader::load<unsigned int __vector(2)>(unsigned char const*, unsigned int __vector(2)&) requires IsTriviallyConstructible<unsigned int __vector(2)> |
25 | | |
26 | | template<typename T> |
27 | | static T* load_pointer(u8 const* address) |
28 | | { |
29 | | FlatPtr value; |
30 | | load<FlatPtr>(address, value); |
31 | | return reinterpret_cast<T*>(value); |
32 | | } |
33 | | |
34 | | static u16 load16(u8 const* address) |
35 | 0 | { |
36 | 0 | u16 value; |
37 | 0 | load(address, value); |
38 | 0 | return value; |
39 | 0 | } |
40 | | |
41 | | static u32 load32(u8 const* address) |
42 | 2.62M | { |
43 | 2.62M | u32 value; |
44 | 2.62M | load(address, value); |
45 | 2.62M | return value; |
46 | 2.62M | } |
47 | | |
48 | | static u64 load64(u8 const* address) |
49 | 2.50M | { |
50 | 2.50M | u64 value; |
51 | 2.50M | load(address, value); |
52 | 2.50M | return value; |
53 | 2.50M | } |
54 | | }; |
55 | | |
56 | | } |
57 | | |
58 | | #if USING_AK_GLOBALLY |
59 | | using AK::ByteReader; |
60 | | #endif |