/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
library/cpp/int128/ut/int128_ut_helpers.cpp
56 строк
2 KB
qkrorlqr
Initial NBS OpenSource export
28 апр 2023, 21:54
28 апр 2023, 21:54
783a858
Код
Авторство
О чём код?
#include "int128_ut_helpers.h" namespace NInt128Private { #if defined(_little_endian_) std::array<ui8, 16> GetAsArray(const ui128 value) { std::array<ui8, 16> result; const ui64 low = GetLow(value); const ui64 high = GetHigh(value); MemCopy(result.data(), reinterpret_cast<const ui8*>(&low), sizeof(low)); MemCopy(result.data() + sizeof(low), reinterpret_cast<const ui8*>(&high), sizeof(high)); return result; } std::array<ui8, 16> GetAsArray(const i128 value) { std::array<ui8, 16> result; const ui64 low = GetLow(value); const ui64 high = GetHigh(value); MemCopy(result.data(), reinterpret_cast<const ui8*>(&low), sizeof(low)); MemCopy(result.data() + sizeof(low), reinterpret_cast<const ui8*>(&high), sizeof(high)); return result; } #elif defined(_big_endian_) std::array<ui8, 16> GetAsArray(const i128 value) { std::array<ui8, 16> result; const ui64 low = GetLow(value); const ui64 high = GetHigh(value); MemCopy(result.data(), reinterpret_cast<const ui8*>(&high), sizeof(high)); MemCopy(result.data() + sizeof(high), reinterpret_cast<const ui8*>(&low), sizeof(low)); return result; } std::array<ui8, 16> GetAsArray(const ui128 value) { std::array<ui8, 16> result; const ui64 low = GetLow(value); const ui64 high = GetHigh(value); MemCopy(result.data(), reinterpret_cast<const ui8*>(&high), sizeof(high)); MemCopy(result.data() + sizeof(high), reinterpret_cast<const ui8*>(&low), sizeof(low)); return result; } #endif #if defined(Y_HAVE_INT128) std::array<ui8, 16> GetAsArray(const unsigned __int128 value) { std::array<ui8, 16> result; MemCopy(result.data(), reinterpret_cast<const ui8*>(&value), sizeof(value)); return result; } std::array<ui8, 16> GetAsArray(const signed __int128 value) { std::array<ui8, 16> result; MemCopy(result.data(), reinterpret_cast<const ui8*>(&value), sizeof(value)); return result; } #endif }