module scheme fn (mut source CustomTranscodedInput) decode_available_positioned(value Value) !bool { mut port := value.input_pointer() if port.position < port.buffer.len || port.ended { return true } commit_custom_text_cursor(value) port.buffer = []u8{} port.position = 0 if source.decoded.len == 0 { source.decoded = []u8{len: int_max(4, int_min(4096, port.read_size))} } mut position := source.position if position.transmitting { // Writes retain no codec provenance. Seed it only when input resumes, // using the latest acknowledged boundary rather than the first packet. position.track.begin(position.history.raw_end, 0)! position.transmitting = false } mut base := position.history.raw_end held := source.cursor.decoder.count > 0 || source.cursor.pending_cr || source.cursor.has_queued // A consumed ignored suffix is not a visible boundary until EOF/error is // observed. A fresh, gap-free publication may begin at a different origin. if !held && base.same(position.track.frontier()) { base = CustomRawPoint{ ...position.raw_origin, offset: position.raw_origin.offset + source.raw.position } } position.history.reset(base) position.decoded_base = 0 mut produced := 0 for !source.finished && produced <= source.decoded.len - 4 { start := CustomRawPoint{ ...position.raw_origin, offset: position.raw_origin.offset + source.raw.position } position.track.begin(start, source.cursor.decoder.count)! copied := copy_transcoded_ascii(mut source.raw, &source.cursor, mut source.decoded, produced) if copied > 0 { end := position.track.observe(0, copied, 0) position.track.scalar_end = end if !position.history.raw_end.same(start) { position.history.append(1, CustomRawPoint{ ...start, offset: start.offset + 1 }) if copied > 1 { position.history.append(copied - 1, end) } } else { position.history.append(copied, end) } produced += copied continue } previous := source.cursor previous_track := position.track source.step_input = codec_input(unsafe { source.raw.buffer[source.raw.position..] }, source.raw.ended) step := position.track.next(mut source.cursor, mut source.step_input) or { if produced > 0 { source.cursor = previous position.track = previous_track source.step_input = CodecInput{} break } source.raw.position += source.step_input.position source.step_input = CodecInput{} header := position.track.take_header() if header.valid { position.history.commit(header) } position.history.commit(position.track.scalar_end) return err } source.raw.position += source.step_input.position source.step_input = CodecInput{} header := position.track.take_header() if header.valid { position.history.commit(header) } match step.kind { .scalar { width := step.scalar.length_in_bytes() position.history.append(width, position.track.scalar_end) produced += unsafe { utf32_decode_to_buffer(u32(step.scalar), mut &source.decoded[produced]) } } .need_input { break } .finished { source.finished = true } .malformed { return failure('unhandled transcoder decoding step') } } } port.ended = source.finished port.buffer = unsafe { source.decoded[..produced] } return produced > 0 || source.finished } fn (state &CustomPortOperation) attached_probe_positions() &CustomAttachedProbePositions { if !positioned_custom_attached(state.resource) || isnil(state.position_cursor) { return unsafe { nil } } return state.attached_operation().probe } fn (mut state CustomPortOperation) remember_custom_attached_probe(index int) ! { point := custom_attached_visible(state.target)! mut operation := state.attached_operation_state() if isnil(operation.probe) { operation.probe = &CustomAttachedProbePositions{} } operation.probe.points[index] = point } fn prepend_custom_attached_coordinates(resource &CustomPortResource, positions &CustomAttachedProbePositions, length int, remaining int) { if !positioned_custom_attached(resource) { return } if length + remaining > 4 { panic('invalid attached replay prefix') } mut position := resource.input_adapter.position mut prefix := [4]CustomRawPoint{} if !isnil(positions) { for i in 0 .. length { prefix[i] = positions.points[i] } } for i in 0 .. remaining { prefix[length + i] = position.prefix[i] } position.prefix = prefix position.prefix_len = length + remaining }