Files
codeql-action/node_modules/@protobuf-ts/runtime/build/commonjs/binary-format-contract.js
Angela P Wen a196a714b8 Bump artifact dependencies if CODEQL_ACTION_ARTIFACT_V2_UPGRADE enabled (#2482)
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>
Co-authored-by: Henry Mercer <henrymercer@github.com>
2024-10-01 09:59:05 -07:00

101 lines
3.7 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WireType = exports.mergeBinaryOptions = exports.UnknownFieldHandler = void 0;
/**
* This handler implements the default behaviour for unknown fields.
* When reading data, unknown fields are stored on the message, in a
* symbol property.
* When writing data, the symbol property is queried and unknown fields
* are serialized into the output again.
*/
var UnknownFieldHandler;
(function (UnknownFieldHandler) {
/**
* The symbol used to store unknown fields for a message.
* The property must conform to `UnknownFieldContainer`.
*/
UnknownFieldHandler.symbol = Symbol.for("protobuf-ts/unknown");
/**
* Store an unknown field during binary read directly on the message.
* This method is compatible with `BinaryReadOptions.readUnknownField`.
*/
UnknownFieldHandler.onRead = (typeName, message, fieldNo, wireType, data) => {
let container = is(message) ? message[UnknownFieldHandler.symbol] : message[UnknownFieldHandler.symbol] = [];
container.push({ no: fieldNo, wireType, data });
};
/**
* Write unknown fields stored for the message to the writer.
* This method is compatible with `BinaryWriteOptions.writeUnknownFields`.
*/
UnknownFieldHandler.onWrite = (typeName, message, writer) => {
for (let { no, wireType, data } of UnknownFieldHandler.list(message))
writer.tag(no, wireType).raw(data);
};
/**
* List unknown fields stored for the message.
* Note that there may be multiples fields with the same number.
*/
UnknownFieldHandler.list = (message, fieldNo) => {
if (is(message)) {
let all = message[UnknownFieldHandler.symbol];
return fieldNo ? all.filter(uf => uf.no == fieldNo) : all;
}
return [];
};
/**
* Returns the last unknown field by field number.
*/
UnknownFieldHandler.last = (message, fieldNo) => UnknownFieldHandler.list(message, fieldNo).slice(-1)[0];
const is = (message) => message && Array.isArray(message[UnknownFieldHandler.symbol]);
})(UnknownFieldHandler = exports.UnknownFieldHandler || (exports.UnknownFieldHandler = {}));
/**
* Merges binary write or read options. Later values override earlier values.
*/
function mergeBinaryOptions(a, b) {
return Object.assign(Object.assign({}, a), b);
}
exports.mergeBinaryOptions = mergeBinaryOptions;
/**
* Protobuf binary format wire types.
*
* A wire type provides just enough information to find the length of the
* following value.
*
* See https://developers.google.com/protocol-buffers/docs/encoding#structure
*/
var WireType;
(function (WireType) {
/**
* Used for int32, int64, uint32, uint64, sint32, sint64, bool, enum
*/
WireType[WireType["Varint"] = 0] = "Varint";
/**
* Used for fixed64, sfixed64, double.
* Always 8 bytes with little-endian byte order.
*/
WireType[WireType["Bit64"] = 1] = "Bit64";
/**
* Used for string, bytes, embedded messages, packed repeated fields
*
* Only repeated numeric types (types which use the varint, 32-bit,
* or 64-bit wire types) can be packed. In proto3, such fields are
* packed by default.
*/
WireType[WireType["LengthDelimited"] = 2] = "LengthDelimited";
/**
* Used for groups
* @deprecated
*/
WireType[WireType["StartGroup"] = 3] = "StartGroup";
/**
* Used for groups
* @deprecated
*/
WireType[WireType["EndGroup"] = 4] = "EndGroup";
/**
* Used for fixed32, sfixed32, float.
* Always 4 bytes with little-endian byte order.
*/
WireType[WireType["Bit32"] = 5] = "Bit32";
})(WireType = exports.WireType || (exports.WireType = {}));