param type param id param body param encoding returns export const encode = ( type , id , body , encoding = 'ascii' ) : Buffer => { const size = Buffer . byteLength ( body ) + 14 ; const buffer = Buffer . alloc ( size ) ; buffer . writeInt32LE ( size - 4 , 0 ) ; buffer . writeInt32LE ( id , 4 ) ; buffer . writeInt32LE ( type , 8 ) ; buffer . write ( body , 12 , size - 2 , encoding ) ; buffer . writeInt16LE ( 0 , size - 2 ) ; return buffer ; } ; param buf param encoding returns export const decode = ( buf , encoding = 'ascii' ) : DecodedPacket => { return { size : buf . readInt32LE ( 0 ) , id : buf . readInt32LE ( 4 ) , type : buf . readInt32LE ( 8 ) , body : buf . toString ( encoding , 12 , buf . byteLength - 2 ) } ; } ; interface DecodedPacket { size : number ; id : number ; type : number ; body : string ; } export type EncodingOptions = 'ascii' | 'utf8' ;