MongoDB C++ Driver current
Loading...
Searching...
No Matches
validate.hpp
1// Copyright 2015 MongoDB Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <cstdint>
18#include <memory>
19
20#include <bsoncxx/document/view.hpp>
21#include <bsoncxx/stdx/optional.hpp>
22
23#include <bsoncxx/config/prelude.hpp>
24
25namespace bsoncxx {
26inline namespace v_noabi {
27class validator;
28
43BSONCXX_API stdx::optional<document::view> BSONCXX_CALL validate(const std::uint8_t* data,
44 std::size_t length);
45
66BSONCXX_API stdx::optional<document::view> BSONCXX_CALL
67validate(const std::uint8_t* data,
68 std::size_t length,
69 const validator& validator,
70 std::size_t* invalid_offset = nullptr);
75class BSONCXX_API validator {
76 public:
81
86
93 void check_utf8(bool check_utf8);
94
100 bool check_utf8() const;
101
110 void check_utf8_allow_null(bool check_utf8_allow_null);
111
120
127 void check_dollar_keys(bool check_dollar_keys);
128
135 bool check_dollar_keys() const;
136
143 void check_dot_keys(bool check_dot_keys);
144
151 bool check_dot_keys() const;
152
153 private:
154 struct BSONCXX_PRIVATE impl;
155 std::unique_ptr<impl> _impl;
156};
157
158} // namespace v_noabi
159} // namespace bsoncxx
160
161#include <bsoncxx/config/postlude.hpp>
A validator is used to enable or disable specific checks that can be performed during BSON validation...
Definition validate.hpp:75
bool check_dollar_keys() const
Getter for the current check_dollar_keys value of the underlying validator.
validator()
Constructs a validator.
void check_dot_keys(bool check_dot_keys)
Verifies that document keys do not contain any '.
~validator()
Destructs a validator.
bool check_dot_keys() const
Getter for the current check_dot_keys value of the underlying validator.
void check_utf8_allow_null(bool check_utf8_allow_null)
Verify that all keys and string values are valid UTF-8, but allow null bytes.
void check_utf8(bool check_utf8)
Verify that all keys and string values are valid UTF-8.
bool check_utf8_allow_null() const
Getter for the current check_utf8_allow_null value of the underlying validator.
void check_dollar_keys(bool check_dollar_keys)
Verifies that document keys are not preceeded with '$'.
bool check_utf8() const
Getter for the current check_utf8 value of the underlying validator.
stdx::optional< document::view > validate(const std::uint8_t *data, std::size_t length)
Validates a BSON document.
The top-level namespace for bsoncxx library entities.
Definition element.hpp:24