def varint.go

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

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

109# The last byte must fit its word; its continuation bit is never allowed.
110def varint.go(fuel: Nat, r: B.Cursor & Maybe<&2, VarintByte>, +i: U32, +last: U32, +max_last: U32, w: Word64) -> Result<&2, &1, Error, B.Cursor & Word64>:
111  match fuel:
112    case 0n:
113      Fail{Malformed{}}
114    case 1n+p:
115      (c, v) = r
116      match v:
117        case None{}:
118          Fail{Incomplete{}}
119        case Some{VarintByte{bad, done, b}}:
120          match bad:
121            case True{}:
122              Fail{Malformed{}}
123            case False{}:
124              match done:
125                case True{}:
126                  Done{(c, varint.add(i, (b .&. 127 : U32), w))}
127                case False{}:
128                  varint.go(p, varint.read((i + 1 : U32), last, max_last, c), (i + 1 : U32), last, max_last, varint.add(i, (b .&. 127 : U32), w))

Uses (15)

Used by (2)