Skip to content

Commit 158a3ce

Browse files
committed
chore: live variable control base
1 parent 5939b02 commit 158a3ce

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

src/main/kotlin/spp/protocol/instrument/variable/LiveVariableControl.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package spp.protocol.instrument.variable
1818

1919
import io.vertx.codegen.annotations.DataObject
20+
import io.vertx.core.json.JsonArray
2021
import io.vertx.core.json.JsonObject
2122

2223
/**
@@ -27,18 +28,31 @@ data class LiveVariableControl(
2728
val maxObjectDepth: Int? = null,
2829
val maxObjectSize: Int? = null,
2930
val maxCollectionLength: Int? = null,
30-
val variableTypeConfig: Map<String, LiveVariableControl> = emptyMap(),
31-
val variableNameConfig: Map<String, LiveVariableControl> = emptyMap()
31+
val variableTypeConfig: Map<String, LiveVariableControlBase> = emptyMap(),
32+
val variableNameConfig: Map<String, LiveVariableControlBase> = emptyMap()
3233
) {
3334
constructor(json: JsonObject) : this(
3435
maxObjectDepth = json.getInteger("maxObjectDepth"),
3536
maxObjectSize = json.getInteger("maxObjectSize"),
3637
maxCollectionLength = json.getInteger("maxCollectionLength"),
37-
variableTypeConfig = json.getJsonObject("variableTypeConfig")?.let {
38-
it.associate { it.key to LiveVariableControl(it.value as JsonObject) }
38+
39+
variableTypeConfig = json.getValue("variableTypeConfig")?.let {
40+
when (it) {
41+
is JsonObject -> it.associate { it.key to LiveVariableControlBase(it.value as JsonObject) }
42+
is JsonArray -> it.map { JsonObject.mapFrom(it) }
43+
.associate { it.getString("type") to LiveVariableControlBase(it.getJsonObject("control")) }
44+
45+
else -> throw IllegalArgumentException("variableTypeConfig must be a JsonObject or JsonArray")
46+
}
3947
}.orEmpty(),
40-
variableNameConfig = json.getJsonObject("variableNameConfig")?.let {
41-
it.associate { it.key to LiveVariableControl(it.value as JsonObject) }
48+
variableNameConfig = json.getValue("variableNameConfig")?.let {
49+
when (it) {
50+
is JsonObject -> it.associate { it.key to LiveVariableControlBase(it.value as JsonObject) }
51+
is JsonArray -> it.map { JsonObject.mapFrom(it) }
52+
.associate { it.getString("type") to LiveVariableControlBase(it.getJsonObject("control")) }
53+
54+
else -> throw IllegalArgumentException("variableTypeConfig must be a JsonObject or JsonArray")
55+
}
4256
}.orEmpty()
4357
)
4458

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Source++, the continuous feedback platform for developers.
3+
* Copyright (C) 2022 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.protocol.instrument.variable
18+
19+
import io.vertx.codegen.annotations.DataObject
20+
import io.vertx.core.json.JsonObject
21+
22+
/**
23+
* Allows for fine-grained control over the serialization of [LiveVariable]s.
24+
*/
25+
@DataObject
26+
data class LiveVariableControlBase(
27+
val maxObjectDepth: Int? = null,
28+
val maxObjectSize: Int? = null,
29+
val maxCollectionLength: Int? = null,
30+
) {
31+
constructor(json: JsonObject) : this(
32+
maxObjectDepth = json.getInteger("maxObjectDepth"),
33+
maxObjectSize = json.getInteger("maxObjectSize"),
34+
maxCollectionLength = json.getInteger("maxCollectionLength")
35+
)
36+
37+
fun toJson(): JsonObject {
38+
return JsonObject.mapFrom(this)
39+
}
40+
}

0 commit comments

Comments
 (0)