~/bend-docscommunity

src/line.bend checks

raw source on the hub · import ezmcp@0.4.0.0/src/line.bend as Line

ezmcp/src/line: the stdio transport's decisions, with no IO (basic/transports#stdio). Bytes read from stdin are cut at each newline, each whole line is decoded from UTF-8 and is one message; a reply is its JSON text and one newline.

4 imports
import Base
import ezjson@1.2.0.0/main.bend as Json
import ezjson@1.2.0.0/src/value.bend as Value
import ./server.bend as Server

Types

type Cut source · line 11 · raw

Data

whole lines, each with its newline, and the bytes after the last newline

type Width source · line 99 · raw

Data

how many bytes a lead byte starts

Definitions

def nl source · line 15 · raw

@+byte:U32 -> Bool

a byte is a newline

def split.put source · line 19 · raw

@byte:U32 -> @ps:List<&2, List<&2, U32>> -> List<&2, List<&2, U32>>

put a byte at the front of the first piece

def split.at source · line 28 · raw

@byte:U32 -> @ps:List<&2, List<&2, U32>> -> @cut:Bool -> List<&2, List<&2, U32>>

a newline ends a piece of its own, which the bytes before it join; any other byte joins the first piece

def split source · line 41 · raw

@bs:List<&2, U32> -> List<&2, List<&2, U32>>

bytes split after every newline: each piece but the last ends with its newline, and the last has none

def cut.cons source · line 48 · raw

@piece:List<&2, U32> -> @cb:Cut -> Cut

def cut.go source · line 53 · raw

@rest:List<&2, List<&2, U32>> -> @piece:List<&2, U32> -> Cut

def cut.of source · line 60 · raw

@ps:List<&2, List<&2, U32>> -> Cut

def cut source · line 68 · raw

@bs:List<&2, U32> -> Cut

the whole lines in a buffer, and what follows the last newline

def cont source · line 74 · raw

@+byte:U32 -> Bool

a byte is a continuation byte, 0x80 to 0xBF

def bad source · line 78 · raw

Char

U+FFFD, for a byte that starts no valid sequence

def low6 source · line 82 · raw

@+byte:U32 -> U32

a continuation byte's six payload bits

def two source · line 86 · raw

@+lead:U32 -> @+byte:U32 -> U32

the code point of a two-byte sequence

def three source · line 90 · raw

@+lead:U32 -> @+byte:U32 -> @+cb:U32 -> U32

the code point of a three-byte sequence

def four source · line 94 · raw

@+lead:U32 -> @+byte:U32 -> @+cb:U32 -> @+db:U32 -> U32

the code point of a four-byte sequence

def width source · line 107 · raw

@+byte:U32 -> Width

1 for ASCII, 2 to 4 for a lead byte, 0 for a byte that starts nothing

def dec.take source · line 117 · raw

@ch:Char -> @ok:Bool -> @after_lead:List<&2, U32> -> @after_seq:List<&2, U32> -> @go:(@_:List<&2, U32> -> String) -> String

a sequence whose continuation bytes are all valid is its char, and the decoding goes on after it; else the lead byte is U+FFFD and the decoding goes on at the byte after it

def dec.two source · line 130 · raw

@+lead:U32 -> @bs:List<&2, U32> -> @go:(@_:List<&2, U32> -> String) -> String

def dec.three source · line 137 · raw

@+lead:U32 -> @bs:List<&2, U32> -> @go:(@_:List<&2, U32> -> String) -> String

def dec.four source · line 149 · raw

@+lead:U32 -> @bs:List<&2, U32> -> @go:(@_:List<&2, U32> -> String) -> String

def dec.lead source · line 158 · raw

@+byte:U32 -> @tail:List<&2, U32> -> @wid:Width -> @go:(@_:List<&2, U32> -> String) -> String

one sequence at a lead byte of width w, then go on what follows

def decode.step source · line 176 · raw

@bs:List<&2, U32> -> @go:(@_:List<&2, U32> -> String) -> String

def decode.go source · line 185 · raw

@fuel:Nat -> @bs:List<&2, U32> -> String

decode with fuel: every step takes at least one byte, so a buffer's length is fuel enough

def decode source · line 193 · raw

@+bs:List<&2, U32> -> String

bytes decoded from UTF-8; a byte that starts no valid sequence is U+FFFD

def line.of source · line 198 · raw

@srv:0x391cc0066bd18b3b1fbf0005e4f14c71/src/server.Server -> @+rev:String -> @+text:String -> @blank:Bool -> 0x391cc0066bd18b3b1fbf0005e4f14c71/src/server.Turn

def line.text source · line 210 · raw

@srv:0x391cc0066bd18b3b1fbf0005e4f14c71/src/server.Server -> @+rev:String -> @+text:String -> 0x391cc0066bd18b3b1fbf0005e4f14c71/src/server.Turn

def line source · line 216 · raw

@srv:0x391cc0066bd18b3b1fbf0005e4f14c71/src/server.Server -> @rev:String -> @bs:List<&2, U32> -> 0x391cc0066bd18b3b1fbf0005e4f14c71/src/server.Turn

what a server does with one line read by revision rev, and the revision the next line is read by: nothing for a blank one, and the revision unchanged; else the server's turn on its text

def frame source · line 220 · raw

@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> String

one message on stdout: its JSON text and a newline