Skip to content

Instantly share code, notes, and snippets.

@sshutovskyi
Created June 27, 2016 13:44
Show Gist options
  • Save sshutovskyi/977facca1156bd6af2c17a0a77e3020f to your computer and use it in GitHub Desktop.
Save sshutovskyi/977facca1156bd6af2c17a0a77e3020f to your computer and use it in GitHub Desktop.
pbf with varint64 as string support
Pbf = require 'pbf'
ByteBuffer = require 'bytebuffer'
Pbf.prototype.readVarint64 = ->
res = ByteBuffer.prototype.readVarint64.call(
buffer: this.buf,
noAssert: true,
offset: 0
, this.pos)
this.pos += res.length
res.value.toString()
Pbf.prototype.writeVarint64 = (val) ->
this.realloc(10)
this.pos += ByteBuffer.prototype.writeVarint64.call({
buffer: this.buf
noAssert: true
offset: 0
}, val, this.pos)
Pbf.prototype.writeVarint64Field = (tag, val) ->
this.writeTag(tag, Pbf.Varint)
this.writeVarint64(val)
module.exports = Pbf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment