Skip to content

Commit

Permalink
JSON wireformat fixes (#41)
Browse files Browse the repository at this point in the history
* JSON wireformat fixes

* bump protoc version
  • Loading branch information
tatethurston authored Oct 22, 2023
1 parent e826b20 commit 3d81e56
Show file tree
Hide file tree
Showing 33 changed files with 4,071 additions and 1,365 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
# Install protoc for e2e:setup
- uses: arduino/setup-protoc@v2
with:
version: "23.4"
version: "24.4"
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.16
18.18.2
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## v0.0.18

- Fix JSON serializtion for Timestamp and Duration well known types. See [#39](https://github.com/tatethurston/ProtoScript/issues/39).
- Accept all value permutations as described by the Proto3 JSON spec when parsing JSON messages.

## v0.0.18

- Fix JSON deserializtion of recursive (self referencing) messages.
- Fix generated TypeScript types for repeated recursive (self referencing) messages.

Expand All @@ -26,7 +31,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.

65 changes: 33 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,7 @@ export const ConformanceRequestJSON = {
): Record<string, unknown> {
const json: Record<string, unknown> = {};
if (msg.protobufPayload?.length) {
json["protobufPayload"] = encodeBase64Bytes(msg.protobufPayload);
json["protobufPayload"] = protoscript.serializeBytes(msg.protobufPayload);
}
if (msg.jsonPayload != undefined) {
json["jsonPayload"] = msg.jsonPayload;
Expand Down Expand Up @@ -982,7 +983,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 +1000,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 +1082,7 @@ export const ConformanceResponseJSON = {
json["runtimeError"] = msg.runtimeError;
}
if (msg.protobufPayload?.length) {
json["protobufPayload"] = encodeBase64Bytes(msg.protobufPayload);
json["protobufPayload"] = protoscript.serializeBytes(msg.protobufPayload);
}
if (msg.jsonPayload != undefined) {
json["jsonPayload"] = msg.jsonPayload;
Expand Down Expand Up @@ -1124,7 +1125,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 3d81e56

Please sign in to comment.