-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move builders to package
...encoding.base*
(#126)
- Loading branch information
Showing
22 changed files
with
1,351 additions
and
131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# MIGRATION | ||
|
||
## Preamble | ||
|
||
`2.0.0` release contained a breaking API change which broke binary compatibility. | ||
This was attributed to an issue with Java 9 `Module`s, for which JPMS disallows | ||
split packages. The `encoding-base16`, `encoding-base32` and `encoding-base64` | ||
dependencies were the cause of the issue because their builder classes and functions | ||
were located in the same package named `io.matthewnelson.encoding.builders`. Those | ||
classes and functions were subsequently deprecated in release `1.2.3` so consumers | ||
could gracefully update before upgrading to `2.0.0` where they have been removed. | ||
|
||
For more details, see [[#124]][124]. | ||
|
||
## Migration guide for 1.x.x -> 2.0.0 | ||
|
||
- Update dependency to `1.2.3` | ||
- Migration method 1: | ||
- Use your IDE or editor to search your project for the following | ||
``` | ||
import io.matthewnelson.encoding.builders | ||
``` | ||
- Replace `.builders` with the new package location (either `base16`, `base32`, or `base64`) | ||
- Migration method 2: | ||
- Use the provided `ReplaceWith` functionality of the `@Deprecated` notice | ||
to update to the new builder class/function package locations. | ||
- Update dependency to `2.0.0` | ||
|
||
[124]: https://github.com/05nelsonm/encoding/issues/124 |
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
144 changes: 144 additions & 0 deletions
144
library/encoding-base16/src/commonMain/kotlin/io/matthewnelson/encoding/base16/Builders.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,144 @@ | ||
/* | ||
* Copyright (c) 2023 Matthew Nelson | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
@file:Suppress("SpellCheckingInspection") | ||
|
||
package io.matthewnelson.encoding.base16 | ||
|
||
import io.matthewnelson.encoding.base16.Base16.Config | ||
import io.matthewnelson.encoding.core.EncodingException | ||
import kotlin.jvm.JvmField | ||
import kotlin.jvm.JvmOverloads | ||
|
||
/** | ||
* Creates a configured [Base16] encoder/decoder. | ||
* | ||
* @param [config] inherit settings from. | ||
* @see [Base16ConfigBuilder] | ||
* */ | ||
public fun Base16( | ||
config: Config?, | ||
block: Base16ConfigBuilder.() -> Unit | ||
): Base16 { | ||
val builder = Base16ConfigBuilder(config) | ||
block.invoke(builder) | ||
return Base16(builder.build()) | ||
} | ||
|
||
/** | ||
* Creates a configured [Base16] encoder/decoder. | ||
* | ||
* @see [Base16ConfigBuilder] | ||
* */ | ||
public fun Base16( | ||
block: Base16ConfigBuilder.() -> Unit | ||
): Base16 { | ||
return Base16(config = null, block) | ||
} | ||
|
||
/** | ||
* Creates a configured [Base16] encoder/decoder | ||
* using the default settings. | ||
* | ||
* @param [strict] If true, configures the encoder/decoder | ||
* to be in strict accordance with RFC 4648. | ||
* @see [Base16ConfigBuilder] | ||
* */ | ||
@JvmOverloads | ||
public fun Base16(strict: Boolean = false): Base16 = Base16 { if (strict) strict() } | ||
|
||
|
||
/** | ||
* Builder for creating a [Base16.Config]. | ||
* | ||
* @see [strict] | ||
* @see [io.matthewnelson.encoding.base16.Base16] | ||
* */ | ||
public class Base16ConfigBuilder { | ||
|
||
public constructor() | ||
public constructor(config: Config?): this() { | ||
if (config == null) return | ||
isLenient = config.isLenient ?: true | ||
lineBreakInterval = config.lineBreakInterval | ||
encodeToLowercase = config.encodeToLowercase | ||
} | ||
|
||
/** | ||
* If true, spaces and new lines ('\n', '\r', ' ', '\t') | ||
* will be skipped over when decoding (against RFC 4648). | ||
* | ||
* If false, an [EncodingException] will be thrown if | ||
* those characters are encountered when decoding. | ||
* */ | ||
@JvmField | ||
public var isLenient: Boolean = true | ||
|
||
/** | ||
* For every [lineBreakInterval] of encoded data, a | ||
* line break will be output. | ||
* | ||
* Will **ONLY** output line breaks if [isLenient] is | ||
* set to **true**. | ||
* | ||
* e.g. | ||
* | ||
* isLenient = true | ||
* lineBreakInterval = 0 | ||
* // 48656C6C6F20576F726C6421 | ||
* | ||
* isLenient = true | ||
* lineBreakInterval = 16 | ||
* // 48656C6C6F20576F | ||
* // 726C6421 | ||
* | ||
* isLenient = false | ||
* lineBreakInterval = 16 | ||
* // 48656C6C6F20576F726C6421 | ||
* | ||
* Enable by setting to a value between 1 and 127, and | ||
* setting [isLenient] to true. | ||
* | ||
* A great value is 64 | ||
* */ | ||
@JvmField | ||
public var lineBreakInterval: Byte = 0 | ||
|
||
/** | ||
* If true, will output lowercase characters when | ||
* encoding (against RFC 4648). | ||
* | ||
* If false, will output uppercase characters when | ||
* encoding. | ||
* */ | ||
@JvmField | ||
public var encodeToLowercase: Boolean = false | ||
|
||
/** | ||
* A shortcut for configuring things to be in strict | ||
* adherence with RFC 4648. | ||
* */ | ||
public fun strict(): Base16ConfigBuilder { | ||
isLenient = false | ||
lineBreakInterval = 0 | ||
encodeToLowercase = false | ||
return this | ||
} | ||
|
||
/** | ||
* Builds a [Base16.Config] for the provided settings. | ||
* */ | ||
public fun build(): Config = Config.from(this) | ||
} |
Oops, something went wrong.