Skip to content

Commit

Permalink
Fixed #167, removed extra size calculation, moved size check to start
Browse files Browse the repository at this point in the history
  • Loading branch information
bjakke committed Sep 26, 2018
1 parent d4289d4 commit 4c4a0de
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,14 @@ private void sendAsymmChunk(int secureChannelId, int requestId, SecurityMode sec
out.put(chunk);
}

private MessageBuffers encodeMessage(ChunkFactory cf, int len, IEncodeable request) throws ServiceResultException {
private MessageBuffers encodeMessage(ChunkFactory cf, final int len, IEncodeable request) throws ServiceResultException {
// check message max size
if ( ctx.maxMessageSize!=0 && len > ctx.maxMessageSize ) {
final EncodingException encodingException = new EncodingException(StatusCodes.Bad_EncodingLimitsExceeded, "MaxMessageSize "+ctx.maxMessageSize+" < "+len);
logger.warn("encodeMessage: failed", encodingException);
throw encodingException;
}

// Calculate chunk count
final int count = (len + cf.maxPlaintextSize - 1) / cf.maxPlaintextSize;
int maxSendChunkCount;
Expand Down Expand Up @@ -1313,15 +1320,6 @@ public void onChunkComplete(ByteBuffer[] chunks, int index) {
ByteBufferArrayWriteable2 outBuffer = new ByteBufferArrayWriteable2(plaintexts, listener);
outBuffer.order(ByteOrder.LITTLE_ENDIAN);

EncoderCalc calc = new EncoderCalc();
calc.setEncoderContext(ctx);
calc.putMessage( request );
if ( ctx.maxMessageSize!=0 && calc.getLength() > ctx.maxMessageSize ) {
final EncodingException encodingException = new EncodingException(StatusCodes.Bad_EncodingLimitsExceeded, "MaxMessageSize "+ctx.maxMessageSize+" < "+len);
logger.warn("encodeMessage: failed", encodingException);
throw encodingException;
}

BinaryEncoder enc = new BinaryEncoder(outBuffer);
enc.setEncoderMode(EncoderMode.NonStrict);
enc.setEncoderContext(ctx);
Expand Down

0 comments on commit 4c4a0de

Please sign in to comment.