def decode.go

bend-kit-protobuf@0.2.0.0 · protobuf.bend:260

import bend-kit-protobuf@0.2.0.0/protobuf.bend as Protobuf
import Base

260# Explicit group stack keeps decoding linear and avoids mutually recursive parsers.
261def decode.go(fuel: Nat, state: DecodeState) -> Result<&2, &1, Error, List<&1, Field>>:
262  match fuel:
263    case 0n:
264      Fail{Limit{}}
265    case 1n+p:
266      DecodeState{empty, c, depth, stack, acc} = state
267      match empty:
268        case True{}:
269          match stack:
270            case Nil{}:
271              Done{List.reverse(&1, Field, acc)}
272            case Con{h, t}:
273              Fail{Incomplete{}}
274        case False{}:
275          do Result<&2, &1, Error, List<&1, Field>>:
276            next : DecodeState <- decode.step(c, depth, stack, acc)
277            decode.go(p, next)

Uses (10)

Used by (1)