blob: 55ccc5e27be3ada89eb7ca5079f42aa67e5eb416 [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
Andreas Wundsam2be7da52013-08-22 07:34:25 -070040abstract class ${msg.name} {
Andreas Wundsam001b1822013-08-02 22:25:55 -070041 // version: ${version}
Yotam Harchol791e4882013-09-05 16:32:56 -070042 final static byte WIRE_VERSION = ${version.int_version};
Andreas Wundsam001b1822013-08-02 22:25:55 -070043//:: if msg.is_fixed_length:
Yotam Harchol791e4882013-09-05 16:32:56 -070044 final static int LENGTH = ${msg.length};
Andreas Wundsam001b1822013-08-02 22:25:55 -070045//:: else:
Yotam Harchol791e4882013-09-05 16:32:56 -070046 final static int MINIMUM_LENGTH = ${msg.min_length};
Andreas Wundsam001b1822013-08-02 22:25:55 -070047//:: #endif
48
49
50 public final static ${msg.name}.Reader READER = new Reader();
51
Andreas Wundsam2be7da52013-08-22 07:34:25 -070052 static class Reader implements OFMessageReader<${msg.interface.inherited_declaration()}> {
Andreas Wundsam001b1822013-08-02 22:25:55 -070053 @Override
Yotam Harchola86e4252013-09-06 15:36:28 -070054 public ${msg.interface.inherited_declaration()} readFrom(ChannelBuffer bb) throws OFParseError {
Yotam Harchol0178c202013-09-05 16:25:50 -070055//:: if msg.is_fixed_length:
56 if(bb.readableBytes() < LENGTH)
57//:: else:
58 if(bb.readableBytes() < MINIMUM_LENGTH)
59//:: #endif
60 return null;
Andreas Wundsam001b1822013-08-02 22:25:55 -070061 int start = bb.readerIndex();
62//:: fields_with_length_member = {}
63//:: for prop in msg.members:
64//:: if prop.is_data:
65 ${prop.java_type.skip_op(version,
66 length=fields_with_length_member[prop.c_name] if prop.c_name in fields_with_length_member else None)};
67//:: elif prop.is_pad:
68 // pad: ${prop.length} bytes
69 bb.skipBytes(${prop.length});
70//:: elif prop.is_fixed_value:
71 // fixed value property ${prop.name} == ${prop.value}
72 ${prop.java_type.priv_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=False)};
Andreas Wundsam1cc5df42013-09-04 18:57:39 -070073 if(${prop.name} != ${prop.priv_value})
Andreas Wundsam001b1822013-08-02 22:25:55 -070074 throw new OFParseError("Wrong ${prop.name}: Expected=${prop.enum_value}(${prop.value}), got="+${prop.name});
75//:: elif prop.is_length_value:
76 ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=True)};
77 if(${prop.name} < MINIMUM_LENGTH)
78 throw new OFParseError("Wrong ${prop.name}: Expected to be >= " + MINIMUM_LENGTH + ", was: " + ${prop.name});
79//:: elif prop.is_field_length_value:
80//:: fields_with_length_member[prop.member.field_name] = prop.name
81 int ${prop.name} = ${prop.java_type.read_op(version)};
82//:: elif prop.is_discriminator:
83 ${prop.java_type.priv_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=False)};
84 bb.readerIndex(start);
85 switch(${prop.name}) {
86//:: for sub in msg.subclasses:
87//:: if not model.generate_class(sub):
88 // skip ${sub.name} - excluded from generation
89//:: else:
90//:: m = sub.get_member(prop.name)
91//:: if not m.is_fixed_value:
92//:: raise Exception("subtype %s of %s does not have fixed value for discriminator %s" %
93//:: (sub.name, msg.name, prop.name))
94//:: #endif
95 case ${m.priv_value}:
96 // discriminator value ${m.enum_value}=${m.value} for class ${sub.name}
97 return ${sub.name}.READER.readFrom(bb);
98//:: #endif # generate_class
99//:: #endfor
100 default:
101 throw new OFParseError("Unknown value for discriminator ${prop.name} of class ${msg.name}: " + ${prop.name});
102 }
103//:: break
104//:: #endif
105//:: #endfor
106 }
107 }
108}