blob: 9f6ca668167becc8751f9e0d9c6309e4a70898b2 [file] [log] [blame]
tejeshwer degala3fe1ed52016-04-22 17:04:01 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
tejeshwer degala3fe1ed52016-04-22 17:04:01 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.isis.controller.impl;
17
18import org.jboss.netty.buffer.ChannelBuffer;
19import org.jboss.netty.buffer.ChannelBuffers;
20import org.jboss.netty.channel.Channel;
21import org.jboss.netty.channel.ChannelHandlerContext;
22import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25
26/**
27 * Encodes an ISIS message for output into a ChannelBuffer, for use in a netty pipeline.
28 */
29public class IsisMessageEncoder extends OneToOneEncoder {
30 private static final Logger log = LoggerFactory.getLogger(IsisMessageEncoder.class);
31
32 @Override
33 protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
34
35 byte[] byteMsg = (byte[]) msg;
36 log.debug("Encoding isisMessage of length {}", byteMsg.length);
37 ChannelBuffer channelBuffer = ChannelBuffers.buffer(byteMsg.length);
38 channelBuffer.writeBytes(byteMsg);
39
40 return channelBuffer;
41 }
42}