Use ByteBuf.readRetainedSlice()
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / TunnelIdEntrySerializer.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.impl.protocol.serialization.match;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
12 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Tunnel;
15 import org.opendaylight.yangtools.yang.common.Uint64;
16
17 public class TunnelIdEntrySerializer extends AbstractMatchEntrySerializer<Tunnel, Uint64> {
18     public TunnelIdEntrySerializer() {
19         super(OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.TUNNEL_ID, Long.BYTES);
20     }
21
22     @Override
23     protected Tunnel extractEntry(Match match) {
24         final Tunnel tunnel = match.getTunnel();
25         return tunnel == null || tunnel.getTunnelId() == null ? null : tunnel;
26     }
27
28     @Override
29     protected Uint64 extractEntryMask(Tunnel entry) {
30         return entry.getTunnelMask();
31     }
32
33     @Override
34     protected void serializeEntry(Tunnel entry, Uint64 mask, ByteBuf outBuffer) {
35         outBuffer.writeBytes(ByteUtil.uint64toBytes(entry.getTunnelId()));
36         if (mask != null) {
37             writeMask(ByteUtil.uint64toBytes(mask), outBuffer, Long.BYTES);
38         }
39     }
40 }