I wrote a TLV parser that returns results like the following tag length value:
<e1> 53 <9f1e0831 36303231 343337ef…>
<9f1e> 8 <31363032 31343337>
<ef> 18 <df0d084d 3030302d 4d5049df 7f04312d 3232>
<df0d> 8 <4d303030 2d4d5049>
<df7f> 4 <312d3232>
<ef> 20 <df0d0b4d 3030302d 54455354 4f53df7f 03362d35>
<df0d> 11 <4d303030 2d544553 544f53>
<df7f> 3 <362d35>
I want to display this in an OutlineView, but I'm not familiar how the store object should look like and how to fill it up. Somehow it needs to be something like below:
class Node: NSObject {
var isConstructed = false
var tag = „Tag“
var length = 0
var value = „Value“
var children = [Node]()
weak var parent: Node?
override init() {
super.init()
}
init(tag: String) {
self.tag = tag
}
init(length: Int) {
self.length = length
}
init(value: String) {
self.value = value
}
init(isConstructed: Bool) {
self.isConstructed = isConstructed
}
func isLeaf() -> Bool {
return children.isEmpty
}
}
The TLV parser demo TLVparser
Should look like this: TLV parse result in NSOutlineView
Finally got some time to work on this question today. Putting this on an
NSOutlineView
is the easy part. The hard part is to define a data model for your TLV data and parse theData
into it.TLVNode.swift
This class stores the TLV data. Your code looks like converted C and then it's not very good C either.
View Controller
Interface Builder Setup
We will use Cocoa Bindings since populating an Outline View manually can be quite tedious (see my other answer) and your example screenshot look like you are already heading in that direction. A word of caution: while Cocoa Binding is very convenient, it should be considered an advanced topic since it's rather hard to troubleshoot. On your storyboard:
Open the Bindings Inspector, for the 5 highlight objects, set their bindings as follow:
Result: