aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/codecs/static/common.h
blob: 84b0349d82b3776bde77e8d8613b914bcdd6310f (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; 
    } 
 
}