Roger Meier | 5c819c0 | 2011-04-09 11:10:04 +0000 | [diff] [blame] | 1 | var thrift = require('thrift'), |
| 2 | ttransport = require('thrift/transport'); |
| 3 | |
| 4 | var UserStorage = require('./gen-nodejs/UserStorage'), |
| 5 | ttypes = require('./gen-nodejs/user_types'); |
| 6 | |
| 7 | var users = {}; |
| 8 | |
Roger Meier | eaa61d8 | 2012-01-12 21:38:29 +0000 | [diff] [blame^] | 9 | var store = function(user, result) { |
Roger Meier | 5c819c0 | 2011-04-09 11:10:04 +0000 | [diff] [blame] | 10 | console.log("stored:", user.uid); |
| 11 | users[user.uid] = user; |
Roger Meier | eaa61d8 | 2012-01-12 21:38:29 +0000 | [diff] [blame^] | 12 | result(null); |
Roger Meier | 5c819c0 | 2011-04-09 11:10:04 +0000 | [diff] [blame] | 13 | }; |
Roger Meier | eaa61d8 | 2012-01-12 21:38:29 +0000 | [diff] [blame^] | 14 | var retrieve = function(uid, result) { |
Roger Meier | 5c819c0 | 2011-04-09 11:10:04 +0000 | [diff] [blame] | 15 | console.log("retrieved:", uid); |
Roger Meier | eaa61d8 | 2012-01-12 21:38:29 +0000 | [diff] [blame^] | 16 | result(null, users[uid]); |
Roger Meier | 5c819c0 | 2011-04-09 11:10:04 +0000 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | var server_framed = thrift.createServer(UserStorage, { |
| 20 | store: store, |
| 21 | retrieve: retrieve |
| 22 | }); |
| 23 | server_framed.listen(9090); |
| 24 | var server_buffered = thrift.createServer(UserStorage, { |
| 25 | store: store, |
| 26 | retrieve: retrieve |
| 27 | }, {transport: ttransport.TBufferedTransport}); |
| 28 | server_buffered.listen(9091); |