1#ifndef ZEROCONF_UTIL_HPP
2#define ZEROCONF_UTIL_HPP
16#define thread_local __declspec(thread)
22class membuf :
public std::streambuf {
24 membuf(
const unsigned char* base,
int size) {
25 auto p =
reinterpret_cast<char*
>(
const_cast<unsigned char*
>(base));
30 virtual pos_type seekoff(off_type offset, std::ios_base::seekdir,
31 std::ios_base::openmode mode)
override {
32 if (offset == 0 && mode == std::ios_base::in)
33 return pos_type(gptr() - eback());
41enum class LogLevel { Error, Warning };
43typedef void (*LogCallback)(LogLevel,
const std::string&);
45static thread_local LogCallback g_logcb =
nullptr;
47inline void Error(
const std::string& message) {
48 if (g_logcb !=
nullptr) g_logcb(LogLevel::Error, message);
51inline void Warning(
const std::string& message) {
52 if (g_logcb !=
nullptr) g_logcb(LogLevel::Warning, message);
55inline void SetLogCallback(LogCallback logcb) { g_logcb = logcb; }