Skip to content

Commit

Permalink
Merge remote-tracking branch 'lk/main' into sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Apr 15, 2023
2 parents 570edf1 + df707d8 commit fb90332
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 42 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,10 @@ jobs:
- name: Build with Gradle
run: ./gradlew build

- name: Upload report to codecov.io
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: library/build/reports/jacoco/test/jacocoTestReport.xml
flags: unittests
fail_ci_if_error: true

- name: Publish SNAPSHOT
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
ORG_GRADLE_PROJECT_useSnapshot: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:

- name: Publish RELEASE to Maven Central
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
run: ./gradlew publishRelease
8 changes: 0 additions & 8 deletions .github/workflows/ci-pulls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,3 @@ jobs:

- name: Build with Gradle
run: ./gradlew build

- name: Upload report to codecov.io
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: library/build/reports/jacoco/test/jacocoTestReport.xml
flags: unittests
fail_ci_if_error: true
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
val serializationVersion = "1.0.0"

allprojects {
group = "de.brudaswen.kotlinx.serialization"
group = "com.lightningkite"

extra["serializationVersion"] = serializationVersion

Expand All @@ -32,7 +32,7 @@ release {
val mavenCentralUsername: String? by project
val mavenCentralPassword: String? by project
nexusStaging {
packageGroup = "de.brudaswen"
packageGroup = "com.lightningkite"
username = mavenCentralUsername
password = mavenCentralPassword
numberOfRetries = 60
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.0.1-SNAPSHOT
version=2.0.4-SNAPSHOT
kotlin.code.style=official

# Disable generation of metadata sha256/sha512 checksum
Expand Down
21 changes: 16 additions & 5 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import java.time.Duration
import java.net.URI

plugins {
kotlin("jvm")
Expand Down Expand Up @@ -94,20 +95,27 @@ publishing {
}
}
developers {
developer {
id.set("LightningKiteJoseph")
name.set("Joseph Ivie")
email.set("[email protected]")
organization.set("Lightning Kite")
organizationUrl.set("https://lightningkite.com")
}
developer {
id.set("brudaswen")
name.set("Sven Obser")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:git://github.com/brudaswen/kotlinx-serialization-csv.git")
developerConnection.set("scm:git:ssh://[email protected]:brudaswen/kotlinx-serialization-csv.git")
url.set("https://github.com/brudaswen/kotlinx-serialization-csv/")
connection.set("scm:git:git://github.com/lightningkite/kotlinx-serialization-csv.git")
developerConnection.set("scm:git:ssh://[email protected]:lightningkite/kotlinx-serialization-csv.git")
url.set("https://github.com/lightningkite/kotlinx-serialization-csv/")
}
issueManagement {
system.set("GitHub Issues")
url.set("https://github.com/brudaswen/kotlinx-serialization-csv/issues/")
url.set("https://github.com/lightningkite/kotlinx-serialization-csv/issues/")
}
}

Expand All @@ -119,7 +127,10 @@ publishing {

nexusPublishing {
repositories {
sonatype()
sonatype() {
this.nexusUrl.set(URI("https://s01.oss.sonatype.org/content/repositories/releases/"))
this.snapshotRepositoryUrl.set(URI("https://s01.oss.sonatype.org/content/repositories/snapshots"))
}
}

clientTimeout.set(Duration.ofMinutes(30))
Expand Down
18 changes: 4 additions & 14 deletions library/src/main/kotlin/kotlinx/serialization/csv/Csv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,7 @@ sealed class Csv(internal val config: CsvConfig) : SerialFormat, StringFormat {
* @param appendable The output where the CSV will be written.
*/
fun <T> encodeSequenceToAppendable(serializer: KSerializer<T>, values: Sequence<T>, appendable: Appendable) {
val encoder = RecordListCsvEncoder(this, CsvWriter(appendable, config))
val listDescriptor = ListSerializer(serializer).descriptor
encoder.encodeStructure(listDescriptor) {
var index = 0
for (value in values) {
encodeSerializableElement(listDescriptor, index++, serializer, value)
}
}
values.forEach(beginEncodingToAppendable(serializer, appendable))
}

/**
Expand All @@ -84,11 +77,9 @@ sealed class Csv(internal val config: CsvConfig) : SerialFormat, StringFormat {
@ExperimentalSerializationApi
fun <T> beginEncodingToAppendable(serializer: KSerializer<T>, appendable: Appendable): (T) -> Unit {
val encoder = RecordListCsvEncoder(this, CsvWriter(appendable, config))
val listDescriptor = ListSerializer(serializer).descriptor
encoder.beginStructure(listDescriptor)
var index = 0
return {
encoder.encodeSerializableElement(listDescriptor, index++, serializer, it)
encoder.encodeSerializableValue(serializer, it)
}
}

Expand Down Expand Up @@ -136,14 +127,13 @@ sealed class Csv(internal val config: CsvConfig) : SerialFormat, StringFormat {
val csv = CsvReader(FetchSource(reader), config)
val listDescriptor = ListSerializer(deserializer).descriptor
val input = RecordListCsvDecoder(this, csv)
val structure = input.beginStructure(listDescriptor)
var previousValue: T? = null

return generateSequence {
val decodedIndex = structure.decodeElementIndex(listDescriptor)
val decodedIndex = input.decodeElementIndex(listDescriptor)
if (decodedIndex == DECODE_DONE) return@generateSequence null
val nextValue =
structure.decodeSerializableElement(listDescriptor, decodedIndex, deserializer, previousValue)
input.decodeSerializableElement(listDescriptor, decodedIndex, deserializer, previousValue)
previousValue = nextValue
nextValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,37 @@ class ExampleTest {
}
assertEquals(testData, result)
}

@Test
fun testStreamingHeaders() {
val csv = Csv {
hasHeaderRecord = true
}
val testData = listOf(
Tire(FRONT, LEFT, 245, 35, 21),
Tire(FRONT, RIGHT, 245, 35, 21),
Tire(REAR, LEFT, 265, 35, 21),
Tire(REAR, RIGHT, 265, 35, 21),
Tire(FRONT, LEFT, 265, 35, 20),
Tire(FRONT, RIGHT, 265, 35, 20),
Tire(REAR, LEFT, 265, 35, 20),
Tire(REAR, RIGHT, 265, 35, 20)
)

val input = PipedReader()
val out = PipedWriter(input)
Thread(
Runnable {
csv.encodeSequenceToAppendable(Tire.serializer(), testData.asSequence(), out)
out.close()
}
).start()
val result = ArrayList<Tire>()
csv.decodeFromReaderUsingSequence(Tire.serializer(), input) {
it.forEach {
result.add(it)
}
}
assertEquals(testData, result)
}
}

0 comments on commit fb90332

Please sign in to comment.