update all wireEncode & add packet test: CPacket

This commit is contained in:
free will committed 2021-04-07 16:37:05 +08:00
1 parent 424d182d60
commit 2bf431af9c
33 files changed
+335 -317

No files matched your search

+24 -33
View File
@@ -74,43 +74,34 @@ public class Payload implements TlvComponentBase,InitialAble, IEncodingAble {
*/
@Override
public int wireEncode(Encoder encoder) throws ComponentException {
int totalLength=0;
// 编码 TLV-VALUE
int tmplen= 0;
try {
tmplen = encoder.prependByteArray(this.value,new SizeT(this.value.length));
int totalLength = 0;
// 编码 TLV-VALUE
int tmplen = encoder.prependByteArray(this.value, new SizeT(this.value.length));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen += encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen += encoder.prependVarNumber(new VlInt(TLV.TlvPayload));
if (tmplen < 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
} catch (EncoderException e) {
throw new ComponentException("Payload.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-LENGTH
try {
tmplen+=encoder.prependVarNumber(new VlInt(totalLength));
} catch (EncoderException e) {
throw new ComponentException("Payload.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-TYPE
try {
tmplen+=encoder.prependVarNumber(new VlInt(TLV.TlvPayload));
} catch (EncoderException e) {
throw new ComponentException("Payload.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
return totalLength;
}
@Override