MCPcopy Create free account
hub / github.com/bajrangCoder/acodex_server / parse_message

Function parse_message

src/lsp.rs:570–584  ·  view source on GitHub ↗

Get JSON message from input using the Content-Length header.

(input: &[u8])

Source from the content-addressed store, hash-verified

568
569/// Get JSON message from input using the Content-Length header.
570fn parse_message(input: &[u8]) -> IResult<&[u8], &[u8]> {
571 let content_len = delimited(tag("Content-Length: "), digit1, crlf);
572
573 let utf8 = alt((tag("utf-8"), tag("utf8")));
574 let charset = tuple((char(';'), space0, tag("charset="), utf8));
575 let content_type = tuple((tag("Content-Type: "), is_not(";\r"), opt(charset), crlf));
576
577 let header = terminated(terminated(content_len, opt(content_type)), crlf);
578
579 let header = map_res(header, str::from_utf8);
580 let length = map_res(header, |s: &str| s.parse::<usize>());
581 let mut message = length_data(length);
582
583 message(input)
584}
585
586fn find_next_message(input: &[u8]) -> IResult<&[u8], usize> {
587 map(take_until("Content-Length"), |s: &[u8]| s.len())(input)

Callers 1

decodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected