@Override
  public byte[] getSerializedValue() {
    byte[] result = value;
    if (result == null) {
      if (substituteValue != null) {
        // The substitute value is set. Serialize it
        isSerializingValue.set(Boolean.TRUE);
        result = EntryEventImpl.serialize(substituteValue);
        isSerializingValue.set(Boolean.FALSE);
        return result;
      }
      @Unretained(OffHeapIdentifier.GATEWAY_SENDER_EVENT_IMPL_VALUE)
      Object vo = valueObj;
      if (vo instanceof StoredObject) {
        synchronized (this) {
          result = value;
          if (result == null) {
            StoredObject so = (StoredObject) vo;
            result = so.getValueAsHeapByteArray();
            value = result;
          }
        }
      } else {
        synchronized (this) {
          result = value;
          if (result == null && vo != null && !(vo instanceof Token)) {
            isSerializingValue.set(Boolean.TRUE);
            result = EntryEventImpl.serialize(vo);
            isSerializingValue.set(Boolean.FALSE);
            value = result;
          } else if (result == null) {
            if (valueObjReleased) {
              serializedValueNotAvailable = true;
              throw new IllegalStateException(
                  "Value is no longer available. getSerializedValue must be called before processEvents returns.");
            }
          }
        }
      }
    }
    return result;
  }
If the value owned of this event is just bytes return that byte array; otherwise serialize the
value object and return the serialized bytes. Use {@link #getValueIsObject()} to determine if
the result is raw or serialized bytes.
geode-core/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventImpl.java