import { UnwrappableCodec } from "./interfaces/UnwrappableCodec" ; import { Bytes } from "./utils/Bytes" ; /** Representation for a Int value in the system. */ export abstract class AbstractInt < T extends number > implements UnwrappableCodec < T > { protected bitLength : i32 ; private _value : T ; constructor ( value , bitLength ) { this . _value = value ; this . bitLength = bitLength ; } description public unwrap ( ) { return this . _value ; } /** Encodes the value as u8[] as per the SCALE codec specification */ public toU8a ( ) { let bytesEncoded = new Array < u8 > ( this . bitLength ) ; Bytes . putUint < T > ( bytesEncoded , this . unwrap ( ) , this . bitLength ) ; return bytesEncoded ; } public eq ( other ) { return this . unwrap ( ) == other . unwrap ( ) ; } public notEq ( other ) { return this . unwrap ( ) != other . unwrap ( ) ; } description param bytes param index public populateFromBytes ( bytes , index = 0 ) { assert ( bytes . length - index > 0 , "AbstractInt: Invalid bytes provided" ) ; this . _value = Bytes . toUint < T > ( bytes , this . bitLength , index ) ; } description toString ( ) { return this . unwrap ( ) . toString ( ) ; } description public encodedLength ( ) { return this . bitLength ; } toU8aPacked ( ) { return this . toU8a ( ) ; } encodedLengthPacked ( ) { return this . encodedLength ( ) ; } populateFromPackedBytes ( bytes , index = 0 ) { this . populateFromBytes ( bytes , index ) ; } }