nlf / protobuf.js

A super rough, super simple, protocol buffer encoding library
24 stars 7 forks source link

Do not encode undefined fields #21

Closed oleksiyk closed 10 years ago

oleksiyk commented 10 years ago

There is probably no sense in wiring undefined fields in messages. Actually doing so breaks things up on Riak server:

error:data_error:[{zlib,call,3,[]},
 {zlib,inflate,2,[]},
 {zlib,unzip,1,[]},
 {riak_object,
 decode_vclock,2,
 [{file,
 "src/riak_object.erl"},
 {line,798}]},............

Of course you can avoid sending undefined keys in application but its really easier to fix the problem in protobuf.js

oleksiyk commented 10 years ago

Without this small patch you will have to write things like:

var putObj = {
        bucket: self.bucket,
        key: self.key,
        content: {
            value: data,
            content_type: 'binary/octet-stream'
        }
    }

    if(self.vclock){
        putObj.vclock = self.vclock;
    }

    return self.riak.put(putObj)

instead of

return self.riak.put({
        bucket: self.bucket,
        key: self.key,
        vclock: self.vclock, // vclock might be undefined
        content: {
            value: data,
            content_type: 'binary/octet-stream'
        }
})
nlf commented 10 years ago

good call, thanks