001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.springframework.messaging.tcp.reactor; 017 018import java.util.Collection; 019import java.util.function.BiConsumer; 020import java.util.function.Function; 021 022import io.netty.buffer.ByteBuf; 023 024import org.springframework.messaging.Message; 025 026/** 027 * Simple holder for a decoding {@link Function} and an encoding 028 * {@link BiConsumer} to use with Reactor Netty. 029 * 030 * @author Rossen Stoyanchev 031 * @since 5.0 032 * @param <P> the message payload type 033 */ 034public interface ReactorNettyCodec<P> { 035 036 /** 037 * Decode the input {@link ByteBuf} into one or more {@link Message Messages}. 038 * @param inputBuffer the input buffer to decode from 039 * @return 0 or more decoded messages 040 */ 041 Collection<Message<P>> decode(ByteBuf inputBuffer); 042 043 /** 044 * Encode the given {@link Message} to the output {@link ByteBuf}. 045 * @param message the message to encode 046 * @param outputBuffer the buffer to write to 047 */ 048 void encode(Message<P> message, ByteBuf outputBuffer); 049 050}