mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-12 22:42:23 +00:00
java: retrofit bindings for JNA generated from Cgo 1.10
Go 1.10 improved the way of passing strings between C and Go with https://go-review.googlesource.com/c/go/+/70890 This change adapts API/helpers to a new convention, without changing existing API surface and without benefiting from a new way of passing strings. Another, perferable on my readind of `go doc cgo`, but more invasive approach would be to change ALL enry C API to always return *C.char \w C.CString() Signed-off-by: Alexander Bezzubov <bzz@apache.org>
This commit is contained in:
parent
115a7bdc64
commit
5147de90b8
@ -35,6 +35,7 @@ pgpSecretRing := baseDirectory.value / "project" / ".gnupg" / "secring.gpg"
|
||||
pgpPublicRing := baseDirectory.value / "project" / ".gnupg" / "pubring.gpg"
|
||||
pgpPassphrase := Some(SONATYPE_PASSPHRASE.toArray)
|
||||
|
||||
libraryDependencies += "com.nativelibs4java" % "jnaerator-runtime" % "0.12"
|
||||
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test
|
||||
|
||||
unmanagedBase := baseDirectory.value / "lib"
|
||||
|
@ -3,13 +3,14 @@ package tech.sourced.enry;
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Pointer;
|
||||
import tech.sourced.enry.nativelib.GoSlice;
|
||||
import tech.sourced.enry.nativelib.GoString;
|
||||
import tech.sourced.enry.nativelib._GoString_;
|
||||
import com.ochafik.lang.jnaerator.runtime.NativeSize;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
class GoUtils {
|
||||
|
||||
static GoString.ByValue toGoString(String str) {
|
||||
static _GoString_.ByValue toGoString(String str) {
|
||||
byte[] bytes;
|
||||
try {
|
||||
bytes = str.getBytes("utf-8");
|
||||
@ -26,19 +27,19 @@ class GoUtils {
|
||||
ptr = ptrFromBytes(bytes);
|
||||
}
|
||||
|
||||
GoString.ByValue val = new GoString.ByValue();
|
||||
val.n = length;
|
||||
_GoString_.ByValue val = new _GoString_.ByValue();
|
||||
val.n = new NativeSize(length);
|
||||
val.p = ptr;
|
||||
return val;
|
||||
}
|
||||
|
||||
static String toJavaString(GoString str) {
|
||||
if (str.n == 0) {
|
||||
static String toJavaString(_GoString_ str) {
|
||||
if (str.n.intValue() == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[(int) str.n];
|
||||
str.p.read(0, bytes, 0, (int) str.n);
|
||||
byte[] bytes = new byte[(int) str.n.intValue()];
|
||||
str.p.read(0, bytes, 0, (int) str.n.intValue());
|
||||
try {
|
||||
return new String(bytes, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user