ByteString

scalus.builtin.ByteString
See theByteString companion class
object ByteString

Attributes

Companion
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
ByteString.type

Members list

Type members

Inherited classlikes

object given_Decoder_ByteString extends Decoder[ByteString]

Attributes

Inherited from:
ByteStringOffchainApi (hidden)
Supertypes
trait Decoder[ByteString]
class Object
trait Matchable
class Any
object given_Encoder_ByteString extends Encoder[ByteString]

Attributes

Inherited from:
ByteStringOffchainApi (hidden)
Supertypes
trait Encoder[ByteString]
class Object
trait Matchable
class Any
object given_Ordering_ByteString extends Ordering[ByteString]

Attributes

Inherited from:
ByteStringOffchainApi (hidden)
Supertypes
trait Ordering[ByteString]
trait PartialOrdering[ByteString]
trait Equiv[ByteString]
trait Serializable
trait Comparator[ByteString]
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

inline def fromBigIntBigEndian(value: BigInt, size: BigInt): ByteString

Encodes a BigInt value as a Big-Endian (most-significant bytes first) ByteString.

Encodes a BigInt value as a Big-Endian (most-significant bytes first) ByteString.

Value parameters

size

is the expected size in number of bytes.

value

is the value to encode.

Attributes

Note

This function fails (i.e. halts the program) if the value cannot fit in the given size. When the size is too large, the ByteString is left-padded with zeroes.

Example
 ByteString.fromBigIntBigEndian(1_000_000, 3) == hex"0f4240"
 ByteString.fromBigIntBigEndian(1_000_000, 5) == hex"00000f4240"
 ByteString.fromBigIntBigEndian(0, 8) == hex"0000000000000000"
 ByteString.fromBigIntBigEndian(1_000_000, 1) => 💥
inline def fromBigIntLittleEndian(value: BigInt, size: BigInt): ByteString

Encodes a BigInt value as a Little-Endian (least-significant bytes first) ByteString.

Encodes a BigInt value as a Little-Endian (least-significant bytes first) ByteString.

Value parameters

size

is the expected size in number of bytes.

value

is the value to encode.

Attributes

Example
 ByteString.fromBigIntLittleEndian(1_000_000, 3) == hex"40420f"
 ByteString.fromBigIntLittleEndian(1_000_000, 5) == hex"40420f0000"
 ByteString.fromBigIntLittleEndian(0, 8) == hex"0000000000000000"
 ByteString.fromBigIntLittleEndian(1_000_000, 1) => 💥

Inherited methods

def apply(bytes: Byte*): ByteString

Creates a ByteString from a variable number of bytes

Creates a ByteString from a variable number of bytes

Offchain operation, not available onchain.

Attributes

Inherited from:
ByteStringOffchainApi (hidden)
def fill(size: Int, byte: Byte): ByteString

Creates a ByteString of a given size filled with a specific byte

Creates a ByteString of a given size filled with a specific byte

Offchain operation, not available onchain.

Value parameters

byte

the byte to fill the ByteString with

size

the size of the ByteString

Attributes

Inherited from:
ByteStringOffchainApi (hidden)
def fromArray(bytes: Array[Byte]): ByteString

