blob: 311cc93e315ab3f6c35fe479fcd258c39ad2a0a8 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
alshabibc4901cd2014-09-05 16:50:40 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
alshabibc4901cd2014-09-05 16:50:40 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
16
17
alshabibc4901cd2014-09-05 16:50:40 -070018
19package org.onlab.packet;
20
21import java.util.Arrays;
22
23/**
24 *
alshabibc4901cd2014-09-05 16:50:40 -070025 */
26public class Data extends BasePacket {
27 protected byte[] data;
28
29 /**
30 *
31 */
32 public Data() {
33 }
34
35 /**
36 * @param data
37 */
38 public Data(final byte[] data) {
39 this.data = data;
40 }
41
42 /**
43 * @return the data
44 */
45 public byte[] getData() {
46 return this.data;
47 }
48
49 /**
50 * @param data
51 * the data to set
52 */
53 public Data setData(final byte[] data) {
54 this.data = data;
55 return this;
56 }
57
58 @Override
59 public byte[] serialize() {
60 return this.data;
61 }
62
63 @Override
64 public IPacket deserialize(final byte[] data, final int offset,
65 final int length) {
66 this.data = Arrays.copyOfRange(data, offset, data.length);
67 return this;
68 }
69
70 /*
71 * (non-Javadoc)
72 *
73 * @see java.lang.Object#hashCode()
74 */
75 @Override
76 public int hashCode() {
77 final int prime = 1571;
78 int result = super.hashCode();
79 result = prime * result + Arrays.hashCode(this.data);
80 return result;
81 }
82
83 /*
84 * (non-Javadoc)
85 *
86 * @see java.lang.Object#equals(java.lang.Object)
87 */
88 @Override
89 public boolean equals(final Object obj) {
90 if (this == obj) {
91 return true;
92 }
93 if (!super.equals(obj)) {
94 return false;
95 }
96 if (!(obj instanceof Data)) {
97 return false;
98 }
99 final Data other = (Data) obj;
100 if (!Arrays.equals(this.data, other.data)) {
101 return false;
102 }
103 return true;
104 }
105}