blob: 588975b8de4aad822e76f6078fb0d9f5bc3b296c (
plain) (
blame)
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
|
#pragma once
#include <util/string/hex.h>
#include <util/digest/city.h>
#include <util/system/byteorder.h>
namespace NCodecs {
template <class T>
ui64 DataSignature(const T& t) {
static_assert(!std::is_scalar<T>::value, "no scalars");
return CityHash64(t.data(), t.size());
}
template <class T>
TString HexWriteScalar(T t) {
static_assert(std::is_scalar<T>::value, "scalars only");
t = LittleToBig(t);
TString res = HexEncode(&t, sizeof(t));
res.to_lower();
return res;
}
template <class T>
T HexReadScalar(TStringBuf s) {
static_assert(std::is_scalar<T>::value, "scalars only");
T t = 0;
HexDecode(s.data(), Min(s.size(), sizeof(T)), &t);
t = BigToLittle(t);
return t;
}
}
|