You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dokka/moduledoc.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ You can learn about "Human-Optimized Config Object Notation" or HOCON from libra
21
21
Allows converting arbitrary hierarchy of Kotlin classes to a flat key-value structure à la Java Properties.
22
22
23
23
# Module kotlinx-serialization-protobuf
24
-
Protocol buffers serialization format implementation, mostly compliant to [proto2](https://developers.google.com/protocol-buffers/docs/proto) specification.
24
+
[Protocol buffers](https://protobuf.dev/) serialization format implementation.
25
25
26
26
# Package kotlinx.serialization
27
27
Basic core concepts and annotations that set up serialization process.
@@ -50,7 +50,10 @@ and JSON-specific serializers.
50
50
Extensions for kotlinx.serialization.json.Json for integration with the popular [Okio](https://square.github.io/okio/) library.
51
51
52
52
# Package kotlinx.serialization.protobuf
53
-
Protocol buffers serialization format implementation, mostly compliant to [proto2](https://developers.google.com/protocol-buffers/docs/proto) specification.
53
+
[Protocol buffers](https://protobuf.dev/) serialization format implementation.
54
+
55
+
# Package kotlinx.serialization.protobuf.schema
56
+
Experimental generator of ProtoBuf schema from Kotlin classes.
54
57
55
58
# Package kotlinx.serialization.properties
56
59
Properties serialization format implementation that represents the input data as a plain map of properties.
Copy file name to clipboardExpand all lines: formats/protobuf/commonMain/src/kotlinx/serialization/protobuf/ProtoBuf.kt
+24-17Lines changed: 24 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -11,12 +11,14 @@ import kotlin.js.*
11
11
12
12
/**
13
13
* Implements [encoding][encodeToByteArray] and [decoding][decodeFromByteArray] classes to/from bytes
14
-
* using [Proto2][https://developers.google.com/protocol-buffers/docs/proto] specification.
15
-
* It is typically used by constructing an application-specific instance, with configured specific behaviour
14
+
* using [Protocol buffers](https://protobuf.dev/) specification.
15
+
* It is typically used by constructing an application-specific instance, with configured specific behavior
16
16
* and, if necessary, registered custom serializers (in [SerializersModule] provided by [serializersModule] constructor parameter).
17
+
* Default encoding is proto2, although proto3 can be used with a number of tweaks (see the section below for details).
18
+
*
17
19
*
18
20
* ### Correspondence between Protobuf message definitions and Kotlin classes
19
-
* Given a ProtoBuf definition with one required field, one optional field and one optional field with a custom default
21
+
* Given a ProtoBuf definition with one required field, one optional field, and one optional field with a custom default
20
22
* value:
21
23
* ```
22
24
* message MyMessage {
@@ -32,27 +34,29 @@ import kotlin.js.*
32
34
* data class MyMessage(val first: Int, val second: Int = 0, val third: Int = 42)
33
35
* ```
34
36
*
35
-
* By default, protobuf fields ids are being assigned to Kotlin properties in incremental order, i.e.
36
-
* the first property in the class has id 1, the second has id 2, and so forth.
37
-
* If you need a more stable order (e.g. to avoid breaking changes when reordering properties),
38
-
* provide custom ids using [ProtoNumber] annotation.
37
+
* By default, protobuf fields numbers are being assigned to Kotlin properties in incremental order, i.e.,
38
+
* the first property in the class has number 1, the second has number 2, and so forth.
39
+
* If you need a more stable order (e.g., to avoid breaking changes when reordering properties),
40
+
* provide custom numbers using [ProtoNumber] annotation.
39
41
*
40
-
* By default, all integer numbers are encoded using [varint][https://developers.google.com/protocol-buffers/docs/encoding#varints]
41
-
* encoding. This behaviour can be changed via [ProtoType] annotation.
42
+
* By default, all integer values are encoded using [varint](https://protobuf.dev/programming-guides/encoding/#varints)
43
+
* encoding. This behavior can be changed via [ProtoType] annotation.
42
44
*
43
45
* ### Known caveats and limitations
44
46
* Lists are represented as repeated fields. Because format spec says that if the list is empty,
45
-
* there are no elements in the stream with such tag, you must explicitly mark any
46
-
* field of list type with default = emptyList(). Same for maps.
47
-
* There's no special support for `oneof` protobuf fields. However, this implementation
47
+
* there are no elements in the stream with such tag, you have to explicitly add to any
48
+
* property of `List` type a default value equals to `emptyList()`. Same for maps.
49
+
* There is no special support for `oneof` protobuf fields. However, this implementation
48
50
* supports standard kotlinx.serialization's polymorphic and sealed serializers,
49
-
* using their default form (message of serialName: string and other embedded message with actual content).
51
+
* using their default form (message consisting of `serialName: string` and other embedded message with actual content).
50
52
*
51
53
* ### Proto3 support
52
-
* This implementation does not support repeated packed fields, so you won't be able to deserialize
53
-
* Proto3 lists. However, other messages could be decoded. You have to remember that since fields in Proto3
54
-
* messages by default are implicitly optional,
55
-
* corresponding Kotlin properties have to be nullable with default value `null`.
54
+
*
55
+
* proto2 and proto3 specifications use the same encoding, so you can use this class to decode Proto3 messages.
56
+
* However, the message structure is slightly different, so you should remember the following:
57
+
*
58
+
* - In proto3, fields by default are implicitly optional, so corresponding Kotlin properties have to be nullable and have a default value `null`.
59
+
* - In proto3, all lists use packed encoding by default. To be able to decode them, annotation [ProtoPacked] should be used on all properties with type `List`.
56
60
*
57
61
* ### Usage example
58
62
* ```
@@ -112,6 +116,9 @@ import kotlin.js.*
112
116
* @param encodeDefaults specifies whether default values are encoded.
113
117
* False by default; meaning that properties with values equal to defaults will be elided.
114
118
* @param serializersModule application-specific [SerializersModule] to provide custom serializers.
0 commit comments