Top Description Constructors Methods
org.springframework.messaging.rsocket

public abstract Class PayloadUtils

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer, io.netty.buffer.ByteBuf, .Unpooled, io.rsocket.Payload, io.rsocket.util.ByteBufPayload, .DefaultPayload, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory, .DefaultDataBuffer, .NettyDataBuffer, .NettyDataBufferFactory

Static utility methods to create Payload from DataBuffers and vice versa.
Author
Rossen Stoyanchev
Since
5.2

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv static ByteBuf
private static ByteBuffer
public static Payload

Returns:

the created payload
createPayload
(DataBuffer
the data part for the payload
data
,
DataBuffer
the metadata part for the payload
metadata
)

Create a Payload from the given metadata and data.

public static Payload

Returns:

created payload
createPayload
(DataBuffer
the data part for the payload
data
)

Create a Payload with data only.

public static DataBuffer

Returns:

the created DataBuffer instance
retainDataAndReleasePayload
(Payload
the payload to process
payload
,
DataBufferFactory
the DataBufferFactory to wrap with
bufferFactory
)

Use this method to slice, retain and wrap the data portion of the Payload, and also to release the Payload.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PayloadUtilsback to summary
public PayloadUtils()

Method Detail

asByteBufback to summary
pack-priv static ByteBuf asByteBuf(DataBuffer buffer)
asByteBufferback to summary
private static ByteBuffer asByteBuffer(DataBuffer dataBuffer)
createPayloadback to summary
public static Payload createPayload(DataBuffer data, 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:DataBuffer

the data part for the payload

metadata:DataBuffer

the metadata part for the payload

Returns:Payload

the created payload

createPayloadback to summary
public static Payload createPayload(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:DataBuffer

the data part for the payload

Returns:Payload

created payload

retainDataAndReleasePayloadback to summary
public static DataBuffer retainDataAndReleasePayload(Payload payload, 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 DataBuffers.

Parameters
payload:Payload

the payload to process

bufferFactory:DataBufferFactory

the DataBufferFactory to wrap with

Returns:DataBuffer

the created DataBuffer instance