blob: 4e651b52baf3905363591dac9471aee80efbaab1 [file] [log] [blame]
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.net.resource;
17
18import com.google.common.annotations.Beta;
19import org.onlab.packet.MplsLabel;
20
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -070021/**
22 * Codec for MplsLabel.
23 */
24@Beta
Sho SHIMIZUcf98b1a2016-05-18 15:11:31 -070025public final class MplsCodec implements DiscreteResourceCodec<MplsLabel> {
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -070026 @Override
Sho SHIMIZUcf98b1a2016-05-18 15:11:31 -070027 public int encode(MplsLabel resource) {
28 return resource.toInt();
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -070029 }
30
31 @Override
Sho SHIMIZUcf98b1a2016-05-18 15:11:31 -070032 public MplsLabel decode(int value) {
33 return MplsLabel.mplsLabel(value);
Sho SHIMIZUf01fe1c2016-05-02 14:41:18 -070034 }
35
36 @Override
37 public boolean equals(Object obj) {
38 if (obj == this) {
39 return true;
40 }
41
42 if (obj == null || getClass() != obj.getClass()) {
43 return false;
44 }
45
46 return true;
47 }
48
49 @Override
50 public int hashCode() {
51 return MplsCodec.class.hashCode();
52 }
53}