Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions okio/api/okio.api
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ public final class okio/-InflaterSourceExtensions {
public static synthetic fun inflate$default (Lokio/Source;Ljava/util/zip/Inflater;ILjava/lang/Object;)Lokio/InflaterSource;
}

public final class okio/-Unsigned {
public static final fun readUByte (Lokio/BufferedSource;)B
public static final fun readUInt (Lokio/BufferedSource;)I
public static final fun readUIntLe (Lokio/BufferedSource;)I
public static final fun readULong (Lokio/BufferedSource;)J
public static final fun readULongLe (Lokio/BufferedSource;)J
public static final fun readUShort (Lokio/BufferedSource;)S
public static final fun readUShortLe (Lokio/BufferedSource;)S
public static final fun writeUByte-EK-6454 (Lokio/BufferedSink;B)Lokio/BufferedSink;
public static final fun writeUInt-Qn1smSk (Lokio/BufferedSink;I)Lokio/BufferedSink;
public static final fun writeUIntLe-Qn1smSk (Lokio/BufferedSink;I)Lokio/BufferedSink;
public static final fun writeULong-2TYgG_w (Lokio/BufferedSink;J)Lokio/BufferedSink;
public static final fun writeULongLe-2TYgG_w (Lokio/BufferedSink;J)Lokio/BufferedSink;
public static final fun writeUShort-i8woANY (Lokio/BufferedSink;S)Lokio/BufferedSink;
public static final fun writeUShortLe-i8woANY (Lokio/BufferedSink;S)Lokio/BufferedSink;
Comment on lines +54 to +60
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use @JvmName for these methods??
I don't think that the api should contain this..
Or is this alright??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mangling seems to be stable
https://kotlinlang.org/docs/inline-classes.html#mangling

functions using inline classes are mangled by adding some stable hashcode to the function name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole type is already invisible to Java due to the hyphen. Otherwise this is public API we have to track.

}

