import { BytesReader , CompactInt } from ".." ; import { DecodedData } from "../interfaces/DecodedData" ; import { ScaleString } from "../ScaleString" ; import { Bytes } from "../utils/Bytes" ; import { AbstractArray } from "./AbstractArray" ; export class StringArray extends AbstractArray < ScaleString , string > { description public decodeElement ( value ) { const stringLength = Bytes . decodeCompactInt ( value ) ; const encodedStringLength = i32 ( stringLength . decBytes + stringLength . value ) ; return new DecodedData < string > ( ScaleString . fromU8a ( value . slice ( 0 , encodedStringLength ) ) . toString ( ) , encodedStringLength ) ; } description public encodedLength ( ) { let len = new CompactInt ( this . values . length ) . encodedLength ( ) ; for ( let i = 0 ; i < this . values . length ; i ++ ) { const value = new ScaleString ( this . values [ i ] ) ; len += value . encodedLength ( ) ; } return len ; } 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 < ScaleString > ( ) ; this . values . push ( element . toString ( ) ) ; } } description static fromU8a ( input ) { return AbstractArray . fromU8a < StringArray > ( input ) ; } @ inline @ operator ( "==" ) static eq ( a , b ) { return a . eq ( b ) ; } @ inline @ operator ( "!=" ) static notEq ( a , b ) { return a . notEq ( b ) ; } }