Skip to content
Discussion options

You must be logged in to vote

Packing binary data was discussed here #501 (comment) with example using avsc as part of benchmark. Ideally do custom binary encode but if you need something to help you can do avscSchema=avsc.Type.forValue(data) and buffer=avscSchema.toBuffer(data) ws.send(buffer,true)

// encode data benchmark
const data={field1:true,field2:false,field3:3,field4:15}

const msgpack=require('@msgpack/msgpack')
const avscSchema=require('avsc').Type.forValue(data)
const packBytes=(...bitsVals)=>bitsVals.reduce((byte,val,i)=>i%2?byte+val:byte<<val,0)>>>0

const encodeFns={
   packBytes:data=>{
      const buf=Buffer.allocUnsafe(1)
      buf.writeUInt8(packBytes(1,data.field1,1,data.field2,2,data.field3,4,data.f…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Wyzix33
Comment options

@Wyzix33
Comment options

Answer selected by Wyzix33
Comment options

You must be logged in to vote
1 reply
@e3dio
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants