Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame^] | 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 17 | * under the License. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame^] | 18 | */ |
| 19 | |
| 20 | |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 21 | |
| 22 | package org.onlab.packet; |
| 23 | |
| 24 | import java.util.Arrays; |
| 25 | |
| 26 | /** |
| 27 | * |
alshabib | c4901cd | 2014-09-05 16:50:40 -0700 | [diff] [blame] | 28 | */ |
| 29 | public class Data extends BasePacket { |
| 30 | protected byte[] data; |
| 31 | |
| 32 | /** |
| 33 | * |
| 34 | */ |
| 35 | public Data() { |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @param data |
| 40 | */ |
| 41 | public Data(final byte[] data) { |
| 42 | this.data = data; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @return the data |
| 47 | */ |
| 48 | public byte[] getData() { |
| 49 | return this.data; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param data |
| 54 | * the data to set |
| 55 | */ |
| 56 | public Data setData(final byte[] data) { |
| 57 | this.data = data; |
| 58 | return this; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public byte[] serialize() { |
| 63 | return this.data; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public IPacket deserialize(final byte[] data, final int offset, |
| 68 | final int length) { |
| 69 | this.data = Arrays.copyOfRange(data, offset, data.length); |
| 70 | return this; |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * (non-Javadoc) |
| 75 | * |
| 76 | * @see java.lang.Object#hashCode() |
| 77 | */ |
| 78 | @Override |
| 79 | public int hashCode() { |
| 80 | final int prime = 1571; |
| 81 | int result = super.hashCode(); |
| 82 | result = prime * result + Arrays.hashCode(this.data); |
| 83 | return result; |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * (non-Javadoc) |
| 88 | * |
| 89 | * @see java.lang.Object#equals(java.lang.Object) |
| 90 | */ |
| 91 | @Override |
| 92 | public boolean equals(final Object obj) { |
| 93 | if (this == obj) { |
| 94 | return true; |
| 95 | } |
| 96 | if (!super.equals(obj)) { |
| 97 | return false; |
| 98 | } |
| 99 | if (!(obj instanceof Data)) { |
| 100 | return false; |
| 101 | } |
| 102 | final Data other = (Data) obj; |
| 103 | if (!Arrays.equals(this.data, other.data)) { |
| 104 | return false; |
| 105 | } |
| 106 | return true; |
| 107 | } |
| 108 | } |