public TLV(byte[] bytes, int offset) { ByteArraySegment byteArraySegment = new ByteArraySegment(bytes, offset, 2); this.TypeLength = new TLVTypeLength(byteArraySegment); this.tlvData = new ByteArraySegment(bytes, offset, this.TypeLength.Length + 2); this.tlvData.Length = this.TypeLength.Length + 2; }
public TLV(byte[] bytes, int offset) { ByteArraySegment byteArraySegment = new ByteArraySegment(bytes, offset, 2); this.TypeLength = new TLVTypeLength(byteArraySegment); this.tlvData = new ByteArraySegment(bytes, offset, this.TypeLength.Length + 2); this.tlvData.Length = this.TypeLength.Length + 2; }
/// <summary> /// Creates a TLV /// </summary> /// <param name="bytes"> /// Bytes that comprise the TLV /// </param> /// <param name="offset"> /// The TLVs offset from the start of byte[] bytes /// </param> public TLV(byte[] bytes, int offset) { // setup a local ByteArrayAndOffset in order to retrieve the value length // NOTE: we cannot set tlvData to retrieve the value length as // setting tlvData results in the TypeLength.Length being updated with // the length of the ByteArrayAndOffset which would overwrite the value // we are trying to retrieve var byteArraySegment = new ByteArraySegment(bytes, offset, TLVTypeLength.TypeLengthLength); TypeLength = new TLVTypeLength(byteArraySegment); // set the tlvData assuming we have at least the bytes required for the // type/length fields tlvData = new ByteArraySegment(bytes, offset, TypeLength.Length + TLVTypeLength.TypeLengthLength); // retrieve the actual length tlvData.Length = TypeLength.Length + TLVTypeLength.TypeLengthLength; }
public void ParseByteArrayIntoTlvs(byte[] bytes, int offset) { int num = 0; this.TlvCollection.Clear(); while (num < bytes.Length) { ByteArraySegment byteArraySegment = new ByteArraySegment(bytes, offset + num, 2); TLVTypeLength length = new TLVTypeLength(byteArraySegment); TLV item = TLVFactory(bytes, offset + num, length.Type); if (item == null) { break; } this.TlvCollection.Add(item); if (item is EndOfLLDPDU) { break; } num += item.TotalLength; } }