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

Refactor JSON support to make kotlinx-serialization an internal dependency of pbandk #61

Closed
garyp opened this issue Jun 18, 2020 · 0 comments · Fixed by #69
Closed

Refactor JSON support to make kotlinx-serialization an internal dependency of pbandk #61

garyp opened this issue Jun 18, 2020 · 0 comments · Fixed by #69
Assignees
Milestone

Comments

@garyp
Copy link
Collaborator

garyp commented Jun 18, 2020

Nice to have with this refactor:

  • Support runtime configuration of camelCase vs snake_case field names
  • Support runtime configuration of which default values to output
@garyp garyp self-assigned this Jun 18, 2020
@garyp garyp added this to the 1.0 milestone Jun 19, 2020
garyp added a commit that referenced this issue Aug 11, 2020
* Rewrote JSON support to better implement the proto3 JSON spec. This
includes support for the `json_name` protobuf option.

* Added `JsonConfig` class that can be used for configuring JSON
marshalling/unmarshalling at runtime. Currently supported configuration
includes `ignoreUnknownFieldsInInput`, `outputDefaultValues`, and
`outputProtoFieldNames`, which match the options described at
https://developers.google.com/protocol-buffers/docs/proto3#json_options.

* Got rid of the need for projects using `pbandk` to use the
`kotlinx-serialization` gradle plugin and add a dependency on the
`kotlinx-serialization` library. The library is now an internal
implementation detail of `pbandk`.

* Moved all of the binary marshalling functionality and most of the
binary unmarshalling functionality from the generated code to the
runtime library.

* Added `protoMarshal(OutputStream)`, `protoUnmarshal(InputStream)`, and
`protoUnmarshal(ByteBuffer)` overloads on the JVM.

* Fixed some bugs with handling of `packed` fields, marshalling
of enums in Javascript, and base64 encoding/decoding in Javascript.

Breaking API changes:

* Changed `Message` so that it no longer needs to extend from itself.

* Added `@PbandkInternal` and `@PublicForGeneratedCode` annotations on
relevant portions of the public API that are only public for pbandk's
internal use.

* The below methods are now defined as extension methods rather than
being part of the `Message` interface. Code that calls these methods
will now need to import them first.

    * `Message.jsonMarshal()`
    * `Message.Companion.jsonUnmarshal(String)`
    * `Message.protoMarshal()`
    * `Message.Companion.protoUnmarshal(ByteArray)`

* These two method overloads:

    * `Message.jsonMarshal(kotlinx.serialization.json.Json)`
    * `Message.Companion.jsonUnmarshal(kotlinx.serialization.json.Json, String)`

    have been replaced with:

    * `Message.jsonMarshal(pbandk.json.JsonConfig)`
    * `Message.Companion.jsonUnmarshal(String, pbandk.json.JsonConfig)`

* These two method overloads:

    * `Message.protoMarshal(pbandk.Marshaller)`
    * `Message.Companion.protoUnmarshal(pbandk.Unmarshaller)`

    have been replaced with:

    * `Message.marshal(pbandk.MessageMarshaller)`
    * `Message.Companion.unmarshal(pbandk.MessageUnmarshaller)`

* Replaced `Marshaller` and `Unmarshaller` interfaces with
`MessageMarshaller` and `MessageUnmarshaller`, which are much simpler
and function differently from the previous interfaces.

* Removed `Sizer` and `Util` from the public API.

* Removed `UnknownField` constructors and the `UnknownField.size()`
method from the public API.

* `MessageMap.entries` is now a `Set` instead of a `List`.

Fixes #23, fixes #61. Portions of the proto3 JSON spec that still need
to be implemented are tracked in #72.
garyp added a commit that referenced this issue Aug 12, 2020
* Rewrote JSON support to better implement the proto3 JSON spec. This
includes support for the `json_name` protobuf option.

* Added `JsonConfig` class that can be used for configuring JSON
marshalling/unmarshalling at runtime. Currently supported configuration
includes `ignoreUnknownFieldsInInput`, `outputDefaultValues`, and
`outputProtoFieldNames`, which match the options described at
https://developers.google.com/protocol-buffers/docs/proto3#json_options.

* Got rid of the need for projects using `pbandk` to use the
`kotlinx-serialization` gradle plugin and add a dependency on the
`kotlinx-serialization` library. The library is now an internal
implementation detail of `pbandk`.

* Moved all of the binary marshalling functionality and most of the
binary unmarshalling functionality from the generated code to the
runtime library.

* Added `protoMarshal(OutputStream)`, `protoUnmarshal(InputStream)`, and
`protoUnmarshal(ByteBuffer)` overloads on the JVM.

* Fixed some bugs with handling of `packed` fields, marshalling
of enums in Javascript, and base64 encoding/decoding in Javascript.

Breaking API changes:

* Changed `Message` so that it no longer needs to extend from itself.

* Added `@PbandkInternal` and `@PublicForGeneratedCode` annotations on
relevant portions of the public API that are only public for pbandk's
internal use.

* The below methods are now defined as extension methods rather than
being part of the `Message` interface. Code that calls these methods
will now need to import them first.

    * `Message.jsonMarshal()`
    * `Message.Companion.jsonUnmarshal(String)`
    * `Message.protoMarshal()`
    * `Message.Companion.protoUnmarshal(ByteArray)`

* These two method overloads:

    * `Message.jsonMarshal(kotlinx.serialization.json.Json)`
    * `Message.Companion.jsonUnmarshal(kotlinx.serialization.json.Json, String)`

    have been replaced with:

    * `Message.jsonMarshal(pbandk.json.JsonConfig)`
    * `Message.Companion.jsonUnmarshal(String, pbandk.json.JsonConfig)`

* These two method overloads:

    * `Message.protoMarshal(pbandk.Marshaller)`
    * `Message.Companion.protoUnmarshal(pbandk.Unmarshaller)`

    have been replaced with:

    * `Message.marshal(pbandk.MessageMarshaller)`
    * `Message.Companion.unmarshal(pbandk.MessageUnmarshaller)`

* Replaced `Marshaller` and `Unmarshaller` interfaces with
`MessageMarshaller` and `MessageUnmarshaller`, which are much simpler
and function differently from the previous interfaces.

* Removed `Sizer` and `Util` from the public API.

* Removed `UnknownField` constructors and the `UnknownField.size()`
method from the public API.

* `MessageMap.entries` is now a `Set` instead of a `List`.

Fixes #23, fixes #61. Portions of the proto3 JSON spec that still need
to be implemented are tracked in #72.
@garyp garyp closed this as completed in #69 Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant