Skip to content

Commit 9a94fe9

Browse files
committed
addString32 to writer
1 parent 3c10abc commit 9a94fe9

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/pg-protocol/src/buffer-writer.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ export class Writer {
5858
return this
5959
}
6060

61+
public addString32(string: string = ''): Writer {
62+
let len = Buffer.byteLength(string)
63+
this.ensure(len + 4)
64+
this.buffer[this.offset++] = (len >>> 24) & 0xff
65+
this.buffer[this.offset++] = (len >>> 16) & 0xff
66+
this.buffer[this.offset++] = (len >>> 8) & 0xff
67+
this.buffer[this.offset++] = (len >>> 0) & 0xff
68+
this.buffer.write(string, this.offset)
69+
this.offset += len
70+
return this
71+
}
72+
6173
public add(otherBuffer: Buffer): Writer {
6274
this.ensure(otherBuffer.length)
6375
otherBuffer.copy(this.buffer, this.offset)

packages/pg-protocol/src/serializer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const password = (password: string): Buffer => {
4848

4949
const sendSASLInitialResponseMessage = function (mechanism: string, initialResponse: string): Buffer {
5050
// 0x70 = 'p'
51-
writer.addCString(mechanism).addInt32(Buffer.byteLength(initialResponse)).addString(initialResponse)
51+
writer.addCString(mechanism).addString32(initialResponse)
5252

5353
return writer.flush(code.startup)
5454
}
@@ -137,8 +137,7 @@ const writeValues = function (values: any[], valueMapper?: ValueMapper): void {
137137
} else {
138138
// add the param type (string) to the writer
139139
writer.addInt16(ParamType.STRING)
140-
paramWriter.addInt32(Buffer.byteLength(mappedVal))
141-
paramWriter.addString(mappedVal)
140+
paramWriter.addString32(mappedVal)
142141
}
143142
}
144143
}

0 commit comments

Comments
 (0)