Creates a ByteString from an [[Array[Byte]]

Creates a ByteString from an [[Array[Byte]]

Offchain operation, not available onchain.

Attributes

Note

This method is specially treated by the Scalus compiler plugin, thus it's not required to be in the @Compile module.

Inherited from:
ByteStringOffchainApi (hidden)
def fromHex(bytes: String): ByteString

Creates a ByteString from a hexadecimal string

Creates a ByteString from a hexadecimal string

Onchain and offchain operation.

Value parameters

bytes

the hexadecimal string to convert to a ByteString

Attributes

Note

This method is specially treated by the Scalus compiler plugin, thus it's not required to be in the @Compile module.

Inherited from:
ByteStringOffchainApi (hidden)
def fromString(s: String): ByteString

Creates a ByteString from a UTF-8 encoded string

Creates a ByteString from a UTF-8 encoded string

Onchain and offchain operation.

Value parameters

s

the string to convert to a ByteString

Attributes

Note

This method is specially treated by the Scalus compiler plugin, thus it's not required to be in the @Compile module.

Inherited from:
ByteStringOffchainApi (hidden)
def unsafeFromArray(bytes: Array[Byte]): ByteString

Creates a ByteString from an array of bytes without copying the array

Creates a ByteString from an array of bytes without copying the array

Attributes

Inherited from:
ByteStringOffchainApi (hidden)

Inherited fields

Creates an empty ByteString

Creates an empty ByteString

Onchain and offchain operation.

Attributes

Note

This field is specially treated by the Scalus compiler plugin, thus it's not required to be in the @Compile module.

Inherited from:
ByteStringOffchainApi (hidden)

Givens

Inherited givens

Attributes

Inherited from:
ByteStringOffchainApi (hidden)

Attributes

Inherited from:
ByteStringOffchainApi (hidden)

Attributes

Inherited from:
ByteStringOffchainApi (hidden)

Extensions

Extensions

extension (b: BigInt)
infix inline def +:(bs: ByteString): ByteString

Prepends a BigInt to a ByteString and returns a new ByteString

Prepends a BigInt to a ByteString and returns a new ByteString

Attributes

extension (self: ByteString)
infix inline def ++(that: ByteString): ByteString

Concatenates two ByteStrings and returns a new ByteString

Concatenates two ByteStrings and returns a new ByteString

Attributes

infix inline def <(that: ByteString): Boolean

Checks if one 'ByteString' is less than another

Checks if one 'ByteString' is less than another

Attributes

infix inline def <=(that: ByteString): Boolean

Checks if one 'ByteString' is less than or equal to another

Checks if one 'ByteString' is less than or equal to another

Attributes

infix inline def >(that: ByteString): Boolean

Checks if one 'ByteString' is greater than another

Checks if one 'ByteString' is greater than another

Attributes

infix inline def >=(that: ByteString): Boolean

Checks if one 'ByteString' is greater than or equal to another

Checks if one 'ByteString' is greater than or equal to another

Attributes

inline def at(index: BigInt): BigInt

Returns the byte at the specified index in the ByteString

Returns the byte at the specified index in the ByteString

Attributes

Throws
BuiltinException

if the index is out of bounds (offchain)

def drop(n: BigInt): ByteString

Drops the first n bytes from the ByteString

Drops the first n bytes from the ByteString

Value parameters

n

the number of bytes to drop

Attributes

Example
 hex"1234567890abcdef".drop(0) // returns hex"1234567890abcdef"
 hex"1234567890abcdef".drop(4) // returns hex"90abcdef"
 hex"1234567890abcdef".drop(20) // returns hex""
 hex"".drop(20) // returns hex""
inline def length: BigInt

Returns the length of the ByteString

Returns the length of the ByteString

Attributes

inline def slice(from: BigInt, len: BigInt): ByteString

Returns a new ByteString that is a slice of the original ByteString

Returns a new ByteString that is a slice of the original ByteString

Value parameters

from

the starting index of the slice (inclusive)

len

the length of the slice

Attributes

Example
 hex"1234567890abcdef".slice(2, 4) // returns hex"567890ab"
 hex"1234567890abcdef".slice(5, 4) // returns hex"abcdef"
 hex"1234567890abcdef".slice(9, 4) // returns hex""
 hex"1234567890abcdef".slice(0, 0) // returns hex""
inline def take(n: BigInt): ByteString

Takes the first n bytes from the ByteString

Takes the first n bytes from the ByteString

Value parameters

n

the number of bytes to take

Attributes

Example
 hex"1234567890abcdef".take(0) // returns hex""
 hex"1234567890abcdef".take(4) // returns hex"12345678"
 hex"1234567890abcdef".take(20) // returns hex"1234567890abcdef"
 hex"".take(20) // returns hex""

Inherited extensions

extension (sc: StringContext)
def hex(args: Any*): ByteString

Hex string interpolator

Hex string interpolator

Works on and offchain. Converts a hexadecimal string to a ByteString.

Attributes

Note

This method is specially treated by the Scalus compiler plugin, thus it's not required to be in the @Compile module.

Example
val hexString = hex"deadbeef"
val withSpaces = hex"de ad be ef"
val upperCase = hex"DEADBEEF"
Inherited from:
ByteStringOffchainApi (hidden)