blob: 613531556d9a1917e31df6164d929890cc700e1a [file] [log] [blame]
mohamed rahile04626f2016-04-05 20:42:53 +05301/*
2 * Copyright 2016 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 */
16package org.onosproject.isis.io.isispacket.tlv;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.primitives.Bytes;
20import io.netty.buffer.ByteBuf;
21
22import java.util.ArrayList;
23import java.util.List;
24
25/**
26 * Represents padding TLV.
27 */
28public class PaddingTlv extends TlvHeader implements IsisTlv {
29 private List<Byte> paddings = new ArrayList();
30
31 /**
32 * Sets TLV type and TLV length of padding TLV.
33 *
34 * @param tlvHeader tlvHeader.
35 */
36 public PaddingTlv(TlvHeader tlvHeader) {
37 this.setTlvType(tlvHeader.tlvType());
38 this.setTlvLength(tlvHeader.tlvLength());
39 }
40
41 @Override
42 public void readFrom(ByteBuf byteBuf) {
43 while (byteBuf.readableBytes() > 0) {
44 this.paddings.add(byteBuf.readByte());
45 }
46 }
47
48 @Override
49 public byte[] asBytes() {
50 byte[] bytes = null;
51
52 byte[] tlvHeader = tlvHeaderAsByteArray();
53 byte[] tlvBody = tlvBodyAsBytes();
54 bytes = Bytes.concat(tlvHeader, tlvBody);
55
56 return bytes;
57 }
58
59 /**
60 * Gets TLV body padding TLV.
61 *
62 * @return areaArea TLV body padding TLV\\
63 */
64 public byte[] tlvBodyAsBytes() {
65 byte[] areaArea = new byte[this.tlvLength()];
66 return areaArea;
67 }
68
69 @Override
70 public String toString() {
71 return MoreObjects.toStringHelper(getClass())
72 .omitNullValues()
73 .toString();
74 }
75}