2015-04-28 16:57:58 +00:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef __GO_SEQ_HDR__
|
|
|
|
#define __GO_SEQ_HDR__
|
|
|
|
|
2015-05-05 19:57:36 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
|
2015-06-02 13:36:44 +00:00
|
|
|
// GoSeq is a sequence of machine-dependent encoded values, which
|
2015-05-14 20:24:09 +00:00
|
|
|
// is a simple C equivalent of seq.Buffer.
|
2015-04-28 16:57:58 +00:00
|
|
|
// Used by automatically generated language bindings to talk to Go.
|
2015-05-14 20:24:09 +00:00
|
|
|
typedef struct GoSeq {
|
|
|
|
uint8_t *buf;
|
|
|
|
size_t off;
|
|
|
|
size_t len;
|
|
|
|
size_t cap;
|
|
|
|
} GoSeq;
|
2015-04-28 16:57:58 +00:00
|
|
|
|
2015-06-02 13:36:44 +00:00
|
|
|
// GoSeqRef is an object tagged with an integer for passing back and
|
|
|
|
// forth across the language boundary. A GoSeqRef may represent either
|
|
|
|
// an instance of a Go object, or an Objective-C object passed to Go.
|
|
|
|
// The explicit allocation of a GoSeqRef is used to pin a Go object
|
|
|
|
// when it is passed to Objective-C. The Go seq package maintains a
|
|
|
|
// reference to the Go object in a map keyed by the refnum. When the
|
|
|
|
// GoSeqRef is deallocated, the Go seq package will clear the
|
|
|
|
// corresponding entry in the map.
|
|
|
|
// TODO(hyangah): update the doc as golang.org/issue/10933 is fixed.
|
|
|
|
@interface GoSeqRef : NSObject {
|
|
|
|
}
|
|
|
|
@property int32_t refnum;
|
|
|
|
@property(strong) id obj; // NULL when representing a Go object.
|
|
|
|
|
|
|
|
- (id)initWithRefnum:(int32_t)refnum obj:(id)obj;
|
|
|
|
@end
|
2015-05-14 20:24:09 +00:00
|
|
|
|
|
|
|
// go_seq_free releases resources of the GoSeq.
|
2015-06-02 13:36:44 +00:00
|
|
|
extern void go_seq_free(GoSeq *seq);
|
2015-05-05 19:57:36 +00:00
|
|
|
|
2015-06-04 19:43:17 +00:00
|
|
|
extern BOOL go_seq_readBool(GoSeq *seq);
|
|
|
|
extern int go_seq_readInt(GoSeq *seq);
|
2015-05-05 19:57:36 +00:00
|
|
|
extern int8_t go_seq_readInt8(GoSeq *seq);
|
|
|
|
extern int16_t go_seq_readInt16(GoSeq *seq);
|
|
|
|
extern int32_t go_seq_readInt32(GoSeq *seq);
|
|
|
|
extern int64_t go_seq_readInt64(GoSeq *seq);
|
|
|
|
extern float go_seq_readFloat32(GoSeq *seq);
|
|
|
|
extern double go_seq_readFloat64(GoSeq *seq);
|
2015-06-02 13:36:44 +00:00
|
|
|
extern GoSeqRef *go_seq_readRef(GoSeq *seq);
|
2015-05-05 19:57:36 +00:00
|
|
|
extern NSString *go_seq_readUTF8(GoSeq *seq);
|
2015-05-11 20:25:42 +00:00
|
|
|
extern NSData *go_seq_readByteArray(GoSeq *seq);
|
2015-05-05 19:57:36 +00:00
|
|
|
|
2015-06-04 19:43:17 +00:00
|
|
|
extern void go_seq_writeBool(GoSeq *seq, BOOL v);
|
|
|
|
extern void go_seq_writeInt(GoSeq *seq, int v);
|
2015-05-05 19:57:36 +00:00
|
|
|
extern void go_seq_writeInt8(GoSeq *seq, int8_t v);
|
|
|
|
extern void go_seq_writeInt16(GoSeq *seq, int16_t v);
|
|
|
|
extern void go_seq_writeInt32(GoSeq *seq, int32_t v);
|
|
|
|
extern void go_seq_writeInt64(GoSeq *seq, int64_t v);
|
|
|
|
extern void go_seq_writeFloat32(GoSeq *seq, float v);
|
|
|
|
extern void go_seq_writeFloat64(GoSeq *seq, double v);
|
2015-06-02 13:36:44 +00:00
|
|
|
extern void go_seq_writeRef(GoSeq *seq, GoSeqRef *v);
|
2015-05-05 19:57:36 +00:00
|
|
|
extern void go_seq_writeUTF8(GoSeq *seq, NSString *v);
|
|
|
|
|
2015-05-11 20:25:42 +00:00
|
|
|
// go_seq_writeByteArray writes the data bytes to the seq. Note that the
|
|
|
|
// data should be valid until the the subsequent go_seq_send call completes.
|
|
|
|
extern void go_seq_writeByteArray(GoSeq *seq, NSData *data);
|
|
|
|
|
2015-05-05 19:57:36 +00:00
|
|
|
// go_seq_send sends a function invocation request to Go.
|
|
|
|
// It blocks until the function completes.
|
|
|
|
// If the request is for a method, the first element in req is
|
|
|
|
// a Ref to the receiver.
|
|
|
|
extern void go_seq_send(char *descriptor, int code, GoSeq *req, GoSeq *res);
|
|
|
|
|
2015-04-28 16:57:58 +00:00
|
|
|
#endif // __GO_SEQ_HDR__
|