import Application from "../application" ; import * as define from "../util/define" ; import { I_encodeDecodeConfig } from "../util/interfaceDefine" ; let app ; export function init ( _app ) { app = _app ; } export let default_encodeDecode = { "protoDecode" : function ( data ) { return { "cmd" : data . readUInt16BE ( 1 ) , "msg" : data . slice ( 3 ) } ; } , "msgDecode" : function ( cmd , msg ) { return JSON . parse ( msg . toString ( ) ) ; } , "protoEncode" : function ( cmd , msg ) { let msgBuf = app . msgEncode ( cmd , msg ) ; let buf = Buffer . allocUnsafe ( msgBuf . length + 7 ) ; buf . writeUInt32BE ( msgBuf . length + 3 , 0 ) ; buf . writeUInt8 ( define . Server_To_Client . msg , 4 ) ; buf . writeUInt16BE ( cmd , 5 ) ; msgBuf . copy ( buf , 7 ) ; return buf ; } , "msgEncode" : function ( cmd , msg ) { return Buffer . from ( JSON . stringify ( msg ) ) ; } } ;