nsmcp::BufferedResultReader method next (public)

 <instance of nsmcp::BufferedResultReader[i]> next

Defined in /usr/local/ns/tcl/nsmcp/log-01-scanner.tcl

Read one complete JSONL record inside the published snapshot. Keep unused channel bytes for the next record. Reject oversized or incomplete records without reading beyond the fixed published limit.

Returns:
A dictionary with start, end and raw, or empty at exhaustion.

Testcases:
No testcase defined.
Source code:
if {${:offset}>=${:limit}} {
    return {}
}
set start ${:offset}
set raw {}
while {${:offset}<${:limit}} {
    if {${:index}>=[string length ${:buffer}]} {
        set started [clock clicks -microseconds]
        set :buffer [read ${:channel} [expr {min(65536,${:limit}-${:offset})}]]
        incr :readMicroseconds [expr {max(0,[clock clicks -microseconds]-$started)}]
        incr :readBytes [string length ${:buffer}]
        incr :readCalls
        set :index 0
        if {${:buffer} eq ""} {
            error "incomplete result cache"
        }
    }
    set newline [string first \n ${:buffer} ${:index}]
    set end [expr {$newline<0 ? [string length ${:buffer}] : $newline}]
    set count [expr {$end-${:index}}]
    set consumed [expr {$count+($newline>=0)}]
    if {${:offset}-$start+$consumed>${:maxBytes}} {
        error "cached record exceeds the page byte limit"
    }
    append raw [string range ${:buffer} ${:index} [expr {$end-1}]]
    incr :index $consumed
    incr :offset $consumed
    if {$newline>=0} {
        return [dict create start $start end ${:offset} raw $raw]
    }
}
error "incomplete result cache"
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: