Standard library · Databases
db/oxiwire
Imported as import "db/oxiwire" as oxiwire, its names are then oxiwire.…. Every signature below is the one the checker infers.
Functions
fn ow_encode(j: Json) -> Str
import "db/oxiwire" import "data/json" import "text/str" as str str.hex_encode(ow_encode(JNull)) # => 00 str.hex_encode(ow_encode(JBool(true))) # => 02 str.hex_encode(ow_encode(JStr("hi"))) # => 06020000006869 str.hex_encode(ow_encode(JArr(Cons(JInt(1), Nil)))) # => 0701000000030100000000000000
fn ow_decode(s: Str, i: Int) -> Parsed
Answers a Parsed — the JSON module's, so a frame that will not decode travels out the same way a document that will not parse does.
import "db/oxiwire" import "data/json" ow_decode(ow_encode(JArr(Cons(JStr("a"), Cons(JNum(1.5), Nil)))), 0) # => Parsed(JArr(Cons(JStr(a), Cons(JNum(1.5), Nil))), 20) ow_decode("not a frame", 0) # => Failed(unknown OxiWire tag 110, 0)
fn ow_send(fd: Int, value: Json) -> Int
# not run import "db/oxiwire" ow_send(fd, request) # one frame down the socket; the bytes written
fn ow_frame_out(fd: Int, body: Str) -> Int
A body as one frame: its length first, then the bytes — what a server answers with, the status byte in front of the value.
# not run import "db/oxiwire" ow_frame_out(conn, chr(219) + chr(0) + ow_encode(data)) # a reply that succeeded
fn ow_recv(fd: Int) -> Str
The reply arrives in whatever pieces the network chose, so read until the length at the front says the frame is whole.
# not run import "db/oxiwire" frame = ow_recv(fd) # one whole frame, however the network cut it
fn ow_call(fd: Int, request: Json) -> Result(Json, Str)
# not run import "db/oxiwire" import "data/json" reply = ow_call(fd, JObj(Cons(Field("cmd", JStr("ping")), Nil))) # Ok(the value), or Err(what the server said)
fn ow_reply(frame: Str) -> Result(Json, Str)
import "db/oxiwire" import "data/json" ow_reply(chr(219) + chr(0) + ow_encode(JStr("pong"))) # => Ok(JStr(pong)) ow_reply(chr(219) + chr(1) + ow_encode(JStr("no such collection"))) # => Err(no such collection) ow_reply("") # => Err(oxidb: the server said nothing)