Skip to content

Expose bitfields #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,14 @@ function defineHasRequest () {
if (!defined(obj.seq)) throw new Error("seq is required")
var len = encodings.varint.encodingLength(obj.seq)
length += 1 + len
if (defined(obj.bitfield)) {
var len = encodings.bool.encodingLength(obj.bitfield)
length += 1 + len
}
if (defined(obj.length)) {
var len = encodings.varint.encodingLength(obj.length)
length += 1 + len
}
return length
}

Expand All @@ -2102,6 +2110,16 @@ function defineHasRequest () {
buf[offset++] = 16
encodings.varint.encode(obj.seq, buf, offset)
offset += encodings.varint.encode.bytes
if (defined(obj.bitfield)) {
buf[offset++] = 24
encodings.bool.encode(obj.bitfield, buf, offset)
offset += encodings.bool.encode.bytes
}
if (defined(obj.length)) {
buf[offset++] = 32
encodings.varint.encode(obj.length, buf, offset)
offset += encodings.varint.encode.bytes
}
encode.bytes = offset - oldOffset
return buf
}
Expand All @@ -2113,7 +2131,9 @@ function defineHasRequest () {
var oldOffset = offset
var obj = {
id: 0,
seq: 0
seq: 0,
bitfield: false,
length: 0
}
var found0 = false
var found1 = false
Expand All @@ -2137,6 +2157,14 @@ function defineHasRequest () {
offset += encodings.varint.decode.bytes
found1 = true
break
case 3:
obj.bitfield = encodings.bool.decode(buf, offset)
offset += encodings.bool.decode.bytes
break
case 4:
obj.length = encodings.varint.decode(buf, offset)
offset += encodings.varint.decode.bytes
break
default:
offset = skip(prefix & 7, buf, offset)
}
Expand All @@ -2154,6 +2182,10 @@ function defineHasResponse () {
if (!defined(obj.has)) throw new Error("has is required")
var len = encodings.bool.encodingLength(obj.has)
length += 1 + len
if (defined(obj.bitfield)) {
var len = encodings.bytes.encodingLength(obj.bitfield)
length += 1 + len
}
return length
}

Expand All @@ -2165,6 +2197,11 @@ function defineHasResponse () {
buf[offset++] = 8
encodings.bool.encode(obj.has, buf, offset)
offset += encodings.bool.encode.bytes
if (defined(obj.bitfield)) {
buf[offset++] = 18
encodings.bytes.encode(obj.bitfield, buf, offset)
offset += encodings.bytes.encode.bytes
}
encode.bytes = offset - oldOffset
return buf
}
Expand All @@ -2175,7 +2212,8 @@ function defineHasResponse () {
if (!(end <= buf.length && offset <= buf.length)) throw new Error("Decoded message is not valid")
var oldOffset = offset
var obj = {
has: false
has: false,
bitfield: null
}
var found0 = false
while (true) {
Expand All @@ -2193,6 +2231,10 @@ function defineHasResponse () {
offset += encodings.bool.decode.bytes
found0 = true
break
case 2:
obj.bitfield = encodings.bytes.decode(buf, offset)
offset += encodings.bytes.decode.bytes
break
default:
offset = skip(prefix & 7, buf, offset)
}
Expand Down
3 changes: 3 additions & 0 deletions schema.proto
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ message SeekResponse {
message HasRequest {
required uint32 id = 1;
required uint64 seq = 2;
optional bool bitfield = 3;
optional uint64 length = 4;
}
message HasResponse {
required bool has = 1;
optional bytes bitfield = 2;
}

message CancelRequest {
Expand Down