66import java .nio .CharBuffer ;
77import java .io .UnsupportedEncodingException ;
88import com .sun .jna .ptr .IntByReference ;
9+ import com .sun .jna .ptr .LongByReference ;
10+ import java .math .BigInteger ;
911import com .fasterxml .jackson .databind .ObjectMapper ;
1012import com .fasterxml .jackson .core .JsonProcessingException ;
1113import java .util .ArrayList ;
@@ -26,6 +28,11 @@ public class LexFloatClient {
2628 */
2729 public static final int LF_FAIL = 1 ;
2830
31+ // Convert long to BigInteger to correctly handle unsigned 64-bit values
32+ private static BigInteger toUnsignedBigInteger (long value ) {
33+ return BigInteger .valueOf (value ).and (BigInteger .valueOf (0xFFFFFFFFFFFFFFFFL ));
34+ }
35+
2936 /**
3037 * Sets the product id of your application
3138 *
@@ -372,19 +379,20 @@ public static String GetFloatingClientMetadata(String key) throws LexFloatClient
372379 */
373380 public static HostLicenseMeterAttribute GetHostLicenseMeterAttribute (String name ) throws LexFloatClientException , UnsupportedEncodingException {
374381 int status ;
375- IntByReference allowedUses = new IntByReference (0 );
376- IntByReference totalUses = new IntByReference (0 );
377- IntByReference grossUses = new IntByReference (0 );
382+ LongByReference allowedUses = new LongByReference (0 );
383+ // These references can still hold the uint64_t values populated by the native function
384+ LongByReference totalUses = new LongByReference (0 );
385+ LongByReference grossUses = new LongByReference (0 );
378386
379387 if (Platform .isWindows ()) {
380388 status = LexFloatClientNative .GetHostLicenseMeterAttribute (new WString (name ), allowedUses , totalUses , grossUses );
381389 if (LF_OK == status ) {
382- return new HostLicenseMeterAttribute (name , allowedUses .getValue (), totalUses .getValue (), grossUses .getValue ());
390+ return new HostLicenseMeterAttribute (name , allowedUses .getValue (), toUnsignedBigInteger ( totalUses .getValue ()), toUnsignedBigInteger ( grossUses .getValue () ));
383391 }
384392 } else {
385393 status = LexFloatClientNative .GetHostLicenseMeterAttribute (name , allowedUses , totalUses , grossUses );
386394 if (LF_OK == status ) {
387- return new HostLicenseMeterAttribute (name , allowedUses .getValue (), totalUses .getValue (), grossUses .getValue ());
395+ return new HostLicenseMeterAttribute (name , allowedUses .getValue (), toUnsignedBigInteger ( totalUses .getValue ()), toUnsignedBigInteger ( grossUses .getValue () ));
388396 }
389397 }
390398 throw new LexFloatClientException (status );
0 commit comments