pg_async
|
There are two types of formats for data on-the-wire with PostgreSQL: text and binary. The text format is more universal, but the binary format is more compact and sometimes closer to the native client data formats.
Query results in simple query mode are always in text format.
In extended query mode the resultset can contain fields in text and in binary formats. When a request is prepared pg_async specifies data formats for each of the fields. A PostgreSQL type oid is determined by a tip::db::pg::io::traits::cpppg_data_mapping specialization for a type. A binary format for a field will be requested if the presence of a binary parser was explicitly specified. (tip::db::pg::io::traits::register_binary_parser )
protocol_parser
ConceptA protocol parser is a functor that gets an lvalue reference to a value in constructor and defines a template operator() that takes two iterators to a char buffer (begin and end iterators) and uses that data range to parse the value. If the parse was a success return the new position of input iterator. If it fails, returns the starting position of the input iterator. It must define a value_type.
Protocol parsers are used by the result set to extract values from data row buffers.
To support parsing of a data type from input buffer a structure conforming to protocol_parser
concept must be implemented. It can be either a specialization of tip::db::pg::io::protocol_parser or any other structure. In the latter case tip::db::pg::io::protocol_io_traits must be specialized for the type using the parser class as a typedef for parser_type
.
A text parser for a data type is mandatory, binary parser is optional. To make pg_async request the data type in a binary format, the PostgreSQL type oid must be registered as having a binary parser.
Adding text data format parser:
Adding a binary data parser:
When there is no specialization of a protocol_formatter for a type, default implementation based on standard C++ iostreams is used. Protocol data format is text in this case.
protocol_formatter
ConceptA protocol_fomatter
is a functor that gets an rvalue reference to data that needs to be output and defines an operator() that takes a reference to a data buffer (std::vector<byte>
) for output.
Protocol formatters are used by query to write parameters sent to PostgreSQL server.
To support formatting of a data type to send data to PostgreSQL server a structure conforming to protocol_formatter
concept must be implemented. It can be either a specialization of tip::db::pg::io::protocol_formatter or any other structure. In the latter case tip::db::pg::io::protocol_io_traits must be specialized for the type using the formatter class as a typedef for formatter_type
.
A text formatter for a data type is mandatory, binary formaater is optional.
Adding text data format parser:
Adding a binary data parser: