Debian Codegraph @

node/@bufbuild/protobuf/dist/commonjs/fields.js

raw
1 "use strict";
2 // Copyright 2021-2026 Buf Technologies, Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 Object.defineProperty(exports, "__esModule", { value: true });
16 exports.isFieldSet = isFieldSet;
17 exports.clearField = clearField;
18 const unsafe_js_1 = require("./reflect/unsafe.js");
19 /**
20 * Returns true if the field is set.
21 *
22 * - Scalar and enum fields with implicit presence (proto3):
23 * Set if not a zero value.
24 *
25 * - Scalar and enum fields with explicit presence (proto2, oneof):
26 * Set if a value was set when creating or parsing the message, or when a
27 * value was assigned to the field's property.
28 *
29 * - Message fields:
30 * Set if the property is not undefined.
31 *
32 * - List and map fields:
33 * Set if not empty.
34 */
35 function isFieldSet(message, field) {
36 return (field.parent.typeName == message.$typeName && (0, unsafe_js_1.unsafeIsSet)(message, field));
37 }
38 /**
39 * Resets the field, so that isFieldSet() will return false.
40 */
41 function clearField(message, field) {
42 if (field.parent.typeName == message.$typeName) {
43 (0, unsafe_js_1.unsafeClear)(message, field);
44 }
45 }