org.springframework.messaging.rsocket

## Class PayloadUtils

- java.lang.Object
- - org.springframework.messaging.rsocket.PayloadUtils

    public abstract class PayloadUtils
    extends Object

Static utility methods to create `Payload` from `DataBuffer`s and vice versa.

Since:
  5.2
Author:
  Rossen Stoyanchev

### Constructor Summary

Constructors
Constructor and Description
`PayloadUtils()`

### Method Summary

All Methods Static Methods Concrete Methods
`static io.rsocket.Payload` `createPayload(org.springframework.core.io.buffer.DataBuffer data)` Create a Payload with data only.
`static io.rsocket.Payload` `createPayload(org.springframework.core.io.buffer.DataBuffer data, org.springframework.core.io.buffer.DataBuffer metadata)` Create a Payload from the given metadata and data.
`static org.springframework.core.io.buffer.DataBuffer` `retainDataAndReleasePayload(io.rsocket.Payload payload, org.springframework.core.io.buffer.DataBufferFactory bufferFactory)` Use this method to slice, retain and wrap the data portion of the `Payload`, and also to release the `Payload`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### PayloadUtils

    public PayloadUtils()

### Method Detail

#### retainDataAndReleasePayload

    public static org.springframework.core.io.buffer.DataBuffer retainDataAndReleasePayload(io.rsocket.Payload payload,
                                                                                            org.springframework.core.io.buffer.DataBufferFactory bufferFactory)

Use this method to slice, retain and wrap the data portion of the `Payload`, and also to release the `Payload`. This assumes the Payload metadata has been read by now and ensures downstream code need only be aware of `DataBuffer`s.

Parameters:
  `payload` - the payload to process
  `bufferFactory` - the DataBufferFactory to wrap with
Returns:
  the created `DataBuffer` instance

#### createPayload

    public static io.rsocket.Payload createPayload(org.springframework.core.io.buffer.DataBuffer data,
                                                   org.springframework.core.io.buffer.DataBuffer metadata)

Create a Payload from the given metadata and data.

If at least one is `NettyDataBuffer` then `ByteBufPayload` is created with either obtaining the underlying native `ByteBuf` or using `Unpooled.wrappedBuffer(ByteBuffer...)` if necessary. Otherwise, if both are `DefaultDataBuffer`, then `DefaultPayload` is created.

Parameters:
  `data` - the data part for the payload
  `metadata` - the metadata part for the payload
Returns:
  the created payload

#### createPayload

    public static io.rsocket.Payload createPayload(org.springframework.core.io.buffer.DataBuffer data)

Create a Payload with data only. The created payload is `ByteBufPayload` if the input is `NettyDataBuffer` or otherwise it is `DefaultPayload`.

Parameters:
  `data` - the data part for the payload
Returns:
  created payload