import { assert } from "@fluidframework/common-utils" ; /**
 * Buffer class, used to sequentially read data.
 * Used by tree code to reconstruct a tree from binary representation.
 */ export class ReadBuffer { protected index = 0 ; public get buffer ( ) { return this . data ; } constructor ( protected readonly data ) { Object . freeze ( data . buffer ) ; } public get eof ( ) { return this . index === this . data . length ; } public get pos ( ) { return this . index ; } public get length ( ) { return this . data . length ; } public slice ( start , end ) { return this . data . slice ( start , end ) ; } public reset ( ) { this . index = 0 ; } public read ( lengthArg = 1 ) { let res = 0 ; let multiplier = 1 ; let length = lengthArg ; while ( length > 0 ) { assert ( ! this . eof , 0x223 ) ; res += this . data [ this . index ] * multiplier ; this . index ++ ; multiplier *= 256 ; length -- ; } return res ; } public skip ( length ) { assert ( length >= 0 , 0x224 ) ; this . index += length ; } }