Tuesday, 4 April 2017

returning protobuf object as json

I have a node-js as part of test infrastructure that behaves like sort of a cache, we use it to make sure that requests are generated correctly, one type of the requests we send to it is protobuf requests, to verify the sent request we store it in a cache object, and then depending on the uri we retrieve it(use uri as a key).

var store = function(req,res) {
    obj['body'] = req.body;
    originalUrl = req.originalUrl;
    cache.record(originalUrl, obj);
}

router.get('/cache', function (req, res, next) {
    var key = req.query['originalUrl'];
    res.set('Content-Type', 'application/json');
    res.send(JSON.stringify(cache.get(key)));
});

for normal post/get requests this is working fine, but I'm having trouble getting the protobuf request in binary format, using debugging I can see its added to the cache but I can't figure out how to return it, best case would be to return the json presentation using the object and the template if a library for that already exists, if that is not possible return the bytes and the client can transform them to protobbuf



via Shadi

No comments:

Post a Comment