-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add support for ByteString #62
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, and thank you for your contribution. I appreciate your efforts.
However, I've encountered an issue with the changes you've made. When I uncomment the following lines:
Protobuf.System.Text.Json/test/Protobuf.System.Text.Json.Tests/Protos/simple_message.proto
Line 35 in 3f9a181
// bytes bytes_property = 15; |
Protobuf.System.Text.Json/test/Protobuf.System.Text.Json.Tests/SimpleMessageTests.cs
Line 33 in 3f9a181
// BytesProperty = ByteString.CopyFromUtf8("abc") |
I'm getting different results than expected:
The output I get differs from what's expected. Specifically, I see:
"bytesProperty":[97,98,99]
when I anticipate:
"bytesProperty": "YWJj"
Furthermore, during the deserialization test, I'm getting the exception:
System.NotSupportedException: The collection type 'Google.Protobuf.ByteString' is abstract, an interface, or is read only, and could not be instantiated and populated. Path: $ | LineNumber: 0 | BytePositionInLine: 299.
---> System.NotSupportedException: The collection type 'Google.Protobuf.ByteString' is abstract, an interface, or is read only, and could not be instantiated and populated.
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ThrowNotSupportedException(ReadStack& state, Utf8JsonReader& reader, NotSupportedException ex)
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_CannotPopulateCollection(Type type, Utf8JsonReader& reader, ReadStack& state)
at System.Text.Json.Serialization.Converters.IEnumerableOfTConverter`2.CreateCollection(Utf8JsonReader& reader, ReadStack& state, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonCollectionConverter`2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonResumableConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at Protobuf.System.Text.Json.InternalConverters.FieldConverter`1.Read(Utf8JsonReader& reader, IMessage obj, Type typeToConvert, JsonSerializerOptions options, IFieldAccessor fieldAccessor) in /Users/krzysztofporebski/git/Protobuf.System.Text.Json/src/Protobuf.System.Text.Json/InternalConverters/FieldConverter.cs:line 22
at Protobuf.System.Text.Json.ProtobufConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) in /Users/krzysztofporebski/git/Protobuf.System.Text.Json/src/Protobuf.System.Text.Json/ProtobufConverter.cs:line 110
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
Thanks for your feedback. I was aware that it was a naive approach, and the only reason it worked in my use case was probably because the ByteString was only in the contract but not in the instances I worked with. Great to see that tests were already waiting. I've added a ByteString converter and added use of it, and now the ByteString tests pass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works for the base case. While further work is needed to handle all cases (see link), I believe we can merge this now and address additional concerns in separate PRs.
This aims to fix issue #5 by supporting the
Google.Protobuf.ByteString
type inFieldTypeResolver
.Furthermore, the error message for unsupported field types has been improved. It now prints the name of the unsupported field type, rather than the name of the
FieldDescriptor
type.Keep in mind that I'm not all too experienced with Protobuf, so I don't know if this fixes the entire issue or if there's more to it, but it has been verified to fix my use case.
Note also that I'm well aware of the lack of testing, but unfortunately, I'm very restricted on my work PC, and so am unable to generate anything new.