Skip to content

Commit 6c09fe2

Browse files
committed
fix: handle uint64_t values
1 parent c43678d commit 6c09fe2

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/main/java/com/cryptlex/lexfloatclient/HostLicenseMeterAttribute.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.cryptlex.lexfloatclient;
2+
import java.math.BigInteger;
23

34
public class HostLicenseMeterAttribute {
45

@@ -15,14 +16,14 @@ public class HostLicenseMeterAttribute {
1516
/**
1617
* The total uses of the meter attribute.
1718
*/
18-
public long totalUses;
19+
public BigInteger totalUses;
1920

2021
/**
2122
* The gross uses of the meter attribute.
2223
*/
23-
public long grossUses;
24+
public BigInteger grossUses;
2425

25-
public HostLicenseMeterAttribute(String name, long allowedUses, long totalUses, long grossUses) {
26+
public HostLicenseMeterAttribute(String name, long allowedUses, BigInteger totalUses, BigInteger grossUses) {
2627
this.name = name;
2728
this.allowedUses = allowedUses;
2829
this.totalUses = totalUses;

src/main/java/com/cryptlex/lexfloatclient/LexFloatClient.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ public class LexFloatClient {
2626
*/
2727
public static final int LF_FAIL = 1;
2828

29-
private static long toUnsignedLong(long value) {
30-
return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL)).longValue();
29+
// Convert long to BigInteger to correctly handle unsigned 64-bit values
30+
private static BigInteger toUnsignedBigInteger(long value) {
31+
return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL));
3132
}
3233

3334
/**
@@ -264,18 +265,19 @@ public static String GetHostLicenseMetadata(String key) throws LexFloatClientExc
264265
public static HostLicenseMeterAttribute GetHostLicenseMeterAttribute(String name) throws LexFloatClientException, UnsupportedEncodingException {
265266
int status;
266267
LongByReference allowedUses = new LongByReference(0);
268+
// These references can still hold the uint64_t values populated by the native function
267269
LongByReference totalUses = new LongByReference(0);
268270
LongByReference grossUses = new LongByReference(0);
269271

270272
if (Platform.isWindows()) {
271273
status = LexFloatClientNative.GetHostLicenseMeterAttribute(new WString(name), allowedUses, totalUses, grossUses);
272274
if (LF_OK == status) {
273-
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedLong(totalUses.getValue()), toUnsignedLong(grossUses.getValue()));
275+
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), toUnsignedBigInteger(grossUses.getValue()));
274276
}
275277
} else {
276278
status = LexFloatClientNative.GetHostLicenseMeterAttribute(name, allowedUses, totalUses, grossUses);
277279
if (LF_OK == status) {
278-
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedLong(totalUses.getValue()), toUnsignedLong(grossUses.getValue()));
280+
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), toUnsignedBigInteger(grossUses.getValue()));
279281
}
280282
}
281283
throw new LexFloatClientException(status);

0 commit comments

Comments
 (0)