Skip to content

Commit 43229c8

Browse files
committed
switch to data class
1 parent 058f8bd commit 43229c8

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/commonMain/kotlin/spp.protocol/platform/auth/DeveloperRole.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717
*/
1818
package spp.protocol.platform.auth
1919

20-
enum class DeveloperRole(var roleName: String, var nativeRole: Boolean) {
21-
ROLE_MANAGER("role_manager", true),
22-
ROLE_USER("role_user", true),
23-
USER("*", false);
20+
import kotlinx.serialization.Serializable
2421

22+
@Serializable
23+
data class DeveloperRole(val roleName: String, val nativeRole: Boolean) {
2524
companion object {
25+
val ROLE_MANAGER = DeveloperRole("role_manager", true)
26+
val ROLE_USER = DeveloperRole("role_user", true)
27+
2628
fun fromString(roleName: String): DeveloperRole {
27-
val nativeRole = values().find { it.name.lowercase() == roleName.lowercase() }
28-
return if (nativeRole != null) {
29-
nativeRole
29+
return if (roleName.equals("role_manager", true)) {
30+
ROLE_MANAGER
31+
} else if (roleName.equals("role_user", true)) {
32+
ROLE_USER
3033
} else {
31-
val user = USER
32-
user.roleName = roleName.toLowerCase().replace(' ', '_').trim()
33-
user
34+
DeveloperRole(roleName.toLowerCase().replace(' ', '_').trim(), false)
3435
}
3536
}
3637
}

src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import spp.protocol.instrument.event.LiveInstrumentRemoved
3939
import spp.protocol.instrument.event.LiveLogHit
4040
import spp.protocol.instrument.variable.LiveVariable
4141
import spp.protocol.platform.auth.DataRedaction
42+
import spp.protocol.platform.auth.DeveloperRole
4243
import spp.protocol.platform.auth.RedactionType
4344
import spp.protocol.platform.developer.SelfInfo
4445
import spp.protocol.platform.general.Service
@@ -424,4 +425,17 @@ object ProtocolMarshaller {
424425
value.getString("replacement")
425426
)
426427
}
428+
429+
@JvmStatic
430+
fun serializeDeveloperRole(value: DeveloperRole): JsonObject {
431+
return JsonObject(Json.encode(value))
432+
}
433+
434+
@JvmStatic
435+
fun deserializeDeveloperRole(value: JsonObject): DeveloperRole {
436+
return DeveloperRole(
437+
value.getString("roleName"),
438+
value.getBoolean("nativeRole")
439+
)
440+
}
427441
}

src/jvmMain/resources/META-INF/vertx/json-mappers.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ spp.protocol.platform.status.ActiveInstance.deserializer=spp.protocol.marshall.P
2929
spp.protocol.instrument.event.LiveInstrumentRemoved.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLiveInstrumentRemoved
3030
spp.protocol.instrument.event.LiveInstrumentRemoved.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveInstrumentRemoved
3131
spp.protocol.instrument.event.LiveBreakpointHit.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeLiveBreakpointHit
32-
spp.protocol.instrument.event.LiveBreakpointHit.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveBreakpointHit
32+
spp.protocol.instrument.event.LiveBreakpointHit.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeLiveBreakpointHit
33+
spp.protocol.platform.auth.DeveloperRole.serializer=spp.protocol.marshall.ProtocolMarshaller#serializeDeveloperRole
34+
spp.protocol.platform.auth.DeveloperRole.deserializer=spp.protocol.marshall.ProtocolMarshaller#deserializeDeveloperRole

0 commit comments

Comments
 (0)