@Override
  public void toData(DataOutput out,
      SerializationContext context) throws IOException {
    context.getSerializer().writeObject(eventID, out);
    context.getSerializer().writeObject(getKey(), out);
    context.getSerializer().writeObject(keyInfo.getValue(), out);
    out.writeByte(op.ordinal);
    out.writeShort(eventFlags & EventFlags.FLAG_TRANSIENT_MASK);
    context.getSerializer().writeObject(getRawCallbackArgument(), out);
    context.getSerializer().writeObject(txId, out);

    {
      out.writeBoolean(false);
      {
        Object nv = basicGetNewValue();
        boolean newValueSerialized = nv instanceof CachedDeserializable;
        if (newValueSerialized) {
          newValueSerialized = ((CachedDeserializable) nv).isSerialized();
        }
        out.writeBoolean(newValueSerialized);
        if (newValueSerialized) {
          if (newValueBytes != null) {
            DataSerializer.writeByteArray(newValueBytes, out);
          } else if (cachedSerializedNewValue != null) {
            DataSerializer.writeByteArray(cachedSerializedNewValue, out);
          } else {
            CachedDeserializable cd = (CachedDeserializable) nv;
            DataSerializer.writeObjectAsByteArray(cd.getValue(), out);
          }
        } else {
          context.getSerializer().writeObject(nv, out);
        }
      }
    }

    {
      Object ov = basicGetOldValue();
      boolean oldValueSerialized = ov instanceof CachedDeserializable;
      if (oldValueSerialized) {
        oldValueSerialized = ((CachedDeserializable) ov).isSerialized();
      }
      out.writeBoolean(oldValueSerialized);
      if (oldValueSerialized) {
        if (oldValueBytes != null) {
          DataSerializer.writeByteArray(oldValueBytes, out);
        } else {
          CachedDeserializable cd = (CachedDeserializable) ov;
          DataSerializer.writeObjectAsByteArray(cd.getValue(), out);
        }
      } else {
        ov = AbstractRegion.handleNotAvailable(ov);
        context.getSerializer().writeObject(ov, out);
      }
    }
    InternalDataSerializer.invokeToData(distributedMember, out);
    context.getSerializer().writeObject(getContext(), out);
    DataSerializer.writeLong(tailKey, out);
  }
Serialize an object into a <code>byte[]</code> . If the byte array provided by the wrapper is
sufficient to hold the data, it is used otherwise a new byte array gets created & its reference
is stored in the wrapper. The User Bit is also appropriately set as Serialized

@param wrapper Object of type BytesAndBitsForCompactor which is used to fetch the serialized
       data. The byte array of the wrapper is used if possible else a the new byte array
       containing the data is set in the wrapper.
@throws IllegalArgumentException If <code>obj</code> should not be serialized
geode-core/src/main/java/org/apache/geode/internal/cache/EntryEventImpl.java