public int construct(byte[] byteArrDest, int iDestPos)
{
int iOffset = iDestPos;
if (byteArrDDUData == null)
{
byteArrDest[iOffset] = 0;
iOffset += 1;
}
else
{
int iLen = byteArrDDUData.length;
byteArrDest[iOffset] = (byte) iLen;
iOffset += 1;
System.arraycopy(byteArrDDUData, 0, byteArrDest, iOffset, iLen);
iOffset += iLen;
}
return iOffset;
}
------解决方案--------------------
There is an instance array variable called byteArrDDUData.
This method will copy all data from byteArrDDUData to another given destination array at the given offset position.
If byteArrDDUData is null, then only insert 0 to the destination array.
if byteArrDDUData contains some data, then insert data length first, followed by all data.
The method returns the updated offset from which some new data can be inserted later.
------解决方案--------------------
不算难吧,大概就是拷贝一个数组到新数组。
这个函数传了一个offset位,实现对拷贝位的控制
------解决方案--------------------
iOffset += 1;
is the same as
iOffset = iOffset + 1;
We also have -=, *=, /=, ... many other short form operators.
You 'd better read java book carefully.
------解决方案--------------------
byteArrDest: | iDestPos | iDestPos+1 -- iDestPos+iLen |
| byteArrDDUData的长度 | byteArrDDUData的数据 |
返回iDestPos+iLen+1作为下次copy的iDestPos
------解决方案--------------------
就是把byteArrDDUData数组 的数据全部添加到byteArrDest数组的后面,并且返回byteArrDest数组的最后一个位子(方便下一次添加或者得到byteArrDest数组的长度)
------解决方案--------------------
作用就是得到要拷贝的位置
------解决方案--------------------
The data length is inserted first. It might be 0 or some other value.
Since one element is inserted in the destination array, the following data should be inserted from next offset, which is iOffset+1.
------解决方案--------------------
因为byteArrDest中有一个字节是保存后面数据长度的,在construct方法中先向byteArrDest里装长度信息,再装里面的内容,所以在装内容前要位置要+1个
后面的parse方法也是一样的
------解决方案--------------------
前面都给你画出来了...
------解决方案--------------------
对,解析时刚好反过来,通过读iOffset位置的的字节获取长度,在根据长度信息获取应该提取的内容。