bytes-core

Provides universal interface for having an immutable representation of sequence of bytes

Лицензия

Лицензия

MIT
Группа

Группа

com.avast.bytes
Идентификатор

Идентификатор

bytes-core
Последняя версия

Последняя версия

2.2.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

bytes-core
Provides universal interface for having an immutable representation of sequence of bytes
Ссылка на сайт

Ссылка на сайт

https://github.com/avast/bytes
Организация-разработчик

Организация-разработчик

Avast
Система контроля версий

Система контроля версий

https://github.com/avast/bytes

Скачать bytes-core

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.avast.bytes/bytes-core/ -->
<dependency>
    <groupId>com.avast.bytes</groupId>
    <artifactId>bytes-core</artifactId>
    <version>2.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.avast.bytes/bytes-core/
implementation 'com.avast.bytes:bytes-core:2.2.0'
// https://jarcasting.com/artifacts/com.avast.bytes/bytes-core/
implementation ("com.avast.bytes:bytes-core:2.2.0")
'com.avast.bytes:bytes-core:jar:2.2.0'
<dependency org="com.avast.bytes" name="bytes-core" rev="2.2.0">
  <artifact name="bytes-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.avast.bytes', module='bytes-core', version='2.2.0')
)
libraryDependencies += "com.avast.bytes" % "bytes-core" % "2.2.0"
[com.avast.bytes/bytes-core "2.2.0"]

Зависимости

test (4)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12
com.novocode : junit-interface jar 0.11
ch.qos.logback : logback-classic jar 1.2.3
javax.annotation : javax.annotation-api jar 1.3.2

Модули Проекта

Данный проект не имеет модулей.

Bytes

Build Version

This library contains an immutable representation of sequence of bytes: com.avast.bytes.Bytes.

The goal is to provide single immutable representation of bytes that is not dependent on a third-party library (like com.google.protobuf.ByteString). However, multiple implementations of the Bytes interface can be created using third-party libraries to take advantage of their benefits (io.netty.buffer.ByteBuf for example). Implementations that require third-party dependencies will be separated to their own module, while the core module provides only the API and implementations based on Java standard library.

Features of Bytes include:

  • reading encapsulated data using random (Bytes.byteAt(int)) and linear (Bytes.newInputStream()) access
  • zero copy substring views (Bytes.view(int, int))
  • zero copy concat (Bytes.concat(otherBytes))
  • utility methods for reading & writing hex strings (Bytes.copyFromHex(someBytes.toHexString))
  • reading directly from InputStream (in some implementations, e.g. ByteArrayBytes.readFrom(is) or ByteArrayBytes.readFrom(is, offset, length))

Usage

Parsing Google Protocol Buffer message: Assume NotificationData is a class generated by protoc.

Bytes bytes = ...

try (InputStream bytesStream = bytes.newInputStream()) {
    NotificationData message = NotificationData.parseFrom(bytesStream);
}

Serializing Google Protocol Buffer message to Bytes:

NotificationData message = ...
try (Bytes.BuilderStream builder = ByteBufBytes.newBuilder(message.getSerializedSize())) {
    message.writeTo(builder);
    Bytes bytes = builder.toBytes();
}

...or serialize the message to ByteString as usual and wrap it with ByteStringBytes.

JDK-based implementations

The core module contains two implementations:

  • ByteArrayBytes - backed by byte[]
  • ByteBufferBytes - backed by java.nio.ByteBuffer
ByteArrayBytes bab = ByteArrayBytes.copyFrom(new byte[]{0, 0, 7});

ByteBufferBytes bbb = ByteBufferBytes.copyFrom(ByteBuffer.allocate(1024)); // the most useless buffer ever

com.google.protobuf.ByteString wrapper

The gpb module provides ByteStringBytes that implements Bytes by wrapping com.google.protobuf.ByteString.

ByteStringBytes bsb = ByteStringBytes.wrap(ByteString.copyFromUtf8("foo"));
com.avast.bytes

Avast

https://avast.github.io

Версии библиотеки

Версия
2.2.0
2.1.2
2.1.1
2.1.0