Skip to content

Doc restructuring update cbor protobuf - #3221

Open
daniCsorbaJB wants to merge 3 commits into
doc-restructuring-update-10from
doc-restructuring-update-cbor-protobuf
Open

Doc restructuring update cbor protobuf#3221
daniCsorbaJB wants to merge 3 commits into
doc-restructuring-update-10from
doc-restructuring-update-cbor-protobuf

Conversation

@daniCsorbaJB

Copy link
Copy Markdown

This PR adds the CBOR and ProtoBuf pages

@daniCsorbaJB
daniCsorbaJB requested a review from sandwwraith July 14, 2026 12:48
[//]: # (title: CBOR format)
<primary-label ref="experimental-general"/>

Concise Binary Object Representation ([CBOR](https://datatracker.ietf.org/doc/html/rfc7049)) is a compact binary format based on JSON.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[//]: # (title: CBOR format)
<primary-label ref="experimental-general"/>

Concise Binary Object Representation ([CBOR](https://datatracker.ietf.org/doc/html/rfc7049)) is a compact binary format based on JSON.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Official docs use "The underlying data model is an extended version of the JSON data model", so let's stick to it — use 'extends' json instead of 'based on' json

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe phrase it as "...format extending the JSON data model". As it is the underlying data model that is extensible, not the actual wire format.

@daniCsorbaJB daniCsorbaJB Aug 7, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🤔 I think we should go with this then (to avoid the gerund):

Concise Binary Object Representation (CBOR) is a compact binary format that extends the JSON data model.

<primary-label ref="experimental-general"/>

Concise Binary Object Representation ([CBOR](https://datatracker.ietf.org/doc/html/rfc7049)) is a compact binary format based on JSON.
It supports a subset of [JSON features](configure-json-serialization.md) and produces binary output instead of text.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is kinda confusing because you've meant what configuration flags are available in kotlinx-serialization-cbor, and you're not talking about format itself.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, is it really a subset or just a set of options that have the same name (and hopefully the same semantics)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

good point 🤔 yes, perhaps we could just delete this sentence. It feels confusing like this. — we cover ignoreUnknownKeys below so I don't think this is needed after all.


The [`Cbor`](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-cbor/kotlinx.serialization.cbor/-cbor/) class provides two main functions:

* [`encodeToByteArray()`](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/encode-to-byte-array.html) serializes objects to a binary array.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

'binary array' term is quite ambiguous, can we use 'byte array' instead?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ofc — nice, I like it 👍

Let's look at an example where a `Project` object is serialized into a binary array and then deserialized back to its original form:

```kotlin
// Imports declarations from the serialization library

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we've discussed to drop this comment, didn't we?


<!-- REMOVE AFTER REVIEW: Like with CBOR examples, I felt like we have shown enough times how it looks in ProtoBuf hex notation so I removed that part to keep it a bit more concise. -->

## Encode empty lists in ProtoBuf

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We fixed this some time ago (

), so this chapter can be dropped, I think

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

nice! 👍 Yes, I agree, let's remove it.

}
```

<!-- REMOVE AFTER REVIEW: I wanted to add an example here as well, please let me know if this works -->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm


1. Define a class for the entire message.
2. Add a property of the polymorphic type to the class. Annotate this property with [`@ProtoOneOf`](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-protobuf/kotlinx.serialization.protobuf/-proto-one-of/).
3. Create a `sealed interface` or `abstract class` to represent the fields inside the `oneof` declaration.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did you reorder 2 and 3? It is more confusing now. Also, it's better to stick to to the 'oneof group' rather than 'fields inside', because fields are represented as subclasses.

Also, why did you delete examples in-text? I think they're worth keeping. Even better, you can make the same structure you used in other docs:

  1. Create a sealed interface or abstract class to represent the fields inside the oneof declaration.
@Serializable sealed interface IPhoneType

@daniCsorbaJB daniCsorbaJB Aug 11, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the order is just to represent the order of the code example. 🤔 but yes, rereading, I think we should switch it.

make the same structure you used in other docs

Sure, I wanted to keep it more concise, but the same structure works as well 👍


// Represents the work_phone field
@OptIn(ExperimentalSerializationApi::class)
@Serializable data class WorkPhone(@ProtoNumber(3) val number: String): IPhoneType

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You lost explanation comment on why one of the classes is value and another is data. Why?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

nice catch! It's an important piece of info, so I re-added it to the step list to have this information, but in the example, it feels arbitrary to me.

However, with Kotlin serialization, you can use Kotlin classes annotated with `@Serializable` as the source for the schema, making `.proto` files optional.

This approach simplifies the process when all the code involved is written in Kotlin,
interoperability with other languages often still requires a `.proto` schema.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
interoperability with other languages often still requires a `.proto` schema.
but interoperability with other languages often still requires a `.proto` schema.

@sandwwraith

Copy link
Copy Markdown
Member

Why base for this PR is doc-restructuring-update-10 and not doc-restructuring-update-master???

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.

3 participants