import * as zlib from 'zlib' ; /**
 * Helper class for parsing and querying property database
 * stored in various 'objects_*.json.gz' assets in an SVF.
 */ export class PropDbReader { protected _ids : number [ ] ; protected _offsets : number [ ] ; protected _avs : number [ ] ; protected _attrs : any [ ] ; protected _vals : any [ ] ; param { Buffer } ids param { Buffer } offsets param { Buffer } avs param { Buffer } attrs param { Buffer } vals constructor ( ids , offsets , avs , attrs , vals ) { this . _ids = JSON . parse ( zlib . gunzipSync ( ids ) . toString ( ) ) ; this . _offsets = JSON . parse ( zlib . gunzipSync ( offsets ) . toString ( ) ) ; this . _avs = JSON . parse ( zlib . gunzipSync ( avs ) . toString ( ) ) ; this . _attrs = JSON . parse ( zlib . gunzipSync ( attrs ) . toString ( ) ) ; this . _vals = JSON . parse ( zlib . gunzipSync ( vals ) . toString ( ) ) ; } generator param { number } id returns { Iterable < { name : string ; category : string ; value : any } > } * enumerateProperties ( id ) { if ( id > 0 && id < this . _offsets . length ) { const avStart = 2 * this . _offsets [ id ] ; const avEnd = 2 * this . _offsets [ id + 1 ] ; for ( let i = avStart ; i < avEnd ; i += 2 ) { const attrOffset = this . _avs [ i ] ; const valOffset = this . _avs [ i + 1 ] ; const attr = this . _attrs [ attrOffset ] ; const value = this . _vals [ valOffset ] ; yield { name : attr [ 0 ] , category : attr [ 1 ] , value } ; } } } param { number } id returns { { [ name : string ] : any } } getProperties ( id ) { let props = { } ; for ( const prop of this . enumerateProperties ( id ) ) { if ( prop . category && prop . category . match ( /^__\w+__$/ ) ) { } else { props [ prop . name ] = prop . value ; } } return props ; } param { number } id returns { number [ ] } getChildren ( id ) { let children = [ ] ; for ( const prop of this . enumerateProperties ( id ) ) { if ( prop . category === '__child__' ) { children . push ( prop . value as number ) ; } } return children ; } }