OZO 「お象」
Boost.Asio and libpq based asynchronous PostgreSQL unofficial header-only C++17 client library.
ozo::recv_impl< Out, typename > Struct Template Reference

#include <ozo/io/recv.h>

Description

template<typename Out, typename = std::void_t<>>
struct ozo::recv_impl< Out, typename >

Defines how to receive an object from an input stream.

This functor is used to deserialize object as query result.

Template Parameters
Out— type of an object to apply to
<anonymous>— SFINAE-based overloading parameter.

The default implementation uses ozo::read function to deserialize simple objects like integers or strings. For the #DynamicSize objects method resize() will be called. So if your special implementation of #DynamicSize type object does not have such method, you need to specialize this template for the type to resize it to fit the incoming size (see the example below). For the #StaticSize objects size check will be made. In case of incoming size does not equal to value returned by ozo::size_of() for the object — std::range_error will be thrown.

To deserialize complex types like Array or Composite special internal implementations are used.

Note
This functor requires type definition via OZO_PG_BIND_TYPE or OZO_PG_DEFINE_CUSTOM_TYPE.

Customization point

This template is a customization point for specializing deserialization for user defined types if it can not be obtained via the library. Typically user does not need it.

Example

File MyString.h

namespace NSdemo {
// Out string-like class with our own code-style
class MyString {
public:
//...
SizeType Size() const;
char* Buffer();
void Resize(size_type size);
//...
};
} // namespace NSdemo

File MyStringOzoAdaptor.h

#include <A/MyString.h>
namespace NSdemo {
// E.g. size and data can be adapted via the free functions
// in same namespace
inline auto size(const MyString& s) { return s.Size(); }
inline auto data(const MyString& s) { return s.Buffer(); }
} // namespace NSdemo
// We want to use it for the 'text' type
OZO_PG_DEFINE_TYPE_AND_ARRAY(demo::my_string, "text", TEXTOID, TEXTARRAYOID, dynamic_size)
namespace ozo {
// Since we do not have resize() method and can not implement it
// we need to specialize ozo::recv_impl template to allocate place
// for the data.
template <>
struct recv_impl<NSdemo::MyString> {
template <typename OidMap>
static istream& apply(istream& in, size_type size, const OidMap&, NSdemo::MyString& out) {
// Allocating space for info
out.Resize(size);
// Reading raw info from the input stream
return read(in, out);
}
};
} // namespace ozo

Static Public Member Functions

template<typename OidMap >
static istream & apply (istream &in, size_type size, const OidMap &, Out &out)
 Implementation of deserialization object from a stream. More...
 

Member Function Documentation

◆ apply()

template<typename Out , typename = std::void_t<>>
template<typename OidMap >
static istream& ozo::recv_impl< Out, typename >::apply ( istream &  in,
size_type  size,
const OidMap &  ,
Out &  out 
)
static

Implementation of deserialization object from a stream.

Parameters
in— input stream
size— size of incoming data
OidMap— #OidMap to get oid for custom types
out— object to deserialize
Returns
ostream& — input stream

References ozo::error::bad_object_size, and ozo::size_of().

ozo::recv_impl::apply
static istream & apply(istream &in, size_type size, const OidMap &, Out &out)
Implementation of deserialization object from a stream.
Definition: recv.h:89
ozo::OidMap
constexpr auto OidMap
Map of C++ types to corresponding PostgreSQL types OIDs.
Definition: type_traits.h:534
ozo::size_type
std::int32_t size_type
PostgreSQL size type.
Definition: type_traits.h:265
OZO_PG_DEFINE_TYPE_AND_ARRAY
#define OZO_PG_DEFINE_TYPE_AND_ARRAY(Type, Name, Oid, ArrayOid, Size)
[[DEPRECATED]] Helper macro to define type mapping
Definition: type_traits.h:415