userver: ugrpc::FieldMask Class Reference
Loading...
Searching...
No Matches
ugrpc::FieldMask Class Reference

#include <userver/ugrpc/field_mask.hpp>

Detailed Description

Utilities to process the field masks. Respects Google's AIP-161: https://google.aip.dev/161.

  1. An empty mask is treated as a mask with all fields.
  2. Map masks (i.e. reviews and reviews.smith for map<string, string> reviews).
  3. Wildcard masks for repeated and map fields (i.e. authors, authors.*, authors.*.name).
  4. Backticks (`) are separation charaters for problematic keys and may not appear in paths.

Definition at line 35 of file field_mask.hpp.

Classes

class  BadPathError
 

Public Types

enum class  Encoding {
  kCommaSeparated = 0 ,
  kWebSafeBase64 = 1
}
 

Public Member Functions

 FieldMask ()=default
 Construct an empty field-mask.
 
 FieldMask (FieldMask &&)=default
 
 FieldMask (const FieldMask &)=default
 
FieldMaskoperator= (FieldMask &other)=default
 
FieldMaskoperator= (FieldMask &&other)=default
 
 FieldMask (const google::protobuf::FieldMask &field_mask)
 Constructs the field-mask from a raw gRPC field-mask.
 
 FieldMask (std::string_view string, Encoding encoding)
 Constructs the field-mask from its string representation.
 
std::string ToString () const
 Constructs a human-readable string representation of the field-mask.
 
std::string ToWebSafeBase64 () const
 Constructs a string representation of the field-mask suitable to transfer over the Internet.
 
void AddPath (std::string_view path)
 Adds a dot-separated path to the field mask. Backtick (`) is treated as a separation character according to AIP-161 and may not appear in the path.
 
void CheckValidity (const google::protobuf::Descriptor *descriptor) const
 Check if the field mask is valid for this message.
 
bool IsPathFullyIn (std::string_view path) const
 Does this field-mask fully contain the given path.
 
bool IsPathPartiallyIn (std::string_view path) const
 Does this field-mask contain the given path or any of its child paths.
 
void Trim (google::protobuf::Message &message) const
 Remove all fields not present in the field-mask from the message. The mask must be valid for this to work. Use IsValid to check.
 
void TrimNoValidate (google::protobuf::Message &message) const
 Same as Trim but does not perform pre-validation of the mask. You should not catch any errors generated by this method. Use this only if you are absolutely sure the mask is valid.
 
bool IsLeaf () const
 Checks if there are any nested masks inside this mask.
 
auto GetFieldNames () const
 Gets the names of all masked fields inside this mask. Returns an std::ranges::transform_view containing std::string_view.
 
std::vector< std::string_view > GetFieldNamesList () const
 Gets the names of all masked fields inside this mask. Returns an std::vector.
 
bool HasFieldName (std::string_view field) const
 Checks if the specified field is in the mask.
 
utils::OptionalRef< const FieldMaskGetMaskForField (std::string_view field) const
 Gets the nested mask or returns nullopt if the field is not in the mask.
 

Member Enumeration Documentation

◆ Encoding

enum class ugrpc::FieldMask::Encoding
strong

Definition at line 54 of file field_mask.hpp.

Member Function Documentation

◆ AddPath()

void ugrpc::FieldMask::AddPath ( std::string_view path)

Adds a dot-separated path to the field mask. Backtick (`) is treated as a separation character according to AIP-161 and may not appear in the path.

Exceptions
BadPathErrorif the path is malformed. In this case, the state of the field mask is undefined. You must not continue using the instance after encountering the exception.

◆ CheckValidity()

void ugrpc::FieldMask::CheckValidity ( const google::protobuf::Descriptor * descriptor) const

Check if the field mask is valid for this message.

Exceptions
BadPathErrorif the field mask contains invalid paths.

◆ GetFieldNames()

auto ugrpc::FieldMask::GetFieldNames ( ) const
inline

Gets the names of all masked fields inside this mask. Returns an std::ranges::transform_view containing std::string_view.

Definition at line 111 of file field_mask.hpp.

◆ IsPathFullyIn()

bool ugrpc::FieldMask::IsPathFullyIn ( std::string_view path) const

Does this field-mask fully contain the given path.

Exceptions
BadPathErrorif the path is malformed.

◆ IsPathPartiallyIn()

bool ugrpc::FieldMask::IsPathPartiallyIn ( std::string_view path) const

Does this field-mask contain the given path or any of its child paths.

Exceptions
BadPathErrorif the path is malformed.

◆ Trim()

void ugrpc::FieldMask::Trim ( google::protobuf::Message & message) const

Remove all fields not present in the field-mask from the message. The mask must be valid for this to work. Use IsValid to check.

Exceptions
BadPathErrorif the field mask contains invalid paths.
Warning
This causes a segmentation fault for messages that contain optional fields in protobuf versions prior to 3.13. See https://github.com/protocolbuffers/protobuf/issues/7801

◆ TrimNoValidate()

void ugrpc::FieldMask::TrimNoValidate ( google::protobuf::Message & message) const

Same as Trim but does not perform pre-validation of the mask. You should not catch any errors generated by this method. Use this only if you are absolutely sure the mask is valid.

Warning
This causes a segmentation fault for messages that contain optional fields in protobuf versions prior to 3.13. See https://github.com/protocolbuffers/protobuf/issues/7801

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