# Byte array functions
Name | Description | Complexity |
---|---|---|
drop(ByteVector, Int): ByteVector | Returns a given byte array without the first N bytes | 6 |
dropRight(ByteVector, Int): ByteVector | Returns a given byte array without the last N bytes | 6 |
size(ByteVector): Int | Returns the number of bytes in a byte array | 1 |
take(ByteVector, Int): ByteVector | Returns the first N bytes of a byte array | 6 |
takeRight(ByteVector, Int): ByteVector | Returns the last N bytes of a byte array | 6 |
# drop(ByteVector, Int): ByteVector
Returns a given byte array without the first N
bytes.
drop(xs: ByteVector, number: Int): ByteVector
# Parameters
Parameter | Description |
---|---|
xs : ByteVector | Byte array |
number : Int | Number N . From 0 to 165,947 |
# Examples
drop(base64'UmlkZQ==', 1) # Returns base58'cQCt'
drop(125.toBytes(), 0) # Returns whole byte array: base58'11111113A'
drop(125.toBytes(), 2) # Returns base58'111113A'
drop(125.toBytes(), 8) # Returns the empty byte array: base58''
drop(125.toBytes(), 12) # Returns the empty byte array: base58''
drop(125.toBytes(), -1) # Fails
# dropRight(ByteVector, Int): ByteVector
Returns a given byte array without the last N
bytes.
dropRight(xs: ByteVector, number: Int): ByteVector
# Parameters
Parameter | Description |
---|---|
xs : ByteVector | Byte array |
number : Int | Number N . From 0 to 165,947 |
# Examples
dropRight(base16'52696465', 3) # Returns base58'2R'
dropRight("Ride".toBytes(), 0) # Returns whole byte array: base58'37BPKA'
dropRight("Ride".toBytes(), 3) # Returns base58'2R'
dropRight("Ride".toBytes(), 4) # Returns the empty byte array: base58''
dropRight("Ride".toBytes(), 28) # Returns the empty byte array: base58''
dropRight("Ride".toBytes(), -1) # Fails
# size(ByteVector): Int
Returns the number of bytes in a byte array.
size(byteVector: ByteVector): Int
# Parameters
Parameter | Description |
---|---|
byteBector : ByteVector | Byte array |
# Examples
size("Hello".toBytes()) # Returns 5
size("Hello world".toBytes()) # Returns 11
size(64.toBytes()) # Returns 8 because all integers in Ride take 8 bytes
size(200000.toBytes()) # Returns 8 because all integers in Ride take 8 bytes
size(base58'37BPKA') # Returns 4
# take(ByteVector, Int): ByteVector
Returns the first N
bytes of a byte array.
take(xs: ByteVector, number: Int): ByteVector
# Parameters
Parameter | Description |
---|---|
xs : ByteVector | Byte array |
number : Int | Number N . From 0 to 165,947 |
# Examples
take(base58'37BPKA', 0) # Returns the empty byte array: base58''
take(base58'37BPKA', 1) # Returns the byte array consisting of first byte of initial byte array: base58'2R'
take(base58'37BPKA', 15) # Returns whole byte array: base58'37BPKA'
take(base58'37BPKA', -10) # Fails
# takeRight(ByteVector, Int): ByteVector
Returns the last N
bytes of a byte array.
takeRight(xs: ByteVector, number: Int): ByteVector
# Parameters
Parameter | Description |
---|---|
xs : ByteVector | Byte array |
number : Int | Number N . From 0 to 165,947 |
# Examples
takeRight(base16'52696465', 0) # Returns the empty byte array: base58''
takeRight(base16'52696465', 1) # Returns the byte array consisting of last byte of initial byte array: base58'2k'
takeRight(base16'52696465', 15) # Returns whole byte array: base58'37BPKA'
takeRight(base16'52696465', -10) # Fails