@bufbuild/protobuf
Advanced tools
Comparing version 1.5.0 to 1.5.1
@@ -28,9 +28,8 @@ /** | ||
/** | ||
* Used for groups | ||
* @deprecated | ||
* Start of a tag-delimited aggregate, such as a proto2 group, or a message | ||
* in editions with message_encoding = DELIMITED. | ||
*/ | ||
StartGroup = 3, | ||
/** | ||
* Used for groups | ||
* @deprecated | ||
* End of a tag-delimited aggregate. | ||
*/ | ||
@@ -37,0 +36,0 @@ EndGroup = 4, |
@@ -49,9 +49,8 @@ "use strict"; | ||
/** | ||
* Used for groups | ||
* @deprecated | ||
* Start of a tag-delimited aggregate, such as a proto2 group, or a message | ||
* in editions with message_encoding = DELIMITED. | ||
*/ | ||
WireType[WireType["StartGroup"] = 3] = "StartGroup"; | ||
/** | ||
* Used for groups | ||
* @deprecated | ||
* End of a tag-delimited aggregate. | ||
*/ | ||
@@ -58,0 +57,0 @@ WireType[WireType["EndGroup"] = 4] = "EndGroup"; |
@@ -19,4 +19,13 @@ import type { Message } from "./message.js"; | ||
* Parse a message from binary data, merging fields. | ||
* | ||
* Supports two message encodings: | ||
* - length-prefixed: delimitedMessageEncoding is false or omitted, and | ||
* lengthOrEndTagFieldNo is the expected length of the message in the reader. | ||
* - delimited: delimitedMessageEncoding is true, and lengthOrEndTagFieldNo is | ||
* the field number in a tag with wire type end-group signalling the end of | ||
* the message in the reader. | ||
* | ||
* delimitedMessageEncoding is optional for backwards compatibility. | ||
*/ | ||
readMessage(message: Message, reader: IBinaryReader, length: number, options: BinaryReadOptions): void; | ||
readMessage(message: Message, reader: IBinaryReader, lengthOrEndTagFieldNo: number, options: BinaryReadOptions, delimitedMessageEncoding?: boolean): void; | ||
/** | ||
@@ -23,0 +32,0 @@ * Serialize a message to binary data. |
@@ -237,2 +237,3 @@ "use strict"; | ||
T: messageType, | ||
delimited: field.proto.type == descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP, | ||
}; | ||
@@ -239,0 +240,0 @@ if (field.repeated) { |
@@ -26,2 +26,3 @@ import type { EnumType } from "./enum.js"; | ||
* - "default": Only proto2: An explicit default value. | ||
* - "delimited": Only proto2: Use the tag-delimited group encoding. | ||
*/ | ||
@@ -50,2 +51,3 @@ export type FieldInfo = fiRules<fiScalar> | fiRules<fiEnum> | fiRules<fiMessage> | fiRules<fiMap>; | ||
readonly default: undefined; | ||
readonly delimited?: undefined; | ||
readonly fields: readonly FieldInfo[]; | ||
@@ -124,2 +126,9 @@ /** | ||
readonly default: number | boolean | string | bigint | Uint8Array | undefined; | ||
/** | ||
* Serialize this message with the delimited format, also known as group | ||
* encoding, as opposed to the standard length prefix. | ||
* | ||
* Only valid for message fields. | ||
*/ | ||
readonly delimited?: undefined; | ||
} | ||
@@ -144,2 +153,9 @@ interface fiMessage extends fiShared { | ||
readonly default: undefined; | ||
/** | ||
* Serialize this message with the delimited format, also known as group | ||
* encoding, as opposed to the standard length prefix. | ||
* | ||
* Only valid for message fields. | ||
*/ | ||
readonly delimited?: boolean; | ||
} | ||
@@ -170,2 +186,9 @@ interface fiEnum extends fiShared { | ||
readonly default: number | undefined; | ||
/** | ||
* Serialize this message with the delimited format, also known as group | ||
* encoding, as opposed to the standard length prefix. | ||
* | ||
* Only valid for message fields. | ||
*/ | ||
readonly delimited?: undefined; | ||
} | ||
@@ -207,2 +230,9 @@ interface fiMap extends fiShared { | ||
readonly default: undefined; | ||
/** | ||
* Serialize this message with the delimited format, also known as group | ||
* encoding, as opposed to the standard length prefix. | ||
* | ||
* Only valid for message fields. | ||
*/ | ||
readonly delimited?: undefined; | ||
} | ||
@@ -230,3 +260,3 @@ type fiRules<T> = Omit<T, "oneof" | "repeat" | "repeated" | "packed" | "opt"> & ({ | ||
}); | ||
type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default" | "L"> & ({ | ||
type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default" | "L" | "delimited"> & ({ | ||
readonly jsonName?: string; | ||
@@ -239,2 +269,3 @@ readonly repeated?: false; | ||
L?: LongType; | ||
delimited?: boolean; | ||
} | { | ||
@@ -248,2 +279,3 @@ readonly jsonName?: string; | ||
L?: LongType; | ||
delimited?: boolean; | ||
} | { | ||
@@ -257,2 +289,3 @@ readonly jsonName?: string; | ||
L?: LongType; | ||
delimited?: boolean; | ||
} | { | ||
@@ -266,2 +299,3 @@ readonly jsonName?: string; | ||
L?: LongType; | ||
delimited?: boolean; | ||
}); | ||
@@ -287,3 +321,3 @@ /** | ||
SFIXED64 = 16, | ||
SINT32 = 17, | ||
SINT32 = 17,// Uses ZigZag encoding. | ||
SINT64 = 18 | ||
@@ -290,0 +324,0 @@ } |
@@ -17,3 +17,3 @@ "use strict"; | ||
exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0; | ||
// @generated by protoc-gen-es v1.5.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated by protoc-gen-es v1.5.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3) | ||
@@ -20,0 +20,0 @@ /* eslint-disable */ |
@@ -17,3 +17,3 @@ "use strict"; | ||
exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0; | ||
// @generated by protoc-gen-es v1.5.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated by protoc-gen-es v1.5.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3) | ||
@@ -20,0 +20,0 @@ /* eslint-disable */ |
@@ -5,3 +5,2 @@ import type { IBinaryReader, IBinaryWriter } from "../binary-encoding.js"; | ||
import { ScalarType } from "../field.js"; | ||
import type { MessageType } from "../message-type.js"; | ||
export declare function makeBinaryFormatCommon(): Omit<BinaryFormat, "writeMessage">; | ||
@@ -12,4 +11,6 @@ export declare function readScalarLTString(reader: IBinaryReader, type: ScalarType): any; | ||
}, key: any, value: any): void; | ||
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions, type: MessageType, fieldNo: number, value: any): void; | ||
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & { | ||
kind: "message"; | ||
}, value: any): void; | ||
export declare function writeScalar(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any, emitIntrinsicDefault: boolean): void; | ||
export declare function writePacked(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any[]): void; |
@@ -68,7 +68,15 @@ "use strict"; | ||
}, | ||
readMessage(message, reader, length, options) { | ||
readMessage(message, reader, lengthOrEndTagFieldNo, options, delimitedMessageEncoding) { | ||
const type = message.getType(); | ||
const end = length === undefined ? reader.len : reader.pos + length; | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
const end = delimitedMessageEncoding | ||
? reader.len | ||
: reader.pos + lengthOrEndTagFieldNo; | ||
let fieldNo, wireType; | ||
while (reader.pos < end) { | ||
const [fieldNo, wireType] = reader.tag(), field = type.fields.find(fieldNo); | ||
[fieldNo, wireType] = reader.tag(); | ||
if (wireType == binary_encoding_js_1.WireType.EndGroup) { | ||
break; | ||
} | ||
const field = type.fields.find(fieldNo); | ||
if (!field) { | ||
@@ -121,10 +129,10 @@ const data = reader.skip(wireType); | ||
// safe to assume presence of array, oneof cannot contain repeated values | ||
target[localName].push(readMessageField(reader, new messageType(), options)); | ||
target[localName].push(readMessageField(reader, new messageType(), options, field)); | ||
} | ||
else { | ||
if (target[localName] instanceof message_js_1.Message) { | ||
readMessageField(reader, target[localName], options); | ||
readMessageField(reader, target[localName], options, field); | ||
} | ||
else { | ||
target[localName] = readMessageField(reader, new messageType(), options); | ||
target[localName] = readMessageField(reader, new messageType(), options, field); | ||
if (messageType.fieldWrapper && | ||
@@ -145,2 +153,6 @@ !field.oneof && | ||
} | ||
if (delimitedMessageEncoding && // eslint-disable-line @typescript-eslint/strict-boolean-expressions | ||
(wireType != binary_encoding_js_1.WireType.EndGroup || fieldNo !== lengthOrEndTagFieldNo)) { | ||
throw new Error(`invalid end group tag`); | ||
} | ||
}, | ||
@@ -152,5 +164,7 @@ }; | ||
// BinaryReadOptions and the IBinaryReader. | ||
function readMessageField(reader, message, options) { | ||
function readMessageField(reader, message, options, field) { | ||
const format = message.getType().runtime.bin; | ||
format.readMessage(message, reader, reader.uint32(), options); | ||
const delimited = field === null || field === void 0 ? void 0 : field.delimited; | ||
format.readMessage(message, reader, delimited ? field === null || field === void 0 ? void 0 : field.no : reader.uint32(), // eslint-disable-line @typescript-eslint/strict-boolean-expressions | ||
options, delimited); | ||
return message; | ||
@@ -177,3 +191,3 @@ } | ||
case "message": | ||
val = readMessageField(reader, new field.V.T(), options); | ||
val = readMessageField(reader, new field.V.T(), options, undefined); | ||
break; | ||
@@ -282,3 +296,3 @@ } | ||
case "message": | ||
writeMessageField(writer, options, field.V.T, 2, value); | ||
writer.tag(2, binary_encoding_js_1.WireType.LengthDelimited).bytes(value.toBinary(options)); | ||
break; | ||
@@ -289,8 +303,15 @@ } | ||
exports.writeMapEntry = writeMapEntry; | ||
function writeMessageField(writer, options, type, fieldNo, value) { | ||
function writeMessageField(writer, options, field, value) { | ||
if (value !== undefined) { | ||
const message = (0, field_wrapper_js_1.wrapField)(type, value); | ||
writer | ||
.tag(fieldNo, binary_encoding_js_1.WireType.LengthDelimited) | ||
.bytes(message.toBinary(options)); | ||
const message = (0, field_wrapper_js_1.wrapField)(field.T, value); | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (field === null || field === void 0 ? void 0 : field.delimited) | ||
writer | ||
.tag(field.no, binary_encoding_js_1.WireType.StartGroup) | ||
.raw(message.toBinary(options)) | ||
.tag(field.no, binary_encoding_js_1.WireType.EndGroup); | ||
else | ||
writer | ||
.tag(field.no, binary_encoding_js_1.WireType.LengthDelimited) | ||
.bytes(message.toBinary(options)); | ||
} | ||
@@ -297,0 +318,0 @@ } |
@@ -68,7 +68,7 @@ "use strict"; | ||
for (const item of value) { | ||
(0, binary_format_common_js_1.writeMessageField)(writer, options, field.T, field.no, item); | ||
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, item); | ||
} | ||
} | ||
else { | ||
(0, binary_format_common_js_1.writeMessageField)(writer, options, field.T, field.no, value); | ||
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, value); | ||
} | ||
@@ -75,0 +75,0 @@ break; |
@@ -59,7 +59,7 @@ "use strict"; | ||
for (const item of value) { | ||
(0, binary_format_common_js_1.writeMessageField)(writer, options, field.T, field.no, item); | ||
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, item); | ||
} | ||
} | ||
else { | ||
(0, binary_format_common_js_1.writeMessageField)(writer, options, field.T, field.no, value); | ||
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, value); | ||
} | ||
@@ -66,0 +66,0 @@ break; |
@@ -26,4 +26,5 @@ "use strict"; | ||
var g = generator.apply(thisArg, _arguments || []), i, q = []; | ||
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; | ||
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } | ||
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i; | ||
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; } | ||
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } } | ||
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } | ||
@@ -30,0 +31,0 @@ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } |
@@ -60,3 +60,3 @@ "use strict"; | ||
function normalizeFieldInfosProto2(fieldInfos) { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e; | ||
const r = []; | ||
@@ -74,4 +74,2 @@ let o; | ||
} | ||
// In contrast to proto3, repeated fields are unpacked except when explicitly specified. | ||
f.packed = (_d = field.packed) !== null && _d !== void 0 ? _d : false; | ||
// We do not surface options at this time | ||
@@ -87,2 +85,8 @@ // f.options = field.options ?? emptyReadonlyObject; | ||
} | ||
// proto2 specific: | ||
if (field.kind == "message") { | ||
f.delimited = (_d = field.delimited) !== null && _d !== void 0 ? _d : false; | ||
} | ||
// In contrast to proto3, repeated fields are unpacked except when explicitly specified. | ||
f.packed = (_e = field.packed) !== null && _e !== void 0 ? _e : false; | ||
r.push(f); | ||
@@ -89,0 +93,0 @@ } |
@@ -76,2 +76,16 @@ "use strict"; | ||
} | ||
// We do not surface options at this time | ||
// f.options = field.options ?? emptyReadonlyObject; | ||
if (field.oneof !== undefined) { | ||
const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name; | ||
if (!o || o.name != ooname) { | ||
o = new field_js_2.InternalOneofInfo(ooname); | ||
} | ||
f.oneof = o; | ||
o.addField(f); | ||
} | ||
// proto3 specific: | ||
if (field.kind == "message") { | ||
f.delimited = false; | ||
} | ||
// From the proto3 language guide: | ||
@@ -87,12 +101,2 @@ // > In proto3, repeated fields of scalar numeric types are packed by default. | ||
field.T != field_js_1.ScalarType.STRING)); | ||
// We do not surface options at this time | ||
// f.options = field.options ?? emptyReadonlyObject; | ||
if (field.oneof !== undefined) { | ||
const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name; | ||
if (!o || o.name != ooname) { | ||
o = new field_js_2.InternalOneofInfo(ooname); | ||
} | ||
f.oneof = o; | ||
o.addField(f); | ||
} | ||
r.push(f); | ||
@@ -99,0 +103,0 @@ } |
@@ -28,9 +28,8 @@ /** | ||
/** | ||
* Used for groups | ||
* @deprecated | ||
* Start of a tag-delimited aggregate, such as a proto2 group, or a message | ||
* in editions with message_encoding = DELIMITED. | ||
*/ | ||
StartGroup = 3, | ||
/** | ||
* Used for groups | ||
* @deprecated | ||
* End of a tag-delimited aggregate. | ||
*/ | ||
@@ -37,0 +36,0 @@ EndGroup = 4, |
@@ -46,9 +46,8 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
/** | ||
* Used for groups | ||
* @deprecated | ||
* Start of a tag-delimited aggregate, such as a proto2 group, or a message | ||
* in editions with message_encoding = DELIMITED. | ||
*/ | ||
WireType[WireType["StartGroup"] = 3] = "StartGroup"; | ||
/** | ||
* Used for groups | ||
* @deprecated | ||
* End of a tag-delimited aggregate. | ||
*/ | ||
@@ -55,0 +54,0 @@ WireType[WireType["EndGroup"] = 4] = "EndGroup"; |
@@ -19,4 +19,13 @@ import type { Message } from "./message.js"; | ||
* Parse a message from binary data, merging fields. | ||
* | ||
* Supports two message encodings: | ||
* - length-prefixed: delimitedMessageEncoding is false or omitted, and | ||
* lengthOrEndTagFieldNo is the expected length of the message in the reader. | ||
* - delimited: delimitedMessageEncoding is true, and lengthOrEndTagFieldNo is | ||
* the field number in a tag with wire type end-group signalling the end of | ||
* the message in the reader. | ||
* | ||
* delimitedMessageEncoding is optional for backwards compatibility. | ||
*/ | ||
readMessage(message: Message, reader: IBinaryReader, length: number, options: BinaryReadOptions): void; | ||
readMessage(message: Message, reader: IBinaryReader, lengthOrEndTagFieldNo: number, options: BinaryReadOptions, delimitedMessageEncoding?: boolean): void; | ||
/** | ||
@@ -23,0 +32,0 @@ * Serialize a message to binary data. |
@@ -27,3 +27,3 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
import { BoolValue, BytesValue, DoubleValue, FloatValue, Int32Value, Int64Value, StringValue, UInt32Value, UInt64Value, } from "./google/protobuf/wrappers_pb.js"; | ||
import { FileDescriptorSet } from "./google/protobuf/descriptor_pb.js"; | ||
import { FieldDescriptorProto_Type, FileDescriptorSet, } from "./google/protobuf/descriptor_pb.js"; | ||
import { createDescriptorSet } from "./create-descriptor-set.js"; | ||
@@ -234,2 +234,3 @@ // well-known message types with specialized JSON representation | ||
T: messageType, | ||
delimited: field.proto.type == FieldDescriptorProto_Type.GROUP, | ||
}; | ||
@@ -236,0 +237,0 @@ if (field.repeated) { |
@@ -26,2 +26,3 @@ import type { EnumType } from "./enum.js"; | ||
* - "default": Only proto2: An explicit default value. | ||
* - "delimited": Only proto2: Use the tag-delimited group encoding. | ||
*/ | ||
@@ -50,2 +51,3 @@ export type FieldInfo = fiRules<fiScalar> | fiRules<fiEnum> | fiRules<fiMessage> | fiRules<fiMap>; | ||
readonly default: undefined; | ||
readonly delimited?: undefined; | ||
readonly fields: readonly FieldInfo[]; | ||
@@ -124,2 +126,9 @@ /** | ||
readonly default: number | boolean | string | bigint | Uint8Array | undefined; | ||
/** | ||
* Serialize this message with the delimited format, also known as group | ||
* encoding, as opposed to the standard length prefix. | ||
* | ||
* Only valid for message fields. | ||
*/ | ||
readonly delimited?: undefined; | ||
} | ||
@@ -144,2 +153,9 @@ interface fiMessage extends fiShared { | ||
readonly default: undefined; | ||
/** | ||
* Serialize this message with the delimited format, also known as group | ||
* encoding, as opposed to the standard length prefix. | ||
* | ||
* Only valid for message fields. | ||
*/ | ||
readonly delimited?: boolean; | ||
} | ||
@@ -170,2 +186,9 @@ interface fiEnum extends fiShared { | ||
readonly default: number | undefined; | ||
/** | ||
* Serialize this message with the delimited format, also known as group | ||
* encoding, as opposed to the standard length prefix. | ||
* | ||
* Only valid for message fields. | ||
*/ | ||
readonly delimited?: undefined; | ||
} | ||
@@ -207,2 +230,9 @@ interface fiMap extends fiShared { | ||
readonly default: undefined; | ||
/** | ||
* Serialize this message with the delimited format, also known as group | ||
* encoding, as opposed to the standard length prefix. | ||
* | ||
* Only valid for message fields. | ||
*/ | ||
readonly delimited?: undefined; | ||
} | ||
@@ -230,3 +260,3 @@ type fiRules<T> = Omit<T, "oneof" | "repeat" | "repeated" | "packed" | "opt"> & ({ | ||
}); | ||
type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default" | "L"> & ({ | ||
type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default" | "L" | "delimited"> & ({ | ||
readonly jsonName?: string; | ||
@@ -239,2 +269,3 @@ readonly repeated?: false; | ||
L?: LongType; | ||
delimited?: boolean; | ||
} | { | ||
@@ -248,2 +279,3 @@ readonly jsonName?: string; | ||
L?: LongType; | ||
delimited?: boolean; | ||
} | { | ||
@@ -257,2 +289,3 @@ readonly jsonName?: string; | ||
L?: LongType; | ||
delimited?: boolean; | ||
} | { | ||
@@ -266,2 +299,3 @@ readonly jsonName?: string; | ||
L?: LongType; | ||
delimited?: boolean; | ||
}); | ||
@@ -287,3 +321,3 @@ /** | ||
SFIXED64 = 16, | ||
SINT32 = 17, | ||
SINT32 = 17,// Uses ZigZag encoding. | ||
SINT64 = 18 | ||
@@ -290,0 +324,0 @@ } |
@@ -14,3 +14,3 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
// limitations under the License. | ||
// @generated by protoc-gen-es v1.5.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated by protoc-gen-es v1.5.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3) | ||
@@ -17,0 +17,0 @@ /* eslint-disable */ |
@@ -14,3 +14,3 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
// limitations under the License. | ||
// @generated by protoc-gen-es v1.5.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated by protoc-gen-es v1.5.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts" | ||
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3) | ||
@@ -17,0 +17,0 @@ /* eslint-disable */ |
@@ -5,3 +5,2 @@ import type { IBinaryReader, IBinaryWriter } from "../binary-encoding.js"; | ||
import { ScalarType } from "../field.js"; | ||
import type { MessageType } from "../message-type.js"; | ||
export declare function makeBinaryFormatCommon(): Omit<BinaryFormat, "writeMessage">; | ||
@@ -12,4 +11,6 @@ export declare function readScalarLTString(reader: IBinaryReader, type: ScalarType): any; | ||
}, key: any, value: any): void; | ||
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions, type: MessageType, fieldNo: number, value: any): void; | ||
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & { | ||
kind: "message"; | ||
}, value: any): void; | ||
export declare function writeScalar(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any, emitIntrinsicDefault: boolean): void; | ||
export declare function writePacked(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any[]): void; |
@@ -65,7 +65,15 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
}, | ||
readMessage(message, reader, length, options) { | ||
readMessage(message, reader, lengthOrEndTagFieldNo, options, delimitedMessageEncoding) { | ||
const type = message.getType(); | ||
const end = length === undefined ? reader.len : reader.pos + length; | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
const end = delimitedMessageEncoding | ||
? reader.len | ||
: reader.pos + lengthOrEndTagFieldNo; | ||
let fieldNo, wireType; | ||
while (reader.pos < end) { | ||
const [fieldNo, wireType] = reader.tag(), field = type.fields.find(fieldNo); | ||
[fieldNo, wireType] = reader.tag(); | ||
if (wireType == WireType.EndGroup) { | ||
break; | ||
} | ||
const field = type.fields.find(fieldNo); | ||
if (!field) { | ||
@@ -118,10 +126,10 @@ const data = reader.skip(wireType); | ||
// safe to assume presence of array, oneof cannot contain repeated values | ||
target[localName].push(readMessageField(reader, new messageType(), options)); | ||
target[localName].push(readMessageField(reader, new messageType(), options, field)); | ||
} | ||
else { | ||
if (target[localName] instanceof Message) { | ||
readMessageField(reader, target[localName], options); | ||
readMessageField(reader, target[localName], options, field); | ||
} | ||
else { | ||
target[localName] = readMessageField(reader, new messageType(), options); | ||
target[localName] = readMessageField(reader, new messageType(), options, field); | ||
if (messageType.fieldWrapper && | ||
@@ -142,2 +150,6 @@ !field.oneof && | ||
} | ||
if (delimitedMessageEncoding && // eslint-disable-line @typescript-eslint/strict-boolean-expressions | ||
(wireType != WireType.EndGroup || fieldNo !== lengthOrEndTagFieldNo)) { | ||
throw new Error(`invalid end group tag`); | ||
} | ||
}, | ||
@@ -148,5 +160,7 @@ }; | ||
// BinaryReadOptions and the IBinaryReader. | ||
function readMessageField(reader, message, options) { | ||
function readMessageField(reader, message, options, field) { | ||
const format = message.getType().runtime.bin; | ||
format.readMessage(message, reader, reader.uint32(), options); | ||
const delimited = field === null || field === void 0 ? void 0 : field.delimited; | ||
format.readMessage(message, reader, delimited ? field === null || field === void 0 ? void 0 : field.no : reader.uint32(), // eslint-disable-line @typescript-eslint/strict-boolean-expressions | ||
options, delimited); | ||
return message; | ||
@@ -173,3 +187,3 @@ } | ||
case "message": | ||
val = readMessageField(reader, new field.V.T(), options); | ||
val = readMessageField(reader, new field.V.T(), options, undefined); | ||
break; | ||
@@ -277,3 +291,3 @@ } | ||
case "message": | ||
writeMessageField(writer, options, field.V.T, 2, value); | ||
writer.tag(2, WireType.LengthDelimited).bytes(value.toBinary(options)); | ||
break; | ||
@@ -283,8 +297,15 @@ } | ||
} | ||
export function writeMessageField(writer, options, type, fieldNo, value) { | ||
export function writeMessageField(writer, options, field, value) { | ||
if (value !== undefined) { | ||
const message = wrapField(type, value); | ||
writer | ||
.tag(fieldNo, WireType.LengthDelimited) | ||
.bytes(message.toBinary(options)); | ||
const message = wrapField(field.T, value); | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (field === null || field === void 0 ? void 0 : field.delimited) | ||
writer | ||
.tag(field.no, WireType.StartGroup) | ||
.raw(message.toBinary(options)) | ||
.tag(field.no, WireType.EndGroup); | ||
else | ||
writer | ||
.tag(field.no, WireType.LengthDelimited) | ||
.bytes(message.toBinary(options)); | ||
} | ||
@@ -291,0 +312,0 @@ } |
@@ -65,7 +65,7 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
for (const item of value) { | ||
writeMessageField(writer, options, field.T, field.no, item); | ||
writeMessageField(writer, options, field, item); | ||
} | ||
} | ||
else { | ||
writeMessageField(writer, options, field.T, field.no, value); | ||
writeMessageField(writer, options, field, value); | ||
} | ||
@@ -72,0 +72,0 @@ break; |
@@ -56,7 +56,7 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
for (const item of value) { | ||
writeMessageField(writer, options, field.T, field.no, item); | ||
writeMessageField(writer, options, field, item); | ||
} | ||
} | ||
else { | ||
writeMessageField(writer, options, field.T, field.no, value); | ||
writeMessageField(writer, options, field, value); | ||
} | ||
@@ -63,0 +63,0 @@ break; |
@@ -25,4 +25,5 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
var g = generator.apply(thisArg, _arguments || []), i, q = []; | ||
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; | ||
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } | ||
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i; | ||
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; } | ||
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } } | ||
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } | ||
@@ -29,0 +30,0 @@ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } |
@@ -57,3 +57,3 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
function normalizeFieldInfosProto2(fieldInfos) { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e; | ||
const r = []; | ||
@@ -71,4 +71,2 @@ let o; | ||
} | ||
// In contrast to proto3, repeated fields are unpacked except when explicitly specified. | ||
f.packed = (_d = field.packed) !== null && _d !== void 0 ? _d : false; | ||
// We do not surface options at this time | ||
@@ -84,2 +82,8 @@ // f.options = field.options ?? emptyReadonlyObject; | ||
} | ||
// proto2 specific: | ||
if (field.kind == "message") { | ||
f.delimited = (_d = field.delimited) !== null && _d !== void 0 ? _d : false; | ||
} | ||
// In contrast to proto3, repeated fields are unpacked except when explicitly specified. | ||
f.packed = (_e = field.packed) !== null && _e !== void 0 ? _e : false; | ||
r.push(f); | ||
@@ -86,0 +90,0 @@ } |
@@ -73,2 +73,16 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
} | ||
// We do not surface options at this time | ||
// f.options = field.options ?? emptyReadonlyObject; | ||
if (field.oneof !== undefined) { | ||
const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name; | ||
if (!o || o.name != ooname) { | ||
o = new InternalOneofInfo(ooname); | ||
} | ||
f.oneof = o; | ||
o.addField(f); | ||
} | ||
// proto3 specific: | ||
if (field.kind == "message") { | ||
f.delimited = false; | ||
} | ||
// From the proto3 language guide: | ||
@@ -84,12 +98,2 @@ // > In proto3, repeated fields of scalar numeric types are packed by default. | ||
field.T != ScalarType.STRING)); | ||
// We do not surface options at this time | ||
// f.options = field.options ?? emptyReadonlyObject; | ||
if (field.oneof !== undefined) { | ||
const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name; | ||
if (!o || o.name != ooname) { | ||
o = new InternalOneofInfo(ooname); | ||
} | ||
f.oneof = o; | ||
o.addField(f); | ||
} | ||
r.push(f); | ||
@@ -96,0 +100,0 @@ } |
{ | ||
"name": "@bufbuild/protobuf", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"license": "(Apache-2.0 AND BSD-3-Clause)", | ||
@@ -28,5 +28,9 @@ "description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.", | ||
".": { | ||
"node": { | ||
"import": "./dist/proxy/index.js", | ||
"require": "./dist/cjs/index.js" | ||
}, | ||
"module": "./dist/esm/index.js", | ||
"require": "./dist/cjs/index.js", | ||
"import": "./dist/proxy/index.js" | ||
"import": "./dist/esm/index.js", | ||
"require": "./dist/cjs/index.js" | ||
} | ||
@@ -33,0 +37,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1412057
35809