当前位置: 首页>>代码示例>>Golang>>正文


Golang Buffer.Data方法代码示例

本文整理汇总了Golang中golang.org/x/mobile/bind/seq.Buffer.Data方法的典型用法代码示例。如果您正苦于以下问题:Golang Buffer.Data方法的具体用法?Golang Buffer.Data怎么用?Golang Buffer.Data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在golang.org/x/mobile/bind/seq.Buffer的用法示例。


在下文中一共展示了Buffer.Data方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: transact

// transact calls a method on an Objective-C object instance.
// It blocks until the call is complete.
//
// Code (>0) is the method id assigned by gobind.
// Code -1 is used to instruct Objective-C to decrement the ref count of
// the Objective-Co object.
func transact(ref *seq.Ref, descriptor string, code int, in *seq.Buffer) *seq.Buffer {
	var (
		res    *C.uint8_t = nil
		resLen C.size_t   = 0
		req    *C.uint8_t = nil
		reqLen C.size_t   = 0
	)

	if len(in.Data) > 0 {
		req = (*C.uint8_t)(unsafe.Pointer(&in.Data[0]))
		reqLen = C.size_t(len(in.Data))
	}

	if debug {
		fmt.Printf("transact: ref.Num = %d code = %d\n", ref.Num, code)
	}

	desc := cstrings.get(descriptor)
	C.go_seq_recv(C.int32_t(ref.Num), desc, C.int(code), req, reqLen, &res, &resLen)

	if resLen > 0 {
		goSlice := (*[maxSliceLen]byte)(unsafe.Pointer(res))[:resLen]
		out := new(seq.Buffer)
		out.Data = make([]byte, int(resLen))
		copy(out.Data, goSlice)
		C.free(unsafe.Pointer(res))
		// TODO: own or copy []bytes whose addresses were passed in.
		return out
	}
	return nil
}
开发者ID:Christeefym,项目名称:lantern,代码行数:37,代码来源:seq_darwin.go

示例2: Send

// Send is called by Java to send a request to run a Go function.
//export Send
func Send(descriptor string, code int, req *C.uint8_t, reqlen C.size_t, res **C.uint8_t, reslen *C.size_t) {
	fn := seq.Registry[descriptor][code]
	in := new(seq.Buffer)
	if reqlen > 0 {
		in.Data = (*[maxSliceLen]byte)(unsafe.Pointer(req))[:reqlen]
	}
	out := new(seq.Buffer)
	fn(out, in)
	seqToBuf(res, reslen, out)
}
开发者ID:TriangleGo,项目名称:golang.org,代码行数:12,代码来源:seq_android.go

示例3: Send

// Send is called by Java to send a request to run a Go function.
//export Send
func Send(descriptor string, code int, req *C.uint8_t, reqlen C.size_t, res **C.uint8_t, reslen *C.size_t) {
	fn := seq.Registry[descriptor][code]
	if fn == nil {
		panic(fmt.Sprintf("invalid descriptor(%s) and code(0x%x)", descriptor, code))
	}
	in := new(seq.Buffer)
	if reqlen > 0 {
		in.Data = (*[maxSliceLen]byte)(unsafe.Pointer(req))[:reqlen]
	}
	out := new(seq.Buffer)
	fn(out, in)
	// BUG(hyangah): the function returning a go byte slice (so fn writes a pointer into 'out') is unsafe.
	// After fn is complete here, Go runtime is free to collect or move the pointed byte slice
	// contents. (Explicitly calling runtime.GC here will surface the problem?)
	// Without pinning support from Go side, it will be hard to fix it without extra copying.

	seqToBuf(res, reslen, out)
}
开发者ID:tendermint,项目名称:mobile,代码行数:20,代码来源:seq_android.go


注:本文中的golang.org/x/mobile/bind/seq.Buffer.Data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。