-
Notifications
You must be signed in to change notification settings - Fork 64
A trimmed-down API #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fzhinkin
merged 83 commits into
prototype-preview
from
prototype-preview-trimmed-down-api
Jun 27, 2023
Merged
A trimmed-down API #136
Changes from 76 commits
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
492c601
Remove ByteString-related API
fzhinkin 87a44b2
First round of the refactoring
fzhinkin ee9c395
Enable Dokka
fzhinkin 8847c34
Enable Kover for core-io
fzhinkin 597bb41
Suppressed/fixed warnings
fzhinkin fb7b533
Update API dump
fzhinkin 5efafef
Extract utf8-related methods from Sink/Source into ext functions
fzhinkin 800bccb
Updated documentation, added additional tests
fzhinkin 78bc776
Add more JVM-specific tests
fzhinkin 372c3c9
Remove some unused and commented out code
fzhinkin 1cc5e14
Update documentation
fzhinkin 2f25f19
Added module description
fzhinkin 863b359
Move internal utf8-related code to -Utf8.kt
fzhinkin 8b00289
Enabled toString test, fixed implementation.
fzhinkin 28cda06
Cleaned up the code.
fzhinkin 198b140
Improve test coverage
fzhinkin 34510ff
Add more tests on UTF-8
fzhinkin efc3a27
Fix FS-related tests on Windows
fzhinkin 45da73f
Updated documentation
fzhinkin cd368b4
Updated usage example
fzhinkin 90c9ba3
Enable explicit API mode
fzhinkin 1568f29
Treat all warnings as errors for native compilation tasks
fzhinkin 9b94d6b
Get rid of unneeded annotations
fzhinkin e6cf5c9
Cleanup imports
fzhinkin 36e779a
Remove more Throws annotations
fzhinkin 93c37af
Extract some JVM-specific member functions to extension functions
fzhinkin 04ab7f7
Move Source.readByteArray to extensions
fzhinkin 18c8637
Move readFully([B) to extensions
fzhinkin ee0dd50
Remove 'cancel' method
fzhinkin fadd590
Accept Byte and Short in corresponding write methods, support unsigne…
fzhinkin 0fc1fad
Don't implement channels on JVM, return proxy objects instead
fzhinkin 336da54
Mark buffer getters and emitCompleteSegments as delicate API requirin…
fzhinkin 33545dc
Source::readFully should accept RawSink instead of Buffer
fzhinkin f349aa8
Fixed line reading tests
fzhinkin f48baab
Cleanup
fzhinkin ddfcd11
Annotate methods using delicate API with corresponding OptIn
fzhinkin dc35855
Cleanup comments and docs
fzhinkin b82fb82
Improve implementations
fzhinkin 863cf29
Rename tests
fzhinkin 08e7cd2
Cleanup
fzhinkin a9d113e
Fixed imports
fzhinkin e55e9b1
Don't override equals/hashCode for Buffer
fzhinkin d55e78a
Enable source /w options test
fzhinkin d3b9179
Throw IllegalArgumentException instead of IOOBE
fzhinkin 2f73fd5
Don't return a receiver from write methods
fzhinkin 79c927c
Enabled missing targets
fzhinkin 008cc82
Get rid of SharedImmutable
fzhinkin b492ae5
Get rid of some platform-specific implementations
fzhinkin cfe3f40
Implement AutoClosable from stdlib instead of custom Closable interface
fzhinkin b404e72
Simplified receiver decl for Sink's extensions
fzhinkin c6a9395
Make Source and Sink regular interfaces, not expects
fzhinkin 29845d6
Update Buffer::toString doc
fzhinkin ef49ac5
Make public API intended for internal use less accessible
fzhinkin d0cff32
Fixed pathSourceWithOptions test on Windows
fzhinkin a6a0f64
Apply new naming conventions
fzhinkin c3720f1
Use start + end indices instead of offset + byteCount
fzhinkin b29ea3c
Change readByteArray signature to avoid too large arrays allocation
fzhinkin 76fc0ec
Improve exception messages by adding more context to it
fzhinkin 281f9c7
Fix readDecimalLong and readHexadecimalUnsignedLong behavior
fzhinkin 2de3209
Cleanup
fzhinkin 0e7646e
Document naming convention and methods behavior
fzhinkin 5d3e19c
Fixed typo
fzhinkin 115e8ea
Updated API dump
fzhinkin 31821a7
Fix arguments handling and closed-state checks
fzhinkin 0041f9f
Improve test coverage
fzhinkin 6a7a03f
Fixed Buffer::toString
fzhinkin e6785c1
Rewrite hex- and decimal-long reading extensions w/o peek
fzhinkin ada8927
Support array's subrange in Source::readTo
fzhinkin 873661e
Renamed Buffer::writeTo(OutputStream) to readTo
fzhinkin 535a8f7
Updated sample in module description
fzhinkin dc7483a
Renamed unsigned int write methods to follow the common naming conven…
fzhinkin afcfd08
Removed JVM-specific unnecessary extensions
fzhinkin 7c49413
Update dependencies
fzhinkin e5fec12
Improved exception messages, fixed few typos, updated docs
fzhinkin eb97548
Add -Xjvm-default=all to compiler args
fzhinkin 32f207f
Renamed methods returning wrappers for Sink/Source and vice versa
fzhinkin 2b7eb60
Change Buffer::toString format
fzhinkin 5171a28
Clarify copyTo behavior in the documentation
fzhinkin a96726f
Make parameter names in public API more verbose
fzhinkin c5f8d0e
Rename BlackholeSink to DiscardingSink
fzhinkin a579e33
Explicitly specify what does the 'buffer bounds' mean
fzhinkin 3a506b8
Removed unused code
fzhinkin 47d2964
Hide utf8Size and code-point related functions
fzhinkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,84 @@ | ||
# Module kotlinx-io-core | ||
|
||
The module provides core multiplatform IO primitives and integrates it with platform-specific APIs. | ||
|
||
`kotlinx-io core` aims to provide a concise but powerful API along with efficient implementation. | ||
|
||
The main interfaces for the IO interaction are [kotlinx.io.Source] and [kotlinx.io.Sink] providing buffered read and | ||
write operations for integer types, byte arrays, and other sources and sinks. There are also extension functions | ||
bringing support for strings and other types. | ||
Implementations of these interfaces are built on top of [kotlinx.io.Buffer], [kotlinx.io.RawSource], | ||
and [kotlinx.io.RawSink]. | ||
|
||
A central part of the library, [kotlinx.io.Buffer], is a container optimized to reduce memory allocations and to avoid | ||
data copying when possible. | ||
|
||
[kotlinx.io.RawSource] and [kotlinx.io.RawSink] are interfaces aimed for integration with anything that can provide | ||
or receive data: network interfaces, files, etc. The module provides integration with some platform-specific IO APIs, | ||
but if something not yet supported by the library needs to be integrated, then these interfaces are exactly what should | ||
be implemented for that. | ||
|
||
Example below shows how to manually serialize an object to [BSON](https://bsonspec.org/spec.html) | ||
and then back to an object using `kotlinx.io`. Please note that the example aimed to show `kotlinx-io` API in action, | ||
rather than to provide a robust BSON-serialization. | ||
```kotlin | ||
data class Message(val timestamp: Long, val text: String) { | ||
companion object | ||
} | ||
|
||
fun Message.toBson(sink: Sink) { | ||
val buffer = Buffer() | ||
with (buffer) { | ||
writeByte(0x9) // UTC-timestamp field | ||
writeUtf8("timestamp") // field name | ||
writeByte(0) | ||
writeLongLe(timestamp) // field value | ||
writeByte(0x2) // string field | ||
writeUtf8("text") // field name | ||
writeByte(0) | ||
writeIntLe(text.utf8Size().toInt() + 1) // field value: length followed by the string | ||
writeUtf8(text) | ||
writeByte(0) | ||
writeByte(0) // end of BSON document | ||
} | ||
|
||
// Write document length and then its body | ||
sink.writeIntLe(buffer.size.toInt() + 4) | ||
buffer.transferTo(sink) | ||
sink.flush() | ||
} | ||
|
||
fun Message.Companion.fromBson(source: Source): Message { | ||
source.require(4) // check if the source contains length | ||
val length = source.readIntLe() - 4L | ||
source.require(length) // check if the source contains the whole message | ||
|
||
fun readFieldName(source: Source): String { | ||
val delimiterOffset = source.indexOf(0) // find offset of the 0-byte terminating the name | ||
check(delimiterOffset >= 0) // indexOf return -1 if value not found | ||
val fieldName = source.readUtf8(delimiterOffset) // read the string until terminator | ||
source.skip(1) // skip the terminator | ||
return fieldName | ||
} | ||
|
||
// for simplicity, let's assume that the order of fields matches serialization order | ||
var tag = source.readByte().toInt() // read the field type | ||
check(tag == 0x9 && readFieldName(source) == "timestamp") | ||
val timestamp = source.readLongLe() // read long value | ||
tag = source.readByte().toInt() | ||
check(tag == 0x2 && readFieldName(source) == "text") | ||
val textLen = source.readIntLe() - 1L // read string length (it includes the terminator) | ||
val text = source.readUtf8(textLen) // read value | ||
source.skip(1) // skip terminator | ||
source.skip(1) // skip end of the document | ||
return Message(timestamp, text) | ||
} | ||
``` | ||
|
||
# Package kotlinx.io | ||
|
||
Core IO primitives. | ||
|
||
# Package kotlinx.io.files | ||
|
||
Basic API for working with files. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.