2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.impl.protocol.serialization.util;
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderSerializer;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
14 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
16 import org.opendaylight.yangtools.yang.common.Uint8;
19 * Utility class for instruction serialization.
21 public final class InstructionUtil {
23 private InstructionUtil() {
27 * Serialize instruction.
29 * @param instruction OpenFlow instruction
30 * @param version OpenFlow version
31 * @param registry OpenFlowJava serializer registry
32 * @param outBuffer output buffer
34 @SuppressWarnings("unchecked")
35 public static void writeInstruction(final Instruction instruction,
37 final SerializerRegistry registry,
38 final ByteBuf outBuffer) {
39 registry.<Instruction, OFSerializer<Instruction>>getSerializer(
40 new MessageTypeKey<>(version, (Class<Instruction>) instruction.implementedInterface()))
41 .serialize(instruction, outBuffer);
45 * Serialize instruction header.
47 * @param instruction OpenFlow instruction
48 * @param version OpenFlow version
49 * @param registry OpenFlowJava serializer registry
50 * @param outBuffer output buffer
52 @SuppressWarnings("unchecked")
53 public static void writeInstructionHeader(final Instruction instruction,
55 final SerializerRegistry registry,
56 final ByteBuf outBuffer) {
57 registry.<Instruction, HeaderSerializer<Instruction>>getSerializer(
58 new MessageTypeKey<>(version, (Class<Instruction>) instruction.implementedInterface()))
59 .serializeHeader(instruction, outBuffer);