Commit Graph

331 Commits

Author SHA1 Message Date
Jan Tattermusch
73c003c309 Merge pull request #1089 from jskeet/map-null
Prohibit null values in maps
2016-01-12 20:55:47 -08:00
Dongjoon Hyun
7b08d49e9d Fix typos in README.md/CHANGES.txt 2016-01-11 14:52:01 -08:00
Jon Skeet
9e4f354f14 Prohibit null values in map fields
On deserialization, missing values for message types
are replaced with a "default" message.
2016-01-11 09:34:43 +00:00
Jan Tattermusch
6d1d415133 Merge pull request #1098 from jskeet/wkt-json
Ensure all formatted well-known-type values are valid JSON
2016-01-08 16:58:47 -08:00
Jan Tattermusch
698f61688c Merge pull request #1088 from jskeet/codec-pruning
Remove unused method in FieldCodec.
2016-01-08 16:50:05 -08:00
Jon Skeet
b4a58173f2 Ensure all formatted well-known-type values are valid JSON
This involves quoting timestamp/duration/field-mask values, even when they're not in fields.
It's better for consistency.

Fixes issue #1097.
2016-01-06 12:05:31 +00:00
Jon Skeet
aa431a0481 Improve number handling in JSON parsing
- Tighten up on Infinity/NaN handling in terms of whitespace handling (and test casing)
- Validate that values are genuinely integers when they've been parsed from a JSON number (ignoring the fact that 1.0000000000000000001 == 1 as a double...)
- Allow exponents and decimal points in string representations
2016-01-06 11:16:10 +00:00
Jon Skeet
9f10c4576a Remove unused method in FieldCodec.
(The method was last used a very long time ago, if ever.)
2016-01-05 14:36:14 +00:00
Jon Skeet
d49b9c81ec Fix C# source generation shell script and remove out of date notes
The conformance tests now use types which are part of src/google/protobuf, so we need to include src in the proto path.
The notes around "fix-ups" have been out of date for some time now.
2016-01-04 14:02:00 +00:00
Jan Tattermusch
00ace95ae3 add reference generator dependency 2015-12-17 09:37:56 -08:00
Jon Skeet
afbc89a263 Merge pull request #1049 from jskeet/any-format
Handle Any formatting for diagnostic purposes
2015-12-17 13:10:16 +00:00
Jan Tattermusch
33106681a5 Merge pull request #1051 from jtattermusch/support_coreclr
Make nuget package support coreCLR
2015-12-16 13:14:02 -08:00
Jan Tattermusch
52139f9fde make nuget package support CoreCLR 2015-12-16 09:21:09 -08:00
Jon Skeet
a4dc5968b1 Add JSON parsing to conformance tests. 2015-12-16 08:58:58 +00:00
Jon Skeet
adee6fe332 Generated code changes from previous commit. 2015-12-15 09:24:04 +00:00
Jon Skeet
aabc6c411a Make ToString() valid without a type registry
This addresses issue #1008, by creating a JsonFormatter which is private and only different
to JsonFormatter.Default in terms of reference equality.

Other plausible designs:

