|
| 1 | +// Protocol Buffers - Google's data interchange format |
| 2 | +// Copyright 2025 Google LLC. All rights reserved. |
| 3 | +// |
| 4 | +// Use of this source code is governed by a BSD-style |
| 5 | +// license that can be found in the LICENSE file or at |
| 6 | +// https://developers.google.com/open-source/licenses/bsd |
| 7 | + |
| 8 | +#ifndef GOOGLE_PROTOBUF_HPB_OPTIONS_H__ |
| 9 | +#define GOOGLE_PROTOBUF_HPB_OPTIONS_H__ |
| 10 | + |
| 11 | +#include "hpb/extension.h" |
| 12 | +#include "hpb/multibackend.h" |
| 13 | + |
| 14 | +namespace hpb { |
| 15 | + |
| 16 | +struct ParseOptions { |
| 17 | + // If true, the parsed proto may alias the input string instead of copying. |
| 18 | + // Aliased data could include string fields, unknown fields, and possibly |
| 19 | + // other data. |
| 20 | + // |
| 21 | + // REQUIRES: the input string outlives the resulting proto. |
| 22 | + bool alias_string = false; |
| 23 | + |
| 24 | +#if HPB_INTERNAL_BACKEND == HPB_INTERNAL_BACKEND_UPB |
| 25 | + // For the upb backend, the user can determine which extension registry |
| 26 | + // they wish to use. Unless there are compelling reasons to do otherwise, |
| 27 | + // we recommend using the generated registry, which uses linker arrays |
| 28 | + // and intelligently performs tree shaking when possible. |
| 29 | + const ExtensionRegistry& extension_registry = |
| 30 | + ExtensionRegistry::generated_registry(); |
| 31 | +#endif |
| 32 | +}; |
| 33 | + |
| 34 | +inline ParseOptions ParseOptionsDefault() { return ParseOptions(); } |
| 35 | + |
| 36 | +#if HPB_INTERNAL_BACKEND == HPB_INTERNAL_BACKEND_UPB |
| 37 | +// The empty registry is provided here as a convenience for extant users. |
| 38 | +// Prefer the generated registry. |
| 39 | +inline ParseOptions ParseOptionsWithEmptyRegistry() { |
| 40 | + ParseOptions options{ |
| 41 | + .alias_string = false, |
| 42 | + .extension_registry = ExtensionRegistry::empty_registry(), |
| 43 | + }; |
| 44 | + return options; |
| 45 | +} |
| 46 | +#endif |
| 47 | + |
| 48 | +} // namespace hpb |
| 49 | + |
| 50 | +#endif // GOOGLE_PROTOBUF_HPB_OPTIONS_H__ |
0 commit comments