Skip to content

Commit

Permalink
JSON wireformat fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tatethurston committed Oct 21, 2023
1 parent e826b20 commit 24ecbb6
Show file tree
Hide file tree
Showing 31 changed files with 3,804 additions and 1,296 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.16
18.18.2
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
- language=typescript
strategy: all
```

## v0.0.15

This release includes a number of bug fixes
Expand Down
653 changes: 653 additions & 0 deletions e2e/conformance/expected_proto2_failing_tests.txt

Large diffs are not rendered by default.

791 changes: 48 additions & 743 deletions e2e/conformance/failing_tests.txt

Large diffs are not rendered by default.

69 changes: 37 additions & 32 deletions e2e/conformance/proto/conformance/conformance.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
/* eslint-disable */

import type { ByteSource, PartialDeep } from "protoscript";
import {
BinaryReader,
BinaryWriter,
encodeBase64Bytes,
decodeBase64Bytes,
} from "protoscript";
import * as protoscript from "protoscript";

//========================================//
// Types //
Expand Down Expand Up @@ -299,7 +294,10 @@ export const FailureSet = {
* Serializes FailureSet to protobuf.
*/
encode: function (msg: PartialDeep<FailureSet>): Uint8Array {
return FailureSet._writeMessage(msg, new BinaryWriter()).getResultBuffer();
return FailureSet._writeMessage(
msg,
new protoscript.BinaryWriter(),
).getResultBuffer();
},

/**
Expand All @@ -308,7 +306,7 @@ export const FailureSet = {
decode: function (bytes: ByteSource): FailureSet {
return FailureSet._readMessage(
FailureSet.initialize(),
new BinaryReader(bytes),
new protoscript.BinaryReader(bytes),
);
},

Expand All @@ -326,8 +324,8 @@ export const FailureSet = {
*/
_writeMessage: function (
msg: PartialDeep<FailureSet>,
writer: BinaryWriter,
): BinaryWriter {
writer: protoscript.BinaryWriter,
): protoscript.BinaryWriter {
if (msg.failure?.length) {
writer.writeRepeatedString(1, msg.failure);
}
Expand All @@ -337,7 +335,10 @@ export const FailureSet = {
/**
* @private
*/
_readMessage: function (msg: FailureSet, reader: BinaryReader): FailureSet {
_readMessage: function (
msg: FailureSet,
reader: protoscript.BinaryReader,
): FailureSet {
while (reader.nextField()) {
const field = reader.getFieldNumber();
switch (field) {
Expand All @@ -362,7 +363,7 @@ export const ConformanceRequest = {
encode: function (msg: PartialDeep<ConformanceRequest>): Uint8Array {
return ConformanceRequest._writeMessage(
msg,
new BinaryWriter(),
new protoscript.BinaryWriter(),
).getResultBuffer();
},

Expand All @@ -372,7 +373,7 @@ export const ConformanceRequest = {
decode: function (bytes: ByteSource): ConformanceRequest {
return ConformanceRequest._readMessage(
ConformanceRequest.initialize(),
new BinaryReader(bytes),
new protoscript.BinaryReader(bytes),
);
},

Expand All @@ -398,8 +399,8 @@ export const ConformanceRequest = {
*/
_writeMessage: function (
msg: PartialDeep<ConformanceRequest>,
writer: BinaryWriter,
): BinaryWriter {
writer: protoscript.BinaryWriter,
): protoscript.BinaryWriter {
if (msg.protobufPayload?.length) {
writer.writeBytes(1, msg.protobufPayload);
}
Expand Down Expand Up @@ -442,7 +443,7 @@ export const ConformanceRequest = {
*/
_readMessage: function (
msg: ConformanceRequest,
reader: BinaryReader,
reader: protoscript.BinaryReader,
): ConformanceRequest {
while (reader.nextField()) {
const field = reader.getFieldNumber();
Expand Down Expand Up @@ -503,7 +504,7 @@ export const ConformanceResponse = {
encode: function (msg: PartialDeep<ConformanceResponse>): Uint8Array {
return ConformanceResponse._writeMessage(
msg,
new BinaryWriter(),
new protoscript.BinaryWriter(),
).getResultBuffer();
},

Expand All @@ -513,7 +514,7 @@ export const ConformanceResponse = {
decode: function (bytes: ByteSource): ConformanceResponse {
return ConformanceResponse._readMessage(
ConformanceResponse.initialize(),
new BinaryReader(bytes),
new protoscript.BinaryReader(bytes),
);
},

Expand All @@ -539,8 +540,8 @@ export const ConformanceResponse = {
*/
_writeMessage: function (
msg: PartialDeep<ConformanceResponse>,
writer: BinaryWriter,
): BinaryWriter {
writer: protoscript.BinaryWriter,
): protoscript.BinaryWriter {
if (msg.parseError != undefined) {
writer.writeString(1, msg.parseError);
}
Expand Down Expand Up @@ -576,7 +577,7 @@ export const ConformanceResponse = {
*/
_readMessage: function (
msg: ConformanceResponse,
reader: BinaryReader,
reader: protoscript.BinaryReader,
): ConformanceResponse {
while (reader.nextField()) {
const field = reader.getFieldNumber();
Expand Down Expand Up @@ -634,7 +635,7 @@ export const JspbEncodingConfig = {
encode: function (msg: PartialDeep<JspbEncodingConfig>): Uint8Array {
return JspbEncodingConfig._writeMessage(
msg,
new BinaryWriter(),
new protoscript.BinaryWriter(),
).getResultBuffer();
},

Expand All @@ -644,7 +645,7 @@ export const JspbEncodingConfig = {
decode: function (bytes: ByteSource): JspbEncodingConfig {
return JspbEncodingConfig._readMessage(
JspbEncodingConfig.initialize(),
new BinaryReader(bytes),
new protoscript.BinaryReader(bytes),
);
},

Expand All @@ -662,8 +663,8 @@ export const JspbEncodingConfig = {
*/
_writeMessage: function (
msg: PartialDeep<JspbEncodingConfig>,
writer: BinaryWriter,
): BinaryWriter {
writer: protoscript.BinaryWriter,
): protoscript.BinaryWriter {
if (msg.useJspbArrayAnyFormat) {
writer.writeBool(1, msg.useJspbArrayAnyFormat);
}
Expand All @@ -675,7 +676,7 @@ export const JspbEncodingConfig = {
*/
_readMessage: function (
msg: JspbEncodingConfig,
reader: BinaryReader,
reader: protoscript.BinaryReader,
): JspbEncodingConfig {
while (reader.nextField()) {
const field = reader.getFieldNumber();
Expand Down Expand Up @@ -935,7 +936,9 @@ export const ConformanceRequestJSON = {
): Record<string, unknown> {
const json: Record<string, unknown> = {};
if (msg.protobufPayload?.length) {
json["protobufPayload"] = encodeBase64Bytes(msg.protobufPayload);
json["protobufPayload"] = protoscript.encodeBase64Bytes(
msg.protobufPayload,
);
}
if (msg.jsonPayload != undefined) {
json["jsonPayload"] = msg.jsonPayload;
Expand Down Expand Up @@ -982,7 +985,7 @@ export const ConformanceRequestJSON = {
const _protobufPayload_ =
json["protobufPayload"] ?? json["protobuf_payload"];
if (_protobufPayload_) {
msg.protobufPayload = decodeBase64Bytes(_protobufPayload_);
msg.protobufPayload = protoscript.parseBytes(_protobufPayload_);
}
const _jsonPayload_ = json["jsonPayload"] ?? json["json_payload"];
if (_jsonPayload_) {
Expand All @@ -999,15 +1002,15 @@ export const ConformanceRequestJSON = {
const _requestedOutputFormat_ =
json["requestedOutputFormat"] ?? json["requested_output_format"];
if (_requestedOutputFormat_) {
msg.requestedOutputFormat = _requestedOutputFormat_;
msg.requestedOutputFormat = WireFormat._fromInt(_requestedOutputFormat_);
}
const _messageType_ = json["messageType"] ?? json["message_type"];
if (_messageType_) {
msg.messageType = _messageType_;
}
const _testCategory_ = json["testCategory"] ?? json["test_category"];
if (_testCategory_) {
msg.testCategory = _testCategory_;
msg.testCategory = TestCategory._fromInt(_testCategory_);
}
const _jspbEncodingOptions_ =
json["jspbEncodingOptions"] ?? json["jspb_encoding_options"];
Expand Down Expand Up @@ -1081,7 +1084,9 @@ export const ConformanceResponseJSON = {
json["runtimeError"] = msg.runtimeError;
}
if (msg.protobufPayload?.length) {
json["protobufPayload"] = encodeBase64Bytes(msg.protobufPayload);
json["protobufPayload"] = protoscript.encodeBase64Bytes(
msg.protobufPayload,
);
}
if (msg.jsonPayload != undefined) {
json["jsonPayload"] = msg.jsonPayload;
Expand Down Expand Up @@ -1124,7 +1129,7 @@ export const ConformanceResponseJSON = {
const _protobufPayload_ =
json["protobufPayload"] ?? json["protobuf_payload"];
if (_protobufPayload_) {
msg.protobufPayload = decodeBase64Bytes(_protobufPayload_);
msg.protobufPayload = protoscript.parseBytes(_protobufPayload_);
}
const _jsonPayload_ = json["jsonPayload"] ?? json["json_payload"];
if (_jsonPayload_) {
Expand Down
Loading

0 comments on commit 24ecbb6

Please sign in to comment.