Skip to content

uWebsockets publish dropping messages #501

Answered by hst-m
rpgehlot asked this question in Q&A
Discussion options

You must be logged in to vote

@rpgehlot Do you have fields using less than 1 byte of data? True/false only needs 1 bit, fields with 4 values need 2 bits, 8 values need 3 bits etc, but the minimum Buffer can write is 1 byte/8 bits, to save space on those you pack the byte with multiple fields, if your data has many small value fields it saves lots of space, I use this function to pack bytes:

const packBytes=(...bitsVals)=>bitsVals.reduce((byte,val,i)=>i%2?byte+val:byte<<val,0)>>>0

Tell it how many bits to use per field and the value of the field:

// example data
data={field1: true, field2: false, field3: 3, field4: 15} // fields use 1 bit, 1 bit, 2 bits, 4 bits

// packBytes(bits, value[, bits, value][, bits, value]..)…

Replies: 20 comments 28 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
16 replies
@uasan
Comment options

@kirbysayshi
Comment options

@hst-m
Comment options

@rpgehlot
Comment options

@hst-m
Comment options

Comment options

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

Comment options

You must be logged in to vote
4 replies
@rpgehlot
Comment options

@hst-m
Comment options

@hst-m
Comment options

@hst-m
Comment options

Answer selected by rpgehlot
Comment options

You must be logged in to vote
7 replies
@hst-m
Comment options

@arupadhy
Comment options

@hst-m
Comment options

@arupadhy
Comment options

@hst-m
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
6 participants
Converted from issue

This discussion was converted from issue #499 on April 08, 2021 15:56.