memview

package
v0.3.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(data []byte, closable bool) (id uint32, closer io.Closer, err error)
Example
package main

import (
	"fmt"
	"io"

	symbols "github.com/taubyte/go-sdk-symbols/i2mv/memview"
	"github.com/taubyte/go-sdk/i2mv/memview"
)

var (
	mvCloser io.Closer
	err      error
	id       uint32
)

func main() {
	// Mocking the calls to the vm for usage in tests and playground
	symbols.MockNew(1)

	id, mvCloser, err = memview.New([]byte{1, 2, 3}, true)
	if err != nil {
		fmt.Printf("New memory view failed with: failed with: %s\n", err)
		return
	}

	fmt.Printf("%d\n", id)
}
Output:

1

Types

type MemoryView

type MemoryView interface {
	io.ReadSeekCloser
	Size() uint32
	OffSet() int64
	Id() uint32
}

TODO: Move to Interfaces once it is open sourced

func Open

func Open(id uint32) (MemoryView, error)
Example
package main

import (
	"fmt"

	symbols "github.com/taubyte/go-sdk-symbols/i2mv/memview"
	"github.com/taubyte/go-sdk/i2mv/memview"
)

func main() {
	// Mocking the calls to the vm for usage in tests and playground
	symbols.MockOpen(5, false)

	mv, err := memview.Open(0)
	if err != nil {
		fmt.Printf("Open failed with: %s\n", err)
		return
	}

	fmt.Printf("%d\n", mv.Size())
}
Output:

5

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL