*/
package org.opendaylight.openflowjava.protocol.impl.deserialization.match;
+import static java.util.Objects.requireNonNull;
+
import io.netty.buffer.ByteBuf;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;
-import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
*
* @author michal.polkorab
*/
-public abstract class AbstractOxmMatchEntryDeserializer implements HeaderDeserializer<MatchEntry> {
+public abstract class AbstractOxmMatchEntryDeserializer
+ implements HeaderDeserializer<MatchEntry>, OFDeserializer<MatchEntry> {
+ private final @NonNull OxmClassBase oxmClass;
+ private final @NonNull MatchField oxmField;
+
+ protected AbstractOxmMatchEntryDeserializer(final OxmClassBase oxmClass,
+ final MatchField oxmField) {
+ this.oxmClass = requireNonNull(oxmClass);
+ this.oxmField = requireNonNull(oxmField);
+ }
+
+ protected AbstractOxmMatchEntryDeserializer(final MatchField oxmField) {
+ this(OpenflowBasicClass.VALUE, oxmField);
+ }
@Override
- public MatchEntry deserializeHeader(ByteBuf input) {
- MatchEntryBuilder builder = processHeader(getOxmClass(), getOxmField(), input);
+ public final MatchEntry deserialize(final ByteBuf input) {
+ final MatchEntryBuilder builder = processHeader(input);
+ deserialize(input, builder);
return builder.build();
}
- /**
- * Returns the oxm_field class.
- */
- protected abstract Class<? extends MatchField> getOxmField();
+ protected abstract void deserialize(ByteBuf input, MatchEntryBuilder builder);
- /**
- * Returns the oxm_class class.
- */
- protected abstract Class<? extends OxmClassBase> getOxmClass();
+ @Override
+ public final MatchEntry deserializeHeader(final ByteBuf input) {
+ return processHeader(input).build();
+ }
/**
* Prepares match entry header - sets oxm_class, oxm_field, hasMask
* + sets the buffer.readerIndex() to the end of match entry
* - where augmentation starts.
*
- * @param oxmClass oxm class type
- * @param oxmField oxm field type
* @param input input bytebuf
* @return MatchEntriesBuilder which can be filled with MatchEntry augmentation
*/
- protected MatchEntryBuilder processHeader(Class<? extends OxmClassBase> oxmClass,
- Class<? extends MatchField> oxmField, ByteBuf input) {
- MatchEntryBuilder builder = new MatchEntryBuilder();
- builder.setOxmClass(oxmClass);
+ protected final MatchEntryBuilder processHeader(final ByteBuf input) {
// skip oxm_class (provided)
- input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
- builder.setOxmMatchField(oxmField);
- boolean hasMask = (input.readUnsignedByte() & 1) != 0;
- builder.setHasMask(hasMask);
+ input.skipBytes(Short.BYTES);
+ final MatchEntryBuilder builder = new MatchEntryBuilder().setOxmClass(oxmClass).setOxmMatchField(oxmField)
+ .setHasMask((input.readUnsignedByte() & 1) != 0);
// skip match entry length - not needed
- input.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
+ input.skipBytes(Byte.BYTES);
return builder;
}
-
}