import * as Bson from 'bson' ; import { Buffer } from 'buffer' ; import { LocoPacketDataCodec } from '.' ; import { DefaultReq , DefaultRes } from '../request' ; export const BsonDataCodec = { canDecode ( dataType ) { return dataType == 0 || dataType == 8 ; } , decode ( data ) { return Bson . deserialize ( Buffer . from ( data ) , { promoteLongs : false , } ) as DefaultRes ; } , encode ( data ) { const buf = Bson . serialize ( data ) ; return [ 0 , buf ] ; } , } ;