Classes | Public Member Functions | Static Public Attributes | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
com.google.protobuf.ByteString Class Referenceabstract
Inheritance diagram for com.google.protobuf.ByteString:
Inheritance graph
[legend]

Classes

class  AbstractByteIterator
 
class  ArraysByteArrayCopier
 
interface  ByteArrayCopier
 
interface  ByteIterator
 
class  SystemByteArrayCopier
 

Public Member Functions

abstract byte byteAt (int index)
 
abstract byte byteAt (int index)
 
final boolean isEmpty ()
 
final boolean isEmpty ()
 
ByteIterator iterator ()
 
ByteIterator iterator ()
 
abstract int size ()
 
abstract int size ()
 

Static Public Attributes

static final ByteString EMPTY = new LiteralByteString(Internal.EMPTY_BYTE_ARRAY)
 

Static Private Member Functions

static int toInt (byte value)
 
static int toInt (byte value)
 

Private Attributes

int hash = 0
 

Static Private Attributes

static final ByteArrayCopier byteArrayCopier
 
static final int UNSIGNED_BYTE_MASK = 0xFF
 
static final Comparator< ByteStringUNSIGNED_LEXICOGRAPHICAL_COMPARATOR
 

Detailed Description

Immutable sequence of bytes. Substring is supported by sharing the reference to the immutable underlying bytes. Concatenation is likewise supported without copying (long strings) by building a tree of pieces in RopeByteString.

Like String, the contents of a ByteString can never be observed to change, not even in the presence of a data race or incorrect API usage in the client code.

Author
crazy.nosp@m.bob@.nosp@m.googl.nosp@m.e.co.nosp@m.m Bob Lee
kento.nosp@m.n@go.nosp@m.ogle..nosp@m.com Kenton Varda
carla.nosp@m.nton.nosp@m.@goog.nosp@m.le.c.nosp@m.om Carl Haverl
marti.nosp@m.nrb@.nosp@m.googl.nosp@m.e.co.nosp@m.m Martin Buchholz

Immutable sequence of bytes. Provides conversions to and from

byte[]

, {}, ByteBuffer}, InputStream}, OutputStream}. Also provides a conversion to CodedInputStream}. Like String, the contents of a ByteString can never be observed to change, not even in the presence of a data race or incorrect API usage in the client code.

Substring is supported by sharing the reference to the immutable underlying bytes. Concatenation is likewise supported without copying (long strings) by building a tree of pieces in RopeByteString.

Author
crazy.nosp@m.bob@.nosp@m.googl.nosp@m.e.co.nosp@m.m Bob Lee
kento.nosp@m.n@go.nosp@m.ogle..nosp@m.com Kenton Varda
carla.nosp@m.nton.nosp@m.@goog.nosp@m.le.c.nosp@m.om Carl Haverl
marti.nosp@m.nrb@.nosp@m.googl.nosp@m.e.co.nosp@m.m Martin Buchholz

Definition at line 67 of file bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java.

Member Function Documentation

◆ byteAt() [1/2]

abstract byte com.google.protobuf.ByteString.byteAt ( int  index)
abstract

Gets the byte at the given index. This method should be used only for random access to individual bytes. To access bytes sequentially, use the ByteIterator returned by {}, and call #substring(int, int)} first if necessary. index index of byte the value IndexOutOfBoundsException index < 0 or index >= size

◆ byteAt() [2/2]

abstract byte com.google.protobuf.ByteString.byteAt ( int  index)
abstract

Gets the byte at the given index. This method should be used only for random access to individual bytes. To access bytes sequentially, use the ByteIterator returned by {}, and call #substring(int, int)} first if necessary. index index of byte the value IndexOutOfBoundsException index < 0 or index >= size

◆ isEmpty() [1/2]

final boolean com.google.protobuf.ByteString.isEmpty ( )
inline

Returns

true

if the size is

0

,

false

otherwise.

Returns
true if this is zero bytes long

Definition at line 225 of file bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java.

◆ isEmpty() [2/2]

final boolean com.google.protobuf.ByteString.isEmpty ( )
inline

Returns

true

if the size is

0

,

false

otherwise.

Returns
true if this is zero bytes long

