github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/bind/objc/seq.h (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #ifndef __GO_SEQ_HDR__ 6 #define __GO_SEQ_HDR__ 7 8 #include <Foundation/Foundation.h> 9 10 // GoSeq is a sequence of machine-dependent encoded values, which 11 // is a simple C equivalent of seq.Buffer. 12 // Used by automatically generated language bindings to talk to Go. 13 typedef struct GoSeq { 14 uint8_t *buf; 15 size_t off; 16 size_t len; 17 size_t cap; 18 } GoSeq; 19 20 // GoSeqRef is an object tagged with an integer for passing back and 21 // forth across the language boundary. A GoSeqRef may represent either 22 // an instance of a Go object, or an Objective-C object passed to Go. 23 // The explicit allocation of a GoSeqRef is used to pin a Go object 24 // when it is passed to Objective-C. The Go seq package maintains a 25 // reference to the Go object in a map keyed by the refnum. When the 26 // GoSeqRef is deallocated, the Go seq package will clear the 27 // corresponding entry in the map. 28 // TODO(hyangah): update the doc as golang.org/issue/10933 is fixed. 29 @interface GoSeqRef : NSObject { 30 } 31 @property int32_t refnum; 32 @property(strong) id obj; // NULL when representing a Go object. 33 34 // new GoSeqRef object to proxy a Go object. The refnum must be 35 // provided from Go side. 36 - (instancetype)initWithRefnum:(int32_t)refnum obj:(id)obj; 37 38 @end 39 40 // go_seq_free releases resources of the GoSeq. 41 extern void go_seq_free(GoSeq *seq); 42 43 extern BOOL go_seq_readBool(GoSeq *seq); 44 extern int go_seq_readInt(GoSeq *seq); 45 extern int8_t go_seq_readInt8(GoSeq *seq); 46 extern int16_t go_seq_readInt16(GoSeq *seq); 47 extern int32_t go_seq_readInt32(GoSeq *seq); 48 extern int64_t go_seq_readInt64(GoSeq *seq); 49 extern float go_seq_readFloat32(GoSeq *seq); 50 extern double go_seq_readFloat64(GoSeq *seq); 51 extern GoSeqRef *go_seq_readRef(GoSeq *seq); 52 extern NSString *go_seq_readUTF8(GoSeq *seq); 53 extern NSData *go_seq_readByteArray(GoSeq *seq); 54 55 extern void go_seq_writeBool(GoSeq *seq, BOOL v); 56 extern void go_seq_writeInt(GoSeq *seq, int v); 57 extern void go_seq_writeInt8(GoSeq *seq, int8_t v); 58 extern void go_seq_writeInt16(GoSeq *seq, int16_t v); 59 extern void go_seq_writeInt32(GoSeq *seq, int32_t v); 60 extern void go_seq_writeInt64(GoSeq *seq, int64_t v); 61 extern void go_seq_writeFloat32(GoSeq *seq, float v); 62 extern void go_seq_writeFloat64(GoSeq *seq, double v); 63 extern void go_seq_writeRef(GoSeq *seq, GoSeqRef *ref); 64 extern void go_seq_writeUTF8(GoSeq *seq, NSString *v); 65 66 // go_seq_writeByteArray writes the data bytes to the seq. Note that the 67 // data should be valid until the the subsequent go_seq_send call completes. 68 extern void go_seq_writeByteArray(GoSeq *seq, NSData *data); 69 70 // go_seq_writeObjcRef is a special case of go_seq_writeRef for 71 // Objective-C objects that implement Go interface. 72 extern void go_seq_writeObjcRef(GoSeq *seq, id obj); 73 74 // go_seq_send sends a function invocation request to Go. 75 // It blocks until the function completes. 76 // If the request is for a method, the first element in req is 77 // a Ref to the receiver. 78 extern void go_seq_send(char *descriptor, int code, GoSeq *req, GoSeq *res); 79 80 extern void go_seq_register_proxy(const char *descriptor, 81 void(*fn)(id, int, GoSeq *, GoSeq *)); 82 83 #endif // __GO_SEQ_HDR__