public class okio/AsyncTimeout : okio/Timeout {
public fun <init> ()V
public final fun access$newTimeoutException (Ljava/io/IOException;)Ljava/io/IOException;
Expand Down
357 changes: 357 additions & 0 deletions okio/src/commonMain/kotlin/okio/Unsigned.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,357 @@
/*
* Copyright (C) 2019 Square, Inc.
*
* 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
*
* http://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:JvmName("-Unsigned")
@file:Suppress("NOTHING_TO_INLINE") // Syntactic sugar.

package okio

import kotlin.jvm.JvmName

/** Writes an unsigned byte to this sink. */
@Throws(IOException::class)
inline fun <S : BufferedSink> S.writeUByte(b: UByte): S {
writeByte(b.toByte().toInt())
return this
}

/**
* Writes a big-endian, unsigned short to this sink using two bytes.
* ```
* val buffer = Buffer()
* buffer.writeUShort(65534u.toUShort())
* buffer.writeUShort(15u.toUShort())
*
* assertEquals(4, buffer.size)
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xfe.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x0f.toByte(), buffer.readByte())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun <S : BufferedSink> S.writeUShort(b: UShort): S {
writeShort(b.toShort().toInt())
return this
}

/**
* Writes a little-endian, unsigned short to this sink using two bytes.
* ```
* val buffer = Buffer()
* buffer.writeUShortLe(65534u.toUShort())
* buffer.writeUShortLe(15u.toUShort())
*
* assertEquals(4, buffer.size)
* assertEquals(0xfe.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0x0f.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun <S : BufferedSink> S.writeUShortLe(b: UShort): S {
writeShortLe(b.toShort().toInt())
return this
}

/**
* Writes a big-endian, unsigned int to this sink using four bytes.
* ```
* val buffer = Buffer()
* buffer.writeUInt(4294967294u)
* buffer.writeUInt(15u)
*
* assertEquals(8, buffer.size)
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xfe.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x0f.toByte(), buffer.readByte())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun <S : BufferedSink> S.writeUInt(b: UInt): S {
writeInt(b.toInt())
return this
}

/**
* Writes a little-endian, unsigned int to this sink using four bytes.
* ```
* val buffer = Buffer()
* buffer.writeUIntLe(4294967294u)
* buffer.writeUIntLe(15u)
*
* assertEquals(8, buffer.size)
* assertEquals(0xfe.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0x0f.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun <S : BufferedSink> S.writeUIntLe(b: UInt): S {
writeIntLe(b.toInt())
return this
}

/**
* Writes a big-endian, unsigned long to this sink using eight bytes.
* ```
* val buffer = Buffer()
* buffer.writeULong(18446744073709551614uL)
* buffer.writeULong(15u)
*
* assertEquals(16, buffer.size)
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xfe.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x0f.toByte(), buffer.readByte())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun <S : BufferedSink> S.writeULong(b: ULong): S {
writeLong(b.toLong())
return this
}

/**
* Writes a little-endian, unsigned long to this sink using eight bytes.
* ```
* val buffer = Buffer()
* buffer.writeULongLe(18446744073709551614uL)
* buffer.writeULongLe(15uL)
*
* assertEquals(16, buffer.size)
* assertEquals(0xfe.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0xff.toByte(), buffer.readByte())
* assertEquals(0x0f.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0x00.toByte(), buffer.readByte())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun <S : BufferedSink> S.writeULongLe(b: ULong): S {
writeLongLe(b.toLong())
return this
}

/** Removes an unsigned byte from this source and returns it. */
@Throws(IOException::class)
inline fun BufferedSource.readUByte(): UByte {
return readByte().toUByte()
}

/**
* Removes two bytes from this source and returns a big-endian, unsigned short.
* ```
* val buffer = Buffer()
* .writeByte(0xff)
* .writeByte(0xfe)
* .writeByte(0x00)
* .writeByte(0x0f)
* assertEquals(4, buffer.size)
*
* assertEquals(65534u.toUShort(), buffer.readUShort())
* assertEquals(2, buffer.size)
*
* assertEquals(15u.toUShort(), buffer.readUShort())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun BufferedSource.readUShort(): UShort {
return readShort().toUShort()
}

/**
* Removes two bytes from this source and returns a little-endian, unsigned short.
* ```
* val buffer = Buffer()
* .writeByte(0xfe)
* .writeByte(0xff)
* .writeByte(0x0f)
* .writeByte(0x00)
* assertEquals(4, buffer.size)
*
* assertEquals(65534u.toUShort(), buffer.readUShortLe())
* assertEquals(2, buffer.size)
*
* assertEquals(15u.toUShort(), buffer.readUShortLe())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun BufferedSource.readUShortLe(): UShort {
return readShortLe().toUShort()
}

/**
* Removes four bytes from this source and returns a big-endian, unsigned int.
* ```
* val buffer = Buffer()
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xfe)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x0f)
* assertEquals(4, buffer.size)
*
* assertEquals(4294967294u, buffer.readUInt())
* assertEquals(2, buffer.size)
*
* assertEquals(15u, buffer.readUInt())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun BufferedSource.readUInt(): UInt {
return readInt().toUInt()
}

/**
* Removes four bytes from this source and returns a little-endian, unsigned int.
* ```
* val buffer = Buffer()
* .writeByte(0xfe)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0x0f)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* assertEquals(8, buffer.size)
*
* assertEquals(4294967294u, buffer.readUIntLe())
* assertEquals(4, buffer.size)
*
* assertEquals(15u, buffer.readUIntLe())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun BufferedSource.readUIntLe(): UInt {
return readIntLe().toUInt()
}

/**
* Removes eight bytes from this source and returns a big-endian, unsigned long.
* ```
* val buffer = Buffer()
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xfe)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x0f)
* assertEquals(16, buffer.size)
*
* assertEquals(18446744073709551614uL, buffer.readULong())
* assertEquals(8, buffer.size)
*
* assertEquals(15u, buffer.readULong())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun BufferedSource.readULong(): ULong {
return readLong().toULong()
}

/**
* Removes eight bytes from this source and returns a little-endian, unsigned long.
* ```
* val buffer = Buffer()
* .writeByte(0xfe)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0xff)
* .writeByte(0x0f)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* .writeByte(0x00)
* assertEquals(16, buffer.size)
*
* assertEquals(18446744073709551614uL, buffer.readULongLe())
* assertEquals(8, buffer.size)
*
* assertEquals(15u, buffer.readULongLe())
* assertEquals(0, buffer.size)
* ```
*/
@Throws(IOException::class)
inline fun BufferedSource.readULongLe(): ULong {
return readLongLe().toULong()
}
Loading