import { UnwrappableCodec } from "./interfaces/UnwrappableCodec" ; /** Representation for a boolean value in the system. */ export class Bool implements UnwrappableCodec < bool > { private _value : bool ; constructor ( value = false ) { this . _value = value ; } description public unwrap ( ) { return this . _value ; } /** Encodes the value as u8[] as per the SCALE codec specification
     * true -> [1]
     * false -> [0]
     */ public toU8a ( ) { let bytesEncoded = new Array < u8 > ( 1 ) ; bytesEncoded [ 0 ] = this . _value ? 0x01 : 0x00 ; return bytesEncoded ; } description param bytes param index public populateFromBytes ( bytes , index = 0 ) { assert ( bytes . length > 0 && ( bytes [ index ] == 1 || bytes [ index ] == 0 ) , 'Bool: Cannot decode invalid input' ) ; this . _value = bytes [ index ] == 1 ; } description toString ( ) { return this . _value . toString ( ) ; } eq ( other ) { return this . _value == other . unwrap ( ) ; } notEq ( other ) { return this . _value != other . unwrap ( ) ; } description public encodedLength ( ) { return 1 ; } /** Instantiates new Bool from u8[] SCALE encoded bytes */ static fromU8a ( value , index = 0 ) { assert ( value . length - index > 0 && ( value [ index ] == 1 || value [ index ] == 0 ) , 'Bool: Cannot decode invalid input' ) ; return new Bool ( value [ index ] == 1 ) ; } @ inline @ operator ( "==" ) static eq ( a , b ) { return a . eq ( b ) ; } @ inline @ operator ( "!=" ) static notEq ( a , b ) { return a . notEq ( b ) ; } toU8aPacked ( ) { return this . toU8a ( ) ; } encodedLengthPacked ( ) { return this . encodedLength ( ) ; } populateFromPackedBytes ( bytes , index = 0 ) { this . populateFromBytes ( bytes , index ) ; } }