Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to-spec json mapping via serde #558

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1e57845
conformance + initial impl
konradjniemiec Mar 23, 2021
ca91e1a
initial try, need to get to WK
konradjniemiec Mar 25, 2021
b940867
saving old work
konradjniemiec Oct 18, 2021
46a5fff
Merge branch 'master' into serde_json_serialization
konradjniemiec Oct 18, 2021
4a13f3c
get back in working state
konradjniemiec Oct 19, 2021
de960ff
uh?
konradjniemiec Oct 19, 2021
6270fff
lifetime error
konradjniemiec Oct 19, 2021
6dd713c
stopping point
konradjniemiec Oct 25, 2021
680f8b7
working
konradjniemiec Nov 1, 2021
6f542b6
work
konradjniemiec Nov 2, 2021
1469062
final check in before putting up for 1 level of review
konradjniemiec Nov 2, 2021
06c0983
fmt
konradjniemiec Nov 2, 2021
a002a23
remove comment + add failed tests
konradjniemiec Nov 2, 2021
7ac0d01
almost ready for review
konradjniemiec Nov 3, 2021
7766e33
no-op
konradjniemiec Nov 3, 2021
0d62c8c
final changes
konradjniemiec Nov 3, 2021
0dd0652
add maps, still haven't cleaned up some code
konradjniemiec Nov 11, 2021
5f6c093
maps working correctly
konradjniemiec Nov 14, 2021
372aa43
updated w partial enums
konradjniemiec Feb 15, 2022
ac9adfd
fmt
konradjniemiec Feb 15, 2022
565d04a
Merge branch 'master' into serde_json_serialization
konradjniemiec Feb 15, 2022
9ef2b42
Added enum visitor and enum opt visitor
Projoh Feb 17, 2022
1ab98b7
cleanup + make enums work mostly
konradjniemiec Feb 17, 2022
9a54788
Fixed oneof and enum unknown handling
Projoh Feb 18, 2022
34c21f4
review ready
konradjniemiec Mar 16, 2022
45fb956
Merge branch 'serde_json_serialization' of github.com:konradjniemiec/…
konradjniemiec Mar 16, 2022
b346867
Merge branch 'master' into serde_json_serialization
konradjniemiec Mar 16, 2022
96755dd
i64/u64 serialize as string, add empty visitor
konradjniemiec Mar 16, 2022
4b5a456
empty + fmt
konradjniemiec Mar 17, 2022
db0d9a8
add better empty impl
konradjniemiec Mar 17, 2022
ac23da0
make a change for enum validations
konradjniemiec Mar 17, 2022
9374f79
timestamp implementation
konradjniemiec Mar 21, 2022
327c852
double precision
konradjniemiec Mar 22, 2022
a6a0777
most of the stuff
konradjniemiec Mar 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target
Cargo.lock
.vscode
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ bench = false
default = ["prost-derive", "std"]
no-recursion-limit = []
std = []
json = []

