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 {
31 return static_cast<std::uint64_t>(v);
32}
33
34std::string ToString(UserId v);
35
36template <class Char>
37std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>& os, UserId v) {
38 return os << ToUInt64(v);
39}
40
41// Optimized output for LogHelper
42logging::LogHelper& operator<<(logging::LogHelper& os, UserId v);
43
44} // namespace server::auth
45
46USERVER_NAMESPACE_END