public final class ServiceMessageCodec extends Object
| 构造器和说明 |
|---|
ServiceMessageCodec()
Message codec with default Headers/Data Codecs.
|
ServiceMessageCodec(io.scalecube.services.transport.api.HeadersCodec headersCodec,
Collection<io.scalecube.services.transport.api.DataCodec> dataCodecs)
Constructor.
|
| 限定符和类型 | 方法和说明 |
|---|---|
io.scalecube.services.api.ServiceMessage |
decode(io.netty.buffer.ByteBuf dataBuffer,
io.netty.buffer.ByteBuf headersBuffer)
Decode buffers.
|
static io.scalecube.services.api.ServiceMessage |
decodeData(io.scalecube.services.api.ServiceMessage message,
Type dataType)
Decode message.
|
<T> T |
encodeAndTransform(io.scalecube.services.api.ServiceMessage message,
java.util.function.BiFunction<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf,T> transformer)
Encode a message, transform it to T.
|
public ServiceMessageCodec()
HeadersCodec.DEFAULT_INSTANCE,
DataCodec.getAllInstances()public ServiceMessageCodec(io.scalecube.services.transport.api.HeadersCodec headersCodec,
Collection<io.scalecube.services.transport.api.DataCodec> dataCodecs)
HeadersCodec instance and DataCodec
collection.
NOTE: If client set several data codecs for one content type (see what's content type
here: DataCodec.contentType()), then the last one specified will be used. Client's
collection of data codes override data codecs from SPI.
headersCodec - codec for service message headers; optional, if not set then JdkCodec will be used.dataCodecs - codecs for service message data; optional, if not set then DataCodec.INSTANCES will be used.public <T> T encodeAndTransform(io.scalecube.services.api.ServiceMessage message,
java.util.function.BiFunction<io.netty.buffer.ByteBuf,io.netty.buffer.ByteBuf,T> transformer)
throws io.scalecube.services.exceptions.MessageCodecException
message - the message to transformtransformer - a function that accepts data and header ByteBuf and return the
required Tio.scalecube.services.exceptions.MessageCodecException - when encoding cannot be done.public io.scalecube.services.api.ServiceMessage decode(io.netty.buffer.ByteBuf dataBuffer,
io.netty.buffer.ByteBuf headersBuffer)
throws io.scalecube.services.exceptions.MessageCodecException
dataBuffer - the buffer of the data (payload)headersBuffer - the buffer of the headersByteBuf data and with parsed headers.io.scalecube.services.exceptions.MessageCodecException - when decode failspublic static io.scalecube.services.api.ServiceMessage decodeData(io.scalecube.services.api.ServiceMessage message,
Type dataType)
throws io.scalecube.services.exceptions.MessageCodecException
message - the original message (with ByteBuf data)dataType - the type of the data.ServiceMessage.data() returns the actual data
(of type data type)io.scalecube.services.exceptions.MessageCodecException - when decode failsCopyright © 2019–2023. All rights reserved.