Skip to content
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

use ByteString.toArrayUnsafe #308

Merged
merged 1 commit into from
May 18, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ object Gzip extends Codec {
override def compress(uncompressed: ByteString): ByteString = {
val baos = new ByteArrayOutputStream(uncompressed.size)
val gzos = new GZIPOutputStream(baos)
try gzos.write(uncompressed.toArray)
try gzos.write(uncompressed.toArrayUnsafe())
finally gzos.close()
ByteString.fromArrayUnsafe(baos.toByteArray)
}

override def uncompress(compressed: ByteString): ByteString = {
val gzis = new GZIPInputStream(new ByteArrayInputStream(compressed.toArray))
val gzis = new GZIPInputStream(new ByteArrayInputStream(compressed.toArrayUnsafe()))
Copy link
Contributor

Choose a reason for hiding this comment

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

could we have used compressed.asInputStream? because toArrayUnsafe can still create a new array in case the byteString is a rope.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. We need to use MethodHandles to still support Pekko 1.0 (asInputStream is only in Pekko 1.1).

Something like https://github.com/apache/pekko-http/pull/539/files (this was reverted because of a bug in the hpack code - twitter/hpack#43).

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to use MethodHandles to still support Pekko 1.0 (asInputStream is only in Pekko 1.1).

thats unfortunate

this was reverted because of a bug in the hpack code - twitter/hpack#43

last commit of that library was 5 years ago. also it seems to be deprecated

Copy link
Member

Choose a reason for hiding this comment

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

May be we can the netty 's Hpack?

Copy link
Member

Choose a reason for hiding this comment

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

We need to use MethodHandles to still support Pekko 1.0 (asInputStream is only in Pekko 1.1).

IMHO we could just require Pekko 1.1 in Pekko gRPC 1.1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@raboof I got rid of the MethodHandle in #309


val baos = new ByteArrayOutputStream(compressed.size)
val buffer = new Array[Byte](32 * 1024)
Expand Down
Loading