[dependencies]
bytes = { version = "1", default-features = false }
Expand Down
83 changes: 82 additions & 1 deletion conformance/failing_tests.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,84 @@
# TODO(tokio-rs/prost#2): prost doesn't preserve unknown fields.
Recommended.FieldMaskNumbersDontRoundTrip.JsonOutput
Recommended.FieldMaskPathsDontRoundTrip.JsonOutput
Recommended.FieldMaskTooManyUnderscore.JsonOutput
Recommended.Proto2.JsonInput.FieldNameExtension.Validator
Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput
Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHas9FractionalDigits.Validator
Recommended.Proto3.JsonInput.MapFieldValueIsNull
Recommended.Proto3.JsonInput.NullValueInOtherOneofNewFormat.Validator
Recommended.Proto3.JsonInput.NullValueInOtherOneofOldFormat.Validator
Recommended.Proto3.JsonInput.RepeatedFieldPrimitiveElementIsNull
Required.DurationProtoInputTooLarge.JsonOutput
Required.DurationProtoInputTooSmall.JsonOutput
Required.Proto2.ProtobufInput.UnknownVarint.ProtobufOutput
Required.Proto3.JsonInput.Any.JsonOutput
Required.Proto3.JsonInput.Any.ProtobufOutput
Required.Proto3.JsonInput.AnyNested.JsonOutput
Required.Proto3.JsonInput.AnyNested.ProtobufOutput
Required.Proto3.JsonInput.AnyUnorderedTypeTag.JsonOutput
Required.Proto3.JsonInput.AnyUnorderedTypeTag.ProtobufOutput
Required.Proto3.JsonInput.AnyWithDuration.JsonOutput
Required.Proto3.JsonInput.AnyWithDuration.ProtobufOutput
Required.Proto3.JsonInput.AnyWithFieldMask.JsonOutput
Required.Proto3.JsonInput.AnyWithFieldMask.ProtobufOutput
Required.Proto3.JsonInput.AnyWithInt32ValueWrapper.JsonOutput
Required.Proto3.JsonInput.AnyWithInt32ValueWrapper.ProtobufOutput
Required.Proto3.JsonInput.AnyWithStruct.JsonOutput
Required.Proto3.JsonInput.AnyWithStruct.ProtobufOutput
Required.Proto3.JsonInput.AnyWithTimestamp.JsonOutput
Required.Proto3.JsonInput.AnyWithTimestamp.ProtobufOutput
Required.Proto3.JsonInput.AnyWithValueForInteger.JsonOutput
Required.Proto3.JsonInput.AnyWithValueForInteger.ProtobufOutput
Required.Proto3.JsonInput.AnyWithValueForJsonObject.JsonOutput
Required.Proto3.JsonInput.AnyWithValueForJsonObject.ProtobufOutput
Required.Proto3.JsonInput.DurationJsonInputTooLarge
Required.Proto3.JsonInput.DurationJsonInputTooSmall
Required.Proto3.JsonInput.DurationMaxValue.JsonOutput
Required.Proto3.JsonInput.DurationMaxValue.ProtobufOutput
Required.Proto3.JsonInput.DurationMinValue.JsonOutput
Required.Proto3.JsonInput.DurationMinValue.ProtobufOutput
Required.Proto3.JsonInput.EmptyFieldMask.JsonOutput
Required.Proto3.JsonInput.EmptyFieldMask.ProtobufOutput
Required.Proto3.JsonInput.EnumFieldUnknownValue.Validator
Required.Proto3.JsonInput.EnumFieldWithAliasDifferentCase.JsonOutput
Required.Proto3.JsonInput.EnumFieldWithAliasDifferentCase.ProtobufOutput
Required.Proto3.JsonInput.EnumFieldWithAliasLowerCase.JsonOutput
Required.Proto3.JsonInput.EnumFieldWithAliasLowerCase.ProtobufOutput
Required.Proto3.JsonInput.EnumFieldWithAliasUseAlias.JsonOutput
Required.Proto3.JsonInput.EnumFieldWithAliasUseAlias.ProtobufOutput
Required.Proto3.JsonInput.FieldMask.JsonOutput
Required.Proto3.JsonInput.FieldMask.ProtobufOutput
Required.Proto3.JsonInput.OneofFieldDuplicate
Required.Proto3.JsonInput.RepeatedListValue.JsonOutput
Required.Proto3.JsonInput.RepeatedListValue.ProtobufOutput
Required.Proto3.JsonInput.RepeatedValue.JsonOutput
Required.Proto3.JsonInput.RepeatedValue.ProtobufOutput
Required.Proto3.JsonInput.Struct.JsonOutput
Required.Proto3.JsonInput.Struct.ProtobufOutput
Required.Proto3.JsonInput.StructWithEmptyListValue.JsonOutput
Required.Proto3.JsonInput.StructWithEmptyListValue.ProtobufOutput
Required.Proto3.JsonInput.TimestampJsonInputLowercaseT
Required.Proto3.JsonInput.TimestampJsonInputLowercaseZ
Required.Proto3.JsonInput.TimestampJsonInputMissingT
Required.Proto3.JsonInput.TimestampJsonInputMissingZ
Required.Proto3.JsonInput.TimestampJsonInputTooSmall
Required.Proto3.JsonInput.ValueAcceptBool.JsonOutput
Required.Proto3.JsonInput.ValueAcceptBool.ProtobufOutput
Required.Proto3.JsonInput.ValueAcceptFloat.JsonOutput
Required.Proto3.JsonInput.ValueAcceptFloat.ProtobufOutput
Required.Proto3.JsonInput.ValueAcceptInteger.JsonOutput
Required.Proto3.JsonInput.ValueAcceptInteger.ProtobufOutput
Required.Proto3.JsonInput.ValueAcceptList.JsonOutput
Required.Proto3.JsonInput.ValueAcceptList.ProtobufOutput
Required.Proto3.JsonInput.ValueAcceptNull.JsonOutput
Required.Proto3.JsonInput.ValueAcceptNull.ProtobufOutput
Required.Proto3.JsonInput.ValueAcceptObject.JsonOutput
Required.Proto3.JsonInput.ValueAcceptObject.ProtobufOutput
Required.Proto3.JsonInput.ValueAcceptString.JsonOutput
Required.Proto3.JsonInput.ValueAcceptString.ProtobufOutput
Required.Proto3.ProtobufInput.UnknownVarint.ProtobufOutput
Required.TimestampProtoInputTooLarge.JsonOutput
Required.TimestampProtoInputTooSmall.JsonOutput
60 changes: 18 additions & 42 deletions conformance/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,53 +49,33 @@ fn main() -> io::Result<()> {
}

