blob: 10a4a0ebd6d5b158d1ab0b01c16eb20e64760e3a [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001// Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
2// Copyright (c) 2011, 2012 Open Networking Foundation
3// Copyright (c) 2012, 2013 Big Switch Networks, Inc.
4// This library was generated by the LoxiGen Compiler.
5// See the file LICENSE.txt which should have been included in the source distribution
6
7// Automatically generated by LOXI from template const_set_serializer.java
8// Do not modify
9
10package org.projectfloodlight.openflow.protocol.ver11;
11
12import org.projectfloodlight.openflow.protocol.*;
13import org.projectfloodlight.openflow.protocol.action.*;
14import org.projectfloodlight.openflow.protocol.actionid.*;
15import org.projectfloodlight.openflow.protocol.bsntlv.*;
16import org.projectfloodlight.openflow.protocol.errormsg.*;
17import org.projectfloodlight.openflow.protocol.meterband.*;
18import org.projectfloodlight.openflow.protocol.instruction.*;
19import org.projectfloodlight.openflow.protocol.instructionid.*;
20import org.projectfloodlight.openflow.protocol.match.*;
21import org.projectfloodlight.openflow.protocol.oxm.*;
22import org.projectfloodlight.openflow.protocol.queueprop.*;
23import org.projectfloodlight.openflow.types.*;
24import org.projectfloodlight.openflow.util.*;
25import org.projectfloodlight.openflow.exceptions.*;
26import org.projectfloodlight.openflow.protocol.OFFlowModFlags;
27import java.util.Set;
28import org.jboss.netty.buffer.ChannelBuffer;
29import com.google.common.hash.PrimitiveSink;
30import java.util.EnumSet;
31import java.util.Collections;
32
33
34public class OFFlowModFlagsSerializerVer11 {
35
36 public final static short SEND_FLOW_REM_VAL = (short) 0x1;
37 public final static short CHECK_OVERLAP_VAL = (short) 0x2;
38
39 public static Set<OFFlowModFlags> readFrom(ChannelBuffer bb) throws OFParseError {
40 try {
41 return ofWireValue(bb.readShort());
42 } catch (IllegalArgumentException e) {
43 throw new OFParseError(e);
44 }
45 }
46
47 public static void writeTo(ChannelBuffer bb, Set<OFFlowModFlags> set) {
48 bb.writeShort(toWireValue(set));
49 }
50
51 public static void putTo(Set<OFFlowModFlags> set, PrimitiveSink sink) {
52 sink.putShort(toWireValue(set));
53 }
54
55
56 public static Set<OFFlowModFlags> ofWireValue(short val) {
57 EnumSet<OFFlowModFlags> set = EnumSet.noneOf(OFFlowModFlags.class);
58
59 if((val & SEND_FLOW_REM_VAL) != 0)
60 set.add(OFFlowModFlags.SEND_FLOW_REM);
61 if((val & CHECK_OVERLAP_VAL) != 0)
62 set.add(OFFlowModFlags.CHECK_OVERLAP);
63 return Collections.unmodifiableSet(set);
64 }
65
66 public static short toWireValue(Set<OFFlowModFlags> set) {
67 short wireValue = 0;
68
69 for(OFFlowModFlags e: set) {
70 switch(e) {
71 case SEND_FLOW_REM:
72 wireValue |= SEND_FLOW_REM_VAL;
73 break;
74 case CHECK_OVERLAP:
75 wireValue |= CHECK_OVERLAP_VAL;
76 break;
77 default:
78 throw new IllegalArgumentException("Illegal enum value for type OFFlowModFlags in version 1.1: " + e);
79 }
80 }
81 return wireValue;
82 }
83
84}