Definition at line 235 of file protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java.

◆ iterator() [1/2]

ByteIterator com.google.protobuf.ByteString.iterator ( )
inline

Return a ByteString.ByteIterator over the bytes in the ByteString. To avoid auto-boxing, you may get the iterator manually and call ByteIterator#nextByte().

Returns
the iterator

Definition at line 165 of file bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java.

◆ iterator() [2/2]

ByteIterator com.google.protobuf.ByteString.iterator ( )
inline

Return a ByteString.ByteIterator over the bytes in the ByteString. To avoid auto-boxing, you may get the iterator manually and call ByteIterator#nextByte().

Returns
the iterator

Definition at line 175 of file protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java.

◆ size() [1/2]

abstract int com.google.protobuf.ByteString.size ( )
abstract

Gets the number of bytes.

Returns
size in bytes

◆ size() [2/2]

abstract int com.google.protobuf.ByteString.size ( )
abstract

Gets the number of bytes.

Returns
size in bytes

◆ toInt() [1/2]

static int com.google.protobuf.ByteString.toInt ( byte  value)
inlinestaticprivate

Returns the value of the given byte as an integer, interpreting the byte as an unsigned value. That is, returns

value + 256

if

is negative;

itself otherwise.

Note: This code was copied from com.google.common.primitives.UnsignedBytes#toInt, as Guava libraries cannot be used in the

package.

Definition at line 242 of file bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java.

◆ toInt() [2/2]

static int com.google.protobuf.ByteString.toInt ( byte  value)
inlinestaticprivate

Returns the value of the given byte as an integer, interpreting the byte as an unsigned value. That is, returns

value + 256

if

is negative;

itself otherwise.

Note: This code was copied from com.google.common.primitives.UnsignedBytes#toInt, as Guava libraries cannot be used in the

package.

Definition at line 252 of file protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java.

Member Data Documentation

◆ byteArrayCopier

static final ByteArrayCopier com.google.protobuf.ByteString.byteArrayCopier
staticprivate

◆ EMPTY

static final ByteString com.google.protobuf.ByteString.EMPTY = new LiteralByteString(Internal.EMPTY_BYTE_ARRAY)
static

◆ hash

int com.google.protobuf.ByteString.hash = 0
private

Cached hash value. Intentionally accessed via a data race, which is safe because of the Java Memory Model's "no out-of-thin-air values" guarantees for ints. A value of 0 implies that the hash has not been set.

Definition at line 133 of file bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java.

◆ UNSIGNED_BYTE_MASK

static final int com.google.protobuf.ByteString.UNSIGNED_BYTE_MASK = 0xFF
staticprivate

◆ UNSIGNED_LEXICOGRAPHICAL_COMPARATOR

static final Comparator< ByteString > com.google.protobuf.ByteString.UNSIGNED_LEXICOGRAPHICAL_COMPARATOR
staticprivate
Initial value:
=
new Comparator<ByteString>() {
@Override
public int compare(ByteString former, ByteString latter) {
ByteIterator formerBytes = former.iterator();
ByteIterator latterBytes = latter.iterator();
while (formerBytes.hasNext() && latterBytes.hasNext()) {
int result =
Integer.compare(toInt(formerBytes.nextByte()), toInt(latterBytes.nextByte()));
if (result != 0) {
return result;
}
}
return Integer.compare(former.size(), latter.size());
}
}

Compares two ByteStrings lexicographically, treating their contents as unsigned byte values between 0 and 255 (inclusive).

For example,

(byte) -1

is considered to be greater than

(byte) 1

because it is interpreted as an unsigned value,

255

.

Definition at line 253 of file bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java.


The documentation for this class was generated from the following file:
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
com.google.protobuf
Definition: bloaty/third_party/protobuf/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java:2
com.google.protobuf.ByteString.toInt
static int toInt(byte value)
Definition: bloaty/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java:242
value
const char * value
Definition: hpack_parser_table.cc:165
ares::byte
unsigned char byte
Definition: ares-test.h:33
com.google
com
compare
static int compare(const TEST_INT **a, const TEST_INT **b)
Definition: stack_test.cc:214


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:02