Couchbase C++ SDK 1.0.2 (rev. 51f4775)
Loading...
Searching...
No Matches
get_replica_result Class Reference

Represents result of collection::get_any_replica operations, also returned by collection::get_all_replicas. More...

#include <couchbase/get_replica_result.hxx>

Inheritance diagram for get_replica_result:
Inheritance graph

Public Member Functions

 get_replica_result ()=default
 
 get_replica_result (couchbase::cas cas, bool is_replica, codec::encoded_value value)
 Constructs result for get_any_replica operation, or an entry for get_all_replicas operation.
 
auto is_replica () const -> bool
 
template<typename Transcoder , std::enable_if_t< codec::is_transcoder_v< Transcoder >, bool > = true>
auto content_as () const -> typename Transcoder::document_type
 Decodes content of the document using given transcoder.
 
template<typename Document , typename Transcoder = codec::default_json_transcoder, std::enable_if_t<!codec::is_transcoder_v< Document >, bool > = true, std::enable_if_t< codec::is_transcoder_v< Transcoder >, bool > = true>
auto content_as () const -> Document
 Decodes content of the document using given codec.
 
- Public Member Functions inherited from result
 result ()=default
 
 result (couchbase::cas cas)
 
auto cas () const -> couchbase::cas
 

Detailed Description

Represents result of collection::get_any_replica operations, also returned by collection::get_all_replicas.

Since
1.0.0
Committed
Generally available API and should be preferred in production

Constructor & Destructor Documentation

◆ get_replica_result() [1/2]

get_replica_result ( )
default
Since
1.0.0
Internal
Internal interface

◆ get_replica_result() [2/2]

get_replica_result ( couchbase::cas cas,
bool is_replica,
codec::encoded_value value )
inline

Constructs result for get_any_replica operation, or an entry for get_all_replicas operation.

Parameters
cas
is_replicatrue if the document originates from replica node
valueraw document contents along with flags describing its structure
Since
1.0.0
Committed
Generally available API and should be preferred in production

Member Function Documentation

◆ content_as() [1/2]

template<typename Document , typename Transcoder = codec::default_json_transcoder, std::enable_if_t<!codec::is_transcoder_v< Document >, bool > = true, std::enable_if_t< codec::is_transcoder_v< Transcoder >, bool > = true>
auto content_as ( ) const -> Document
inlinenodiscard

Decodes content of the document using given codec.

Template Parameters
Documentcustom type that Transcoder returns
Transcodertype that has static function decode that takes codec::encoded_value and returns Document
Returns
decoded document content
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ content_as() [2/2]

template<typename Transcoder , std::enable_if_t< codec::is_transcoder_v< Transcoder >, bool > = true>
auto content_as ( ) const -> typename Transcoder::document_type
inlinenodiscard

Decodes content of the document using given transcoder.

Template Parameters
Transcodertype that has static function decode that takes codec::encoded_value and returns Transcoder::document_type
Returns
decoded document content
Get flags and value as they are stored in the result
Here is an example of custom transcoder, that just extracts value and flags as they are stored in the result.
struct smuggling_transcoder {
using document_type = std::pair<std::vector<std::byte>, std::uint32_t>;
static auto decode(const couchbase::codec::encoded_value& encoded) -> document_type
{
return { encoded.data, encoded.flags };
}
};
template<>
struct couchbase::codec::is_transcoder<smuggling_transcoder> : public std::true_type {
};
Usage
auto [data, flags] = result.content_as<smuggling_transcoder>();
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ is_replica()

auto is_replica ( ) const -> bool
inlinenodiscard
Returns
true if the document came from replica, false for active node.
Since
1.0.0
Committed
Generally available API and should be preferred in production

The documentation for this class was generated from the following file: