| | |
| | | |
| | | import android.util.Log; |
| | | |
| | | import com.anyun.exam.lib.MyLog; |
| | | import com.anyun.im_lib.util.ByteUtil; |
| | | |
| | | import safeluck.drive.evaluation.util.Utils; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | |
| | | * @return |
| | | */ |
| | | public byte[] toBytes(){ |
| | | byte[] desBytes = new byte[1+16+2+1+1]; |
| | | byte[] desBytes = new byte[1+16+msgBodyLength()+1+1]; |
| | | int pos = 0; |
| | | |
| | | |
| | |
| | | System.arraycopy(msgIdBytes,0,desBytes,pos,msgIdBytes.length); |
| | | pos+=msgIdBytes.length; |
| | | |
| | | //消息体属性 |
| | | //消息体属性 默认为消息体长度 |
| | | msg_property = msgBodyLength(); |
| | | byte[] msg_pro_bytes = ByteUtil.shortGetBytes(msg_property); |
| | | System.arraycopy(msg_pro_bytes,0,desBytes,pos,msg_pro_bytes.length); |
| | | pos+=msg_pro_bytes.length; |
| | |
| | | pos+=messageBodyBytes.length; |
| | | |
| | | //校验码 |
| | | // TODO: 2019/12/18 校验码需要计算 还有转义需要处理 |
| | | checkCode = Utils.calCheckCode(ByteUtil.subArray(desBytes,1,pos-1)); |
| | | desBytes[pos] = checkCode; |
| | | pos++; |
| | | //末尾结束标识位 |
| | | desBytes[pos] = MESSAGE_TAIL; |
| | | |
| | | Log.i(TAG, "包长度="+(pos+1)); |
| | | Log.i(TAG, "包内容: "+ByteUtil.byte2HexStr(desBytes)); |
| | | |
| | | return desBytes; |
| | | MyLog.i(TAG, "原始包长度="+(pos+1)); |
| | | MyLog.i(TAG, "原始包内容: "+ByteUtil.byte2HexStr(desBytes)); |
| | | byte[] tranferbytes = Utils.transferMeaning(desBytes); |
| | | MyLog.i(TAG,"转义后的包内容:"+ByteUtil.byte2HexStr(tranferbytes)); |
| | | return tranferbytes; |
| | | } |
| | | |
| | | protected abstract short msgBodyLength(); |
| | | |
| | | } |