userver: userver/server/auth/user_id.hpp Source File
Loading...
Searching...
No Matches
user_id.hpp
1#pragma once
2
3#include <cstdint>
4#include <iosfwd>
5#include <string>
6#include <vector>
7
8#include <userver/formats/parse/to.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace logging {
13class LogHelper;
14}
15
16namespace server::auth {
17
18/// Type that represents a yandex uid and has all the comparison and hashing
19/// operators. It is not implicitly convertible to/from integers and provides
20/// better type safety.
21enum class UserId : std::uint64_t {};
22
23using UserIds = std::vector<UserId>;
24
25template <class Value>
26UserId Parse(const Value& v, formats::parse::To<UserId>) {
27 return UserId{v.template As<std::uint64_t>()};
28}
29
30inline std::uint64_t ToUInt64(UserId v) noexcept { return static_cast<std::uint64_t>(v); }
31
32std::string ToString(UserId v);
33
34template <class Char>
35std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>& os, UserId v) {
36 return os << ToUInt64(v);
37}
38
39// Optimized output for LogHelper
40logging::LogHelper& operator<<(logging::LogHelper& os, UserId v);
41
42} // namespace server::auth
43
44USERVER_NAMESPACE_END