- The same, but expose the diagnostic-only formatter
- Add something to settings to say "I don't have a type registry at all"
- Change the behaviour of JsonFormatter.Default (bad idea IMO, as we really *don't* want the result of this used as regular JSON to be parsed)

Note that just trying to find a separate fix to issue #933 and using that to override Any.ToString() differently wouldn't work for messages that *contain* an Any.

Generated code changes follow in the next commit.
2015-12-15 09:23:38 +00:00
Jon Skeet
3de2fced6b Handle JSON parsing for Any.
This required a rework of the tokenizer to allow for a "replaying" tokenizer, basically in case the @type value comes after the data itself. This rework is nice in some ways (all the pushback and object depth logic in one place) but is a little fragile in terms of token push-back when using the replay tokenizer. It'll be fine for the scenario we need it for, but we should be careful...
2015-12-02 07:54:34 +00:00
Jon Skeet
567579b505 JSON formatting for Any. 2015-12-02 07:26:55 +00:00
Jon Skeet
a2667aafd8 Generated code changes for previous commit (basically InternalBuildGeneratedFileFrom => FromGeneratedCode) 2015-11-22 16:30:36 +00:00
Jon Skeet
72ec33676f Tidy up reflection in advance of attempting to implement DynamicMessage.
There are corner cases where MessageDescriptor.{ClrType,Parser} will return null, and these are now documented. However, normally they *should* be implemented, even for descriptors of for dynamic messages. Ditto FieldDescriptor.Accessor.
We'll still need a fair amount of work to implement dynamic messages, but this change means that the public API will be remain intact.

Additionally, this change starts making use of C# 6 features in the files that it touches. This is far from exhaustive, and later PRs will have more.

Generated code changes coming in the next commit.
2015-11-22 16:25:44 +00:00
Jon Skeet
f7e43c6f80 Added the type registry in advance of implementing Any support.
Biting off just this bit first as I don't need the changes from a previous PR for this part.
2015-11-21 03:34:58 +00:00
Jan Tattermusch
956a770adc Merge pull request #988 from gabikliot/CSharp-SampleUsage-Big-Fix
Fixed a bug in CSharp SampleUsage.
2015-11-19 20:02:18 -08:00
Gabriel Kliot
bdec990703 Removed redundant comment. 2015-11-19 08:05:05 -08:00
Jon Skeet
360feda5f7 Finished an implementation comment 2015-11-19 09:40:49 +00:00
Jon Skeet
eadd4caa09 Generated code from previous commit. 2015-11-19 09:38:49 +00:00
Jon Skeet
2a15051a1e Introduce a Parser property into MessageDescriptor, and populate it from generated types.
Generated code coming in next commit - in a subsequent PR I want to do a bit of renaming and redocumenting around this, in anticipation of DynamicMessage.
2015-11-19 08:50:28 +00:00
Gabriel Kliot
09d03dfc7e Fixed a bug in CSharp SampleUsage. 2015-11-18 23:09:05 -08:00
Jon Skeet
284bb452e4 Generated code changes and manual changes for previous commit. 2015-11-09 09:22:45 +00:00
Jon Skeet
cff900e8f9 Generated code for previous commit. 2015-11-06 18:38:31 +00:00
Jan Tattermusch
ffe25c76ea Merge pull request #941 from jskeet/recursion-limit
Add recursion limit handling to JSON parsing.
2015-11-05 18:41:05 -08:00
Jon Skeet
6fa17e7597 Reimplement JSON recursion by detecting the depth in the tokenizer.
Added a TODO around a possible change to the tokenizer API, changing PushBack(token) into just Rewind() or something similar.
2015-11-05 19:44:26 +00:00
Jon Skeet
3a72a1eeaf Merge pull request #940 from jskeet/json-names
Move the creation of the "fields by JSON name" dictionary to the descriptor
2015-11-05 17:09:37 +00:00
Jon Skeet
0fb39c4afe Created a new exception for JSON failures.
This is only thrown directly by JsonTokenizer, but surfaces from JsonParser as well. I've added doc comments to hopefully make everything clear.

The exception is actually thrown by the reader within JsonTokenizer, in anticipation of keeping track of the location within the document, but that change is not within this PR.
2015-11-05 10:40:22 +00:00
Jon Skeet
3d257a9dc1 Add recursion limit handling to JSON parsing.
Fixes issue #932.
2015-11-04 11:30:22 +00:00
Jon Skeet
6a94273549 Move the creation of the "fields by JSON name" dictionary to the descriptor. 2015-11-04 09:09:14 +00:00
Jon Skeet
fb2488225f Implement JSON parsing in C#.
This includes all the well-known types except Any.
Some aspects are likely to require further work when the details of the JSON parsing expectations are hammered out in more detail. Some of these have "ignored" tests already.

Note that the choice *not* to use Json.NET was made for two reasons:
- Going from 0 dependencies to 1 dependency is a big hit, and there's not much benefit here
- Json.NET parses more leniently than we'd want; accommodating that would be nearly as much work as writing the tokenizer
This only really affects the JsonTokenizer, which could be replaced by Json.NET. The JsonParser code would be about the same length with Json.NET... but I wouldn't be as confident in it.
2015-11-03 19:05:11 +00:00
Jon Skeet
885406abcf Make BytesString.Unsafe internal (which it should have been all along) 2015-11-02 09:59:06 +00:00
Jon Skeet
f5a0a7feeb Fix clearing wrapper type fields with reflection.
The nullable value type fields already worked, but the use of the CLR property concealed the difference between string and StringWrapper fields.
2015-10-30 09:37:01 +00:00
Jon Skeet
55313c9c5d Generated code for previous commit (oneof case contributing to hash code and equality). 2015-10-24 06:46:02 +01:00
Jon Skeet
964627ece0 Include the oneof-case in equality and hash code generated code.
The included C# test will fail until the regenerated code is used, which is in the next commit.
2015-10-24 06:45:20 +01:00
Jon Skeet
c34ed5c9bf Merge pull request #846 from jskeet/tostring
Support ToString in RepeatedField and MapField.
2015-10-07 17:08:25 +01:00
Jon Skeet
9ed6d4da37 Support ToString in RepeatedField and MapField.
This changes how we approach JSON formatting in general - instead of looking  at the field a value came from, we just look at the type of the value. It's possible this *could* be slightly inefficient, but if we start caring about JSON performance deeply, we'll probably want to rewrite all of this anyway. It's definitely simpler this way.

When we support dynamic messages, we'll need to modify JsonFormatter to handle enum values, as they won't come be "real" .NET enums at that point. It shouldn't be hard to do though.
2015-10-01 13:07:47 +01:00
Jon Skeet
18e0a2e5ec Generated code from previous commit. 2015-10-01 10:38:01 +01:00
Jon Skeet
6bbbdfa24c Fix typo in oneof case enum comment 2015-09-30 06:59:38 +01:00
Jon Skeet
e2c823027e Generated code changes for previous commit. 2015-09-29 14:34:31 +01:00
Jon Skeet
b0888a42ad Generated code for previous commit 2015-09-29 13:37:30 +01:00
Jon Skeet
2212f56bcd Added documentation to generated code.
There are now summaries for:
- The Types nested class (which holds nested types)
- The file descriptor class for each proto
- The enum generated for each oneof

(Also fixed two typos.)

Generated code in next commit.
2015-09-29 13:37:15 +01:00
Jan Tattermusch
97a1c1e08d Merge pull request #785 from jskeet/csharp-directories
Generate C# directory hierarchy with new option
2015-09-23 14:31:31 -07:00
Jon Skeet
e50461d809 Pack/Unpack implementation for Any.
We still need the JSON representation, which relies on something like a DescriptorPool to fetch message types from based on the type URL. That will come a bit later.
(The DescriptorPool comment in this commit is just a note which will prove useful if we use DescriptorPool itself.)
2015-09-04 12:43:26 +01:00
Jon Skeet
9489817df2 Regenerated code. Most changes are whitespace, removing trailing spaces.
Other changes are due to the well-known types changing without us regenerating.
2015-09-01 15:47:48 +01:00