Paste: read lsp message from stdin

Author: itmuckel
Mode: factor
Date: Sun, 21 Jun 2020 18:26:45
Plain Text |
: read-message ( -- message-as-string )
    readln
    "Content-Length: " "" replace
    parse-number ! <-- The Content-Length
    "{" read-until drop ! drop the '{', it will be prepended later.
    drop ! also drop the read string, it doesn't matter
    ! now the stream contains the actual message without '{'
    1 -
    CHAR: x <string> read-into drop
    >string
    ;

Annotation: oop

Author: ^alex
Mode: factor
Date: Sun, 21 Jun 2020 18:43:12
Plain Text |
IN: scratchpad : parse-message ( -- jsons )
  readln >lower
  "content-length:" ?head
  [ "bad content length" throw ] unless
  [ blank? ] trim
  parse-number
  read json> ;
IN: scratchpad parse-message
Content-length: 2
{}

--- Data stack:
H{ }

New Annotation

Summary:
Author:
Mode:
Body: