Skip to content
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

Ensure binary buffers are correctly extracted in CommManager #6818

Merged
merged 5 commits into from
May 9, 2024
Merged
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
28 changes: 17 additions & 11 deletions panel/models/comm_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import {View} from "@bokehjs/core/view"
import {Model} from "@bokehjs/model"
import {Message} from "@bokehjs/protocol/message"
import {Receiver} from "@bokehjs/protocol/receiver"
import {Buffer} from "@bokehjs/core/serialization/buffer"
import type {Patch, DocumentChangedEvent} from "@bokehjs/document"
import {isArray, isPlainObject} from "@bokehjs/core/util/types"
import {values, size} from "@bokehjs/core/util/object"
import {keys} from "@bokehjs/core/util/object"

export const comm_settings: any = {
debounce: true,
Expand Down Expand Up @@ -103,21 +104,26 @@ export class CommManager extends Model {
}
}

protected _extract_buffers(value: unknown, buffers: ArrayBuffer[]): void {
protected _extract_buffers(value: unknown, buffers: ArrayBuffer[]): any {
if (isArray(value)) {
for (const val of value) {
this._extract_buffers(val, buffers)
}
} else if (value instanceof Map) {
for (const key of value.keys()) {
const v = value.get(key)
this._extract_buffers(v, buffers)
}
} else if (value instanceof Buffer) {
const {buffer} = value
const id = buffers.length
buffers.push(buffer)
return {id}
} else if (isPlainObject(value)) {
if (size(value) == 1 && value.buffer instanceof ArrayBuffer) {
const {buffer} = value
delete value.buffer
const id = buffers.length
value.id = id
buffers.push(buffer)
} else {
for (const val of values(value)) {
this._extract_buffers(val, buffers)
for (const key of keys(value)) {
const replaced = this._extract_buffers(value[key], buffers)
if (replaced != null) {
value[key] = replaced
}
}
}
Expand Down
Loading