~/bend-docscommunity

src/lsp/frame.bend checks

raw source on the hub · import bolt@1.30.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)

type Digit source · line 104 · raw

Data

a decimal digit

type Cut source · line 294 · raw

Data

the front of a buffer: a whole body and the bytes after it, or not yet

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 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