Package com.google.protobuf
Class ByteString.BoundedByteString
java.lang.Object
com.google.protobuf.ByteString
com.google.protobuf.ByteString.LeafByteString
com.google.protobuf.ByteString.LiteralByteString
com.google.protobuf.ByteString.BoundedByteString
- All Implemented Interfaces:
Serializable
,Iterable<Byte>
- Enclosing class:
ByteString
This class is used to represent the substring of a
ByteString
over a single byte array.
In terms of the public API of ByteString
, you end up here by calling ByteString.copyFrom(byte[])
followed by ByteString.substring(int, int)
.
This class contains most of the overhead involved in creating a substring from a ByteString.LiteralByteString
. The overhead involves some range-checking and two extra fields.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.protobuf.ByteString
ByteString.AbstractByteIterator, ByteString.ByteIterator, ByteString.CodedBuilder, ByteString.LeafByteString, ByteString.Output
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
private final int
private static final long
Fields inherited from class com.google.protobuf.ByteString.LiteralByteString
bytes
Fields inherited from class com.google.protobuf.ByteString
CONCATENATE_BY_COPY_SIZE, EMPTY, MAX_READ_FROM_CHUNK_SIZE, MIN_READ_FROM_CHUNK_SIZE
-
Constructor Summary
ConstructorsConstructorDescriptionBoundedByteString
(byte[] bytes, int offset, int length) Creates aBoundedByteString
backed by the sub-range of given array, without copying. -
Method Summary
Modifier and TypeMethodDescriptionbyte
byteAt
(int index) Gets the byte at the given index.protected void
copyToInternal
(byte[] target, int sourceOffset, int targetOffset, int numberToCopy) Internal (package private) implementation ofByteString.copyTo(byte[],int,int,int)
.protected int
Offset intobytes[]
to use, non-zero for substrings.(package private) byte
internalByteAt
(int index) Gets the byte at the given index, assumes bounds checking has already been performed.private void
int
size()
Gets the number of bytes.(package private) Object
Methods inherited from class com.google.protobuf.ByteString.LiteralByteString
asReadOnlyByteBuffer, asReadOnlyByteBufferList, copyTo, equals, equalsRange, isValidUtf8, newCodedInput, newInput, partialHash, partialIsValidUtf8, substring, toStringInternal, writeTo, writeTo, writeToInternal
Methods inherited from class com.google.protobuf.ByteString.LeafByteString
getTreeDepth, isBalanced, writeToReverse
Methods inherited from class com.google.protobuf.ByteString
checkIndex, checkRange, concat, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFrom, copyFromUtf8, copyTo, copyTo, empty, endsWith, fromHex, hashCode, isEmpty, iterator, newCodedBuilder, newOutput, newOutput, nioByteString, peekCachedHashCode, readFrom, readFrom, readFrom, startsWith, substring, toByteArray, toString, toString, toString, toStringUtf8, unsignedLexicographicalComparator, wrap, wrap, wrap, writeTo
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
bytesOffset
private final int bytesOffset -
bytesLength
private final int bytesLength -
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
BoundedByteString
BoundedByteString(byte[] bytes, int offset, int length) Creates aBoundedByteString
backed by the sub-range of given array, without copying.- Parameters:
bytes
- array to wrapoffset
- index to first byte to use in byteslength
- number of bytes to use from bytes- Throws:
IllegalArgumentException
- ifoffset < 0
,length < 0
, or ifoffset + length > bytes.length
.
-
-
Method Details
-
byteAt
public byte byteAt(int index) Gets the byte at the given index. ThrowsArrayIndexOutOfBoundsException
for backwards-compatibility reasons although it would more properly beIndexOutOfBoundsException
.- Overrides:
byteAt
in classByteString.LiteralByteString
- Parameters:
index
- index of byte- Returns:
- the value
- Throws:
ArrayIndexOutOfBoundsException
-index
is invalid input: '<' 0 or >= size
-
internalByteAt
byte internalByteAt(int index) Description copied from class:ByteString
Gets the byte at the given index, assumes bounds checking has already been performed.- Overrides:
internalByteAt
in classByteString.LiteralByteString
- Parameters:
index
- index of byte- Returns:
- the value
-
size
public int size()Description copied from class:ByteString
Gets the number of bytes.- Overrides:
size
in classByteString.LiteralByteString
- Returns:
- size in bytes
-
getOffsetIntoBytes
protected int getOffsetIntoBytes()Description copied from class:ByteString.LiteralByteString
Offset intobytes[]
to use, non-zero for substrings.- Overrides:
getOffsetIntoBytes
in classByteString.LiteralByteString
- Returns:
- always 0 for this class
-
copyToInternal
protected void copyToInternal(byte[] target, int sourceOffset, int targetOffset, int numberToCopy) Description copied from class:ByteString
Internal (package private) implementation ofByteString.copyTo(byte[],int,int,int)
. It assumes that all error checking has already been performed and thatnumberToCopy > 0
.- Overrides:
copyToInternal
in classByteString.LiteralByteString
-
writeReplace
Object writeReplace() -
readObject
- Throws:
IOException
-