2
0
mirror of synced 2025-02-22 06:28:04 +00:00

bind: fix interface methods' multiple return values handling.

Fixes golang/go#12403

Change-Id: I9b8e6d69beb1ceb27e991348212acb5054497e47
Reviewed-on: https://go-review.googlesource.com/14077
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Hyang-Ah (Hana) Kim 2015-08-31 01:06:30 -04:00 committed by Hyang-Ah Hana Kim
parent 0c8c4ad3bc
commit 671f57b233
15 changed files with 490 additions and 43 deletions

View File

@ -30,6 +30,7 @@ var tests = []string{
"testdata/interfaces.go",
"testdata/issue10788.go",
"testdata/issue12328.go",
"testdata/issue12403.go",
"testdata/try.go",
}

View File

@ -597,7 +597,7 @@ func (g *objcGen) genInterfaceMethodProxy(obj *types.TypeName, s *funcSummary) {
if s.returnsVal() { // len(s.retParams) == 1 && s.retParams[0] != error
p := s.retParams[0]
if stype := g.seqType(p.typ); stype == "Ref" {
g.Printf("if [(id<NSObject>)(returnVal) isKindOfClass:[%s class]]) {\n", g.refTypeBase(p.typ))
g.Printf("if ([(id<NSObject>)(returnVal) isKindOfClass:[%s class]]) {\n", g.refTypeBase(p.typ))
g.Indent()
g.Printf("id<goSeqRefInterface>retVal_proxy = (id<goSeqRefInterface>)(returnVal);\n")
g.Printf("go_seq_writeRef(out, retVal_proxy.ref);\n")
@ -633,9 +633,9 @@ func (g *objcGen) genInterfaceMethodProxy(obj *types.TypeName, s *funcSummary) {
g.Printf("go_seq_writeUTF8(out, %sDesc);\n", p.name)
g.Outdent()
g.Printf("}\n")
} else if seqTyp := g.seqType(p.typ); seqTyp != "Ref" {
} else if seqTyp := g.seqType(p.typ); seqTyp == "Ref" {
// TODO(hyangah): NULL.
g.Printf("if [(id<NSObject>)(%s) isKindOfClass:[%s class]]) {\n", p.name, g.refTypeBase(p.typ))
g.Printf("if ([(id<NSObject>)(%s) isKindOfClass:[%s class]]) {\n", p.name, g.refTypeBase(p.typ))
g.Indent()
g.Printf("id<goSeqRefInterface>%[1]s_proxy = (id<goSeqRefInterface>)(%[1]s);\n", p.name)
g.Printf("go_seq_writeRef(out, %s_proxy.ref);\n", p.name)
@ -735,6 +735,7 @@ func (g *objcGen) refTypeBase(typ types.Type) string {
}
// fallback to whatever objcType returns. This must not happen.
panic(fmt.Sprintf("wtf: %+T", typ))
return g.objcType(typ)
}

View File

@ -107,6 +107,18 @@ static int numI = 0;
}
@synthesize value;
- (BOOL)StringError:(NSString *)s
ret0_:(NSString **)ret0_
error:(NSError **)error {
if ([s isEqualTo:@"number"]) {
if (ret0_ != NULL) {
*ret0_ = @"OK";
}
return true;
}
return false;
}
- (BOOL)Error:(BOOL)triggerError error:(NSError **)error {
if (!triggerError) {
return YES;
@ -120,6 +132,7 @@ static int numI = 0;
- (int64_t)Times:(int32_t)v {
return v * value;
}
- (void)dealloc {
if (self.value == 0) {
numI++;
@ -179,6 +192,28 @@ void testIssue12307() {
}
}
void testIssue12403() {
Number *num = [[Number alloc] init];
num.value = 1024;
NSString *ret;
NSError *error;
if (GoTestpkgCallIStringError(num, @"alphabet", &ret, &error) == YES) {
ERROR(
@"GoTestpkgCallIStringError(Number, 'alphabet') succeeded; want error");
}
NSError *error2;
if (GoTestpkgCallIStringError(num, @"number", &ret, &error2) == NO) {
ERROR(
@"GoTestpkgCallIStringError(Number, 'number') failed(%@); want success",
error2);
} else if (![ret isEqualTo:@"OK"]) {
ERROR(@"GoTestpkgCallIStringError(Number, 'number') returned unexpected "
@"results %@",
ret);
}
}
// Invokes functions and object methods defined in Testpkg.h.
//
// TODO(hyangah): apply testing framework (e.g. XCTestCase)

View File

@ -33,6 +33,24 @@ func proxy_CallIError(out, in *seq.Buffer) {
}
}
func proxy_CallIStringError(out, in *seq.Buffer) {
var param_i testpkg.I
param_i_ref := in.ReadRef()
if param_i_ref.Num < 0 { // go object
param_i = param_i_ref.Get().(testpkg.I)
} else { // foreign object
param_i = (*proxyI)(param_i_ref)
}
param_s := in.ReadString()
res, err := testpkg.CallIStringError(param_i, param_s)
out.WriteString(res)
if err == nil {
out.WriteString("")
} else {
out.WriteString(err.Error())
}
}
func proxy_CallSSum(out, in *seq.Buffer) {
// Must be a Go object
param_s_ref := in.ReadRef()
@ -63,9 +81,10 @@ func proxy_Hi(out, in *seq.Buffer) {
}
const (
proxyI_Descriptor = "go.testpkg.I"
proxyI_Error_Code = 0x10a
proxyI_Times_Code = 0x20a
proxyI_Descriptor = "go.testpkg.I"
proxyI_Error_Code = 0x10a
proxyI_StringError_Code = 0x20a
proxyI_Times_Code = 0x30a
)
func proxyI_Error(out, in *seq.Buffer) {
@ -80,6 +99,19 @@ func proxyI_Error(out, in *seq.Buffer) {
}
}
func proxyI_StringError(out, in *seq.Buffer) {
ref := in.ReadRef()
v := ref.Get().(testpkg.I)
param_s := in.ReadString()
res, err := v.StringError(param_s)
out.WriteString(res)
if err == nil {
out.WriteString("")
} else {
out.WriteString(err.Error())
}
}
func proxyI_Times(out, in *seq.Buffer) {
ref := in.ReadRef()
v := ref.Get().(testpkg.I)
@ -90,6 +122,7 @@ func proxyI_Times(out, in *seq.Buffer) {
func init() {
seq.Register(proxyI_Descriptor, proxyI_Error_Code, proxyI_Error)
seq.Register(proxyI_Descriptor, proxyI_StringError_Code, proxyI_StringError)
seq.Register(proxyI_Descriptor, proxyI_Times_Code, proxyI_Times)
}
@ -103,6 +136,15 @@ func (p *proxyI) Error(triggerError bool) error {
return res_0
}
func (p *proxyI) StringError(s string) (string, error) {
in := new(seq.Buffer)
in.WriteString(s)
out := seq.Transact((*seq.Ref)(p), "go.testpkg.I", proxyI_StringError_Code, in)
res_0 := out.ReadString()
res_1 := out.ReadError()
return res_0, res_1
}
func (p *proxyI) Times(v int32) int64 {
in := new(seq.Buffer)
in.WriteInt32(v)
@ -285,18 +327,19 @@ func proxy_UnregisterI(out, in *seq.Buffer) {
func init() {
seq.Register("testpkg", 1, proxy_BytesAppend)
seq.Register("testpkg", 2, proxy_CallIError)
seq.Register("testpkg", 3, proxy_CallSSum)
seq.Register("testpkg", 4, proxy_CollectS)
seq.Register("testpkg", 5, proxy_GC)
seq.Register("testpkg", 6, proxy_Hello)
seq.Register("testpkg", 7, proxy_Hi)
seq.Register("testpkg", 8, proxy_Int)
seq.Register("testpkg", 9, proxy_Multiply)
seq.Register("testpkg", 10, proxy_NewI)
seq.Register("testpkg", 11, proxy_NewNode)
seq.Register("testpkg", 12, proxy_NewS)
seq.Register("testpkg", 13, proxy_RegisterI)
seq.Register("testpkg", 14, proxy_ReturnsError)
seq.Register("testpkg", 15, proxy_Sum)
seq.Register("testpkg", 16, proxy_UnregisterI)
seq.Register("testpkg", 3, proxy_CallIStringError)
seq.Register("testpkg", 4, proxy_CallSSum)
seq.Register("testpkg", 5, proxy_CollectS)
seq.Register("testpkg", 6, proxy_GC)
seq.Register("testpkg", 7, proxy_Hello)
seq.Register("testpkg", 8, proxy_Hi)
seq.Register("testpkg", 9, proxy_Int)
seq.Register("testpkg", 10, proxy_Multiply)
seq.Register("testpkg", 11, proxy_NewI)
seq.Register("testpkg", 12, proxy_NewNode)
seq.Register("testpkg", 13, proxy_NewS)
seq.Register("testpkg", 14, proxy_RegisterI)
seq.Register("testpkg", 15, proxy_ReturnsError)
seq.Register("testpkg", 16, proxy_Sum)
seq.Register("testpkg", 17, proxy_UnregisterI)
}

View File

@ -14,6 +14,7 @@
@protocol GoTestpkgI
- (BOOL)Error:(BOOL)triggerError error:(NSError**)error;
- (BOOL)StringError:(NSString*)s ret0_:(NSString**)ret0_ error:(NSError**)error;
- (int64_t)Times:(int32_t)v;
@end
@ -45,6 +46,8 @@ FOUNDATION_EXPORT NSData* GoTestpkgBytesAppend(NSData* a, NSData* b);
FOUNDATION_EXPORT BOOL GoTestpkgCallIError(id<GoTestpkgI> i, BOOL triggerError, NSError** error);
FOUNDATION_EXPORT BOOL GoTestpkgCallIStringError(id<GoTestpkgI> i, NSString* s, NSString** ret0_, NSError** error);
FOUNDATION_EXPORT double GoTestpkgCallSSum(GoTestpkgS* s);
FOUNDATION_EXPORT int GoTestpkgCollectS(int want, int timeoutSec);

View File

@ -17,24 +17,26 @@ static NSString* errDomain = @"go.golang.org/x/mobile/bind/objc/testpkg";
#define _CALL_BytesAppend_ 1
#define _CALL_CallIError_ 2
#define _CALL_CallSSum_ 3
#define _CALL_CollectS_ 4
#define _CALL_GC_ 5
#define _CALL_Hello_ 6
#define _CALL_Hi_ 7
#define _CALL_Int_ 8
#define _CALL_Multiply_ 9
#define _CALL_NewI_ 10
#define _CALL_NewNode_ 11
#define _CALL_NewS_ 12
#define _CALL_RegisterI_ 13
#define _CALL_ReturnsError_ 14
#define _CALL_Sum_ 15
#define _CALL_UnregisterI_ 16
#define _CALL_CallIStringError_ 3
#define _CALL_CallSSum_ 4
#define _CALL_CollectS_ 5
#define _CALL_GC_ 6
#define _CALL_Hello_ 7
#define _CALL_Hi_ 8
#define _CALL_Int_ 9
#define _CALL_Multiply_ 10
#define _CALL_NewI_ 11
#define _CALL_NewNode_ 12
#define _CALL_NewS_ 13
#define _CALL_RegisterI_ 14
#define _CALL_ReturnsError_ 15
#define _CALL_Sum_ 16
#define _CALL_UnregisterI_ 17
#define _GO_testpkg_I_DESCRIPTOR_ "go.testpkg.I"
#define _GO_testpkg_I_Error_ (0x10a)
#define _GO_testpkg_I_Times_ (0x20a)
#define _GO_testpkg_I_StringError_ (0x20a)
#define _GO_testpkg_I_Times_ (0x30a)
@interface GoTestpkgI : NSObject <GoTestpkgI> {
}
@ -42,6 +44,7 @@ static NSString* errDomain = @"go.golang.org/x/mobile/bind/objc/testpkg";
- (id)initWithRef:(id)ref;
- (BOOL)Error:(BOOL)triggerError error:(NSError**)error;
- (BOOL)StringError:(NSString*)s ret0_:(NSString**)ret0_ error:(NSError**)error;
- (int64_t)Times:(int32_t)v;
@end
@ -71,6 +74,27 @@ static NSString* errDomain = @"go.golang.org/x/mobile/bind/objc/testpkg";
return ([_error length] == 0);
}
- (BOOL)StringError:(NSString*)s ret0_:(NSString**)ret0_ error:(NSError**)error {
GoSeq in_ = {};
GoSeq out_ = {};
go_seq_writeRef(&in_, self.ref);
go_seq_writeUTF8(&in_, s);
go_seq_send(_GO_testpkg_I_DESCRIPTOR_, _GO_testpkg_I_StringError_, &in_, &out_);
NSString* ret0__val = go_seq_readUTF8(&out_);
if (ret0_ != NULL) {
*ret0_ = ret0__val;
}
NSString* _error = go_seq_readUTF8(&out_);
if ([_error length] != 0 && error != nil) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
go_seq_free(&in_);
go_seq_free(&out_);
return ([_error length] == 0);
}
- (int64_t)Times:(int32_t)v {
GoSeq in_ = {};
GoSeq out_ = {};
@ -102,6 +126,23 @@ static void proxyGoTestpkgI(id obj, int code, GoSeq* in, GoSeq* out) {
go_seq_writeUTF8(out, errorDesc);
}
} break;
case _GO_testpkg_I_StringError_: {
id<GoTestpkgI> o = (id<GoTestpkgI>)(obj);
NSString* s = go_seq_readUTF8(in);
NSString* ret0_;
NSError* error = NULL;
BOOL returnVal = [o StringError:s ret0_:&ret0_ error:&error];
go_seq_writeUTF8(out, ret0_);
if (returnVal) {
go_seq_writeUTF8(out, NULL);
} else {
NSString* errorDesc = [error localizedDescription];
if (errorDesc == NULL || errorDesc.length == 0) {
errorDesc = @"gobind: unknown error";
}
go_seq_writeUTF8(out, errorDesc);
}
} break;
case _GO_testpkg_I_Times_: {
id<GoTestpkgI> o = (id<GoTestpkgI>)(obj);
int32_t v = go_seq_readInt32(in);
@ -291,6 +332,32 @@ BOOL GoTestpkgCallIError(id<GoTestpkgI> i, BOOL triggerError, NSError** error) {
return ([_error length] == 0);
}
BOOL GoTestpkgCallIStringError(id<GoTestpkgI> i, NSString* s, NSString** ret0_, NSError** error) {
GoSeq in_ = {};
GoSeq out_ = {};
if ([(id<NSObject>)(i) isKindOfClass:[GoTestpkgI class]]) {
id<goSeqRefInterface> i_proxy = (id<goSeqRefInterface>)(i);
go_seq_writeRef(&in_, i_proxy.ref);
} else {
go_seq_writeObjcRef(&in_, i);
}
go_seq_writeUTF8(&in_, s);
go_seq_send(_DESCRIPTOR_, _CALL_CallIStringError_, &in_, &out_);
NSString* ret0__val = go_seq_readUTF8(&out_);
if (ret0_ != NULL) {
*ret0_ = ret0__val;
}
NSString* _error = go_seq_readUTF8(&out_);
if ([_error length] != 0 && error != nil) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
go_seq_free(&in_);
go_seq_free(&out_);
return ([_error length] == 0);
}
double GoTestpkgCallSSum(GoTestpkgS* s) {
GoSeq in_ = {};
GoSeq out_ = {};

View File

@ -17,6 +17,8 @@ import (
type I interface {
Times(v int32) int64
Error(triggerError bool) error
StringError(s string) (string, error)
}
type myI struct{}
@ -32,10 +34,18 @@ func (i *myI) Error(e bool) error {
return nil
}
func (i *myI) StringError(s string) (string, error) {
return s, nil
}
func CallIError(i I, triggerError bool) error {
return i.Error(triggerError)
}
func CallIStringError(i I, s string) (string, error) {
return i.StringError(s)
}
func NewI() I {
return &myI{}
}

View File

@ -146,8 +146,6 @@ func (p *proxyI3) F() interfaces.I1 {
res_0_ref := out.ReadRef()
if res_0_ref.Num < 0 { // go object
res_0 = res_0_ref.Get().(interfaces.I1)
} else { // foreign object
res_0 = (*proxyI1)(res_0_ref)
}
return res_0
}

View File

@ -8,6 +8,10 @@
#include <Foundation/Foundation.h>
@class GoInterfacesI1;
@class GoInterfacesI2;
@protocol GoInterfacesError
- (BOOL)Err:(NSError**)error;
@end
@ -35,7 +39,7 @@
@protocol GoInterfacesI3
- (id<GoInterfacesI1>)F;
- (GoInterfacesI1*)F;
@end
@protocol GoInterfacesWithParam

View File

@ -179,7 +179,7 @@ static void proxyGoInterfacesI(id obj, int code, GoSeq* in, GoSeq* out) {
@property(strong, readonly) id ref;
- (id)initWithRef:(id)ref;
- (id<GoInterfacesI1>)F;
- (GoInterfacesI1*)F;
@end
@implementation GoInterfacesI3 {
@ -191,13 +191,13 @@ static void proxyGoInterfacesI(id obj, int code, GoSeq* in, GoSeq* out) {
return self;
}
- (id<GoInterfacesI1>)F {
- (GoInterfacesI1*)F {
GoSeq in_ = {};
GoSeq out_ = {};
go_seq_writeRef(&in_, self.ref);
go_seq_send(_GO_interfaces_I3_DESCRIPTOR_, _GO_interfaces_I3_F_, &in_, &out_);
GoSeqRef* ret0__ref = go_seq_readRef(&out_);
id<GoInterfacesI1> ret0_ = ret0__ref.obj;
GoInterfacesI1* ret0_ = ret0__ref.obj;
if (ret0_ == NULL) {
ret0_ = [[GoInterfacesI1 alloc] initWithRef:ret0__ref];
}
@ -212,8 +212,8 @@ static void proxyGoInterfacesI3(id obj, int code, GoSeq* in, GoSeq* out) {
switch (code) {
case _GO_interfaces_I3_F_: {
id<GoInterfacesI3> o = (id<GoInterfacesI3>)(obj);
id<GoInterfacesI1> returnVal = [o F];
if [(id<NSObject>)(returnVal) isKindOfClass:[GoInterfacesI1 class]]) {
GoInterfacesI1* returnVal = [o F];
if ([(id<NSObject>)(returnVal) isKindOfClass:[GoInterfacesI1 class]]) {
id<goSeqRefInterface>retVal_proxy = (id<goSeqRefInterface>)(returnVal);
go_seq_writeRef(out, retVal_proxy.ref);
} else {

6
bind/testdata/issue12403.go vendored Normal file
View File

@ -0,0 +1,6 @@
package issue12403
type Parsable interface {
FromJSON(jstr string) string
ToJSON() (string, error)
}

59
bind/testdata/issue12403.go.golden vendored Normal file
View File

@ -0,0 +1,59 @@
// Package go_issue12403 is an autogenerated binder stub for package issue12403.
// gobind -lang=go issue12403
//
// File is generated by gobind. Do not edit.
package go_issue12403
import (
"golang.org/x/mobile/bind/seq"
"issue12403"
)
const (
proxyParsable_Descriptor = "go.issue12403.Parsable"
proxyParsable_FromJSON_Code = 0x10a
proxyParsable_ToJSON_Code = 0x20a
)
func proxyParsable_FromJSON(out, in *seq.Buffer) {
ref := in.ReadRef()
v := ref.Get().(issue12403.Parsable)
param_jstr := in.ReadString()
res := v.FromJSON(param_jstr)
out.WriteString(res)
}
func proxyParsable_ToJSON(out, in *seq.Buffer) {
ref := in.ReadRef()
v := ref.Get().(issue12403.Parsable)
res, err := v.ToJSON()
out.WriteString(res)
if err == nil {
out.WriteString("")
} else {
out.WriteString(err.Error())
}
}
func init() {
seq.Register(proxyParsable_Descriptor, proxyParsable_FromJSON_Code, proxyParsable_FromJSON)
seq.Register(proxyParsable_Descriptor, proxyParsable_ToJSON_Code, proxyParsable_ToJSON)
}
type proxyParsable seq.Ref
func (p *proxyParsable) FromJSON(jstr string) string {
in := new(seq.Buffer)
in.WriteString(jstr)
out := seq.Transact((*seq.Ref)(p), "go.issue12403.Parsable", proxyParsable_FromJSON_Code, in)
res_0 := out.ReadString()
return res_0
}
func (p *proxyParsable) ToJSON() (string, error) {
in := new(seq.Buffer)
out := seq.Transact((*seq.Ref)(p), "go.issue12403.Parsable", proxyParsable_ToJSON_Code, in)
res_0 := out.ReadString()
res_1 := out.ReadError()
return res_0, res_1
}

98
bind/testdata/issue12403.java.golden vendored Normal file
View File

@ -0,0 +1,98 @@
// Java class go.issue12403.Issue12403 is a proxy for talking to a Go program.
// gobind -lang=java issue12403
//
// File is generated by gobind. Do not edit.
package go.issue12403;
import go.Seq;
public abstract class Issue12403 {
private Issue12403() {} // uninstantiable
public interface Parsable extends go.Seq.Object {
public String FromJSON(String jstr);
public String ToJSON() throws Exception;
public static abstract class Stub implements Parsable {
static final String DESCRIPTOR = "go.issue12403.Parsable";
private final go.Seq.Ref ref;
public Stub() {
ref = go.Seq.createRef(this);
}
public go.Seq.Ref ref() { return ref; }
public void call(int code, go.Seq in, go.Seq out) {
switch (code) {
case Proxy.CALL_FromJSON: {
String param_jstr;
param_jstr = in.readString();
String result = this.FromJSON(param_jstr);
out.writeString(result);
return;
}
case Proxy.CALL_ToJSON: {
try {
String result = this.ToJSON();
out.writeString(result);
out.writeString(null);
} catch (Exception e) {
String result = null;
out.writeString(result);
out.writeString(e.getMessage());
}
return;
}
default:
throw new RuntimeException("unknown code: "+ code);
}
}
}
static final class Proxy implements Parsable {
static final String DESCRIPTOR = Stub.DESCRIPTOR;
private go.Seq.Ref ref;
Proxy(go.Seq.Ref ref) { this.ref = ref; }
public go.Seq.Ref ref() { return ref; }
public void call(int code, go.Seq in, go.Seq out) {
throw new RuntimeException("cycle: cannot call proxy");
}
public String FromJSON(String jstr) {
go.Seq _in = new go.Seq();
go.Seq _out = new go.Seq();
String _result;
_in.writeRef(ref);
_in.writeString(jstr);
Seq.send(DESCRIPTOR, CALL_FromJSON, _in, _out);
_result = _out.readString();
return _result;
}
public String ToJSON() throws Exception {
go.Seq _in = new go.Seq();
go.Seq _out = new go.Seq();
String _result;
_in.writeRef(ref);
Seq.send(DESCRIPTOR, CALL_ToJSON, _in, _out);
_result = _out.readString();
String _err = _out.readString();
if (_err != null) {
throw new Exception(_err);
}
return _result;
}
static final int CALL_FromJSON = 0x10a;
static final int CALL_ToJSON = 0x20a;
}
}
private static final String DESCRIPTOR = "issue12403";
}

16
bind/testdata/issue12403.objc.h.golden vendored Normal file
View File

@ -0,0 +1,16 @@
// Objective-C API for talking to issue12403 Go package.
// gobind -lang=objc issue12403
//
// File is generated by gobind. Do not edit.
#ifndef __GoIssue12403_H__
#define __GoIssue12403_H__
#include <Foundation/Foundation.h>
@protocol GoIssue12403Parsable
- (NSString*)FromJSON:(NSString*)jstr;
- (BOOL)ToJSON:(NSString**)ret0_ error:(NSError**)error;
@end
#endif

106
bind/testdata/issue12403.objc.m.golden vendored Normal file
View File

@ -0,0 +1,106 @@
// Objective-C API for talking to issue12403 Go package.
// gobind -lang=objc issue12403
//
// File is generated by gobind. Do not edit.
#include "GoIssue12403.h"
#include <Foundation/Foundation.h>
#include "seq.h"
static NSString* errDomain = @"go.issue12403";
@protocol goSeqRefInterface
-(GoSeqRef*) ref;
@end
#define _DESCRIPTOR_ "issue12403"
#define _GO_issue12403_Parsable_DESCRIPTOR_ "go.issue12403.Parsable"
#define _GO_issue12403_Parsable_FromJSON_ (0x10a)
#define _GO_issue12403_Parsable_ToJSON_ (0x20a)
@interface GoIssue12403Parsable : NSObject <GoIssue12403Parsable> {
}
@property(strong, readonly) id ref;
- (id)initWithRef:(id)ref;
- (NSString*)FromJSON:(NSString*)jstr;
- (BOOL)ToJSON:(NSString**)ret0_ error:(NSError**)error;
@end
@implementation GoIssue12403Parsable {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { _ref = ref; }
return self;
}
- (NSString*)FromJSON:(NSString*)jstr {
GoSeq in_ = {};
GoSeq out_ = {};
go_seq_writeRef(&in_, self.ref);
go_seq_writeUTF8(&in_, jstr);
go_seq_send(_GO_issue12403_Parsable_DESCRIPTOR_, _GO_issue12403_Parsable_FromJSON_, &in_, &out_);
NSString* ret0_ = go_seq_readUTF8(&out_);
go_seq_free(&in_);
go_seq_free(&out_);
return ret0_;
}
- (BOOL)ToJSON:(NSString**)ret0_ error:(NSError**)error {
GoSeq in_ = {};
GoSeq out_ = {};
go_seq_writeRef(&in_, self.ref);
go_seq_send(_GO_issue12403_Parsable_DESCRIPTOR_, _GO_issue12403_Parsable_ToJSON_, &in_, &out_);
NSString* ret0__val = go_seq_readUTF8(&out_);
if (ret0_ != NULL) {
*ret0_ = ret0__val;
}
NSString* _error = go_seq_readUTF8(&out_);
if ([_error length] != 0 && error != nil) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
go_seq_free(&in_);
go_seq_free(&out_);
return ([_error length] == 0);
}
@end
static void proxyGoIssue12403Parsable(id obj, int code, GoSeq* in, GoSeq* out) {
switch (code) {
case _GO_issue12403_Parsable_FromJSON_: {
id<GoIssue12403Parsable> o = (id<GoIssue12403Parsable>)(obj);
NSString* jstr = go_seq_readUTF8(in);
NSString* returnVal = [o FromJSON:jstr];
go_seq_writeUTF8(out, returnVal);
} break;
case _GO_issue12403_Parsable_ToJSON_: {
id<GoIssue12403Parsable> o = (id<GoIssue12403Parsable>)(obj);
NSString* ret0_;
NSError* error = NULL;
BOOL returnVal = [o ToJSON:&ret0_ error:&error];
go_seq_writeUTF8(out, ret0_);
if (returnVal) {
go_seq_writeUTF8(out, NULL);
} else {
NSString* errorDesc = [error localizedDescription];
if (errorDesc == NULL || errorDesc.length == 0) {
errorDesc = @"gobind: unknown error";
}
go_seq_writeUTF8(out, errorDesc);
}
} break;
default:
NSLog(@"unknown code %x for _GO_issue12403_Parsable_DESCRIPTOR_", code);
}
}
__attribute__((constructor)) static void init() {
go_seq_register_proxy("go.issue12403.Parsable", proxyGoIssue12403Parsable);
}