fn handle_request(request: ConformanceRequest) -> conformance_response::Result {
match request.requested_output_format() {
WireFormat::Unspecified => {
let rof = request.requested_output_format();
match (rof, request.payload.as_ref()) {
(WireFormat::Unspecified, _) | (_, None) => {
return conformance_response::Result::ParseError(
"output format unspecified".to_string(),
"input/output format unspecified".to_string(),
);
}
WireFormat::Json => {
(WireFormat::Jspb, _) | (_, Some(conformance_request::Payload::JspbPayload(_))) => {
return conformance_response::Result::Skipped(
"JSON output is not supported".to_string(),
"JSPB input/output is not supported".to_string(),
);
}
WireFormat::Jspb => {
(WireFormat::TextFormat, _) | (_, Some(conformance_request::Payload::TextPayload(_))) => {
return conformance_response::Result::Skipped(
"JSPB output is not supported".to_string(),
"TEXT_FORMAT input/output is not supported".to_string(),
);
}
WireFormat::TextFormat => {
return conformance_response::Result::Skipped(
"TEXT_FORMAT output is not supported".to_string(),
);
}
WireFormat::Protobuf => (),
(WireFormat::Protobuf, _) | (WireFormat::Json, _) => (),
};

let buf = match request.payload {
None => return conformance_response::Result::ParseError("no payload".to_string()),
Some(conformance_request::Payload::JsonPayload(_)) => {
return conformance_response::Result::Skipped(
"JSON input is not supported".to_string(),
);
}
Some(conformance_request::Payload::JspbPayload(_)) => {
return conformance_response::Result::Skipped(
"JSON input is not supported".to_string(),
);
let result = match (&*request.message_type, request.payload) {
("protobuf_test_messages.proto2.TestAllTypesProto2", Some(payload)) => {
roundtrip::<TestAllTypesProto2>(payload, rof)
}
Some(conformance_request::Payload::TextPayload(_)) => {
return conformance_response::Result::Skipped(
"JSON input is not supported".to_string(),
);
("protobuf_test_messages.proto3.TestAllTypesProto3", Some(payload)) => {
roundtrip::<TestAllTypesProto3>(payload, rof)
}
Some(conformance_request::Payload::ProtobufPayload(buf)) => buf,
};

let roundtrip = match &*request.message_type {
"protobuf_test_messages.proto2.TestAllTypesProto2" => roundtrip::<TestAllTypesProto2>(&buf),
"protobuf_test_messages.proto3.TestAllTypesProto3" => roundtrip::<TestAllTypesProto3>(&buf),
_ => {
return conformance_response::Result::ParseError(format!(
"unknown message type: {}",
Expand All @@ -104,13 +84,9 @@ fn handle_request(request: ConformanceRequest) -> conformance_response::Result {
}
};

match roundtrip {
RoundtripResult::Ok(buf) => conformance_response::Result::ProtobufPayload(buf),
RoundtripResult::DecodeError(error) => {
conformance_response::Result::ParseError(error.to_string())
}
RoundtripResult::Error(error) => {
conformance_response::Result::RuntimeError(error.to_string())
}
match result {
RoundtripResult::Ok(result) => result,
RoundtripResult::DecodeError(error) => conformance_response::Result::ParseError(error),
RoundtripResult::Error(error) => conformance_response::Result::RuntimeError(error),
}
}
Loading