Skip to content

Instantly share code, notes, and snippets.

@et4te
Created July 3, 2011 08:09
Show Gist options
  • Save et4te/1062055 to your computer and use it in GitHub Desktop.
Save et4te/1062055 to your computer and use it in GitHub Desktop.
example factor
USING: assocs byte-arrays.hex io io.binary io.encodings.binary
io.sockets kernel sequences ;
IN: riak
! ----------------------------------------------------------------------------
CONSTANT: rpb-ping-req HEX{ 00 00 00 01 01 }
: decode-ping-response ( -- n )
0 ;
CONSTANT: rpb-get-client-id-req HEX{ 00 00 00 01 03 }
CONSTANT: response-map H{
{ HEX{ 2 } [ decode-ping-response ] }
}
: lookup-response ( id -- val ? )
response-map at* ;
: decode-response ( resp -- val ? )
1 head lookup-response ;
: read-response ( -- val ? )
4 read be> read decode-response ;
: request ( req -- val ? )
"127.0.0.1" 8087 <inet> binary [
write flush read-response
] with-client ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment