in Legacy/PlaygroundLogger/PlaygroundLogger/PlaygroundObjectWriter.swift [107:145]
func encode(structure: LoggerMirror, depth : UInt64, ranges : ChildrenRange...) {
let actual_ranges = boundCheckRanges(generateNonOverlappingUnion(ranges),UInt64(structure.count))
let nested_depth = depth + structure.displayStyle.getConsumedDepthLevels()
let disposition = PlaygroundRepresentation(structure.displayStyle)
Woodchuck.chuck {
return Woodchuck.LogEntry("ranges to log: \(actual_ranges), depth = \(depth), nested_depth = \(nested_depth), disposition = \(disposition)")
}
stream.write(disposition)
let count = UInt64(structure.count)
let (type_name,summary) = structure.getSummaries()
Woodchuck.chuck {
return Woodchuck.LogEntry("type_name = \(type_name), summary = \(summary)")
}
var real_count : UInt64 = 0
actual_ranges.forEach { real_count += UInt64($0.count) }
stream.write(type_name).write(summary).write(count)
if count == 0 { return } // nothing to log - don't write real_count since it will also be zero, eject
if (max_depth == nested_depth) {
// this is the maximum depth - just emit a gap here
stream.write(UInt8(1))
encode_gap()
return
}
let encode_gaps = (real_count < count)
if (encode_gaps) {
var num_gaps : UInt64 = 0
actual_ranges.forEach { if $0.endIndex < count { num_gaps += 1 } }
real_count += num_gaps
}
stream.write(real_count)
for range in actual_ranges {
// in practice, we always start logging at 0, so we don't need a "start range"
encode(children: structure, depth: nested_depth, range: range)
// encode a gap after each range - unless the range goes all the way to the end
if (encode_gaps && range.endIndex < count) {
encode_gap()
}
}
}