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

Add some documentation for ProtoBufSchemaGenerator in formats.md #1855

Merged

Conversation

justinhj
Copy link
Contributor

@justinhj justinhj commented Feb 4, 2022

Hi, this is a PR for #1778

I've added a bit of documentation in formats.md about the ProtoBufSchemaGenerator. Just enough to help the interested party see that it exists, an example and a link to the code.

If you think it will be useful I'll be happy to make any requested changes.

It is targeted at master since it is documentation only, but it looks like it will cleanly merge with dev if you prefer.

BTW Knit fails with the following, I'm not sure why.

> Task :knit FAILED
ERROR: /Users/justin.heyes-jones/projects/kotlinx.serialization/docs/formats.md: 486: Previous test was not emitted with TEST

docs/formats.md Outdated
### ProtoBuf schema generator (experimental)

As mentioned above, when working with protocol buffers you usually use a ".proto" file and use a code generator for your
language includes the code to your message to an output stream and deserialize it from an input stream. When using
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your language includes

Something is missing before 'includes', at least a comma

input stream. When using

Two spaces instead of one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I'm sure I proof read it multiple times but then committed total nonsense.

docs/formats.md Outdated
Kotlin Serialization this step is not necessary because your `@Serializable` Kotlin data types are used as the source
for the schema.

This is very convenient for Kotlin-to-Kotlin communication, but makes interoperability between languages complicated. Fortunately you can use to output the ".proto" representation of your messages. You can keep your Kotlin classes as a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fortunately, you can use SOMETHIING to output the ".proto" representation of your messages.

SOMETHING is missing

val schemas = ProtoBufSchemaGenerator.generateSchemaText(descriptors)
println(schemas)
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Knit uses several magic lines, and

> You can get the full code [here](../guide/example/example-formats-07.kt).

is one of them you should insert here. Don't worry, number of example would be automatically updated by a knit task.

optional string department = 3;
}
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test output should be finished with <!--- TEST --> knit directive

@sandwwraith
Copy link
Member

Have you re-run knit? It looks like the commit should also have generated example files, since their numeration got updated

@justinhj
Copy link
Contributor Author

Have you re-run knit? It looks like the commit should also have generated example files, since their numeration got updated

I'm sorry I missed that step. I have run it now and updated the PR.

@sandwwraith
Copy link
Member

Your example should be separate compilable unit:

e: /opt/buildAgent/work/b2fef8360e1bcf3d/guide/example/example-formats-08.kt: (13, 1): Expecting a top level declaration
e: /opt/buildAgent/work/b2fef8360e1bcf3d/guide/example/example-formats-08.kt: (13, 8): Expecting a top level declaration
e: /opt/buildAgent/work/b2fef8360e1bcf3d/guide/example/example-formats-08.kt: (13, 9): Expecting a top level declaration
e: /opt/buildAgent/work/b2fef8360e1bcf3d/guide/example/example-formats-08.kt: (13, 16): Expecting a top level declaration
e: /opt/buildAgent/work/b2fef8360e1bcf3d/guide/example/example-formats-08.kt: (4, 2): Cannot access 'Serializable': it is internal in 'kotlin.io'
e: /opt/buildAgent/work/b2fef8360e1bcf3d/guide/example/example-formats-08.kt: (4, 2): This class does not have a constructor
e: /opt/buildAgent/work/b2fef8360e1bcf3d/guide/example/example-formats-08.kt: (11, 37): Unresolved reference: serializer
e: /opt/buildAgent/work/b2fef8360e1bcf3d/guide/example/example-formats-08.kt: (12, 15): Unresolved reference: ProtoBufSchemaGenerator
e: /opt/buildAgent/work/b2fef8360e1bcf3d/guide/test/FormatsTest.kt: (64, 70): Unresolved reference: main

I suggest adding import kotlinx.serialization.* and other required imports and wrapping vals/println into fun main(). Then update Knit and run ./gradlew :guide:test knitCheck to check that everything is ok

@justinhj
Copy link
Contributor Author

./gradlew :guide:test knitCheck

Thanks for your patience! I wasn't familiar with what knit did. Have now fixed the knit related issues.

Copy link
Member

@sandwwraith sandwwraith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all your efforts and time!

@sandwwraith sandwwraith merged commit 41b3996 into Kotlin:master Feb 24, 2022
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 this pull request may close these issues.

2 participants