Skip to content

Commit f6cd5de

Browse files
Update docs
1 parent fefc497 commit f6cd5de

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

docs/formats.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ stable, these are currently experimental features of Kotlin Serialization.
1919
* [Lists as repeated fields](#lists-as-repeated-fields)
2020
* [Packed fields](#packed-fields)
2121
* [Oneof field (experimental)](#oneof-field-experimental)
22+
* [Usage](#usage)
23+
* [Alternative](#alternative)
2224
* [ProtoBuf schema generator (experimental)](#protobuf-schema-generator-experimental)
2325
* [Properties (experimental)](#properties-experimental)
2426
* [Custom formats (experimental)](#custom-formats-experimental)

docs/serialization-guide.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ Once the project is set up, we can start serializing some classes.
152152
* <a name='lists-as-repeated-fields'></a>[Lists as repeated fields](formats.md#lists-as-repeated-fields)
153153
* <a name='packed-fields'></a>[Packed fields](formats.md#packed-fields)
154154
* <a name='oneof-field-experimental'></a>[Oneof field (experimental)](formats.md#oneof-field-experimental)
155+
* <a name='usage'></a>[Usage](formats.md#usage)
156+
* <a name='alternative'></a>[Alternative](formats.md#alternative)
155157
* <a name='protobuf-schema-generator-experimental'></a>[ProtoBuf schema generator (experimental)](formats.md#protobuf-schema-generator-experimental)
156158
* <a name='properties-experimental'></a>[Properties (experimental)](formats.md#properties-experimental)
157159
* <a name='custom-formats-experimental'></a>[Custom formats (experimental)](formats.md#custom-formats-experimental)

guide/example/example-formats-08.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ package example.exampleFormats08
44
import kotlinx.serialization.*
55
import kotlinx.serialization.protobuf.*
66

7+
// The outer class
78
@Serializable
89
data class Data(
910
@ProtoNumber(1) val name: String,
1011
@ProtoOneOf val phone: IPhoneType,
1112
)
13+
14+
// The oneof interface
1215
@Serializable sealed interface IPhoneType
13-
@Serializable @ProtoNumber(2) @JvmInline value class HomePhone(val number: String): IPhoneType
14-
@Serializable @ProtoNumber(3) data class WorkPhone(val number: String): IPhoneType
16+
17+
// Message holder for home_phone
18+
@Serializable @JvmInline value class HomePhone(@ProtoNumber(2) val number: String): IPhoneType
19+
20+
// Message holder for work_phone
21+
@Serializable data class WorkPhone(@ProtoNumber(3) val number: String): IPhoneType
1522

1623
fun main() {
1724
val dataTom = Data("Tom", HomePhone("123"))

guide/example/example-formats-09.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// This file was automatically generated from formats.md by Knit tool. Do not edit.
22
package example.exampleFormats09
33

4+
@Serializable
5+
data class Data2(
6+
@ProtoNumber(1) val name: String,
7+
@ProtoNumber(2) val homeNumber: String? = null,
8+
@ProtoNumber(3) val workNumber: String? = null,
9+
)
410
import kotlinx.serialization.*
511
import kotlinx.serialization.protobuf.*
612
import kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator

0 commit comments

Comments
 (0)