Skip to content

feat(nodejs): protocol version option, binary protocol for doubles #49

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 17 commits into
base: main
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
447 changes: 447 additions & 0 deletions src/buffer/base.ts

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions src/buffer/bufferv1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @ts-check
import { SenderOptions } from "../options";
import { SenderBuffer } from "./index";
import { SenderBufferBase } from "./base";

/**
* Buffer implementation for protocol version 1.
* Sends floating point numbers in their text form.
*/
class SenderBufferV1 extends SenderBufferBase {
constructor(options: SenderOptions) {
super(options);
}

/**
* Write a float column with its value into the buffer using v1 serialization (text format).
*
* @param {string} name - Column name.
* @param {number} value - Column value, accepts only number values.
* @return {Sender} Returns with a reference to this sender.
*/
floatColumn(name: string, value: number): SenderBuffer {
this.writeColumn(
name,
value,
() => {
const valueStr = value.toString();
this.checkCapacity([valueStr]);
this.write(valueStr);
},
"number",
);
return this;
}
}

export { SenderBufferV1 };
41 changes: 41 additions & 0 deletions src/buffer/bufferv2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// @ts-check
import { SenderOptions } from "../options";
import { SenderBuffer } from "./index";
import { SenderBufferBase } from "./base";

const ENTITY_TYPE_DOUBLE: number = 16;
const EQUALS_SIGN: number = "=".charCodeAt(0);

/**
* Buffer implementation for protocol version 2.
* Sends floating point numbers in binary form.
*/
class SenderBufferV2 extends SenderBufferBase {
constructor(options: SenderOptions) {
super(options);
}

/**
* Write a float column with its value into the buffer using v2 serialization (binary format).
*
* @param {string} name - Column name.
* @param {number} value - Column value, accepts only number values.
* @return {Sender} Returns with a reference to this sender.
*/
floatColumn(name: string, value: number): SenderBuffer {
this.writeColumn(
name,
value,
() => {
this.checkCapacity([], 10);
this.writeByte(EQUALS_SIGN);
this.writeByte(ENTITY_TYPE_DOUBLE);
this.writeDouble(value);
},
"number",
);
return this;
}
}

export { SenderBufferV2 };
Loading