// Copyright 2021, Beeri 15. All rights reserved. // Author: Roman Gershman (romange@gmail.com) // #pragma once #include #include #include #include namespace dfly { class RespExpr { public: using Buffer = absl::Span; enum Type : uint8_t { STRING, ARRAY, INT64, NIL, NIL_ARRAY, ERROR }; using Vec = std::vector; Type type; bool has_support; // whether pointers in this item are supported by external storage. std::variant u; RespExpr(Type t = NIL) : type(t), has_support(false) { } static Buffer buffer(std::string* s) { return Buffer{reinterpret_cast(s->data()), s->size()}; } Buffer GetBuf() const { return std::get(u); } static const char* TypeName(Type t); }; using RespVec = RespExpr::Vec; using RespSpan = absl::Span; inline std::string_view ToSV(const absl::Span& s) { return std::string_view{reinterpret_cast(s.data()), s.size()}; } } // namespace dfly namespace std { ostream& operator<<(ostream& os, const dfly::RespExpr& e); ostream& operator<<(ostream& os, dfly::RespSpan rspan); } // namespace std