blob: c457725e51660a1420f2648aeebb78f7b06181be [file] [log] [blame]
Dhruv Dhody4d8943a2016-02-17 16:36:08 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Dhruv Dhody4d8943a2016-02-17 16:36:08 +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 */
16
17package org.onosproject.ospf.controller.impl;
18
19import org.jboss.netty.buffer.ChannelBuffer;
sunishvkf7c56552016-07-18 16:02:39 +053020import org.jboss.netty.buffer.ChannelBuffers;
Dhruv Dhody4d8943a2016-02-17 16:36:08 +053021import org.jboss.netty.channel.Channel;
22import org.jboss.netty.channel.ChannelHandlerContext;
23import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
Dhruv Dhody4d8943a2016-02-17 16:36:08 +053024import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
26
27/**
28 * Encodes an OSPF message for output into a ChannelBuffer, for use in a netty pipeline.
29 */
30public class OspfMessageEncoder extends OneToOneEncoder {
31
32 private static final Logger log = LoggerFactory.getLogger(OspfMessageEncoder.class);
Dhruv Dhody4d8943a2016-02-17 16:36:08 +053033
34 @Override
Ray Milkey019fba42018-01-31 14:07:47 -080035 protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) {
Dhruv Dhody4d8943a2016-02-17 16:36:08 +053036
sunishvkf7c56552016-07-18 16:02:39 +053037 byte[] byteMsg = (byte[]) msg;
38 log.debug("Encoding ospfMessage of length {}", byteMsg.length);
39 ChannelBuffer channelBuffer = ChannelBuffers.buffer(byteMsg.length);
40 channelBuffer.writeBytes(byteMsg);
Dhruv Dhody4d8943a2016-02-17 16:36:08 +053041
sunishvkf7c56552016-07-18 16:02:39 +053042 return channelBuffer;
Dhruv Dhody4d8943a2016-02-17 16:36:08 +053043 }
sunish vka2c5b162016-03-04 14:18:55 +053044}