Title: | Apache Thrift Client Server |
---|---|
Description: | Pure R implementation of Apache Thrift. This library doesn't require any code generation. To learn more about Thrift go to <https://thrift.apache.org>. |
Authors: | Marek Jagielski [aut, cre, cph], Lixin Yu [aut, cph] |
Maintainer: | Marek Jagielski <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.5 |
Built: | 2025-02-10 04:13:49 UTC |
Source: | https://github.com/systemincloud/thriftr |
Binary protocol: read value from binary buffer
binary_read_val(inbuf, ttype, spec = NA, decode_response = TRUE)
binary_read_val(inbuf, ttype, spec = NA, decode_response = TRUE)
inbuf |
binary buffor |
ttype |
type of value |
spec |
specification of value |
decode_response |
for string decode binary as chars |
value of type ttype
Binary protocol: write value to binary buffer
binary_write_val(outbuf, ttype, val, spec = NA)
binary_write_val(outbuf, ttype, val, spec = NA)
outbuf |
binary buffor |
ttype |
type of value |
val |
value to write |
spec |
specification of value |
String representation of raw array
hexlify(byte_array, delimeter = " ")
hexlify(byte_array, delimeter = " ")
byte_array |
raw array |
delimeter |
separation character |
string
Create client side thrift API
make_client(service, host = "localhost", port = 9090, proto_factory = TBinaryProtocolFactory$new(), trans_factory = TBufferedTransportFactory$new())
make_client(service, host = "localhost", port = 9090, proto_factory = TBinaryProtocolFactory$new(), trans_factory = TBufferedTransportFactory$new())
service |
parsed service |
host |
server host |
port |
server tcp port |
proto_factory |
factory that generates protocol implementation |
trans_factory |
factory that generates transport implementation |
## Not run: # File calc.thrift content: # service Calculator { # i32 add(1:i32 a, 2:i32 b); # i32 sub(1:i32 a, 2:i32 b); # i32 mult(1:i32 a, 2:i32 b); # i32 div(1:i32 a, 2:i32 b); # } # calc_thrift <- thriftr::t_load("calc.thrift", module_name="calc_thrift") cal <- thriftr::make_client( calc_thrift$Calculator, "127.0.0.1", 6000) a <- cal$mult(5, 2) b <- cal$sub(7, 3) c <- cal$sub(6, 4) d <- cal$mult(b, 10) e <- cal$add(a, d) f <- cal$div(e, c) print(f) ## End(Not run)
## Not run: # File calc.thrift content: # service Calculator { # i32 add(1:i32 a, 2:i32 b); # i32 sub(1:i32 a, 2:i32 b); # i32 mult(1:i32 a, 2:i32 b); # i32 div(1:i32 a, 2:i32 b); # } # calc_thrift <- thriftr::t_load("calc.thrift", module_name="calc_thrift") cal <- thriftr::make_client( calc_thrift$Calculator, "127.0.0.1", 6000) a <- cal$mult(5, 2) b <- cal$sub(7, 3) c <- cal$sub(6, 4) d <- cal$mult(b, 10) e <- cal$add(a, d) f <- cal$div(e, c) print(f) ## End(Not run)
Create server side thrift API
make_server(service, handler, host = "localhost", port = 9090, proto_factory = TBinaryProtocolFactory$new(), trans_factory = TBufferedTransportFactory$new())
make_server(service, handler, host = "localhost", port = 9090, proto_factory = TBinaryProtocolFactory$new(), trans_factory = TBufferedTransportFactory$new())
service |
parsed service |
handler |
R6 class implementing service |
host |
server host |
port |
port server tcp port |
proto_factory |
factory that generates protocol implementation |
trans_factory |
factory that generates transport implementation |
## Not run: # File calc.thrift content: # service Calculator { # i32 add(1:i32 a, 2:i32 b); # i32 sub(1:i32 a, 2:i32 b); # i32 mult(1:i32 a, 2:i32 b); # i32 div(1:i32 a, 2:i32 b); # } # calc_thrift <- thriftr::t_load("calc.thrift", module_name="calc_thrift") Dispatcher <- R6::R6Class("Dispatcher", public = list( add = function(a, b) { print(sprintf("add -> %s + %s", a, b)) return(a + b) }, sub = function(a, b) { print(sprintf("sub -> %s - %s", a, b)) return(a - b) }, mult = function(a, b) { print(sprintf("mult -> %s * %s", a, b)) return(a * b) }, div = function(a, b) { print(sprintf("div -> %s / %s", a, b)) return(a / b) } ) ) server <- thriftr::make_server( calc_thrift$Calculator, Dispatcher$new(), "127.0.0.1", 6000) print("serving...") server$serve() ## End(Not run)
## Not run: # File calc.thrift content: # service Calculator { # i32 add(1:i32 a, 2:i32 b); # i32 sub(1:i32 a, 2:i32 b); # i32 mult(1:i32 a, 2:i32 b); # i32 div(1:i32 a, 2:i32 b); # } # calc_thrift <- thriftr::t_load("calc.thrift", module_name="calc_thrift") Dispatcher <- R6::R6Class("Dispatcher", public = list( add = function(a, b) { print(sprintf("add -> %s + %s", a, b)) return(a + b) }, sub = function(a, b) { print(sprintf("sub -> %s - %s", a, b)) return(a - b) }, mult = function(a, b) { print(sprintf("mult -> %s * %s", a, b)) return(a * b) }, div = function(a, b) { print(sprintf("div -> %s / %s", a, b)) return(a / b) } ) ) server <- thriftr::make_server( calc_thrift$Calculator, Dispatcher$new(), "127.0.0.1", 6000) print("serving...") server$serve() ## End(Not run)
Parse a single thrift file to R6 class instance
parse(path, module_name = NA, include_dirs = NA, lexer = NA, parser = NA, enable_cache = TRUE)
parse(path, module_name = NA, include_dirs = NA, lexer = NA, parser = NA, enable_cache = TRUE)
path |
file path to parse, should be a string ending with '.thrift' |
module_name |
the name for parsed module, the default is the basename without extension of 'path' |
include_dirs |
directories to find thrift files while processing the ‘include' directive, by default: [’.'] |
lexer |
rly lexer to use, if not provided, 'parse' will use a new one |
parser |
rly parser to use, if not provided, 'parse' will use a new one |
enable_cache |
if this is set to be 'TRUE', parsed module will be cached, this is enabled by default. If 'module_name' is provided, use it as cache key, else use the 'path' |
Thrift module
String representation of specification
parse_spec(ttype, spec = NA)
parse_spec(ttype, spec = NA)
ttype |
type |
spec |
specification |
string representation
The module loaded and objects inside may only be pickled if module_name was provided.
t_load(path, module_name = NA, include_dirs = NA)
t_load(path, module_name = NA, include_dirs = NA)
path |
file path to parse, should be a string ending with '.thrift' |
module_name |
the name for parsed module, the default is the basename without extension of 'path' |
include_dirs |
directories to find thrift files while processing the ‘include' directive, by default: [’.'] |
Thrift R6 class instance
Binary implementation of the Thrift protocol driver.
TBinaryProtocol
TBinaryProtocol
An R6Class
generator object
TBinaryProtocolFactory generates TBinaryProtocol driver.
TBinaryProtocolFactory
TBinaryProtocolFactory
An R6Class
generator object
Class that wraps another transport and buffers its I/O.
TBufferedTransport
TBufferedTransport
An R6Class
generator object
TBufferedTransportFactory generates TBufferedTransport.
TBufferedTransportFactory
TBufferedTransportFactory
An R6Class
generator object
Wraps a raw array as a TTransport.
TMemoryBuffer
TMemoryBuffer
An R6Class
generator object
Help method for tests. It changes predefined structure to parsed thrift instead of parsing file.
to_proper_struct(thrift_spec_list, default_spec)
to_proper_struct(thrift_spec_list, default_spec)
thrift_spec_list |
raw array |
default_spec |
separation character |
R6 class
Socket implementation for server side.
TServerSocket
TServerSocket
An R6Class
generator object
Identificator of value type.
TType
TType
An object of class environment
of length 18.