import { logger } from 'shared/util/logger' ; class MetaLength { readonly type : number ; head : number ; body : number ; constructor ( ) { this . type = 1 ; this . head = 0 ; this . body = 0 ; } } export abstract class ModelType { length : MetaLength ; constructor ( ) { this . length = new MetaLength ( ) ; } public typeId : number ; protected abstract read ( buffer , offset ) ; protected abstract write ( buffer , value , offset ) ; public create ( data ) { try { const length = this . getLength ( data ) ; const buffer = Buffer . alloc ( length ) ; this . write ( buffer , data , 0 ) ; return buffer ; } catch ( e ) { logger . error ( `[ByteSerializer][create] error` , e ) ; } } protected writeTypeId ( buffer , offset ) { return buffer . writeUInt8 ( this . typeId , offset ) ; } abstract getLength ( value ? ) ; }