import { BytesReader } from ".." ; import { Byte } from "../Byte" ; import { CompactInt } from "../Int" ; import { DecodedData } from "../interfaces/DecodedData" ; import { AbstractArray } from "./AbstractArray" ; export class ByteArray extends AbstractArray < Byte , u8 > { description public toHexString ( ) { let result = "0x" ; for ( let i = 0 ; i < super . values . length ; i ++ ) { const str = super . values [ i ] . toString ( 16 ) ; if ( str . length == 1 ) { result += "0" ; } result += str ; } return result ; } description public decodeElement ( value ) { const scaleByte = Byte . fromU8a ( [ value [ 0 ] ] ) ; return new DecodedData < u8 > ( scaleByte . unwrap ( ) , scaleByte . encodedLength ( ) ) ; } description public encodedLength ( ) { return ( new CompactInt ( i64 ( this . values . length ) ) . encodedLength ( ) ) + super . values . length ; } description param bytes param index populateFromBytes ( bytes , index = 0 ) { const bytesReader = new BytesReader ( bytes . slice ( index ) ) ; const data = bytesReader . readInto < CompactInt > ( ) ; for ( let i = 0 ; i < i32 ( data . unwrap ( ) ) ; i ++ ) { const element = bytesReader . readInto < Byte > ( ) ; this . values . push ( element . unwrap ( ) ) ; } } description static fromU8a ( input , index = 0 ) { return AbstractArray . fromU8a < ByteArray > ( input . slice ( index ) ) ; } @ inline @ operator ( "==" ) static eq ( a , b ) { return a . eq ( b ) ; } @ inline @ operator ( "!=" ) static notEq ( a , b ) { return a . notEq ( b ) ; } }