scodec.bits

ByteVector

sealed trait ByteVector extends BitwiseOperations[ByteVector, Int] with Serializable

An immutable vector of bytes, backed by a balanced binary tree of chunks. Most operations are logarithmic in the depth of this tree, including ++, :+, +:, update, and insert. Where possible, operations return lazy views rather than copying any underlying bytes. Use copy to copy all underlying bytes to a fresh, array-backed ByteVector.

Unless otherwise noted, operations follow the same naming as the scala standard library collections, though this class does not extend any of the standard scala collections. Use toIndexedSeq, toSeq, or toIterable to obtain a regular scala.collection type.

Source
ByteVector.scala
Linear Supertypes
Type Hierarchy Learn more about scaladoc diagrams
Ordering
  1. Grouped
  2. Alphabetic
  3. By inheritance
Inherited
  1. ByteVector
  2. Serializable
  3. Serializable
  4. BitwiseOperations
  5. AnyRef
  6. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def getImpl(index: Int): Byte

    Attributes
    protected
  2. abstract def size: Int

    Returns the number of bytes in this vector.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. final def &(other: ByteVector): ByteVector

    Returns a bitwise AND of this value with the specified value.

    Returns a bitwise AND of this value with the specified value.

    The resulting value's size is the minimum of this value's size and the specified value's size.

    Definition Classes
    BitwiseOperations
  4. def +(other: String): String

    Implicit information
    This member is added by an implicit conversion from ByteVector to any2stringadd[ByteVector] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  5. def ++(other: ByteVector): ByteVector

    Returns a new byte vector representing this vector's contents followed by the specified vector's contents.

  6. final def +:(byte: Byte): ByteVector

    Returns a new vector with the specified byte prepended.

  7. def ->[B](y: B): (ByteVector, B)

    Implicit information
    This member is added by an implicit conversion from ByteVector to ArrowAssoc[ByteVector] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  8. def :+(byte: Byte): ByteVector

    Returns a new vector with the specified byte appended.

  9. final def <<(n: Int): ByteVector

    Returns a value of the same size with each bit shifted to the left n bits.

    Returns a value of the same size with each bit shifted to the left n bits.

    Definition Classes
    BitwiseOperations
  10. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. final def >>(n: Int): ByteVector

    Returns a value of the same size with each bit shifted to the right n bits where the n left-most bits are sign extended.

    Returns a value of the same size with each bit shifted to the right n bits where the n left-most bits are sign extended.

    Definition Classes
    BitwiseOperations
  12. final def >>>(n: Int): ByteVector

    Returns a value of the same size with each bit shifted to the right n bits where the n left-most bits are low.

    Returns a value of the same size with each bit shifted to the right n bits where the n left-most bits are low.

    Definition Classes
    BitwiseOperations
  13. final def ^(other: ByteVector): ByteVector

    Returns a bitwise XOR of this value with the specified value.

    Returns a bitwise XOR of this value with the specified value.

    The resulting value's size is the minimum of this value's size and the specified value's size.

    Definition Classes
    BitwiseOperations
  14. def acquire(n: Int): Either[String, ByteVector]

    Returns a vector whose contents are the results of taking the first n bytes of this vector.

    Returns a vector whose contents are the results of taking the first n bytes of this vector.

    If this vector does not contain at least n bytes, an error message is returned.

    See also

    take

  15. final def and(other: ByteVector): ByteVector

    Returns a bitwise AND of this bit vector with the specified bit vector.

    Returns a bitwise AND of this bit vector with the specified bit vector.

    The resulting bit vector's size is the minimum of this bit vector's size and the specified bit vector's size.

    Definition Classes
    ByteVectorBitwiseOperations
  16. final def apply(index: Int): Byte

    Alias for get.

    Alias for get.

    Exceptions thrown
    IndexOutOfBoundsException

    if the specified index is not in [0, size)

  17. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  18. final def bits: BitVector

    Alias for toBitVector.

  19. final def buffer: ByteVector

    Allocate (unobservable) mutable scratch space at the end of this ByteVector, which will be used to support fast :+ and ++ of small vectors.

    Allocate (unobservable) mutable scratch space at the end of this ByteVector, which will be used to support fast :+ and ++ of small vectors. A default chunk size is used.

    Note that :+, ++, and drop on the result of a call to buffer are guaranteed to return another buffered ByteVector.

  20. final def bufferBy(chunkSize: Int): ByteVector

    Allocate (unobservable) mutable scratch space at the end of this ByteVector, with chunks of the given size, which will be used to support fast :+ and ++ of small vectors.

    Allocate (unobservable) mutable scratch space at the end of this ByteVector, with chunks of the given size, which will be used to support fast :+ and ++ of small vectors.

    Note that :+, ++, and drop on the result of a call to buffer are guaranteed to return another buffered ByteVector, with the same size scratch space.

  21. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def compact: ByteVector

    Returns a vector with the same contents but represented as a single tree node internally.

    Returns a vector with the same contents but represented as a single tree node internally.

    This may involve copying data, but has the advantage that lookups index directly into a single node rather than traversing a logarithmic number of nodes in this tree.

    Calling this method on an already compacted vector is a no-op.

  23. final def consume[A](n: Int)(decode: (ByteVector) ⇒ Either[String, A]): Either[String, (ByteVector, A)]

    Consumes the first n bytes of this vector and decodes them with the specified function, resulting in a vector of the remaining bytes and the decoded value.

    Consumes the first n bytes of this vector and decodes them with the specified function, resulting in a vector of the remaining bytes and the decoded value. If this vector does not have n bytes or an error occurs while decoding, an error is returned instead.

  24. final def containsSlice(slice: ByteVector): Boolean

    Determines if the specified slice is in this vector.

  25. final def copy: ByteVector

    Returns a vector with the same contents as this vector but with a single compacted node made up by evaluating all internal nodes and concatenating their values.

  26. final def copyToArray(xs: Array[Byte], start: Int): Unit

    Copies the contents of this vector to array xs, beginning at index start.

  27. final def copyToStream(s: OutputStream): Unit

    Copies the contents of this vector to OutputStream s.

  28. final def digest(digest: MessageDigest): ByteVector

    Computes a digest of this byte vector.

    Computes a digest of this byte vector.

    digest

    digest to use

  29. final def digest(algorithm: String): ByteVector

    Computes a digest of this byte vector.

    Computes a digest of this byte vector.

    algorithm

    digest algorithm to use

  30. def drop(n: Int): ByteVector

    Returns a vector of all bytes in this vector except the first n bytes.

    Returns a vector of all bytes in this vector except the first n bytes.

    The resulting vector's size is 0 max (size - n).

  31. final def dropRight(n: Int): ByteVector

    Returns a vector of all bytes in this vector except the last n bytes.

    Returns a vector of all bytes in this vector except the last n bytes.

    The resulting vector's size is 0 max (size - n).

  32. final def endsWith(b: ByteVector): Boolean

    Returns true if this byte vector ends with the specified vector.

  33. def ensuring(cond: (ByteVector) ⇒ Boolean, msg: ⇒ Any): ByteVector

    Implicit information
    This member is added by an implicit conversion from ByteVector to Ensuring[ByteVector] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  34. def ensuring(cond: (ByteVector) ⇒ Boolean): ByteVector

    Implicit information
    This member is added by an implicit conversion from ByteVector to Ensuring[ByteVector] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  35. def ensuring(cond: Boolean, msg: ⇒ Any): ByteVector

    Implicit information
    This member is added by an implicit conversion from ByteVector to Ensuring[ByteVector] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  36. def ensuring(cond: Boolean): ByteVector

    Implicit information
    This member is added by an implicit conversion from ByteVector to Ensuring[ByteVector] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  37. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  38. def equals(other: Any): Boolean

    Returns true if the specified value is a ByteVector with the same contents as this vector.

    Returns true if the specified value is a ByteVector with the same contents as this vector.

    Definition Classes
    ByteVector → AnyRef → Any
  39. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  40. final def foldLeft[A](z: A)(f: (A, Byte) ⇒ A): A

    Applies a binary operator to a start value and all elements of this vector, going left to right.

    Applies a binary operator to a start value and all elements of this vector, going left to right.

    z

    starting value

    f

    operator to apply

  41. final def foldRight[A](z: A)(f: (Byte, A) ⇒ A): A

    Applies a binary operator to a start value and all elements of this vector, going right to left.

    Applies a binary operator to a start value and all elements of this vector, going right to left.

    z

    starting value

    f

    operator to apply

  42. final def foreach(f: (Byte) ⇒ Unit): Unit

    Applies the specified function to each element of this vector.

  43. def formatted(fmtstr: String): String

    Implicit information
    This member is added by an implicit conversion from ByteVector to StringFormat[ByteVector] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  44. def get(index: Int): Byte

    Gets the byte at the specified index.

    Gets the byte at the specified index.

    Exceptions thrown
    IndexOutOfBoundsException

    if the specified index is not in [0, size)

  45. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  46. final def grouped(chunkSize: Int): Stream[ByteVector]

    Converts this vector in to a sequence of chunkSize-byte vectors.

  47. lazy val hashCode: Int

    Calculates the hash code of this vector.

    Calculates the hash code of this vector. The result is cached.

    Definition Classes
    ByteVector → AnyRef → Any
  48. final def head: Byte

    Returns the first byte of this vector or throws if vector is emtpy.

  49. final def headOption: Option[Byte]

    Returns the first byte of this vector or None if vector is emtpy.

  50. def iff(other: ByteVector): ByteVector

    Returns a bitwise if-and-only-if of this value with the specified value.

    Returns a bitwise if-and-only-if of this value with the specified value.

    The resulting value's size is the minimum of this value's size and the specified value's size.

    Definition Classes
    BitwiseOperations
  51. def implies(other: ByteVector): ByteVector

    Returns a bitwise implication of this value with the specified value.

    Returns a bitwise implication of this value with the specified value.

    The resulting value's size is the minimum of this value's size and the specified value's size.

    Definition Classes
    BitwiseOperations
  52. final def indexOfSlice(slice: ByteVector, from: Int): Int

    Finds the first index after from of the specified byte pattern in this vector.

    Finds the first index after from of the specified byte pattern in this vector.

    returns

    index of slice or -1 if not found

  53. final def indexOfSlice(slice: ByteVector): Int

    Finds the first index of the specified byte pattern in this vector.

    Finds the first index of the specified byte pattern in this vector.

    returns

    index of slice or -1 if not found

  54. final def init: ByteVector

    Returns a vector of all bytes in this vector except the last byte.

  55. final def insert(idx: Int, b: Byte): ByteVector

    Returns a vector with the specified byte inserted at the specified index.

  56. final def isEmpty: Boolean

    Returns true if this vector has no bytes.

  57. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  58. final def last: Byte

    Returns the last byte in this vector or throws if vector is empty.

  59. final def lastOption: Option[Byte]

    Returns the last byte in this vector or returns None if vector is empty.

  60. final def length: Int

    Alias for size.

  61. final def lift(index: Int): Option[Byte]

    Returns the byte at the specified index, or None if the index is out of range.

  62. final def map(f: (Byte) ⇒ Byte): ByteVector

    Returns a vector where each byte is the result of applying the specified function to the corresponding byte in this vector.

    Returns a vector where each byte is the result of applying the specified function to the corresponding byte in this vector. This method returns a view and hence, is O(1). Call compact generate a new strict vector.

  63. final def mapI(f: (Byte) ⇒ Int): ByteVector

    Returns a vector where each byte is the result of applying the specified function to the corresponding byte in this vector.

    Returns a vector where each byte is the result of applying the specified function to the corresponding byte in this vector. Only the least significant byte is used (the three most significant bytes are ignored). This method returns a view and hence, is O(1). Call compact generate a new strict vector.

  64. def nand(other: ByteVector): ByteVector

    Returns a bitwise NAND of this value with the specified value.

    Returns a bitwise NAND of this value with the specified value.

    The resulting value's size is the minimum of this value's size and the specified value's size.

    Definition Classes
    BitwiseOperations
  65. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  66. final def nonEmpty: Boolean

    Returns true if this vector has a non-zero number of bytes.

  67. def nor(other: ByteVector): ByteVector

    Returns a bitwise NOR of this value with the specified value.

    Returns a bitwise NOR of this value with the specified value.

    The resulting value's size is the minimum of this value's size and the specified value's size.

    Definition Classes
    BitwiseOperations
  68. final def not: ByteVector

    Returns a bitwise complement of this bit vector.

    Returns a bitwise complement of this bit vector.

    Definition Classes
    ByteVectorBitwiseOperations
  69. final def notify(): Unit

    Definition Classes
    AnyRef
  70. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  71. final def or(other: ByteVector): ByteVector

    Returns a bitwise OR of this bit vector with the specified bit vector.

    Returns a bitwise OR of this bit vector with the specified bit vector.

    The resulting bit vector's size is the minimum of this bit vector's size and the specified bit vector's size.

    Definition Classes
    ByteVectorBitwiseOperations
  72. final def padLeft(n: Int): ByteVector

    Returns an n-bytes vector whose contents are 0 or more zero bytes followed by this vector's contents.

    Returns an n-bytes vector whose contents are 0 or more zero bytes followed by this vector's contents.

    Exceptions thrown
    IllegalArgumentException

    if n < size

  73. final def padRight(n: Int): ByteVector

    Returns an n-byte vector whose contents are this vector's contents followed by 0 or more zero bytes.

    Returns an n-byte vector whose contents are this vector's contents followed by 0 or more zero bytes.

    Exceptions thrown
    IllegalArgumentException

    if n < size

  74. final def padTo(n: Int): ByteVector

    Alias for padRight.

    Alias for padRight.

    Exceptions thrown
    IllegalArgumentException

    if n < size

  75. final def partialCompact(chunkSize: Int): ByteVector

    Invokes compact on any subtrees whose size is <= chunkSize.

  76. final def patch(idx: Int, b: ByteVector): ByteVector

    Returns a vector with the specified byte vector replacing bytes [idx, idx + b.size].

  77. final def reverse: ByteVector

    Returns a vector with the bytes of this vector in reverse order.

    Returns a vector with the bytes of this vector in reverse order. This method returns a view and hence, is O(1). Call compact generate a new strict vector.

  78. final def rotateLeft(n: Int): ByteVector

    Returns a bit vector of the same size with each bit circularly shifted to the left n bits.

    Returns a bit vector of the same size with each bit circularly shifted to the left n bits.

    Definition Classes
    ByteVectorBitwiseOperations
  79. final def rotateRight(n: Int): ByteVector

    Returns a bit vector of the same size with each bit circularly shifted to the right n bits.

    Returns a bit vector of the same size with each bit circularly shifted to the right n bits.

    Definition Classes
    ByteVectorBitwiseOperations
  80. final def shiftLeft(n: Int): ByteVector

    Returns a bit vector of the same size with each bit shifted to the left n bits.

    Returns a bit vector of the same size with each bit shifted to the left n bits.

    Definition Classes
    ByteVectorBitwiseOperations
  81. final def shiftRight(n: Int, signExtension: Boolean): ByteVector

    Returns a bit vector of the same size with each bit shifted to the right n bits.

    Returns a bit vector of the same size with each bit shifted to the right n bits.

    signExtension

    whether the n left-msot bits should take on the value of bit 0

    Definition Classes
    ByteVectorBitwiseOperations
  82. final def slice(from: Int, until: Int): ByteVector

    Returns a vector made up of the bytes starting at index from up to index until.

  83. final def splice(idx: Int, b: ByteVector): ByteVector

    Returns a vector with the specified byte vector inserted at the specified index.

  84. final def splitAt(n: Int): (ByteVector, ByteVector)

    Returns a pair of vectors that is equal to (take(n), drop(n)).

  85. final def startsWith(b: ByteVector): Boolean

    Returns true if this byte vector starts with the specified vector.

  86. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  87. final def tail: ByteVector

    Returns a vector of all bytes in this vector except the first byte.

  88. def take(n: Int): ByteVector

    Returns a vector of the first n bytes of this vector.

    Returns a vector of the first n bytes of this vector.

    The resulting vector's size is n min size.

    Note: if an n-bit vector is required, use the acquire method instead.

    See also

    acquire

  89. final def takeRight(n: Int): ByteVector

    Returns a vector of the last n bytes of this vector.

    Returns a vector of the last n bytes of this vector.

    The resulting vector's size is n min size.

  90. final def toArray: Array[Byte]

    Converts the contents of this vector to a byte array.

  91. final def toBase64(alphabet: Base64Alphabet): String

    Converts the contents of this vector to a base 64 string using the specified alphabet.

  92. final def toBase64: String

    Converts the contents of this vector to a base 64 string.

  93. final def toBin(alphabet: BinaryAlphabet): String

    Converts the contents of this byte vector to a binary string of size * 8 digits.

  94. final def toBin: String

    Converts the contents of this byte vector to a binary string of size * 8 digits.

  95. final def toBitVector: BitVector

    Converts the contents of this vector to a bit vector of size * 8 bits.

  96. final def toByte(signed: Boolean = true): Byte

    Converts the contents of this vector to a byte.

    Converts the contents of this vector to a byte.

    signed

    whether sign extension should be performed

    Exceptions thrown
    IllegalArgumentException

    if size is greater than 8

  97. final def toByteBuffer: ByteBuffer

    Represents the contents of this vector as a read-only java.nio.ByteBuffer.

    Represents the contents of this vector as a read-only java.nio.ByteBuffer.

    The returned buffer is read-only with limit set to the minimum number of bytes needed to represent the contents of this vector, position set to zero, and remaining set to the limit.

  98. final def toHex(alphabet: HexAlphabet): String

    Converts the contents of this byte vector to a hexadecimal string of size * 2 nibbles.

  99. final def toHex: String

    Converts the contents of this byte vector to a hexadecimal string of size * 2 nibbles.

  100. final def toIndexedSeq: IndexedSeq[Byte]

    Converts the contents of this vector to an IndexedSeq.

  101. final def toInt(signed: Boolean = true, ordering: ByteOrdering = ByteOrdering.BigEndian): Int

    Converts the contents of this vector to an int.

    Converts the contents of this vector to an int.

    signed

    whether sign extension should be performed

    ordering

    order bytes should be processed in

    Exceptions thrown
    IllegalArgumentException

    if size is greater than 32

  102. final def toIterable: Iterable[Byte]

    Converts the contents of this vector to an Iterable.

  103. final def toLong(signed: Boolean = true, ordering: ByteOrdering = ByteOrdering.BigEndian): Long

    Converts the contents of this vector to an int.

    Converts the contents of this vector to an int.

    signed

    whether sign extension should be performed

    ordering

    order bytes should be processed in

    Exceptions thrown
    IllegalArgumentException

    if size is greater than 64

  104. final def toSeq: Seq[Byte]

    Converts the contents of this vector to a Seq.

  105. final def toShort(signed: Boolean = true, ordering: ByteOrdering = ByteOrdering.BigEndian): Short

    Converts the contents of this vector to a short.

    Converts the contents of this vector to a short.

    signed

    whether sign extension should be performed

    ordering

    order bytes should be processed in

    Exceptions thrown
    IllegalArgumentException

    if size is greater than 16

  106. def toString(): String

    Display the size and bytes of this ByteVector.

    Display the size and bytes of this ByteVector. For bit vectors beyond a certain size, only a hash of the contents are shown.

    Definition Classes
    ByteVector → AnyRef → Any
  107. final def unary_~(): ByteVector

    Returns a bitwise complement of this value.

    Returns a bitwise complement of this value.

    Definition Classes
    BitwiseOperations
  108. def unbuffer: ByteVector

    Collapse any buffered chunks at the end of this ByteVector, resulting in an unbuffered ByteVector.

  109. final def update(idx: Int, b: Byte): ByteVector

    Returns a vector with the byte at the specified index replaced with the specified byte.

  110. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  111. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  112. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  113. final def writeReplace(): AnyRef

    Attributes
    protected
  114. final def xor(other: ByteVector): ByteVector

    Returns a bitwise XOR of this bit vector with the specified bit vector.

    Returns a bitwise XOR of this bit vector with the specified bit vector.

    The resulting bit vector's size is the minimum of this bit vector's size and the specified bit vector's size.

    Definition Classes
    ByteVectorBitwiseOperations
  115. final def zipWith(other: ByteVector)(f: (Byte, Byte) ⇒ Byte): ByteVector

    Returns a new vector where each byte is the result of evaluating the specified function against the bytes of this vector and the specified vector at the corresponding index.

    Returns a new vector where each byte is the result of evaluating the specified function against the bytes of this vector and the specified vector at the corresponding index. The resulting vector has size this.size min other.size. This method returns a view and hence, is O(1). Call compact generate a new strict vector.

  116. final def zipWithI(other: ByteVector)(op: (Byte, Byte) ⇒ Int): ByteVector

    Returns a new vector where each byte is the result of evaluating the specified function against the bytes of this vector and the specified vector at the corresponding index.

    Returns a new vector where each byte is the result of evaluating the specified function against the bytes of this vector and the specified vector at the corresponding index. The resulting vector has size this.size min other.size. Only the least significant byte is used (the three most significant bytes are ignored). This method returns a view and hence, is O(1). Call compact generate a new strict vector.

  117. final def |(other: ByteVector): ByteVector

    Returns a bitwise OR of this value with the specified value.

    Returns a bitwise OR of this value with the specified value.

    The resulting value's size is the minimum of this value's size and the specified value's size.

    Definition Classes
    BitwiseOperations
  118. def [B](y: B): (ByteVector, B)

    Implicit information
    This member is added by an implicit conversion from ByteVector to ArrowAssoc[ByteVector] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from Serializable

Inherited from Serializable

Inherited from BitwiseOperations[ByteVector, Int]

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from ByteVector to any2stringadd[ByteVector]

Inherited by implicit conversion StringFormat from ByteVector to StringFormat[ByteVector]

Inherited by implicit conversion Ensuring from ByteVector to Ensuring[ByteVector]

Inherited by implicit conversion ArrowAssoc from ByteVector to ArrowAssoc[ByteVector]

Collection Like Methods

Bitwise Operations

Conversions

Buffering

Ungrouped