blob: 36d407c46c20791b8d9df4dc0eeeae320eda5262 [file] [log] [blame]
Andreas Wundsam27303462013-07-16 12:52:35 -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 *
Andreas Wundsambc679f72013-08-01 22:13:09 -070029//:: import os
Andreas Wundsam27303462013-07-16 12:52:35 -070030//:: 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 Wundsam99e931d2013-08-22 07:53:53 -070040class ${impl_class} implements ${msg.interface.inherited_declaration()} {
Andreas Wundsam70aa5492013-10-23 15:26:53 -070041//:: if genopts.instrument:
42 private static final Logger logger = LoggerFactory.getLogger(${impl_class}.class);
43//:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -070044 // version: ${version}
Yotam Harchol791e4882013-09-05 16:32:56 -070045 final static byte WIRE_VERSION = ${version.int_version};
Andreas Wundsam27303462013-07-16 12:52:35 -070046//:: if msg.is_fixed_length:
Yotam Harchol791e4882013-09-05 16:32:56 -070047 final static int LENGTH = ${msg.length};
Andreas Wundsam27303462013-07-16 12:52:35 -070048//:: else:
Yotam Harchol791e4882013-09-05 16:32:56 -070049 final static int MINIMUM_LENGTH = ${msg.min_length};
Andreas Wundsam27303462013-07-16 12:52:35 -070050//:: #endif
51
52//:: for prop in msg.data_members:
Andreas Wundsamf89f7822013-09-23 14:49:24 -070053 //:: if prop.default_value:
54 private final static ${prop.java_type.public_type} ${prop.default_name} = ${prop.default_value};
55 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -070056//:: #end
57
58 // OF message fields
59//:: for prop in msg.data_members:
60 private final ${prop.java_type.public_type} ${prop.name};
61//:: #endfor
Andreas Wundsame962d372013-10-02 18:15:58 -070062//
63//:: if all(prop.default_value for prop in msg.data_members):
64 // Immutable default instance
65 final static ${impl_class} DEFAULT = new ${impl_class}(
66 ${", ".join(prop.default_name for prop in msg.data_members)}
67 );
68//:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -070069
Andreas Wundsam99e931d2013-08-22 07:53:53 -070070 //:: if msg.data_members:
71 // package private constructor - used by readers, builders, and factory
Andreas Wundsam27303462013-07-16 12:52:35 -070072 ${impl_class}(${
73 ", ".join("%s %s" %(prop.java_type.public_type, prop.name) for prop in msg.data_members) }) {
74//:: for prop in msg.data_members:
75 this.${prop.name} = ${prop.name};
76//:: #endfor
77 }
Andreas Wundsam99e931d2013-08-22 07:53:53 -070078 //:: else:
79 final static ${impl_class} INSTANCE = new ${impl_class}();
80 // private empty constructor - use shared instance!
81 private ${impl_class}() {
82 }
83 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -070084
85 // Accessors for OF message fields
Yotam Harcholf25e8142013-09-09 14:30:13 -070086 //:: include("_field_accessors.java", msg=msg, generate_setters=False, builder=False, has_parent=False)
Andreas Wundsam27303462013-07-16 12:52:35 -070087
Andreas Wundsambc679f72013-08-01 22:13:09 -070088 //:: if os.path.exists("%s/custom/%s.java" % (template_dir, msg.name)):
89 //:: include("custom/%s.java" % msg.name, msg=msg)
90 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -070091
Andreas Wundsam99e931d2013-08-22 07:53:53 -070092 //:: if msg.data_members:
Andreas Wundsam5204de22013-07-30 11:34:45 -070093 public ${msg.interface.name}.Builder createBuilder() {
94 return new BuilderWithParent(this);
Andreas Wundsam27303462013-07-16 12:52:35 -070095 }
96
Andreas Wundsam5204de22013-07-30 11:34:45 -070097 static class BuilderWithParent implements ${msg.interface.name}.Builder {
Andreas Wundsam27303462013-07-16 12:52:35 -070098 final ${impl_class} parentMessage;
99
100 // OF message fields
101//:: for prop in msg.data_members:
102 private boolean ${prop.name}Set;
103 private ${prop.java_type.public_type} ${prop.name};
104//:: #endfor
105
Andreas Wundsam5204de22013-07-30 11:34:45 -0700106 BuilderWithParent(${impl_class} parentMessage) {
Andreas Wundsam27303462013-07-16 12:52:35 -0700107 this.parentMessage = parentMessage;
108 }
109
Yotam Harcholf25e8142013-09-09 14:30:13 -0700110//:: include("_field_accessors.java", msg=msg, generate_setters=True, builder=True, has_parent=True)
Andreas Wundsam27303462013-07-16 12:52:35 -0700111
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700112
Andreas Wundsam27303462013-07-16 12:52:35 -0700113 @Override
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700114 public ${msg.interface.name} build() {
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700115 //:: for prop in msg.data_members:
116 ${prop.java_type.public_type} ${prop.name} = this.${prop.name}Set ? this.${prop.name} : parentMessage.${prop.name};
117 //:: if not prop.is_nullable and not prop.java_type.is_primitive:
118 if(${prop.name} == null)
119 throw new NullPointerException("Property ${prop.name} must not be null");
120 //:: #endif
121 //:: #endfor
122
123 //
124 //:: if os.path.exists("%s/custom/%s.Builder_normalize_stanza.java" % (template_dir, msg.name)):
125 //:: include("custom/%s.Builder_normalize_stanza.java" % msg.name, msg=msg, has_parent=False)
126 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -0700127 return new ${impl_class}(
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700128 //:: for i, prop in enumerate(msg.data_members):
129 //:: comma = "," if i < len(msg.data_members)-1 else ""
130 ${prop.name}${comma}
131 //:: #endfor
132 );
Andreas Wundsam27303462013-07-16 12:52:35 -0700133 }
Andreas Wundsambc679f72013-08-01 22:13:09 -0700134 //:: if os.path.exists("%s/custom/%s.Builder.java" % (template_dir, msg.name)):
Yotam Harchol98af7752013-08-22 14:59:38 -0700135 //:: include("custom/%s.Builder.java" % msg.name, msg=msg, has_parent=True)
Andreas Wundsambc679f72013-08-01 22:13:09 -0700136 //:: #endif
137
Andreas Wundsam27303462013-07-16 12:52:35 -0700138 }
139
Andreas Wundsam5204de22013-07-30 11:34:45 -0700140 static class Builder implements ${msg.interface.name}.Builder {
Andreas Wundsam27303462013-07-16 12:52:35 -0700141 // OF message fields
142//:: for prop in msg.data_members:
143 private boolean ${prop.name}Set;
144 private ${prop.java_type.public_type} ${prop.name};
145//:: #endfor
146
Yotam Harcholf25e8142013-09-09 14:30:13 -0700147//:: include("_field_accessors.java", msg=msg, generate_setters=True, builder=True, has_parent=False)
Andreas Wundsam27303462013-07-16 12:52:35 -0700148//
149 @Override
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700150 public ${msg.interface.name} build() {
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700151 //:: for prop in msg.data_members:
152 //:: if prop.default_value:
153 ${prop.java_type.public_type} ${prop.name} = this.${prop.name}Set ? this.${prop.name} : ${prop.default_name};
154 //:: else:
155 if(!this.${prop.name}Set)
156 throw new IllegalStateException("Property ${prop.name} doesn't have default value -- must be set");
157 //:: #endif
158 //:: if not prop.is_nullable and not prop.java_type.is_primitive:
159 if(${prop.name} == null)
160 throw new NullPointerException("Property ${prop.name} must not be null");
161 //:: #endif
162 //:: #endfor
163
164 //:: if os.path.exists("%s/custom/%s.Builder_normalize_stanza.java" % (template_dir, msg.name)):
165 //:: include("custom/%s.Builder_normalize_stanza.java" % msg.name, msg=msg, has_parent=False)
166 //:: #endif
167
Andreas Wundsam27303462013-07-16 12:52:35 -0700168 return new ${impl_class}(
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700169 //:: for i, prop in enumerate(msg.data_members):
170 //:: comma = "," if i < len(msg.data_members)-1 else ""
171 ${prop.name}${comma}
172 //:: #endfor
Andreas Wundsam27303462013-07-16 12:52:35 -0700173 );
174 }
Andreas Wundsambc679f72013-08-01 22:13:09 -0700175 //:: if os.path.exists("%s/custom/%s.Builder.java" % (template_dir, msg.name)):
Yotam Harchol98af7752013-08-22 14:59:38 -0700176 //:: include("custom/%s.Builder.java" % msg.name, msg=msg, has_parent=False)
Andreas Wundsambc679f72013-08-01 22:13:09 -0700177 //:: #endif
178
Andreas Wundsam27303462013-07-16 12:52:35 -0700179 }
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700180 //:: else:
181 // no data members - do not support builder
182 public ${msg.interface.name}.Builder createBuilder() {
183 throw new UnsupportedOperationException("${impl_class} has no mutable properties -- builder unneeded");
184 }
185 //:: #endif
186
Andreas Wundsam27303462013-07-16 12:52:35 -0700187
188 final static Reader READER = new Reader();
189 static class Reader implements OFMessageReader<${msg.interface.name}> {
190 @Override
191 public ${msg.interface.name} readFrom(ChannelBuffer bb) throws OFParseError {
Yotam Harchola86e4252013-09-06 15:36:28 -0700192//:: for prop in msg.members:
193//:: if not prop.is_virtual and (prop.is_length_value or prop.is_field_length_value):
Andreas Wundsam001b1822013-08-02 22:25:55 -0700194 int start = bb.readerIndex();
Yotam Harchola86e4252013-09-06 15:36:28 -0700195//:: break
196//:: #endif
197//:: #endfor
Andreas Wundsam27303462013-07-16 12:52:35 -0700198//:: fields_with_length_member = {}
199//:: for prop in msg.members:
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700200//:: if prop.is_virtual:
201//:: continue
202//:: elif prop.is_data:
Andreas Wundsam001b1822013-08-02 22:25:55 -0700203 ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=True,
Andreas Wundsam27303462013-07-16 12:52:35 -0700204 length=fields_with_length_member[prop.c_name] if prop.c_name in fields_with_length_member else None)};
205//:: elif prop.is_pad:
206 // pad: ${prop.length} bytes
207 bb.skipBytes(${prop.length});
Andreas Wundsam27303462013-07-16 12:52:35 -0700208//:: elif prop.is_length_value:
Andreas Wundsam83d877a2013-09-30 14:26:44 -0700209 ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=True)};
210 //:: if prop.is_fixed_value:
211 if(${prop.name} != ${prop.value})
212 throw new OFParseError("Wrong ${prop.name}: Expected=${prop.enum_value}(${prop.value}), got="+${prop.name});
213 //:: else:
Andreas Wundsam27303462013-07-16 12:52:35 -0700214 if(${prop.name} < MINIMUM_LENGTH)
215 throw new OFParseError("Wrong ${prop.name}: Expected to be >= " + MINIMUM_LENGTH + ", was: " + ${prop.name});
Andreas Wundsam83d877a2013-09-30 14:26:44 -0700216 //:: #endif
Yotam Harchol0178c202013-09-05 16:25:50 -0700217 if(bb.readableBytes() + (bb.readerIndex() - start) < ${prop.name}) {
218 // Buffer does not have all data yet
219 bb.readerIndex(start);
220 return null;
221 }
Andreas Wundsam70aa5492013-10-23 15:26:53 -0700222 //:: if genopts.instrument:
Andreas Wundsame8802ac2013-11-05 11:47:04 -0800223 if(logger.isTraceEnabled())
224 logger.trace("readFrom - length={}", ${prop.name});
Andreas Wundsam70aa5492013-10-23 15:26:53 -0700225 //:: #endif
Andreas Wundsam83d877a2013-09-30 14:26:44 -0700226//:: elif prop.is_fixed_value:
227 // fixed value property ${prop.name} == ${prop.value}
228 ${prop.java_type.priv_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=False)};
229 if(${prop.name} != ${prop.priv_value})
230 throw new OFParseError("Wrong ${prop.name}: Expected=${prop.enum_value}(${prop.value}), got="+${prop.name});
231//:: elif prop.is_field_length_value:
232//:: fields_with_length_member[prop.member.field_name] = prop.name
233 ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version, pub_type=True)};
234//:: else:
235 // fixme: todo ${prop.name}
Yotam Harchol0178c202013-09-05 16:25:50 -0700236//:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -0700237//:: #endfor
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700238 //:: if msg.align:
Andreas Wundsam87bdcf42013-10-23 15:19:01 -0700239 //:: if msg.length_includes_align:
240 // align message to ${msg.align} bytes (length contains aligned value)
241 bb.skipBytes(length - (bb.readerIndex() - start));
242 //:: else:
243 // align message to ${msg.align} bytes (length does not contain alignment)
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700244 bb.skipBytes(((length + ${msg.align-1})/${msg.align} * ${msg.align} ) - length );
245 //:: #endif
Andreas Wundsam87bdcf42013-10-23 15:19:01 -0700246 //:: #endif
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700247
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700248 //:: if msg.data_members:
Andreas Wundsamf89f7822013-09-23 14:49:24 -0700249 //:: if os.path.exists("%s/custom/%s.Reader_normalize_stanza.java" % (template_dir, msg.name)):
250 //:: include("custom/%s.Reader_normalize_stanza.java" % msg.name, msg=msg, has_parent=False)
251 //:: #endif
Andreas Wundsam70aa5492013-10-23 15:26:53 -0700252 ${impl_class} ${msg.variable_name} = new ${impl_class}(
Andreas Wundsam27303462013-07-16 12:52:35 -0700253 ${",\n ".join(
254 [ prop.name for prop in msg.data_members])}
255 );
Andreas Wundsam70aa5492013-10-23 15:26:53 -0700256 //:: if genopts.instrument:
Andreas Wundsame8802ac2013-11-05 11:47:04 -0800257 if(logger.isTraceEnabled())
258 logger.trace("readFrom - read={}", ${msg.variable_name});
Andreas Wundsam70aa5492013-10-23 15:26:53 -0700259 //:: #endif
260 return ${msg.variable_name};
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700261 //:: else:
Andreas Wundsam70aa5492013-10-23 15:26:53 -0700262 //:: if genopts.instrument:
Andreas Wundsame8802ac2013-11-05 11:47:04 -0800263 if(logger.isTraceEnabled())
264 logger.trace("readFrom - returning shared instance={}", INSTANCE);
Andreas Wundsam70aa5492013-10-23 15:26:53 -0700265 //:: #endif
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700266 return INSTANCE;
267 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -0700268 }
269 }
270
Andreas Wundsam22ba3af2013-10-04 16:00:30 -0700271 public void putTo(PrimitiveSink sink) {
272 FUNNEL.funnel(this, sink);
273 }
274
275 final static ${impl_class}Funnel FUNNEL = new ${impl_class}Funnel();
276 static class ${impl_class}Funnel implements Funnel<${impl_class}> {
277 private static final long serialVersionUID = 1L;
278 @Override
279 public void funnel(${impl_class} message, PrimitiveSink sink) {
280//:: for prop in msg.members:
281//:: if prop.is_virtual:
282//:: continue
283//:: elif prop.is_data:
284 ${prop.java_type.funnel_op(version, "message." + prop.name, pub_type=True)};
285//:: elif prop.is_pad:
286 // skip pad (${prop.length} bytes)
287//:: elif prop.is_fixed_value:
288 // fixed value property ${prop.name} = ${prop.value}
289 ${prop.java_type.funnel_op(version, prop.priv_value, pub_type=False)};
290//:: else:
291 // FIXME: skip funnel of ${prop.name}
292//:: #endif
293//:: #endfor
294 }
295 }
296
297
Yotam Harchol5c9d6f42013-08-01 11:09:20 -0700298 public void writeTo(ChannelBuffer bb) {
299 WRITER.write(bb, this);
Andreas Wundsam27303462013-07-16 12:52:35 -0700300 }
301
302 final static Writer WRITER = new Writer();
303 static class Writer implements OFMessageWriter<${impl_class}> {
304 @Override
Andreas Wundsama94273b2013-08-01 22:11:33 -0700305 public void write(ChannelBuffer bb, ${impl_class} message) {
Yotam Harchola86e4252013-09-06 15:36:28 -0700306//:: if not msg.is_fixed_length:
Andreas Wundsam482f6d92013-07-24 16:10:21 -0700307 int startIndex = bb.writerIndex();
Yotam Harchola86e4252013-09-06 15:36:28 -0700308//:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -0700309//:: fields_with_length_member = {}
310//:: for prop in msg.members:
311//:: if prop.c_name in fields_with_length_member:
312 int ${prop.name}StartIndex = bb.writerIndex();
313//:: #endif
Andreas Wundsam99e931d2013-08-22 07:53:53 -0700314//:: if prop.is_virtual:
315//:: continue
316//:: elif prop.is_data:
Andreas Wundsam001b1822013-08-02 22:25:55 -0700317 ${prop.java_type.write_op(version, "message." + prop.name, pub_type=True)};
Andreas Wundsam27303462013-07-16 12:52:35 -0700318//:: elif prop.is_pad:
319 // pad: ${prop.length} bytes
320 bb.writeZero(${prop.length});
321//:: elif prop.is_fixed_value:
322 // fixed value property ${prop.name} = ${prop.value}
Andreas Wundsam2bf357c2013-08-03 22:50:40 -0700323 ${prop.java_type.write_op(version, prop.priv_value, pub_type=False)};
Andreas Wundsam27303462013-07-16 12:52:35 -0700324//:: elif prop.is_length_value:
325 // ${prop.name} is length of variable message, will be updated at the end
Andreas Wundsam001b1822013-08-02 22:25:55 -0700326//:: if not msg.is_fixed_length:
327 int lengthIndex = bb.writerIndex();
328//:: #end
Andreas Wundsam27303462013-07-16 12:52:35 -0700329 ${prop.java_type.write_op(version, 0)};
Andreas Wundsam001b1822013-08-02 22:25:55 -0700330
Andreas Wundsam27303462013-07-16 12:52:35 -0700331//:: elif prop.is_field_length_value:
332//:: fields_with_length_member[prop.member.field_name] = prop.name
333 // ${prop.name} is length indicator for ${prop.member.field_name}, will be
334 // udpated when ${prop.member.field_name} has been written
335 int ${prop.name}Index = bb.writerIndex();
Andreas Wundsam001b1822013-08-02 22:25:55 -0700336 ${prop.java_type.write_op(version, 0, pub_type=False)};
Andreas Wundsam27303462013-07-16 12:52:35 -0700337//:: else:
338 // FIXME: todo write ${prop.name}
339//:: #endif
340//:: if prop.c_name in fields_with_length_member:
341//:: length_member_name = fields_with_length_member[prop.c_name]
342 // update field length member ${length_member_name}
343 int ${prop.name}Length = bb.writerIndex() - ${prop.name}StartIndex;
344 bb.setShort(${length_member_name}Index, ${prop.name}Length);
345//:: #endif
346//:: #endfor
347
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700348//:: if not msg.is_fixed_length:
Andreas Wundsam27303462013-07-16 12:52:35 -0700349 // update length field
350 int length = bb.writerIndex() - startIndex;
Andreas Wundsam5da68512013-10-22 22:18:00 -0700351 //:: if msg.align:
352 int alignedLength = ((length + ${msg.align-1})/${msg.align} * ${msg.align});
353 //:: #endif
354 bb.setShort(lengthIndex, ${"alignedLength" if msg.length_includes_align else "length"});
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700355 //:: if msg.align:
356 // align message to ${msg.align} bytes
Andreas Wundsam5da68512013-10-22 22:18:00 -0700357 bb.writeZero(alignedLength - length);
Andreas Wundsam758c9cc2013-08-01 22:16:06 -0700358 //:: #endif
Andreas Wundsam27303462013-07-16 12:52:35 -0700359//:: #end
360
361 }
362 }
363
Andreas Wundsameeefb552013-07-30 11:04:35 -0700364 @Override
Andreas Wundsamd7d5bb32013-07-30 12:26:31 -0700365 public String toString() {
366 StringBuilder b = new StringBuilder("${msg.name}(");
367 //:: for i, prop in enumerate(msg.data_members):
368 //:: if i > 0:
369 b.append(", ");
370 //:: #endif
371 b.append("${prop.name}=").append(${ "Arrays.toString(%s)" % prop.name if prop.java_type.is_array else prop.name });
372 //:: #endfor
373 b.append(")");
374 return b.toString();
375 }
376
377
378 @Override
Andreas Wundsameeefb552013-07-30 11:04:35 -0700379 public boolean equals(Object obj) {
380 if (this == obj)
381 return true;
382 if (obj == null)
383 return false;
384 if (getClass() != obj.getClass())
385 return false;
Yotam Harchola86e4252013-09-06 15:36:28 -0700386 //:: if len(msg.data_members) > 0:
Andreas Wundsameeefb552013-07-30 11:04:35 -0700387 ${msg.name} other = (${msg.name}) obj;
Yotam Harchola86e4252013-09-06 15:36:28 -0700388 //:: #endif
Andreas Wundsameeefb552013-07-30 11:04:35 -0700389
390 //:: for prop in msg.data_members:
391 //:: if prop.java_type.is_primitive:
392 if( ${prop.name} != other.${prop.name})
393 return false;
394 //:: elif prop.java_type.is_array:
395 if (!Arrays.equals(${prop.name}, other.${prop.name}))
396 return false;
Andreas Wundsamd7d5bb32013-07-30 12:26:31 -0700397 //:: else:
Andreas Wundsameeefb552013-07-30 11:04:35 -0700398 if (${prop.name} == null) {
399 if (other.${prop.name} != null)
400 return false;
401 } else if (!${prop.name}.equals(other.${prop.name}))
402 return false;
403 //:: #endif
404 //:: #endfor
405 return true;
406 }
407
408 @Override
409 public int hashCode() {
Yotam Harchola86e4252013-09-06 15:36:28 -0700410 //:: if len(msg.data_members) > 0:
Andreas Wundsameeefb552013-07-30 11:04:35 -0700411 final int prime = 31;
Yotam Harchola86e4252013-09-06 15:36:28 -0700412 //:: #endif
Andreas Wundsameeefb552013-07-30 11:04:35 -0700413 int result = 1;
414
415 //:: for prop in msg.data_members:
Andreas Wundsam2bf357c2013-08-03 22:50:40 -0700416 //:: if prop.java_type.pub_type == 'long':
417 result = prime * (int) (${prop.name} ^ (${prop.name} >>> 32));
Rob Vaterlausfeee3712013-09-30 11:24:19 -0700418 //:: elif prop.java_type.pub_type == 'boolean':
419 result = prime * result + (${prop.name} ? 1231 : 1237);
Andreas Wundsam2bf357c2013-08-03 22:50:40 -0700420 //:: elif prop.java_type.is_primitive:
Andreas Wundsameeefb552013-07-30 11:04:35 -0700421 result = prime * result + ${prop.name};
422 //:: elif prop.java_type.is_array:
423 result = prime * result + Arrays.hashCode(${prop.name});
424 //:: else:
425 result = prime * result + ((${prop.name} == null) ? 0 : ${prop.name}.hashCode());
426 //:: #endif
427 //:: #endfor
428 return result;
429 }
430
Andreas Wundsam27303462013-07-16 12:52:35 -0700431
432}