Decentralised Art Server
High-performance C++ backend that exposes HTML interface and a secure REST API for managing Performative Transactions entities
 
Loading...
Searching...
No Matches
byte_order.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6namespace dcn::crypto
7{
8 inline std::uint64_t readUint64BE(const std::uint8_t * ptr)
9 {
10 std::uint64_t out = 0;
11 for(std::size_t i = 0; i < sizeof(std::uint64_t); ++i)
12 {
13 out = (out << 8) | static_cast<std::uint64_t>(ptr[i]);
14 }
15
16 return out;
17 }
18
19 inline void writeUint64BE(std::uint8_t * ptr, std::uint64_t value)
20 {
21 for(std::size_t i = 0; i < sizeof(std::uint64_t); ++i)
22 {
23 const std::size_t shift = (sizeof(std::uint64_t) - 1 - i) * 8;
24 ptr[i] = static_cast<std::uint8_t>((value >> shift) & 0xFFu);
25 }
26 }
27
28 inline void writeUint32BE(std::uint8_t * ptr, std::uint32_t value)
29 {
30 for(std::size_t i = 0; i < sizeof(std::uint32_t); ++i)
31 {
32 const std::size_t shift = (sizeof(std::uint32_t) - 1 - i) * 8;
33 ptr[i] = static_cast<std::uint8_t>((value >> shift) & 0xFFu);
34 }
35 }
36}
Definition byte_order.hpp:7
void writeUint64BE(std::uint8_t *ptr, std::uint64_t value)
Definition byte_order.hpp:19
void writeUint32BE(std::uint8_t *ptr, std::uint32_t value)
Definition byte_order.hpp:28
std::uint64_t readUint64BE(const std::uint8_t *ptr)
Definition byte_order.hpp:8