blob: a3bab3e48bf9d7e7164f3fe87a5e72b77570d909 [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.ver10;
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 OFFlowModFlagsSerializerVer10 {
35
36 public final static short SEND_FLOW_REM_VAL = (short) 0x1;
37 public final static short CHECK_OVERLAP_VAL = (short) 0x2;
38 public final static short EMERG_VAL = (short) 0x4;
39
40 public static Set<OFFlowModFlags> readFrom(ChannelBuffer bb) throws OFParseError {
41 try {
42 return ofWireValue(bb.readShort());
43 } catch (IllegalArgumentException e) {
44 throw new OFParseError(e);
45 }
46 }
47
48 public static void writeTo(ChannelBuffer bb, Set<OFFlowModFlags> set) {
49 bb.writeShort(toWireValue(set));
50 }
51
52 public static void putTo(Set<OFFlowModFlags> set, PrimitiveSink sink) {
53 sink.putShort(toWireValue(set));
54 }
55
56
57 public static Set<OFFlowModFlags> ofWireValue(short val) {
58 EnumSet<OFFlowModFlags> set = EnumSet.noneOf(OFFlowModFlags.class);
59
60 if((val & SEND_FLOW_REM_VAL) != 0)
61 set.add(OFFlowModFlags.SEND_FLOW_REM);
62 if((val & CHECK_OVERLAP_VAL) != 0)
63 set.add(OFFlowModFlags.CHECK_OVERLAP);
64 if((val & EMERG_VAL) != 0)
65 set.add(OFFlowModFlags.EMERG);
66 return Collections.unmodifiableSet(set);
67 }
68
69 public static short toWireValue(Set<OFFlowModFlags> set) {
70 short wireValue = 0;
71
72 for(OFFlowModFlags e: set) {
73 switch(e) {
74 case SEND_FLOW_REM:
75 wireValue |= SEND_FLOW_REM_VAL;
76 break;
77 case CHECK_OVERLAP:
78 wireValue |= CHECK_OVERLAP_VAL;
79 break;
80 case EMERG:
81 wireValue |= EMERG_VAL;
82 break;
83 default:
84 throw new IllegalArgumentException("Illegal enum value for type OFFlowModFlags in version 1.0: " + e);
85 }
86 }
87 return wireValue;
88 }
89
90}