blob: 9754cebf84f1317766ce4af3e8d678fe0703dbfe [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 *
39 * @author David Erickson (daviderickson@cs.stanford.edu)
40 */
41public class Data extends BasePacket {
42 protected byte[] data;
43
44 /**
45 *
46 */
47 public Data() {
48 }
49
50 /**
51 * @param data
52 */
53 public Data(final byte[] data) {
54 this.data = data;
55 }
56
57 /**
58 * @return the data
59 */
60 public byte[] getData() {
61 return this.data;
62 }
63
64 /**
65 * @param data
66 * the data to set
67 */
68 public Data setData(final byte[] data) {
69 this.data = data;
70 return this;
71 }
72
73 @Override
74 public byte[] serialize() {
75 return this.data;
76 }
77
78 @Override
79 public IPacket deserialize(final byte[] data, final int offset,
80 final int length) {
81 this.data = Arrays.copyOfRange(data, offset, data.length);
82 return this;
83 }
84
85 /*
86 * (non-Javadoc)
87 *
88 * @see java.lang.Object#hashCode()
89 */
90 @Override
91 public int hashCode() {
92 final int prime = 1571;
93 int result = super.hashCode();
94 result = prime * result + Arrays.hashCode(this.data);
95 return result;
96 }
97
98 /*
99 * (non-Javadoc)
100 *
101 * @see java.lang.Object#equals(java.lang.Object)
102 */
103 @Override
104 public boolean equals(final Object obj) {
105 if (this == obj) {
106 return true;
107 }
108 if (!super.equals(obj)) {
109 return false;
110 }
111 if (!(obj instanceof Data)) {
112 return false;
113 }
114 final Data other = (Data) obj;
115 if (!Arrays.equals(this.data, other.data)) {
116 return false;
117 }
118 return true;
119 }
120}