blob: 47762da823dcb586a70d8612db0f6ab5b422cc23 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright 2011, Big Switch Networks, Inc.
3* Originally created by David Erickson, Stanford University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18package net.floodlightcontroller.packet;
19
20import java.util.Arrays;
21
22/**
23 *
24 * @author David Erickson (daviderickson@cs.stanford.edu)
25 */
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(byte[] data) {
39 this.data = data;
40 }
41
42 /**
43 * @return the data
44 */
45 public byte[] getData() {
46 return data;
47 }
48
49 /**
50 * @param data the data to set
51 */
52 public Data setData(byte[] data) {
53 this.data = data;
54 return this;
55 }
56
57 public byte[] serialize() {
58 return this.data;
59 }
60
61 @Override
62 public IPacket deserialize(byte[] data, int offset, int length) {
63 this.data = Arrays.copyOfRange(data, offset, data.length);
64 return this;
65 }
66
67 /* (non-Javadoc)
68 * @see java.lang.Object#hashCode()
69 */
70 @Override
71 public int hashCode() {
72 final int prime = 1571;
73 int result = super.hashCode();
74 result = prime * result + Arrays.hashCode(data);
75 return result;
76 }
77
78 /* (non-Javadoc)
79 * @see java.lang.Object#equals(java.lang.Object)
80 */
81 @Override
82 public boolean equals(Object obj) {
83 if (this == obj)
84 return true;
85 if (!super.equals(obj))
86 return false;
87 if (!(obj instanceof Data))
88 return false;
89 Data other = (Data) obj;
90 if (!Arrays.equals(data, other.data))
91 return false;
92 return true;
93 }
94}