src/lsp/frame.bend checks
raw source on the hub · import bolt@1.52.0.0/src/lsp/frame.bend as Frame
lsp/frame: LSP's base protocol, purely: Content-Length: N\r\n\r\n and then
N bytes of UTF-8. Framing counts bytes and a read may end inside a char, so
the transport reads bytes, cuts on bytes, and only then decodes.
2 imports
import Base import ../rchars.bend as Rchars
Types
type Dec source · line 12 · raw
Data
the decoder's state: continuation bytes still owed, the code point so far, the chars so far (reversed)
Dec@need:Nat -> @acc:U32 -> @out:List<&2, Char> -> Dec
type Digit source · line 104 · raw
Data
a decimal digit
D0Digit
D1Digit
D2Digit
D3Digit
D4Digit
D5Digit
D6Digit
D7Digit
D8Digit
D9Digit
type Head source · line 289 · raw
Data
the header block's Content-Length and the bytes after it, once it is whole
NoHeadHead
Head@len:List<&2, Digit> -> @rest:List<&2, U32> -> Head
type Cut source · line 294 · raw
Data
the front of a buffer: a whole body and the bytes after it, or not yet
MoreCut
Whole@body:List<&2, U32> -> @rest:List<&2, U32> -> Cut
type Next source · line 368 · raw
Data
what to read next: a header line, or this many bytes of the body
LineNext
Bytes@count:U32 -> Next
Definitions
def decode.lead source · line 16 · raw
@hi:U32 -> @+bb:U32 -> @out:List<&2, Char> -> Dec
a lead byte, by its high nibble; a stray continuation byte stands for itself
def decode.more source · line 29 · raw
@left:Nat -> @+acc:U32 -> @out:List<&2, Char> -> Dec
def decode.step source · line 36 · raw
@+bb:U32 -> @st:Dec -> Dec
def decode.run source · line 44 · raw
@bs:List<&2, U32> -> @st:Dec -> Dec
def decode.end source · line 51 · raw
@st:Dec -> String
def decode source · line 56 · raw
@bs:List<&2, U32> -> String
UTF-8 bytes as a string (a bad byte is skipped)
def width source · line 63 · raw
@+xx:U32 -> U32
how many bytes a code point takes
def encode.char source · line 69 · raw
@ww:U32 -> @+xx:U32 -> @rest:List<&2, U32> -> List<&2, U32>
a code point's bytes, by its width, in front of the rest
def encode.one source · line 81 · raw
@+xx:U32 -> @rest:List<&2, U32> -> List<&2, U32>
def encode.go source · line 84 · raw
@cs:List<&2, Char> -> List<&2, U32>
def encode source · line 92 · raw
@ss:String -> List<&2, U32>
a string as UTF-8 bytes
def digit.code source · line 117 · raw
@dd:Digit -> U32
a digit's char code, '0' to '9'
def digit.read source · line 141 · raw
@xx:U32 -> Maybe<&2, Digit>
the digit a char code stands for, if it is one
def tick source · line 167 · raw
@ds:List<&2, Digit> -> List<&2, Digit>
a count one more (digits least significant first)
def tick.by source · line 193 · raw
@ww:U32 -> @ds:List<&2, Digit> -> List<&2, Digit>
a count plus a char's width in bytes
def byte_count source · line 205 · raw
@cs:List<&2, Char> -> @ds:List<&2, Digit> -> List<&2, Digit>
how many UTF-8 bytes the chars take, counted on from ds
def count.show source · line 213 · raw
@ds:List<&2, Digit> -> @acc:String -> String
a count's digits, most significant first, in front of acc
def count.zero source · line 221 · raw
@ds:List<&2, Digit> -> Bool
is the count zero?
def untick source · line 231 · raw
@ds:List<&2, Digit> -> List<&2, Digit>
a count one less (zero stays zero)
def count.push source · line 257 · raw
@md:Maybe<&2, Digit> -> @acc:Maybe<&2, List<&2, Digit>> -> Maybe<&2, List<&2, Digit>>
one more char's digit onto the count read so far; None once one is no digit
def count.read.go source · line 266 · raw
@ss:String -> @acc:Maybe<&2, List<&2, Digit>> -> Maybe<&2, List<&2, Digit>>
def count.read source · line 274 · raw
@ss:String -> Maybe<&2, List<&2, Digit>>
a string of digits as a count; None when it is empty or holds anything else
def wrap source · line 285 · raw
@+body:String -> String
a message on its way out
def chars source · line 299 · raw
@bs:List<&2, U32> -> @acc:List<&2, Char> -> List<&2, Char>
bytes as chars, one each (for the ASCII header)
def line_len source · line 307 · raw
@line:List<&2, U32> -> @+len:List<&2, Digit> -> List<&2, Digit>
a header line (reversed, its \r already dropped) updates the length
def header source · line 314 · raw
@bs:List<&2, U32> -> @line:List<&2, U32> -> @len:List<&2, Digit> -> Head
the header block read up to its blank line: Content-Length, and the bytes after; not whole yet when the blank line has not come
def split.on source · line 329 · raw
@zz:Bool -> @xs:List<&2, U32> -> @acc:List<&2, U32> -> @more:(@_:Unit -> Cut) -> Cut
the bytes taken so far and the rest once the count is down to zero, else what more gives
def split source · line 338 · raw
@xs:List<&2, U32> -> @+ds:List<&2, Digit> -> @+acc:List<&2, U32> -> Cut
the first ds bytes (reversed onto acc) and the rest, or not yet when there are fewer. The count goes down a digit at a time: never a Nat of its size
def cut.body source · line 345 · raw
@hh:Head -> Cut
def cut source · line 354 · raw
@buf:List<&2, U32> -> Cut
the front of a buffer: a whole message body and the bytes after it, or not yet
def lack source · line 374 · raw
@xs:List<&2, U32> -> @ds:List<&2, Digit> -> List<&2, Digit>
a count less one for each byte held (zero stays zero): what a body of that count still lacks
def digit.value source · line 382 · raw
@dd:Digit -> U32
a digit's value, 0 to 9
def held source · line 407 · raw
@+nn:U32 -> U32
a number held to 65536, the most one read asks for; what is past it is asked for by the next read
def count.held source · line 411 · raw
@ds:List<&2, Digit> -> U32
a count as a number, held to 65536 at every digit so it never wraps
def at_least_one source · line 420 · raw
@+nn:U32 -> U32
a number, or one when it is none: a read of no bytes answers none, which the transport takes for a peer that closed
def next.of source · line 423 · raw
@hh:Head -> Next
def next source · line 431 · raw
@buf:List<&2, U32> -> Next
what a buffer short of a whole message needs read next