[add] base64 handling
This commit is contained in:
parent
04134c720b
commit
6d5323918b
3 changed files with 32 additions and 18 deletions
|
|
@ -5,7 +5,7 @@ It written for BaseX 12.0 and uses the [BaseX websocket](https://docs.basex.org/
|
|||
RFC 6455](https://www.rfc-editor.org/rfc/rfc6455.html)
|
||||
|
||||
# Demo
|
||||
The demos expect `Docker` or `Podman` on the local machine. This is only a requirement for the demos.
|
||||
The demo makes use of `Docker` or `Podman` for ease of setup. This is not a requirement to use the software.
|
||||
|
||||
1 Clone this repo
|
||||
2. Run `docker compose up -d` The LSP server shall now running on port 3000 (edit `compose.yaml` to change port)
|
||||
|
|
|
|||
|
|
@ -33,21 +33,6 @@ declare variable $rpc:Methods:=map:merge((
|
|||
$lsp-text:methods
|
||||
));
|
||||
|
||||
(:~ return map if $msg is jsonrpc else empty :)
|
||||
declare
|
||||
function rpc:parse($msg as xs:string)
|
||||
as map(*)?
|
||||
{
|
||||
try {
|
||||
let $json:=parse-json($msg)
|
||||
return if($json?jsonrpc eq "2.0" and exists($json?method))
|
||||
then $json
|
||||
else ()
|
||||
} catch *{
|
||||
()
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
(:~ send reply to $json message
|
||||
get functions for methods
|
||||
|
|
|
|||
|
|
@ -40,13 +40,14 @@ function lsp-ws:message(
|
|||
$message as xs:string
|
||||
) as empty-sequence() {
|
||||
|
||||
let $json := rpc:parse($message)
|
||||
let $json := lsp-ws:parse($message)
|
||||
return if(exists($json))
|
||||
then rpc:reply($json)
|
||||
else message($message,"bad RPC: ")
|
||||
};
|
||||
|
||||
|
||||
|
||||
(:~
|
||||
: Closes a WebSocket connection.
|
||||
:)
|
||||
|
|
@ -55,3 +56,31 @@ declare
|
|||
function lsp-ws:close() as empty-sequence() {
|
||||
rpc:admin-log("CLOSE","🥀")
|
||||
};
|
||||
|
||||
(:~ return map if $msg is jsonrpc else empty :)
|
||||
declare
|
||||
function lsp-ws:parse($msg as xs:string)
|
||||
as map(*)?
|
||||
{
|
||||
try {
|
||||
let $jtext:=if(starts-with($msg,"{"))
|
||||
then $msg
|
||||
else lsp-ws:decode($msg)
|
||||
|
||||
let $json:=parse-json($jtext)
|
||||
return if($json?jsonrpc eq "2.0" and exists($json?method))
|
||||
then $json
|
||||
else ()
|
||||
} catch *{
|
||||
()
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
(:~ decode
|
||||
"Q29udGVudC1MZW5ndGg6IDU4NDUNCg0K" -> "Content-Length: 5845"
|
||||
:)
|
||||
declare function lsp-ws:decode($basex64 as xs:string)
|
||||
as xs:string{
|
||||
xs:base64Binary($basex64) => bin:to-octets() => codepoints-to-string()
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue