/// <summary> /// Parse byte[] into TLVs /// </summary> public void ParseByteArrayIntoTlvs(byte[] bytes, int offset) { int position = 0; TlvCollection.Clear(); while (position < bytes.Length) { // The payload type var byteArraySegment = new ByteArraySegment(bytes, offset + position, TLVTypeLength.TypeLengthLength); var typeLength = new TLVTypeLength(byteArraySegment); // create a TLV based on the type and // add it to the collection TLV currentTlv = TLVFactory(bytes, offset + position, typeLength.Type); if (currentTlv == null) { break; } TlvCollection.Add(currentTlv); // stop at the first end tlv we run into if (currentTlv is EndOfLLDPDU) { break; } // Increment the position to seek the next TLV position += (currentTlv.TotalLength); } }
/// <summary> /// Parse byte[] into TLVs /// </summary> public void ParseByteArrayIntoTlvs(byte[] bytes, int offset) { log.DebugFormat("bytes.Length {0}, offset {1}", bytes.Length, offset); int position = 0; TlvCollection.Clear(); while (position < bytes.Length) { // The payload type var byteArraySegment = new ByteArraySegment(bytes, offset + position, TLVTypeLength.TypeLengthLength); var typeLength = new TLVTypeLength(byteArraySegment); // create a TLV based on the type and // add it to the collection TLV currentTlv = TLVFactory(bytes, offset + position, typeLength.Type); if (currentTlv == null) { log.Debug("currentTlv == null"); break; } log.DebugFormat("Adding tlv {0}, Type {1}", currentTlv.GetType(), currentTlv.Type); TlvCollection.Add(currentTlv); // stop at the first end tlv we run into if (currentTlv is EndOfLLDPDU) { break; } // Increment the position to seek the next TLV position += (currentTlv.TotalLength); } log.DebugFormat("Done, position {0}", position); }