blob: dec4046a21d934e511645d0d671de2db342d2635 (
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;
}
}
|