blob: f1ac8497025a9fa8fa23c6e0818d7a05929568db [file] [log] [blame]
Andreas Wundsam001b1822013-08-02 22:25:55 -07001//:: # Copyright 2013, Big Switch Networks, Inc.
2//:: #
3//:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4//:: # the following special exception:
5//:: #
6//:: # LOXI Exception
7//:: #
8//:: # As a special exception to the terms of the EPL, you may distribute libraries
9//:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10//:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
11//:: # from the LoxiGen Libraries and the notice provided below is (i) included in
12//:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13//:: # documentation for the LoxiGen Libraries, if distributed in binary form.
14//:: #
15//:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16//:: #
17//:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18//:: # a copy of the EPL at:
19//:: #
20//:: # http::: #www.eclipse.org/legal/epl-v10.html
21//:: #
22//:: # Unless required by applicable law or agreed to in writing, software
23//:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24//:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25//:: # EPL for the specific language governing permissions and limitations
26//:: # under the EPL.
27//::
28//:: from loxi_ir import *
29//:: import os
30//:: import itertools
31//:: import of_g
32//:: include('_copyright.java')
33
34//:: include('_autogen.java')
35
36package ${msg.package};
37
38//:: include("_imports.java", msg=msg)
39
40abstract class ${msg.name} implements ${msg.interface.name} {
41 // version: ${version}
42 private final static byte WIRE_VERSION = ${version.int_version};
43//:: if msg.is_fixed_length:
44 private final static int LENGTH = ${msg.length};
45//:: else:
46 private final static int MINIMUM_LENGTH = ${msg.min_length};
47//:: #endif
48
49
50 public final static ${msg.name}.Reader READER = new Reader();
51
52 static class Reader implements OFMessageReader<${msg.interface.name}> {
53 @Override
54 public ${msg.interface.name} readFrom(ChannelBuffer bb) throws OFParseError {
55 int start = bb.readerIndex();
56//:: fields_with_length_member = {}
57//:: for prop in msg.members:
58//:: if prop.is_data:
59 ${prop.java_type.skip_op(version,
60 length=fields_with_length_member[prop.c_name] if prop.c_name in fields_with_length_member else None)};
61//:: elif prop.is_pad:
62 // pad: ${prop.length} bytes
63 bb.skipBytes(${prop.length});
64//:: elif prop.is_fixed_value:
65 // fixed value property ${prop.name} == ${prop.value}
66 ${prop.java_type.priv_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=False)};
67 if(${prop.name} != ${prop.value})
68 throw new OFParseError("Wrong ${prop.name}: Expected=${prop.enum_value}(${prop.value}), got="+${prop.name});
69//:: elif prop.is_length_value:
70 ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=True)};
71 if(${prop.name} < MINIMUM_LENGTH)
72 throw new OFParseError("Wrong ${prop.name}: Expected to be >= " + MINIMUM_LENGTH + ", was: " + ${prop.name});
73//:: elif prop.is_field_length_value:
74//:: fields_with_length_member[prop.member.field_name] = prop.name
75 int ${prop.name} = ${prop.java_type.read_op(version)};
76//:: elif prop.is_discriminator:
77 ${prop.java_type.priv_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=False)};
78 bb.readerIndex(start);
79 switch(${prop.name}) {
80//:: for sub in msg.subclasses:
81//:: if not model.generate_class(sub):
82 // skip ${sub.name} - excluded from generation
83//:: else:
84//:: m = sub.get_member(prop.name)
85//:: if not m.is_fixed_value:
86//:: raise Exception("subtype %s of %s does not have fixed value for discriminator %s" %
87//:: (sub.name, msg.name, prop.name))
88//:: #endif
89 case ${m.priv_value}:
90 // discriminator value ${m.enum_value}=${m.value} for class ${sub.name}
91 return ${sub.name}.READER.readFrom(bb);
92//:: #endif # generate_class
93//:: #endfor
94 default:
95 throw new OFParseError("Unknown value for discriminator ${prop.name} of class ${msg.name}: " + ${prop.name});
96 }
97//:: break
98//:: #endif
99//:: #endfor
100 }
101 }
102}