-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @bencode and @DefaultValue annotations support for Enums
- Loading branch information
1 parent
c426801
commit 8ecbcf0
Showing
7 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
kben-core/src/main/kotlin/kekmech/kben/annotations/DefaultValue.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package kekmech.kben.annotations | ||
|
||
/** | ||
* Annotation pointing to the default enum value. | ||
* | ||
* Add this annotation to one of the enum values so that it is returned in case of an enum deserialization error. | ||
* Annotation affects only the result of deserialization and does not change the result of enum serialization in any way. | ||
* | ||
* Example: | ||
* ```kotlin | ||
* // enum with default value | ||
* enum class SomeOptions { | ||
* OPTION_1, | ||
* OPTION_2, | ||
* | ||
* @DefaultValue UNKNOWN | ||
* } | ||
* // ... | ||
* kben.fromBencode<SomeOptions>("OPTION_3") // returns SomeOptions.UNKNOWN | ||
* ``` | ||
*/ | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target(AnnotationTarget.FIELD) | ||
annotation class DefaultValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 12 additions & 3 deletions
15
kben-core/src/main/kotlin/kekmech/kben/domain/adapters/EnumTypeAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters