示例#1
0
文件: coding.go 项目: vanadium/go.jni
// VomCopy copies the provided Go value by encoding/decoding it from VOM.
func VomCopy(src interface{}, dstptr interface{}) error {
	data, err := vom.Encode(src)
	if err != nil {
		return err
	}
	return vom.Decode(data, dstptr)
}
示例#2
0
文件: coding.go 项目: vanadium/go.jni
// GoVomCopy copies the provided Java object into a provided Go value pointer by
// encoding/decoding it from VOM.
func GoVomCopy(env Env, obj Object, class Class, dstptr interface{}) error {
	data, err := JVomEncode(env, obj, Object(uintptr(unsafe.Pointer(class.value()))))
	if err != nil {
		return err
	}
	return vom.Decode(data, dstptr)
}
示例#3
0
文件: coding.go 项目: vanadium/go.jni
// VomDecodeToValue VOM-decodes the provided value into *vdl.Value using a new
// instance of a VOM decoder.
func VomDecodeToValue(data []byte) (*vdl.Value, error) {
	var value *vdl.Value
	if err := vom.Decode(data, &value); err != nil {
		return nil, err
	}
	return value, nil
}
示例#4
0
func BenchmarkVomDecoding(b *testing.B) {
	data := vomBytesCustomer()
	for i := 0; i < b.N; i++ {
		var c Customer
		vom.Decode(data, &c)
	}
}
示例#5
0
文件: util.go 项目: vanadium/go.jni
// GoSignature converts the provided Java VSignature into a Go Signature.
func GoSignature(env jutil.Env, jSignature jutil.Object) (security.Signature, error) {
	encoded, err := jutil.CallStaticByteArrayMethod(env, jUtilClass, "encodeSignature", []jutil.Sign{signatureSign}, jSignature)
	if err != nil {
		return security.Signature{}, err
	}
	var sig security.Signature
	if err := vom.Decode(encoded, &sig); err != nil {
		return security.Signature{}, err
	}
	return sig, nil
}
示例#6
0
//export swift_io_v_v23_security_simple_nativeSetBlessings
func swift_io_v_v23_security_simple_nativeSetBlessings(ctxHandle C.GoContextHandle, encodedSwiftBlessings C.SwiftByteArray, errOut *C.SwiftVError) {
	ctx := context.GoContext(uint64(ctxHandle))
	encodedBlessings := util.GoBytesNoCopy(unsafe.Pointer(&encodedSwiftBlessings))
	var blessings security.Blessings
	if err := vom.Decode(encodedBlessings, &blessings); err != nil {
		ctx.Error("Unable to decode:", err)
		util.ThrowSwiftError(nil, err, unsafe.Pointer(errOut))
		return
	}
	principal := v23.GetPrincipal(ctx)
	if err := principal.BlessingStore().SetDefault(blessings); err != nil {
		util.ThrowSwiftError(nil, err, unsafe.Pointer(errOut))
		return
	}
}
示例#7
0
文件: util.go 项目: vanadium/go.jni
// GoError converts the provided Java Exception into a Go error, converting VException into
// verror.T and all other exceptions into a Go error.
func GoError(env Env, jException Object) error {
	if jException.IsNull() {
		return nil
	}
	if IsInstanceOf(env, jException, jVExceptionClass) {
		// VException: convert it into a verror.
		// Note that we can't use CallStaticObjectMethod below as it may lead to
		// an infinite loop.
		jmid, jArgArr, freeFunc, err := setupStaticMethodCall(env, jVomUtilClass, "encode", []Sign{ObjectSign, TypeSign}, ByteArraySign, jException, jVExceptionClass)
		if err != nil {
			return fmt.Errorf("error converting VException: " + err.Error())
		}
		defer freeFunc()
		dataObj := C.CallStaticObjectMethodA(env.value(), jVomUtilClass.value(), jmid, jArgArr)
		if e := C.ExceptionOccurred(env.value()); e != nil {
			C.ExceptionClear(env.value())
			return fmt.Errorf("error converting VException: exception during VomUtil.encode()")
		}
		data := GoByteArray(env, Object(uintptr(unsafe.Pointer(dataObj))))
		var verr error
		if err := vom.Decode(data, &verr); err != nil {
			return fmt.Errorf("error converting VException: " + err.Error())
		}
		return verr
	}
	// Not a VException: convert it into a Go error.
	// Note that we can't use CallObjectMethod below, as it may lead to an
	// infinite loop.
	jmid, jArgArr, freeFunc, err := setupMethodCall(env, jException, "getMessage", nil, StringSign)
	if err != nil {
		return fmt.Errorf("error converting exception: " + err.Error())
	}
	defer freeFunc()
	strObj := C.CallObjectMethodA(env.value(), jException.value(), jmid, jArgArr)
	if e := C.ExceptionOccurred(env.value()); e != nil {
		C.ExceptionClear(env.value())
		return fmt.Errorf("error converting exception: exception during Throwable.getMessage()")
	}
	return errors.New(GoString(env, Object(uintptr(unsafe.Pointer(strObj)))))
}