2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.pcep.controller.impl;
18 import java.util.List;
20 import org.jboss.netty.buffer.ChannelBuffer;
21 import org.jboss.netty.buffer.ChannelBuffers;
22 import org.jboss.netty.channel.Channel;
23 import org.jboss.netty.channel.ChannelHandlerContext;
24 import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
25 import org.onosproject.pcepio.protocol.PcepMessage;
26 import org.onosproject.pcepio.util.HexDump;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Encode an pcep message for output into a ChannelBuffer, for use in a
34 public class PcepMessageEncoder extends OneToOneEncoder {
35 protected static final Logger log = LoggerFactory.getLogger(PcepMessageEncoder.class);
38 protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
39 log.debug("Sending message");
40 if (!(msg instanceof List)) {
41 log.debug("Invalid msg.");
45 @SuppressWarnings("unchecked")
46 List<PcepMessage> msglist = (List<PcepMessage>) msg;
48 ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
50 for (PcepMessage pm : msglist) {
54 HexDump.pcepHexDump(buf);