Commit Graph

101 Commits

Author SHA1 Message Date
Paul MARS
59b3d97f6d Reserve extension id for protoc-gen-psql & protoc-gen-sanitize 2021-02-05 10:34:04 -08:00
brucearctor
6c970b5a05 Update options.md - Added 'Astounding' Project 2020-12-28 13:44:56 -08:00
Nadav Samet
9637a3b57c Allocate extension 1089 to ScalaPB validate
ScalaPB validate is a sub-package of ScalaPB that allows user to generate data validation code for ScalaPB generated classes.
2020-12-01 15:53:51 -08:00
Nadav Samet
b5d2cc08f1 Update scalapb URL and fix typo in name 2020-11-02 12:45:58 -08:00
Robert Yokota
300dfcc5bf Reserve 1088 for Confluent Schema Registry 2020-09-25 11:12:03 -07:00
James Brock
c2d089e413 Add Purescript protobuf to third-party list 2020-09-18 10:26:39 -07:00
Peter Newman
e2cc2de304
Fix lots of spelling errors (#7751)
* Fix a typo

* Fix lots of spelling errors

* Fix a few more spelling mistakes

* s/parsable/parseable/

* Don't touch the third party files

* Cloneable is the preferred C# term

* Copyable is the preferred C++ term

* Revert "s/parsable/parseable/"

This reverts commit 534ecf7675.

* Revert unparseable->unparsable corrections
2020-08-10 11:08:25 -07:00
Benoît Quenaudon
8d74659c7a Reserve 1087 for Wire wire_package
release notes: no
2020-08-10 10:19:56 -07:00
Nikolai Vavilov
6b73371e7d Update third_party.md
Add a library that helps develop protoc plugins in Node.js, and an example plugin that can serve as a template for alternative generators.
2020-08-10 10:14:55 -07:00
Jeremy Volkman
963ead3e37 [docs] Update IntelliJ plugin link
The previously-linked project hasn't been updated for years.
2020-08-10 10:13:28 -07:00
yohei yoshimuta
36d39a0266
Add parser and linter libraries to third party docs (#6474)
* Add Protobuf parser and linter

* chore: Add some third-party tools
2020-08-05 14:40:51 -07:00
Jon Godbout
8e09396ba1 Update third_party.md
Common Lisp: 
http://github.com/ndantam/s-protobuf  hasn't been updated in 5 years, and hasn't had a real update in 8.
http://github.com/qitab/cl-protobuf is the one used internally and maintained by Googlers (third_party/lisp/cl-protobufs) though I don't know
how to or if I should express that.
2020-07-27 10:21:56 -07:00
Alexandre Hamez
2676f4dcc5 Add third-party Elixir library 2020-06-19 10:38:58 -07:00
Bart Hertog
2655a0aa0f Added Embedded Proto to third_party.md. 2020-06-08 11:12:51 -07:00
Joshua Haberman
9952e36f92
Merge release branch into master. (#7517)
* Added background information about proto3 presence. (#7501)

* Fixed bug in map key sorting for Java TextFormat. (#7508)

Fixes: https://github.com/protocolbuffers/protobuf/issues/7505

* Update protobuf version

* Added a changelog entry about the Java fix. (#7516)
2020-05-16 16:42:02 -07:00
Greg Steuck
4059c61f27
Typo in 'disciplines' (#7423) 2020-04-27 08:21:52 -07:00
Joshua Haberman
7eddac7877
Added some info about Reflection, and a note about timeline. (#7416)
* Added some info about Reflection, and a note about timeline.

* Fixed heading levels.

* A bit more info.
2020-04-23 14:33:53 -07:00
Joshua Haberman
fda8544a59
Howto doc for implementing proto3 presence in a code generator. (#7407) 2020-04-23 13:00:30 -07:00
David L. Jones
e48c92952d
Add application note for explicit presence tracking. (#7390)
This includes instructions for enabling explicit presence tracking in proto3, and also explains implicit presence. The language examples were written by inspection, and not individually tested.
2020-04-23 12:59:51 -07:00
Daniel G. Taylor
97f5f649a4 docs: add python-betterproto
Adds the `betterproto` Python module to the list of implementations.
2020-04-16 09:22:52 -07:00
Adam Cozzette
cf601047eb Allocated option number 1086 for ADLINK EdgeSDK
Fixes #7339.
2020-04-02 09:07:16 -07:00
Robert Morris
a015ca8cf8
Request SummaFT extension (#7314)
SummaFT develops a protoc plugin for both internal and external use that allows specific extensions to be made to extend the platform for GraphQL and OpenAPI 3.
2020-03-19 14:20:01 -07:00
James Roper
ab968155e5 Add Cloudstate extensions 2020-03-19 08:40:39 -07:00
Adam Cozzette
a80775c391 Allocated extension number 1079 for grpc-graphql-gateway
Fixes issue #7302.
2020-03-17 08:27:19 -07:00
Mark Schaller
88579a44fb Reserve extension for Bazel failure detail metadata
The Bazel project (https://github.com/bazelbuild/bazel) intends to
enrich its server app's (protobuf-defined) command service's status
message with a structured representation of what, if anything, went
wrong while processing a command. We wish to use custom options to add
metadata to the protobuf constructs involved.

release notes: no
2020-02-25 14:40:36 -08:00
Maxime Guerreiro
158b269097 Cleanup the RPC Implementations section
Remove dead links and update the ones that were moved.

Use https when possible.

Isolate inactive projects (not updated in the last few years) in a subsection.

release notes: no
2020-01-17 16:08:02 -08:00
Jesse Wilson
6263268b8c Reserve 1076, 1077 for Wire since and until
release notes: no
2019-12-17 10:27:25 -08:00
Adam Cozzette
16b0c054a1 Allocated a custom option number for Analyze Re Graphene 2019-12-06 10:33:25 -08:00
Florian Enner
2220670ed9 Added 3rd party Java library (QuickBuffers) 2019-12-05 10:48:35 -08:00
Adam Cozzette
403df1d047 Added a descriptor option number for ocaml-protoc-plugin 2019-10-29 14:34:50 -07:00
Sigurd Meldgaard
f4a3e06101 Add option for dart 2019-09-27 14:41:42 -07:00
Marco Ferrer
580f585f58 add kotlin kroto plus 2019-09-12 09:33:22 -07:00
Erik Moqvist
d5fbdb45b0 Added pbtools to third party implementations list. 2019-09-11 09:54:01 -07:00
Mathias LANG
c656d76894
Remove duplicate entry in third party list
On the linked Wiki page, it can be seen that the creator is `opticron`, whose Github repository is also linked, and contains a more up-to-date implementation.
2019-09-07 21:38:22 +09:00
Gregory Haskins
5102df2904 Add Protojure to third-party wiki (#6554)
This adds links under the Clojure header to

https://protojure.github.io

Signed-off-by: Greg Haskins <gregory.haskins@gmail.com>
2019-09-03 16:29:53 -07:00
Sydney Acksman
c920715cf5
Remove wording indicating proto2 support is reimplemented 2019-09-03 04:24:46 -05:00
Sydney Acksman
c9a9818075
Update proto2.md
Reworded info about message initialization
2019-09-02 18:05:33 -05:00
Sydney Acksman
7feb16a377
Update proto2.md
Addressed review comments
2019-09-02 18:00:15 -05:00
Sydney Acksman
54a3d8e7ef Add proto2 doc 2019-08-13 03:50:12 -05:00
Ben Gordon
f5362e11fd
Requesting extension id 1072
This library supports an idiomatic proto3 protobuf generator for kotlin.
The library will be open sourced by Toast Inc under the Apache2 license, and is currently used in production at Toast.
The following is the readme.md that will be released with the code by the end of Q4 2019.

Supports only the Protocol Buffers language version 3.

#### Features
- Clean data class generation
- Oneof types handled as sealed classes
- JavaDoc comments on generated code
- Deprecation option pass-through to Kotlin's `@Deprecated` annotation
- Protokt-specific options: non-null types, wrapper types, interface implementation,
and more
- Tight integration with Protobuf's Java library: compatibility with its well-known
types and usage of CodedInputStream and CodedOutputStream for best performance

#### Not yet implemented
- Kotlin native support
- Kotlin JS support
- Support for gRPC service generation
- Protobuf JSON support

See examples in [protokt-testing](https://github.com/toasttab/protokt/tree/master/protokt-testing).

### Generated Code
Generated code is placed in `<buildDir>/generated-sources/main/protokt`.

A simple example:
```proto
syntax = "proto3";

package com.protokt.sample;

message Sample {
  string sample_field = 1;
}
```

will produce:
```kotlin
/*
 * Generated by protokt. Do not modify.
 */
package com.protokt.sample

import com.toasttab.protokt.rt.*

data class Sample(
    val sampleField: String,
    val unknown: Map<Int, Unknown> = emptyMap()
) : KtMessage {
    @Suppress("UNUSED")
    constructor(
        sampleField: String = ""
    ) : this(
        sampleField,
        emptyMap()
    )

    override val messageSize by lazy { sizeof() }

    override fun serialize(serializer: KtMessageSerializer) {
        if (sampleField.isNotEmpty()) {
            serializer.write(Tag(10)).write(sampleField)
        }
        if (unknown.isNotEmpty()) {
            serializer.writeUnknown(unknown)
        }
    }

    private fun sizeof(): Int {
        var res = 0
        if (sampleField.isNotEmpty()) {
            res += sizeof(Tag(1)) + sizeof(sampleField)
        }
        res += unknown.entries.sumBy { it.value.sizeof() }
        return res
    }

    companion object Deserializer : KtDeserializer<Sample> {
        override fun deserialize(deserializer: KtMessageDeserializer): Sample {
            var sampleField = ""
            val unknown = mutableMapOf<Int, Unknown>()
            while (true) {
                when (deserializer.readTag()) {
                    0 ->
                        return Sample(
                            sampleField,
                            unknown
                        )
                    10 -> sampleField = deserializer.readString()
                    else -> {
                        val unk = deserializer.readUnknown()
                        unknown[unk.fieldNum] = unknown[unk.fieldNum].let {
                            when (it) {
                                null -> unk
                                else ->
                                    when (val v = it.value) {
                                        is ListVal ->
                                            Unknown(unk.fieldNum, ListVal(v.value + unk.value))
                                        else ->
                                            Unknown(unk.fieldNum, ListVal(listOf(v, unk.value)))
                                    }
                            }
                        }
                    }
                }
            }
        }
    }
}
```

#### Runtime Notes
##### Package
The Kotlin package of a generated file can be overridden from protobuf package with the `(protokt).package` option:
```proto
syntax = "proto3";

import "protokt.proto";

package com.example;

option (protokt).package = "com.package";
```

##### Message
Each protokt message implements the `KtMessage` interface. `KtMessage` defines the `serialize()`
method and its overloads which can serialize to a byte array, a `KtMessageSerializer`, or on the JVM,
an `OutputStream`.

Each protokt message has a companion object `Deserializer` that implements the `KtDeserializer`
interface, which provides the `deserialize()` method and its overloads to construct an
instance of the message from a byte array, a Java InputStream, or others.

In order to enjoy the full benefits of Kotlin data classes, byte arrays are wrapped in the
protokt `Bytes` class, which provides appropriate `equals()` and `hashCode()` implementations.

##### Enums
Enum fields are generated as data classes with a single integer field. Kotlin enum classes are
closed and cannot retain unknown values, and protobuf requires that unknown enum values are
preserved for reserialization. This compromise exposes a constructor taking an integer, but the
`from(value: Int)` on an enum's `Deserializer` should be preferred as it avoids instantiation
when possible.


Other notes:
- `optimize_for` is ignored.
- `repeated` fields are deserialized to Lists.
- `map` fields are deserialized to Maps.
- `oneof` fields are represented as data class subtypes of a sealed base class with a single property.

### Extensions
See examples of each option in the [protokt-options](https://github.com/toasttab/protokt/tree/master/protokt-testing/protokt-options/src/main/proto)
module. All protokt-specific options require importing `protokt.proto` in the protocol file.
#### Wrapper Types
Sometimes a field on a protobuf message corresponds to a concrete nonprimitive type. In
standard protobuf the user would be responsible for this extra transformation, but the
protokt wrapper type option allows specification of a converter that will automatically
encode and decode custom types to protobuf primitives and well-known types. Some standard
types are implemented in
[protokt-extensions](https://github.com/toasttab/protokt/tree/master/protokt-extensions/src/main/kotlin/com/toasttab/protokt/ext).

Wrap a field by invoking the `(protokt_property).wrap` option:
```proto
message DateWrapperMessage {
  int64 date = 1 [
    (protokt_property).wrap = "java.util.Date"
  ];
}
```

Converters implement the `Converter` interface:
```kotlin
interface Converter<S: Any, T: Any> {
    val wrapper: KClass<S>

    fun wrap(unwrapped: T): S

    fun unwrap(wrapped: S): T
}
```

and protokt will reference the converter's methods to wrap and unwrap from protobuf primitives:
```kotlin
object DateConverter : Converter<Date, Long> {
    override val wrapper = Date::class

    override fun wrap(unwrapped: Long) =
        Date(unwrapped)

    override fun unwrap(wrapped: Date) =
        wrapped.time
}
```

```kotlin
data class WrapperModel(
    val date: java.util.Date,
    ...
) : KtMessage {
    ...
    override fun serialize(serializer: KtMessageSerializer) {
        serializer.write(Tag(10)).write(Int64(DateConverter.unwrap(date)))
        ...
    }

    override fun deserialize(deserializer: KtMessageDeserializer): WrapperModel {
        var date = 0L

        while (true) {
            when (deserializer.readTag()) {
                0 ->
                    return WrapperModel(
                        DateConverter.wrap(date),
                        ...
                    )
                ...
            }
        }
    }
}
```

Converters can also implement the `OptimizedSizeofConverter` interface adding `sizeof()`,
which allows them to optimize the calculation of the wrapper's size rather than unwrap
the object twice. For example, a UUID is always 16 bytes:

```kotlin
object UuidConverter : OptimizedSizeofConverter<UUID, ByteArray> {
    override val wrapper = UUID::class

    private val sizeofProxy = ByteArray(16)

    override fun sizeof(wrapped: UUID) =
        sizeof(sizeofProxy)

    override fun wrap(unwrapped: ByteArray): UUID {
        require(unwrapped.size == 16) {
            "input must have size 16; had ${unwrapped.size}"
        }

        return ByteBuffer.wrap(unwrapped)
            .run { UUID(long, long) }
    }

    override fun unwrap(wrapped: UUID) =
        ByteBuffer.allocate(16)
            .putLong(wrapped.mostSignificantBits)
            .putLong(wrapped.leastSignificantBits)
            .array()
}
```

Rather than convert a UUID to a byte array both for size calculation and for serialization
(which is what a naïve implementation would do), UuidConverter always returns the size of a
constant 16-byte array.

If the wrapper type is in the same package as the generated protobuf message, then it
does not need a fully-qualified name. Custom wrapper type converters can be in the same module as
protobuf types that reference them. In order to use any wrapper type defined in
`protokt-extensions`, the module must be included as a dependency:

```groovy
dependencies {
    implementation 'com.toasttab.protokt:protokt-extensions:0.0.3'
}
```

#### Interface implementation
To avoid the need to create domain-specific objects from protobuf messages you can declare
that a protobuf message implements a custom interface with properties and default methods.

```kotlin
package com.protokt.sample

interface Model {
    val id: String
}
```

```proto
package com.protokt.sample;

message ImplementsSampleMessage {
  option (protokt_class).implements = "Model";

  string id = 1;
}
```

If the wrapper interface is in the same package as the generated protobuf message, then it
does not need a fully-qualified name. Wrapper interfaces cannot be used by protobuf messages
in the same module that defines them; the dependency must be declared with`protoktExtensions`
in `build.gradle`:

```groovy
dependencies {
    protoktExtensions project(':api-module')
}
```

#### Nonnull fields
If there is a message that has no meaning whatsoever when a particular field is missing, you
can emulate proto2's `required` key word by using the `(protokt_oneof).non_null` option:

```proto
message Sample {
}

message NonNullSampleMessage {
  Sample non_null_sample = 1 [
    (protokt_property).non_null = true
  ];
}
```

Generated code will not have a nullable type so the field can be referenced without using
Kotlin's `!!`.

Oneof fields can also be declared non-null:

```proto
message NonNullSampleMessage {
  oneof non_null_oneof {
    option (protokt_oneof).non_null = true;

    string message = 2;
  }
}
```

Note that deserialization of a message with a non-nullable field will fail if the
message being decoded does not contain an instance of the required field.

#### BytesSlice
When reading messages that contain other serialized messages as `bytes` fields, protokt can
keep a reference to the originating byte array to prevent a large copy operation on
deserialization. This can be desirable when the wrapping message is a thin metadata shim and
doesn't include much memory overhead:

```proto
message SliceModel {
  int64 version = 1;

  bytes encoded_message = 2 [
    (protokt_property).bytes_slice = true
  ];
}
```

### Usage

#### Gradle

```groovy
buildscript {
    dependencies {
        classpath "com.toasttab.protokt:protokt-gradle-plugin:0.0.3"
    }
}

apply plugin: 'com.toasttab.protokt'
```

This will automatically download and install protokt, apply the Google protobuf plugin,
and configure all the necessary boilerplate. By default it will also add `protokt-runtime`
to the api scope of the project, and `protobuf-java` to the implementation scope.

If your project is pure Kotlin you may run into the following error:

```
Execution failed for task ':compileJava'.
> error: no source files
```

To work around it, disable all `JavaCompile` tasks in the project:

```groovy
tasks.withType(JavaCompile) {
    enabled = false
}
```

or:
```groovy
compileJava.enabled = false
```

#### Command line code generation

```bash
protokt-codegen$ ./gradlew assemble [OR ./gradlew installDist]

protokt-codegen$ ./run-protokt.sh -h

protokt-codegen$ ./run-protokt.sh \
  -out=../kotlin \
  -pkg=com.toasttab.protokt.conformance \
  -file=conformance.proto \
  -cp=../build/libs/protokt-codegen-0.0.3-SNAPSHOT-all.jar \
  -plugin=../bin/protokt.sh
```

### Contribution
To enable rapid development of the code generator, the protobuf conformance tests have been 
compiled and included in the protokt-testing project. They run on Mac OS 10.14+ and Ubuntu
16.04 x86-64.

Publish the plugin to the integration repository:
```bash
protokt$ ./gradlew publishToIntegrationRepository
```

Then run the tests from `protokt-testing`:
```bash
protokt-testing$ ./gradlew protokt-conformance-tests:test
```

All integration tests can be run with:
```
protokt-testing$ ./gradlew test
```
2019-07-10 09:58:38 -04:00
Alex Konradi
619ffac4f7
Merge branch 'master' into patch-1 2019-06-20 14:10:06 -04:00
marwan-at-work
36cd11a2bf Add twirpql ID to global registry 2019-06-11 07:34:41 -07:00
Alex Konradi
b44a1364ec
Add extension number for protoc-gen-validate
This project is used by the [Envoy proxy](https://www.envoyproxy.io/) and several others.

The existing code is using the extension value [919191](54b08a686f/validate/validate.proto (L29)) but since maintaining binary compatibility is not important, it shouldn't be a problem to change once this allocation is approved.
2019-05-24 07:44:51 -04:00
TechProofreader
02a4c720c3
Update performance.md
Even though I just proofread this file, I noticed one more thing that needed correcting, which I fixed. The word "genereated" had to be corrected to "generated". My apologies for missing this on the initial check.
2019-05-21 03:18:36 -04:00
TechProofreader
5b628d552b
Update performance.md
I corrected a few grammatical mistakes and increased the document's readability by easing the language flow.
2019-05-18 01:04:58 -04:00
haoyuanli
62246b9166
Fix typo 'pythong'
Changed 'pythong' to 'python'
2019-05-14 10:47:09 -07:00
Pavel Perestoronin
e9faff8514 Update third_party.md
I've deprecated the separate web page for the project and moved everything to `README.md`, so for now it's better to point to the GitHub project page.
2019-03-26 13:35:54 -07:00
Matthew Paletta
5f470c3992
Added Optional GRPC library to third party docs 2019-02-24 10:59:15 -08:00
Xiang Dai
e479410564 delete all duplicate empty blanks (#5758)
Signed-off-by: Xiang Dai <764524258@qq.com>
2019-02-20 19:28:50 -08:00
Cy
9c1c94f770 Update third party implementation links (#5702) 2019-02-11 18:08:08 -08:00