From ad50218e9499d10f9bf5787e2be406bd0224098d Mon Sep 17 00:00:00 2001 From: tursom Date: Mon, 20 Jul 2020 08:41:48 +0800 Subject: [PATCH] add AsyncChannelEnhance.kt --- .../cn/tursom/channel/AsyncChannelEnhance.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 AsyncSocket/src/main/kotlin/cn/tursom/channel/AsyncChannelEnhance.kt diff --git a/AsyncSocket/src/main/kotlin/cn/tursom/channel/AsyncChannelEnhance.kt b/AsyncSocket/src/main/kotlin/cn/tursom/channel/AsyncChannelEnhance.kt new file mode 100644 index 0000000..23eb5ac --- /dev/null +++ b/AsyncSocket/src/main/kotlin/cn/tursom/channel/AsyncChannelEnhance.kt @@ -0,0 +1,23 @@ +package cn.tursom.channel + +import cn.tursom.channel.enhance.ChannelReader +import cn.tursom.channel.enhance.ChannelWriter +import cn.tursom.channel.enhance.EnhanceChannel +import cn.tursom.channel.enhance.impl.* +import cn.tursom.core.buffer.ByteBuffer + +fun AsyncChannel.reader(): ChannelReader = ChannelReaderImpl(this) +fun AsyncChannel.writer(): ChannelWriter = ChannelWriterImpl(this) +fun AsyncChannel.enhance(): EnhanceChannel = EnhanceChannel(this) + +fun ChannelReader.lengthField(): ChannelReader = LengthFieldBasedFrameReader(this) +fun ChannelWriter.lengthField(): ChannelWriter = LengthFieldPrependWriter(this) +fun EnhanceChannel.lengthField(): EnhanceChannel = LengthFieldChannel(this) + +fun ChannelReader.string() = StringReader(this) +fun ChannelWriter.string() = StringWriter(this) +fun EnhanceChannel.string() = StringChannel(this) + +fun ChannelWriter.stringObjectWriter( + toString: (obj: Any) -> String = { it.toString() } +): StringObjectWriter = StringObjectWriter(this, toString) \ No newline at end of file