Skip to content

Commit

Permalink
Serializer cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Aug 21, 2023
1 parent 0da4c62 commit 6eb9ac1
Showing 1 changed file with 1 addition and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ context(BitFlags, GenerationContext)
internal fun TypeSpec.Builder.addSerializer() = addObject("Serializer") {
addModifiers(INTERNAL)
addSuperinterface(K_SERIALIZER.parameterizedBy(collectionCN))

addProperty<SerialDescriptor>("descriptor", OVERRIDE) {
initializer(
"%M(%S, %T)",
Expand All @@ -34,25 +33,22 @@ internal fun TypeSpec.Builder.addSerializer() = addObject("Serializer") {
valueType.toPrimitiveKind(),
)
}

addProperty("delegate", K_SERIALIZER.parameterizedBy(valueCN), PRIVATE) {
when (valueType) {
INT -> initializer("%T.%M()", valueCN, SERIALIZER_METHOD)
BIT_SET -> initializer("%T.serializer()", valueCN)
}
}

addFunction("serialize") {
addModifiers(OVERRIDE)
addParameter<Encoder>("encoder")
addParameter("value", collectionCN)
addStatement("encoder.encodeSerializableValue(delegate, value.$valueName)")
}

addFunction("deserialize") {
addModifiers(OVERRIDE)
returns(collectionCN)
addParameter<Decoder>("decoder")
returns(collectionCN)
addStatement("return %T(decoder.decodeSerializableValue(delegate))", collectionCN)
}
}

0 comments on commit 6eb9ac1

Please sign in to comment.