You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an array of integers, which also happens to contain some null values
I'm trying to use a writePackedVarint however it's converting my nulls into 0's
const Pbf = require('pbf')
const array = [0, null, 1, null, 2]
// Write the pbf
var pbf = new Pbf();
function writeData(data, pbf) {
pbf.writePackedVarint(3, data);
}
writeData(array, pbf)
var buffer = pbf.finish();
// Decode the pbf
var data = new Pbf(buffer).readFields(readData, {values: []});
function readData(tag, data, pbf) {
if (tag === 3) pbf.readPackedVarint(data.values);
}
// What my output looks like
console.log(data.values)
=> [0, 0, 1, 0, 2]
I'm not a protocol buffer guru by any stretch but is this expected behaviour? Is there an alternate way to handle null values?
The text was updated successfully, but these errors were encountered:
Hi Rowan, as far as I understand, there's no way to handle that with "packed" fields because they assume a batch of items of the same type (in this case varint). You'd have to either change the proto schema somehow to acommodate arrays of messages that contain different fields, or designate some special integer value (e.g. -1 or Number.MAX_SAFE_INTEGER) to treat as null on the app side.
I have an array of integers, which also happens to contain some
null
valuesI'm trying to use a
writePackedVarint
however it's converting my nulls into0
'sI'm not a protocol buffer guru by any stretch but is this expected behaviour? Is there an alternate way to handle
null
values?The text was updated successfully, but these errors were encountered: