Closed amitguptagwl closed 6 years ago
Yeah, we don't currently support importing google protobuf extensions. Same as #92
As a workaround, you can inline Timestamp definition from Google:
Great thanks
@mourner One more question. For float field, If I input 987654321 I get 987654336 back. I know that is because of 'ieee754' encoding. But just want to ensure that if this problem persist with actual google library as well? (TBH I didn't tested that yet)
@mourner I've created gist extracted from google protobuf implementation. However it doesn't work for any number. So I'm not sure what's wrong I'm doing.
@amitguptagwl float
in protobuf corresponds to a 32-bit float. Single precision floats can only represent integers up to 16777216 accurately.
const assert = require('assert');
const num = 987654321;
const expected = 987654336;
const buf = Buffer.alloc(4);
buf.writeFloatLE(num);
const actual = buf.readFloatLE();
assert.strictEqual(actual, expected);
If you use a double precision float (64-bit, double
in protobuf), it can accurately represent that number.
Thanks @kjvalencik . I actually noticed that google protobuf implementation stops user to write data which is out of range or can't read same. Shouldn't we do the same?
I don't think so. Those bounds check could impact performance. Also, there are some intentional inaccuracies. For example, int64
and uint64
both use a JS Number
which can't represent the range.
Hmm
Here is the complete list supported by protobuf 3: https://developers.google.com/protocol-buffers/docs/proto3#json
I face an issue in compiling proto file with Timestamp field. So I was wondering if I'm using the wrong syntax or it is not supported.