def utf8.push
bend-kit-protobuf@0.2.0.0 · protobuf.bend:769
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
769def utf8.push(width: U32, +c: U32, out: B.Bytes) -> Result<&2, &1, Error, B.Bytes>:
770 match width:
771 case 1:
772 byte(out, c, 2147483647)
773 case 2:
774 do Result<&2, &1, Error, B.Bytes>:
775 a : B.Bytes <- byte(out, (192 .|. (c >> 6n) : U32), 2147483647)
776 byte(a, utf8.cont_byte(c, 0n), 2147483647)
777 case 3:
778 do Result<&2, &1, Error, B.Bytes>:
779 a : B.Bytes <- byte(out, (224 .|. (c >> 12n) : U32), 2147483647)
780 b : B.Bytes <- byte(a, utf8.cont_byte(c, 6n), 2147483647)
781 byte(b, utf8.cont_byte(c, 0n), 2147483647)
782 case _:
783 do Result<&2, &1, Error, B.Bytes>:
784 a : B.Bytes <- byte(out, (240 .|. (c >> 18n) : U32), 2147483647)
785 b : B.Bytes <- byte(a, utf8.cont_byte(c, 12n), 2147483647)
786 d : B.Bytes <- byte(b, utf8.cont_byte(c, 6n), 2147483647)
787 byte(d, utf8.cont_byte(c, 0n), 2147483647)