2023-02-25 19:13:07 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// CEF 二进制类型 BinaryValueRef.New() or Create()
|
|
|
|
//
|
|
|
|
// ICefBinaryValue
|
|
|
|
// 示例:
|
|
|
|
// Go: 创建并绑定 ICefBinaryValue 对象名称: myobj
|
|
|
|
// JavaScript: let obj = new Uint8Array(window.myobj);
|
|
|
|
// console.log(obj)
|
2023-06-01 10:15:20 +08:00
|
|
|
|
2023-02-25 02:15:15 +08:00
|
|
|
package cef
|
|
|
|
|
2023-02-25 17:09:39 +08:00
|
|
|
import (
|
2023-06-11 00:10:55 +08:00
|
|
|
"github.com/energye/energy/v2/cef/internal/def"
|
2023-05-31 18:00:34 +08:00
|
|
|
"github.com/energye/energy/v2/common/imports"
|
2023-02-25 17:09:39 +08:00
|
|
|
"github.com/energye/golcl/lcl/api"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// BinaryValueRef -> ICefBinaryValue
|
|
|
|
var BinaryValueRef cefBinaryValue
|
|
|
|
|
|
|
|
//cefBinaryValue
|
|
|
|
type cefBinaryValue uintptr
|
|
|
|
|
2023-02-25 19:13:07 +08:00
|
|
|
// New 创建一个带有数据的二进对象
|
2023-02-25 17:09:39 +08:00
|
|
|
func (*cefBinaryValue) New(data []byte) *ICefBinaryValue {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefBinaryValueRef_New).Call(uintptr(unsafe.Pointer(&data[0])), uintptr(uint32(len(data))), uintptr(unsafe.Pointer(&result)))
|
2023-02-25 17:09:39 +08:00
|
|
|
return &ICefBinaryValue{
|
|
|
|
instance: unsafe.Pointer(result),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-25 19:13:07 +08:00
|
|
|
// Create 创建一个二进对象
|
2023-02-25 17:09:39 +08:00
|
|
|
func (*cefBinaryValue) Create() *ICefBinaryValue {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefBinaryValueRef_Create).Call(uintptr(unsafe.Pointer(&result)))
|
2023-02-25 17:09:39 +08:00
|
|
|
return &ICefBinaryValue{
|
|
|
|
instance: unsafe.Pointer(result),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-04 11:19:45 +08:00
|
|
|
// UnWrap
|
|
|
|
func (*cefBinaryValue) UnWrap(data *ICefBinaryValue) *ICefBinaryValue {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefBinaryValueRef_UnWrap).Call(data.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-03-04 11:58:35 +08:00
|
|
|
data.instance = unsafe.Pointer(result)
|
|
|
|
return data
|
2023-03-04 11:19:45 +08:00
|
|
|
}
|
|
|
|
|
2023-02-25 02:15:15 +08:00
|
|
|
// Instance 实例
|
|
|
|
func (m *ICefBinaryValue) Instance() uintptr {
|
|
|
|
if m == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return uintptr(m.instance)
|
|
|
|
}
|
2023-02-25 17:09:39 +08:00
|
|
|
|
|
|
|
func (m *ICefBinaryValue) IsValid() bool {
|
2023-05-31 17:41:14 +08:00
|
|
|
if m == nil || m.instance == nil {
|
2023-03-14 17:30:45 +08:00
|
|
|
return false
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CefBinaryValue_IsValid).Call(m.Instance())
|
2023-02-25 17:09:39 +08:00
|
|
|
return api.GoBool(r1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefBinaryValue) IsOwned() bool {
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CefBinaryValue_IsOwned).Call(m.Instance())
|
2023-02-25 17:09:39 +08:00
|
|
|
return api.GoBool(r1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefBinaryValue) Copy() *ICefBinaryValue {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefBinaryValue_Copy).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-02-25 17:09:39 +08:00
|
|
|
return &ICefBinaryValue{
|
|
|
|
instance: unsafe.Pointer(result),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefBinaryValue) GetSize() uint32 {
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CefBinaryValue_GetSize).Call(m.Instance())
|
2023-02-25 17:09:39 +08:00
|
|
|
return uint32(r1)
|
|
|
|
}
|
|
|
|
|
2023-03-06 18:33:31 +08:00
|
|
|
func (m *ICefBinaryValue) GetData(buffer []byte, dataOffset uint32) uint32 {
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CefBinaryValue_GetData).Call(m.Instance(), uintptr(unsafe.Pointer(&buffer[0])), uintptr(uint32(len(buffer))), uintptr(dataOffset))
|
2023-02-25 17:09:39 +08:00
|
|
|
return uint32(r1)
|
|
|
|
}
|
2023-03-09 16:35:38 +08:00
|
|
|
|
|
|
|
func (m *ICefBinaryValue) Free() {
|
2023-03-16 09:13:31 +08:00
|
|
|
if m.instance != nil {
|
|
|
|
m.base.Free(m.Instance())
|
|
|
|
m.instance = nil
|
|
|
|
}
|
2023-03-09 16:35:38 +08:00
|
|
|
}
|
2023-05-31 17:41:14 +08:00
|
|
|
|
|
|
|
// ************************** TCefBinaryValueArray ************************** //
|
|
|
|
|
|
|
|
func (m *TCefBinaryValueArray) Get(index uint32) *ICefBinaryValue {
|
|
|
|
if index < m.count {
|
|
|
|
if m.binaryValues == nil {
|
|
|
|
m.binaryValues = make([]*ICefBinaryValue, m.count, m.count)
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefBinaryValueArray_Get).Call(uintptr(m.instance), uintptr(index), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
m.binaryValues[index] = &ICefBinaryValue{instance: unsafe.Pointer(result)}
|
|
|
|
return m.binaryValues[index]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCefBinaryValueArray) Count() uint32 {
|
|
|
|
return m.count
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCefBinaryValueArray) Free() {
|
|
|
|
if m.instance != nil {
|
|
|
|
if m.binaryValues != nil {
|
|
|
|
for _, cert := range m.binaryValues {
|
|
|
|
cert.Free()
|
|
|
|
}
|
|
|
|
m.binaryValues = nil
|
|
|
|
}
|
|
|
|
m.instance = nil
|
|
|
|
m.count = 0
|
|
|
|
}
|
|
|
|
}
|