Skip to content
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
7 changes: 7 additions & 0 deletions src/lexfloatclient-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ export function arrayToString(array: Uint8Array): string {
return Buffer.from(array).toString('utf8').replace(/\0.*$/g, '');
}
}

export function getCArray(length: number): Uint8Array {
if (process.platform == 'win32') {
return new Uint8Array(length * 2);
}
return new Uint8Array(length);
}
28 changes: 14 additions & 14 deletions src/lexfloatclient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LexFloatClientException } from "./lexfloatclient-exception";
import { arrayToString, LexFloatClientNative } from "./lexfloatclient-native";
import { arrayToString, getCArray, LexFloatClientNative } from "./lexfloatclient-native";
import { LexFloatStatusCodes } from "./lexfloatstatus-codes";

/**
Expand Down Expand Up @@ -193,7 +193,7 @@ export class LexFloatClient {
* @throws {LexFloatClientException}
*/
static GetHostProductVersionName(): string {
const array = new Uint8Array(256);
const array = getCArray(256);
const status = LexFloatClientNative.GetHostProductVersionName(array, array.length);
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand All @@ -208,7 +208,7 @@ export class LexFloatClient {
* @throws {LexFloatClientException}
*/
static GetHostProductVersionDisplayName(): string {
const array = new Uint8Array(256);
const array = getCArray(256);
const status = LexFloatClientNative.GetHostProductVersionDisplayName(array, array.length);
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand All @@ -222,7 +222,7 @@ export class LexFloatClient {
* @throws {LexFloatClientException}
*/
static GetFloatingLicenseMode(): string {
const array = new Uint8Array(256);
const array = getCArray(256);
const status = LexFloatClientNative.GetFloatingLicenseMode(array, array.length);
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand All @@ -239,7 +239,7 @@ export class LexFloatClient {
*/
static GetHostProductVersionFeatureFlag(name: string): HostProductVersionFeatureFlag {
const enabled = new Uint32Array(1);
const array = new Uint8Array(256);
const array = getCArray(256);
const status = LexFloatClientNative.GetHostProductVersionFeatureFlag(name, enabled, array, array.length);
switch (status) {
case LexFloatStatusCodes.LF_OK:
Expand All @@ -255,7 +255,7 @@ export class LexFloatClient {
* @throws {LexFloatClientException}
*/
static GetHostLicenseEntitlementSetName(): string {
const array = new Uint8Array(256);
const array = getCArray(256);
const status = LexFloatClientNative.GetHostLicenseEntitlementSetName(array, array.length);
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand All @@ -269,7 +269,7 @@ export class LexFloatClient {
* @throws {LexFloatClientException}
*/
static GetHostLicenseEntitlementSetDisplayName(): string {
const array = new Uint8Array(256);
const array = getCArray(256);
const status = LexFloatClientNative.GetHostLicenseEntitlementSetDisplayName(array, array.length);
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand All @@ -283,7 +283,7 @@ export class LexFloatClient {
* @throws {LexFloatClientException}
*/
static GetHostFeatureEntitlements(): HostFeatureEntitlement[] {
const array = new Uint8Array(4096);
const array = getCArray(4096);
const status = LexFloatClientNative.GetHostFeatureEntitlements(array, array.length);
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand All @@ -298,7 +298,7 @@ export class LexFloatClient {
* @throws {LexFloatClientException}
*/
static GetHostFeatureEntitlement(featureName: string): HostFeatureEntitlement {
const array = new Uint8Array(1024);
const array = getCArray(1024);
const status = LexFloatClientNative.GetHostFeatureEntitlement(featureName, array, array.length);
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand All @@ -315,7 +315,7 @@ export class LexFloatClient {
* @throws {LexFloatClientException}
*/
static GetHostProductMetadata(key: string): string {
const array = new Uint8Array(4096);
const array = getCArray(4096);
const status = LexFloatClientNative.GetHostProductMetadata(key, array, array.length);
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand All @@ -332,7 +332,7 @@ export class LexFloatClient {
* @throws {LexFloatClientException}
*/
static GetHostLicenseMetadata(key: string): string {
const array = new Uint8Array(256);
const array = getCArray(256);
const status = LexFloatClientNative.GetHostLicenseMetadata(key, array, array.length);
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand Down Expand Up @@ -385,7 +385,7 @@ export class LexFloatClient {
* @throws {LexActivatorException}
*/
static GetHostConfig(): HostConfig | null {
const array = new Uint8Array(1024);
const array = getCArray(1024);
const status = LexFloatClientNative.GetHostConfig(array, array.length)
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand Down Expand Up @@ -429,7 +429,7 @@ export class LexFloatClient {
* @throws {LexFloatClientException}
*/
static GetFloatingClientMetadata(key: string): string {
const array = new Uint8Array(4096);
const array = getCArray(4096);
const status = LexFloatClientNative.GetFloatingClientMetadata(key, array, array.length);
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand All @@ -442,7 +442,7 @@ export class LexFloatClient {
* @throws {LexFloatClientException}
*/
static GetFloatingClientLibraryVersion(): string {
const array = new Uint8Array(256);
const array = getCArray(256);
const status = LexFloatClientNative.GetFloatingClientLibraryVersion(array, array.length);
if (status != LexFloatStatusCodes.LF_OK) {
throw new LexFloatClientException(status);
Expand Down
79 changes: 66 additions & 13 deletions src/native/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ STRING toEncodedString(Napi::String input)
#endif
}

size_t getCharCount(Napi::Env env, size_t byteLength)
{
#ifdef _WIN32
if (byteLength % sizeof(CHARTYPE) != 0) {
Napi::TypeError::New(env, "Invalid UTF-16 buffer length").ThrowAsJavaScriptException();
return 0;
}
return byteLength / sizeof(CHARTYPE);
#else
return byteLength;
#endif
}


void floatingLicenseCallback(uint32_t status)
{
auto it = LicenseCallbacks.find(HostProductId);
Expand Down Expand Up @@ -66,7 +80,10 @@ Napi::Value getHostConfig(const Napi::CallbackInfo &info)
return env.Null();
}
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements, as seen in other functions (e.g., lines 72-75, 77-80, 112-115). Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg0 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetHostConfigInternal(arg0, length));
}
Expand Down Expand Up @@ -197,7 +214,10 @@ Napi::Value getHostProductVersionName(const Napi::CallbackInfo &info)
return env.Null();
}
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg0 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetHostProductVersionName(arg0, length));
}
Expand All @@ -216,7 +236,10 @@ Napi::Value getHostProductVersionDisplayName(const Napi::CallbackInfo &info)
return env.Null();
}
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg0 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetHostProductVersionDisplayName(arg0, length));
}
Expand Down Expand Up @@ -248,7 +271,10 @@ Napi::Value getHostProductVersionFeatureFlag(const Napi::CallbackInfo &info) {
uint32_t *arg1 = reinterpret_cast<uint32_t *>(array1.ArrayBuffer().Data());
Napi::Uint8Array array2 = info[2].As<Napi::Uint8Array>();
CHARTYPE *arg2 = reinterpret_cast<CHARTYPE *>(array2.ArrayBuffer().Data());
size_t length = array2.ElementLength();
size_t length = getCharCount(env, array2.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
return Napi::Number::New(env, GetHostProductVersionFeatureFlag(arg0.c_str(), arg1, arg2, length));
}

Expand All @@ -266,7 +292,10 @@ Napi::Value getHostLicenseEntitlementSetName(const Napi::CallbackInfo &info)
return env.Null();
}
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg0 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetHostLicenseEntitlementSetName(arg0, length));
}
Expand All @@ -285,7 +314,10 @@ Napi::Value getHostLicenseEntitlementSetDisplayName(const Napi::CallbackInfo &in
return env.Null();
}
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg0 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetHostLicenseEntitlementSetDisplayName(arg0, length));
}
Expand All @@ -304,7 +336,10 @@ Napi::Value getHostFeatureEntitlements(const Napi::CallbackInfo &info)
return env.Null();
}
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg0 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetHostFeatureEntitlementsInternal(arg0, length));
}
Expand All @@ -329,7 +364,10 @@ Napi::Value getHostFeatureEntitlement(const Napi::CallbackInfo &info)
}
STRING arg0 = toEncodedString(info[0].As<Napi::String>());
Napi::Uint8Array array = info[1].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg1 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetHostFeatureEntitlementInternal(arg0.c_str(), arg1, length));
}
Expand All @@ -354,7 +392,10 @@ Napi::Value getHostProductMetadata(const Napi::CallbackInfo &info)
}
STRING arg0 = toEncodedString(info[0].As<Napi::String>());
Napi::Uint8Array array = info[1].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg1 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetHostProductMetadata(arg0.c_str(), arg1, length));
}
Expand All @@ -379,7 +420,10 @@ Napi::Value getHostLicenseMetadata(const Napi::CallbackInfo &info)
}
STRING arg0 = toEncodedString(info[0].As<Napi::String>());
Napi::Uint8Array array = info[1].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg1 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetHostLicenseMetadata(arg0.c_str(), arg1, length));
}
Expand Down Expand Up @@ -484,7 +528,10 @@ Napi::Value getFloatingClientMetadata(const Napi::CallbackInfo &info)
}
STRING arg0 = toEncodedString(info[0].As<Napi::String>());
Napi::Uint8Array array = info[1].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg1 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetFloatingClientMetadata(arg0.c_str(), arg1, length));
}
Expand All @@ -503,7 +550,10 @@ Napi::Value getFloatingClientLibraryVersion(const Napi::CallbackInfo &info)
return env.Null();
}
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg0 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetFloatingClientLibraryVersion(arg0, length));
}
Expand Down Expand Up @@ -540,7 +590,10 @@ Napi::Value getFloatingLicenseMode(const Napi::CallbackInfo &info)
return env.Null();
}
Napi::Uint8Array array = info[0].As<Napi::Uint8Array>();
size_t length = array.ElementLength();
size_t length = getCharCount(env, array.ByteLength());
if(env.IsExceptionPending()) {
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The opening brace style is inconsistent with the rest of the codebase. The established convention in this file is to place opening braces on a new line for if statements. Consider changing to match the existing style for consistency.

Copilot uses AI. Check for mistakes.
return env.Null();
}
CHARTYPE *arg0 = reinterpret_cast<CHARTYPE *>(array.ArrayBuffer().Data());
return Napi::Number::New(env, GetFloatingLicenseMode(arg0, length));
}
Expand Down