public void flattenToBuffer(ByteBuffer buf) throws IOException { assert (!((params == null) && (serializedParams == null))); assert ((params != null) || (serializedParams != null)); buf.put(type.getValue()); // version and type if (ProcedureInvocationType.isDeprecatedInternalDRType(type)) { buf.putLong(originalTxnId); buf.putLong(originalUniqueId); } if (type.getValue() >= BatchTimeoutOverrideType.BATCH_TIMEOUT_VERSION) { if (batchTimeout == BatchTimeoutOverrideType.NO_TIMEOUT) { buf.put(BatchTimeoutOverrideType.NO_OVERRIDE_FOR_BATCH_TIMEOUT.getValue()); } else { buf.put(BatchTimeoutOverrideType.HAS_OVERRIDE_FOR_BATCH_TIMEOUT.getValue()); buf.putInt(batchTimeout); } } buf.putInt(procName.length()); buf.put(procName.getBytes(Constants.UTF8ENCODING)); buf.putLong(clientHandle); if (serializedParams != null) { if (serializedParams.hasArray()) { // if position can be non-zero, then the dup/rewind logic below // would be wrong? assert (serializedParams.position() == 0); buf.put( serializedParams.array(), serializedParams.position() + serializedParams.arrayOffset(), serializedParams.remaining()); } else { // duplicate for thread-safety assert (serializedParams.position() == 0); ByteBuffer dup = serializedParams.duplicate(); dup.rewind(); buf.put(dup); } } else if (params != null) { try { getParams().flattenToBuffer(buf); } catch (BufferOverflowException e) { hostLog.info("SP \"" + procName + "\" has thrown BufferOverflowException"); hostLog.info(toString()); throw e; } } }
public int getSerializedSize() { int timeoutSize = 0; if (type.getValue() >= BatchTimeoutOverrideType.BATCH_TIMEOUT_VERSION) { timeoutSize = 1 + (batchTimeout == BatchTimeoutOverrideType.NO_TIMEOUT ? 0 : 4); } int size = 1 // Version/type + timeoutSize // batch time out byte + 4 // proc name string length + procName.length() + 8; // clientHandle if (ProcedureInvocationType.isDeprecatedInternalDRType(type)) { size += 8 + // original TXN ID for WAN replication procedures 8; // original timestamp for WAN replication procedures } if (serializedParams != null) { size += serializedParams.remaining(); } else if (params != null) { ParameterSet pset = getParams(); assert (pset != null); int serializedSize = pset.getSerializedSize(); if ((pset.size() > 0) && (serializedSize <= 2)) { throw new IllegalStateException( String.format( "Parameter set for invocation " + "%s doesn't have the proper size (currently = %s)", getProcName(), serializedSize)); } size += pset.getSerializedSize(); } return size; }