bind: replace {Read,Write}UTF16 with {Read,Write}String for string.

This is to enable more flexible encoding/decoding of Go string.
For Java, we use UTF16 to be compatible with java string.
For other languages, we will want other way to represent a string.

Change-Id: Iccd53e2eea18d37636c3c619d06cb473facef0cd
Reviewed-on: https://go-review.googlesource.com/8628
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Hyang-Ah (Hana) Kim
2015-04-09 12:44:56 +00:00
committed by Hyang-Ah Hana Kim
parent d886eeda27
commit 334412418f
11 changed files with 73 additions and 47 deletions
+2
View File
@@ -36,6 +36,7 @@ public class Seq {
public native float readFloat32();
public native double readFloat64();
public native String readUTF16();
public String readString() { return readUTF16(); }
public native byte[] readByteArray();
public native void writeInt8(byte v);
@@ -47,6 +48,7 @@ public class Seq {
public native void writeFloat32(float v);
public native void writeFloat64(double v);
public native void writeUTF16(String v);
public void writeString(String v) { writeUTF16(v); }
public native void writeByteArray(byte[] v);
public void writeRef(Ref ref) {
+11 -1
View File
@@ -86,7 +86,7 @@ func initSeq() {
}
func seqToBuf(bufptr **C.uint8_t, lenptr *C.size_t, buf *seq.Buffer) {
if false {
if debug {
fmt.Printf("seqToBuf tag 1, len(buf.Data)=%d, *lenptr=%d\n", len(buf.Data), *lenptr)
}
if len(buf.Data) == 0 {
@@ -166,6 +166,14 @@ func transact(ref *seq.Ref, code int, in *seq.Buffer) *seq.Buffer {
return out
}
func encodeString(out *seq.Buffer, v string) {
out.WriteUTF16(v)
}
func decodeString(in *seq.Buffer) string {
return in.ReadUTF16()
}
func init() {
seq.FinalizeRef = func(ref *seq.Ref) {
if ref.Num < 0 {
@@ -175,4 +183,6 @@ func init() {
}
seq.Transact = transact
seq.EncString = encodeString
seq.DecString = decodeString
}
+16 -16
View File
@@ -24,7 +24,7 @@ public abstract class Testpkg {
go.Seq _in = new go.Seq();
go.Seq _out = new go.Seq();
byte[] _result;
_in.writeUTF16(str);
_in.writeString(str);
_in.writeByteArray(someBytes);
Seq.send(DESCRIPTOR, CALL_AppendToString, _in, _out);
_result = _out.readByteArray();
@@ -47,7 +47,7 @@ public abstract class Testpkg {
go.Seq _out = new go.Seq();
_in.writeRef(i.ref());
Seq.send(DESCRIPTOR, CALL_CallE, _in, _out);
String _err = _out.readUTF16();
String _err = _out.readString();
if (_err != null) {
throw new Exception(_err);
}
@@ -97,7 +97,7 @@ public abstract class Testpkg {
_in.writeRef(i.ref());
Seq.send(DESCRIPTOR, CALL_CallVE, _in, _out);
_result = _out.readInt();
String _err = _out.readUTF16();
String _err = _out.readString();
if (_err != null) {
throw new Exception(_err);
}
@@ -107,9 +107,9 @@ public abstract class Testpkg {
public static void Err(String s) throws Exception {
go.Seq _in = new go.Seq();
go.Seq _out = new go.Seq();
_in.writeUTF16(s);
_in.writeString(s);
Seq.send(DESCRIPTOR, CALL_Err, _in, _out);
String _err = _out.readUTF16();
String _err = _out.readString();
if (_err != null) {
throw new Exception(_err);
}
@@ -151,9 +151,9 @@ public abstract class Testpkg {
case Proxy.CALL_E: {
try {
this.E();
out.writeUTF16(null);
out.writeString(null);
} catch (Exception e) {
out.writeUTF16(e.getMessage());
out.writeString(e.getMessage());
}
return;
}
@@ -173,7 +173,7 @@ public abstract class Testpkg {
}
case Proxy.CALL_String: {
String result = this.String();
out.writeUTF16(result);
out.writeString(result);
return;
}
case Proxy.CALL_V: {
@@ -185,11 +185,11 @@ public abstract class Testpkg {
try {
long result = this.VE();
out.writeInt(result);
out.writeUTF16(null);
out.writeString(null);
} catch (Exception e) {
long result = 0;
out.writeInt(result);
out.writeUTF16(e.getMessage());
out.writeString(e.getMessage());
}
return;
}
@@ -217,7 +217,7 @@ public abstract class Testpkg {
go.Seq _out = new go.Seq();
_in.writeRef(ref);
Seq.send(DESCRIPTOR, CALL_E, _in, _out);
String _err = _out.readUTF16();
String _err = _out.readString();
if (_err != null) {
throw new Exception(_err);
}
@@ -256,7 +256,7 @@ public abstract class Testpkg {
String _result;
_in.writeRef(ref);
Seq.send(DESCRIPTOR, CALL_String, _in, _out);
_result = _out.readUTF16();
_result = _out.readString();
return _result;
}
@@ -277,7 +277,7 @@ public abstract class Testpkg {
_in.writeRef(ref);
Seq.send(DESCRIPTOR, CALL_VE, _in, _out);
_result = _out.readInt();
String _err = _out.readUTF16();
String _err = _out.readString();
if (_err != null) {
throw new Exception(_err);
}
@@ -348,7 +348,7 @@ public abstract class Testpkg {
String _result;
_in.writeRef(ref);
Seq.send(DESCRIPTOR, CALL_String, _in, _out);
_result = _out.readUTF16();
_result = _out.readString();
return _result;
}
@@ -376,9 +376,9 @@ public abstract class Testpkg {
go.Seq _in = new go.Seq();
go.Seq _out = new go.Seq();
String _result;
_in.writeUTF16(s);
_in.writeString(s);
Seq.send(DESCRIPTOR, CALL_StrDup, _in, _out);
_result = _out.readUTF16();
_result = _out.readString();
return _result;
}
+17 -17
View File
@@ -17,7 +17,7 @@ func proxy_Add(out, in *seq.Buffer) {
}
func proxy_AppendToString(out, in *seq.Buffer) {
param_str := in.ReadUTF16()
param_str := in.ReadString()
param_someBytes := in.ReadByteArray()
res := testpkg.AppendToString(param_str, param_someBytes)
out.WriteByteArray(res)
@@ -40,9 +40,9 @@ func proxy_CallE(out, in *seq.Buffer) {
}
err := testpkg.CallE(param_i)
if err == nil {
out.WriteUTF16("")
out.WriteString("")
} else {
out.WriteUTF16(err.Error())
out.WriteString(err.Error())
}
}
@@ -104,19 +104,19 @@ func proxy_CallVE(out, in *seq.Buffer) {
res, err := testpkg.CallVE(param_i)
out.WriteInt(res)
if err == nil {
out.WriteUTF16("")
out.WriteString("")
} else {
out.WriteUTF16(err.Error())
out.WriteString(err.Error())
}
}
func proxy_Err(out, in *seq.Buffer) {
param_s := in.ReadUTF16()
param_s := in.ReadString()
err := testpkg.Err(param_s)
if err == nil {
out.WriteUTF16("")
out.WriteString("")
} else {
out.WriteUTF16(err.Error())
out.WriteString(err.Error())
}
}
@@ -140,9 +140,9 @@ func proxyIE(out, in *seq.Buffer) {
v := ref.Get().(testpkg.I)
err := v.E()
if err == nil {
out.WriteUTF16("")
out.WriteString("")
} else {
out.WriteUTF16(err.Error())
out.WriteString(err.Error())
}
}
@@ -170,7 +170,7 @@ func proxyIString(out, in *seq.Buffer) {
ref := in.ReadRef()
v := ref.Get().(testpkg.I)
res := v.String()
out.WriteUTF16(res)
out.WriteString(res)
}
func proxyIV(out, in *seq.Buffer) {
@@ -186,9 +186,9 @@ func proxyIVE(out, in *seq.Buffer) {
res, err := v.VE()
out.WriteInt(res)
if err == nil {
out.WriteUTF16("")
out.WriteString("")
} else {
out.WriteUTF16(err.Error())
out.WriteString(err.Error())
}
}
@@ -241,7 +241,7 @@ func (p *proxyI) S() *testpkg.S {
func (p *proxyI) String() string {
in := new(seq.Buffer)
out := seq.Transact((*seq.Ref)(p), proxyIStringCode, in)
res_0 := out.ReadUTF16()
res_0 := out.ReadString()
return res_0
}
@@ -299,7 +299,7 @@ func proxySString(out, in *seq.Buffer) {
ref := in.ReadRef()
v := ref.Get().(*testpkg.S)
res := v.String()
out.WriteUTF16(res)
out.WriteString(res)
}
func init() {
@@ -308,9 +308,9 @@ func init() {
}
func proxy_StrDup(out, in *seq.Buffer) {
param_s := in.ReadUTF16()
param_s := in.ReadString()
res := testpkg.StrDup(param_s)
out.WriteUTF16(res)
out.WriteString(res)
}
func init() {