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)
 
final boolean isEmpty ()
 
ByteIterator iterator ()
 
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)
 

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

Definition at line 67 of file ByteString.java.

Member Function Documentation

◆ byteAt()

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()

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 ByteString.java.

◆ iterator()

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 ByteString.java.

◆ size()

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

Gets the number of bytes.

Returns
size in bytes

◆ toInt()

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 ByteString.java.

Member Data Documentation

◆ byteArrayCopier

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

Definition at line 121 of file ByteString.java.

◆ EMPTY

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

Empty

ByteString

.

Definition at line 85 of file ByteString.java.

◆ 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 ByteString.java.

◆ UNSIGNED_BYTE_MASK

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

Definition at line 232 of file ByteString.java.

◆ UNSIGNED_LEXICOGRAPHICAL_COMPARATOR

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 ByteString.java.


The documentation for this class was generated from the following file:
com.google.protobuf
Definition: ProtoCaliperBenchmark.java:2
com.google.protobuf.ByteString.toInt
static int toInt(byte value)
Definition: ByteString.java:242
byte
SETUP_TEARDOWN_TESTCONTEXT typedef uint8_t byte
Definition: test_stream.cpp:12
com.google
com
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:06