001/* 002 * Copyright 2002-2016 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.simp.stomp; 017 018import java.nio.ByteBuffer; 019import java.util.List; 020 021import org.springframework.messaging.Message; 022import org.springframework.messaging.tcp.reactor.AbstractNioBufferReactorNettyCodec; 023 024/** 025 * Simple delegation to StompDecoder and StompEncoder. 026 * 027 * @author Rossen Stoyanchev 028 * @since 5.0 029 */ 030public class StompReactorNettyCodec extends AbstractNioBufferReactorNettyCodec<byte[]> { 031 032 private final StompDecoder decoder; 033 034 private final StompEncoder encoder; 035 036 037 public StompReactorNettyCodec() { 038 this(new StompDecoder()); 039 } 040 041 public StompReactorNettyCodec(StompDecoder decoder) { 042 this(decoder, new StompEncoder()); 043 } 044 045 public StompReactorNettyCodec(StompDecoder decoder, StompEncoder encoder) { 046 this.decoder = decoder; 047 this.encoder = encoder; 048 } 049 050 051 @Override 052 protected List<Message<byte[]>> decodeInternal(ByteBuffer nioBuffer) { 053 return this.decoder.decode(nioBuffer); 054 } 055 056 @Override 057 protected ByteBuffer encodeInternal(Message<byte[]> message) { 058 return ByteBuffer.wrap(this.encoder.encode(message)); 059 } 060 061}