blob: 429b456ffb3a773a85c726f8c502c3a7b7e05d69 [file] [log] [blame]
alshabibc4901cd2014-09-05 16:50:40 -07001/*******************************************************************************
2 * Copyright 2014 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 ******************************************************************************/
16/**
17 * Copyright 2011, Big Switch Networks, Inc.
18 * Originally created by David Erickson, Stanford University
19 *
20 * Licensed under the Apache License, Version 2.0 (the "License"); you may
21 * not use this file except in compliance with the License. You may obtain
22 * a copy of the License at
23 *
24 * http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
28 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
29 * License for the specific language governing permissions and limitations
30 * under the License.
31 **/
32
33package org.onlab.packet;
34
35import java.util.Arrays;
36
37/**
38 *
alshabibc4901cd2014-09-05 16:50:40 -070039 */
40public class Data extends BasePacket {
41 protected byte[] data;
42
43 /**
44 *
45 */
46 public Data() {
47 }
48
49 /**
50 * @param data
51 */
52 public Data(final byte[] data) {
53 this.data = data;
54 }
55
56 /**
57 * @return the data
58 */
59 public byte[] getData() {
60 return this.data;
61 }
62
63 /**
64 * @param data
65 * the data to set
66 */
67 public Data setData(final byte[] data) {
68 this.data = data;
69 return this;
70 }
71
72 @Override
73 public byte[] serialize() {
74 return this.data;
75 }
76
77 @Override
78 public IPacket deserialize(final byte[] data, final int offset,
79 final int length) {
80 this.data = Arrays.copyOfRange(data, offset, data.length);
81 return this;
82 }
83
84 /*
85 * (non-Javadoc)
86 *
87 * @see java.lang.Object#hashCode()
88 */
89 @Override
90 public int hashCode() {
91 final int prime = 1571;
92 int result = super.hashCode();
93 result = prime * result + Arrays.hashCode(this.data);
94 return result;
95 }
96
97 /*
98 * (non-Javadoc)
99 *
100 * @see java.lang.Object#equals(java.lang.Object)
101 */
102 @Override
103 public boolean equals(final Object obj) {
104 if (this == obj) {
105 return true;
106 }
107 if (!super.equals(obj)) {
108 return false;
109 }
110 if (!(obj instanceof Data)) {
111 return false;
112 }
113 final Data other = (Data) obj;
114 if (!Arrays.equals(this.data, other.data)) {
115 return false;
116 }
117 return true;
118 }
119}