Sho SHIMIZU
Committed by Sho Shimizu

Add DiscreteResourceCodec for PortNumber

Change-Id: Iedda1a0ba46b3d044f127334a8abdb419dabcd9f
(cherry picked from commit cbd103df)
......@@ -17,6 +17,7 @@ package org.onosproject.store.resource.impl;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.resource.DiscreteResource;
import org.onosproject.net.resource.DiscreteResourceCodec;
......@@ -46,6 +47,7 @@ final class Codecs {
}
private void init() {
codecs.put(PortNumber.class, new PortNumberCodec());
codecs.put(VlanId.class, new VlanIdCodec());
codecs.put(MplsLabel.class, new MplsLabelCodec());
}
......
......@@ -78,6 +78,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
.register(EmptyDiscreteResources.class)
.register(new EncodedResourcesSerializer(), EncodedDiscreteResources.class)
.register(ContinuousResourceAllocation.class)
.register(PortNumberCodec.class)
.register(VlanIdCodec.class)
.register(MplsLabelCodec.class)
.build());
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.store.resource.impl;
import org.onosproject.net.PortNumber;
import org.onosproject.net.resource.DiscreteResourceCodec;
class PortNumberCodec implements DiscreteResourceCodec<PortNumber> {
@Override
public int encode(PortNumber resource) {
return (int) resource.toLong();
}
@Override
public PortNumber decode(int value) {
return PortNumber.portNumber(value);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
return true;
}
@Override
public int hashCode() {
return PortNumber.class.hashCode();
}
}