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

Support binary result format #3316

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
10 changes: 6 additions & 4 deletions packages/pg-protocol/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,15 @@ export class Parser {
}

private parseDataRowMessage(offset: number, length: number, bytes: Buffer) {
this.reader.setBuffer(offset, bytes)
const fieldCount = this.reader.int16()
const reader = this.reader
reader.setBuffer(offset, bytes)
const fieldCount = reader.int16()
const fields: any[] = new Array(fieldCount)
const textMode = this.mode === 'text'
for (let i = 0; i < fieldCount; i++) {
const len = this.reader.int32()
const len = reader.int32()
// a -1 for length means the value of the field is null
fields[i] = len === -1 ? null : this.reader.string(len)
fields[i] = len === -1 ? null : textMode ? reader.string(len) : reader.bytes(len)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use the field’s mode?

The constructor also still has

if (opts?.mode === 'binary') {
  throw new Error('Binary mode not supported yet')
}

}
return new DataRowMessage(length, fields)
}
Expand Down
10 changes: 9 additions & 1 deletion packages/pg-protocol/src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,15 @@ const bind = (config: BindOpts = {}): Buffer => {
writer.add(paramWriter.flush())

// format code
writer.addInt16(binary ? ParamType.BINARY : ParamType.STRING)
if (binary) {
const columnFormatCount = 1
writer.addInt16(columnFormatCount)
writer.addInt16(ParamType.BINARY)
} else {
const columnFormatCount = 0
writer.addInt16(columnFormatCount)
}

return writer.flush(code.bind)
}

Expand Down