|
8 | 8 | <topic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
9 | 9 | xsi:noNamespaceSchemaLocation="https://resources.jetbrains.com/writerside/1.0/topic.v2.xsd"
|
10 | 10 | title="Configuration" id="configuration">
|
11 |
| - <p><code>KrpcConfig</code> is a class used to configure <code>KrpcClient</code> and <code>KrpcServer</code> |
12 |
| - (not to be confused with <code>KrpcClient</code> and <code>KrpcServer</code>). |
13 |
| - It has two children: <code>KrpcConfig.Client</code> and <code>KrpcConfig.Server</code>. |
14 |
| - <code>Client</code> and <code>Server</code> may have shared properties as well as distinct ones. |
15 |
| - To create instances of these configurations, DSL builders are provided |
16 |
| - (<code>KrpcConfigBuilder.Client</code> class with <code>rpcClientConfig</code> function |
17 |
| - and <code>KrpcConfigBuilder.Server</code> class with <code>rpcServerConfig</code> function respectively): |
| 11 | + <p> |
| 12 | + <code>KrpcConfig</code> is a class used to configure <code>KrpcClient</code> and <code>KrpcServer</code> |
| 13 | + (not to be confused with <code>RpcClient</code> and <code>RpcServer</code>). |
| 14 | + </p> |
| 15 | + <p> |
| 16 | + It has two children: <code>KrpcConfig.Client</code> and <code>KrpcConfig.Server</code>. |
| 17 | + <code>Client</code> and <code>Server</code> may have shared properties as well as distinct ones. |
| 18 | + To create instances of these configurations, DSL builders are provided: |
| 19 | + </p> |
| 20 | + <list> |
| 21 | + <li> |
| 22 | + <code>rpcClientConfig</code> |
| 23 | + </li> |
| 24 | + <li> |
| 25 | + <code>rpcServerConfig</code> |
| 26 | + </li> |
| 27 | + </list> |
| 28 | + |
| 29 | + <code-block lang="kotlin"> |
| 30 | + val config: KrpcConfig.Client = rpcClientConfig { // same for KrpcConfig.Server with rpcServerConfig |
| 31 | + waitForServices = true // default parameter |
| 32 | + } |
| 33 | + </code-block> |
| 34 | + <p> |
| 35 | + The following configuration options are available: |
| 36 | + </p> |
| 37 | + <chapter id="serialization-dsl"> |
| 38 | + <title> |
| 39 | + <code>serialization</code> DSL |
| 40 | + </title> |
| 41 | + <p> |
| 42 | + This parameter defines how serialization should work in RPC services |
| 43 | + and is present in both client and server configurations. |
| 44 | + </p> |
| 45 | + <p> |
| 46 | + The serialization process is used to encode and decode data in RPC requests, |
| 47 | + so that the data can be transferred through the network. |
| 48 | + </p> |
| 49 | + <p> |
| 50 | + Currently only <code>StringFormat</code> and <code>BinaryFormat</code> from |
| 51 | + <a href="https://github.com/Kotlin/kotlinx.serialization">kotlinx.serialization</a> are supported, |
| 52 | + and by default you can choose from Json, Protobuf or Cbor formats: |
18 | 53 | </p>
|
19 | 54 |
|
20 | 55 | <code-block lang="kotlin">
|
21 |
| - val config: KrpcConfig.Client = rpcClientConfig { // same for KrpcConfig.Server with rpcServerConfig |
22 |
| - waitForServices = true // default parameter |
| 56 | + rpcClientConfig { |
| 57 | + serialization { |
| 58 | + json { /* this: JsonBuilder from kotlinx.serialization */ } |
| 59 | + cbor { /* this: CborBuilder from kotlinx.serialization */ } |
| 60 | + protobuf { /* this: ProtobufBuilder from kotlinx.serialization */ } |
| 61 | + } |
23 | 62 | }
|
24 | 63 | </code-block>
|
25 |
| - <p>The following configuration options are available:</p> |
26 |
| - <chapter id="serialization-dsl"> |
27 |
| - <title> |
28 |
| - <code>serialization</code> DSL |
29 |
| - </title> |
30 |
| - <p>This parameter defines how serialization should work in RPC services |
31 |
| - and is present in both client and server configurations.</p> |
32 |
| - <p>The serialization process is used to encode and decode data in RPC requests, |
33 |
| - so that the data can be transferred through the network.</p> |
34 |
| - <p>Currently only <code>StringFormat</code> and <code>BinaryFormat</code> from |
35 |
| - <a href="https://github.com/Kotlin/kotlinx.serialization">kotlinx.serialization</a> are supported, |
36 |
| - and by default you can choose from Json, Protobuf or Cbor formats:</p> |
37 |
| - |
38 |
| - <code-block lang="kotlin"> |
39 |
| - rpcClientConfig { |
40 |
| - serialization { |
41 |
| - json { /* this: JsonBuilder from kotlinx.serialization */ } |
42 |
| - cbor { /* this: CborBuilder from kotlinx.serialization */ } |
43 |
| - protobuf { /* this: ProtobufBuilder from kotlinx.serialization */ } |
44 |
| - } |
45 |
| - } |
46 |
| - </code-block> |
47 |
| - <p>Only last defined format will be used to serialize requests. |
48 |
| - If no format is specified, the error will be thrown. |
49 |
| - You can also define a custom format.</p> |
50 |
| - </chapter> |
51 |
| - <chapter id="sharedflowparameters-dsl"> |
52 |
| - <title> |
53 |
| - <code>sharedFlowParameters</code> DSL |
54 |
| - </title> |
55 |
| - |
56 |
| - <warning> |
57 |
| - These parameters are deprecated since <code>0.5.0</code>. For more information, |
58 |
| - see the <a href="0-5-0.topic">migration guide</a>. |
59 |
| - </warning> |
60 |
| - |
61 |
| - <code-block lang="kotlin"> |
62 |
| - rpcClientConfig { |
63 |
| - sharedFlowParameters { |
64 |
| - replay = 1 // default parameter |
65 |
| - extraBufferCapacity = 10 // default parameter |
66 |
| - onBufferOverflow = BufferOverflow.SUSPEND // default parameter |
67 |
| - } |
68 |
| - } |
69 |
| - </code-block> |
70 |
| - <p>This parameter is needed to decode <code>SharedFlow</code> parameters received from a peer. |
71 |
| - <code>MutableSharedFlow</code>, the default function to create a <code>SharedFlow</code> instance, |
72 |
| - has the following signature:</p> |
73 |
| - |
74 |
| - <code-block lang="kotlin"> |
75 |
| - fun <T> MutableSharedFlow( |
76 |
| - replay: Int = 0, |
77 |
| - extraBufferCapacity: Int = 0, |
78 |
| - onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND |
79 |
| - ): MutableSharedFlow<T> { /* ... */ |
80 |
| - } |
81 |
| - </code-block> |
82 |
| - <p>It creates a <code>SharedFlowImpl</code> class that contains these parameters as properties, |
83 |
| - but this class in internal in <code>kotlinx.coroutines</code> and neither <code>SharedFlow</code>, |
84 |
| - nor <code>MutableShatedFlow</code> interfaces define these properties, |
85 |
| - which makes it impossible (at least for now) to send these properties from one endpoint to another. |
86 |
| - But instances of these flows when deserialized should be created somehow, |
87 |
| - so to overcome this - configuration parameter is created. |
88 |
| - Configuration builder allows defining these parameters |
89 |
| - and produces a builder function that is then placed into the <code>KrpcConfig</code>.</p> |
90 |
| - </chapter> |
91 |
| - <chapter id="waitforservices-dsl"> |
92 |
| - <title> |
93 |
| - <code>waitForServices</code> DSL |
94 |
| - </title> |
95 |
| - <p><code>waitForServices</code> parameter is available for both client and server. |
96 |
| - It specifies the behavior for an endpoint in situations |
97 |
| - when the message for a service is received, |
98 |
| - but the service is not present in <code>KrpcClient</code> or <code>KrpcServer</code>. |
99 |
| - If set to <code>true</code>, the message will be stored in memory, |
100 |
| - otherwise, the error will be sent to a peer endpoint, |
101 |
| - saying that the message was not handled. |
102 |
| - Default value is <code>true</code>.</p> |
103 |
| - </chapter> |
| 64 | + <p> |
| 65 | + Only last defined format will be used to serialize requests. |
| 66 | + If no format is specified, a runtime error will be thrown. |
| 67 | + You can also define a custom format. |
| 68 | + </p> |
| 69 | + </chapter> |
| 70 | + <chapter id="waitforservices-dsl"> |
| 71 | + <title> |
| 72 | + <code>waitForServices</code> DSL |
| 73 | + </title> |
| 74 | + <p> |
| 75 | + <code>waitForServices</code> parameter is available for both client and server. |
| 76 | + It specifies the behavior for an endpoint in situations |
| 77 | + when the message for a service is received, |
| 78 | + but the service is not present in <code>KrpcClient</code> or <code>KrpcServer</code>. |
| 79 | + If set to <code>true</code>, the message will be stored in memory, |
| 80 | + otherwise, the error will be sent to a peer endpoint, |
| 81 | + saying that the message was not handled. |
| 82 | + Default value is <code>true</code>. |
| 83 | + </p> |
| 84 | + </chapter> |
104 | 85 | </topic>
|
0 commit comments