event

package
v0.1.39 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event uint32

Represents a p2p event.

func (Event) Command

func (e Event) Command() (string, error)

Command returns the command used to call the given p2p function and an error.

Example
package main

import (
	"fmt"

	symbols "bitbucket.org/taubyte/go-sdk-symbols/p2p/event"

	"bitbucket.org/taubyte/go-sdk/p2p/event"
)

func main() {
	// Mocking the calls to the vm for usage in tests and playground
	symbols.MockData{
		Command: "someCommand",
	}.Mock()

	var p2pEvent event.Event // Event for a taubyte p2p function called by command, `someCommand`

	command, err := p2pEvent.Command()
	if err != nil {
		return
	}

	fmt.Println(command)
}
Output:

someCommand

func (Event) Data

func (e Event) Data() ([]byte, error)

Data returns the data sent to the function as bytes and an error.

Example
package main

import (
	"fmt"

	symbols "bitbucket.org/taubyte/go-sdk-symbols/p2p/event"

	"bitbucket.org/taubyte/go-sdk/p2p/event"
)

func main() {
	// Mocking the calls to the vm for usage in tests and playground
	symbols.MockData{
		Data: []byte("Hello, world!"),
	}.Mock()

	var p2pEvent event.Event // Event for a taubyte p2p function called with data []byte("Hello, world!")

	data, err := p2pEvent.Data()
	if err != nil {
		return
	}

	fmt.Println(string(data))
}
Output:

Hello, world!

func (Event) From

func (e Event) From() (cid.Cid, error)

From returns a cid.Cid of the sending node and an error.

Example
// Mocking the calls to the vm for usage in tests and playground
_cid, err := cid.Parse("QmZjBpQzRw8UovKaMoWJ3qvQrHZvErqQuXNyXNusm4XYK3")
if err != nil {
	return
}
symbols.MockData{
	From: _cid,
}.Mock()

var p2pEvent event.Event // Event for a taubyte p2p function sent by a node with id: `QmZjBpQzRw8UovKaMoWJ3qvQrHZvErqQuXNyXNusm4XYK3`

cid, err := p2pEvent.From()
if err != nil {
	return
}

fmt.Println(cid.String())
Output:

QmZjBpQzRw8UovKaMoWJ3qvQrHZvErqQuXNyXNusm4XYK3

func (Event) Protocol

func (e Event) Protocol() (string, error)

Protocol returns the protocol which the event was called and an error.

Example
package main

import (
	"fmt"

	symbols "bitbucket.org/taubyte/go-sdk-symbols/p2p/event"

	"bitbucket.org/taubyte/go-sdk/p2p/event"
)

func main() {
	// Mocking the calls to the vm for usage in tests and playground
	symbols.MockData{
		Protocol: "/test/v1",
	}.Mock()

	var p2pEvent event.Event // Event for a taubyte p2p function sent on protocol `/test/v1`

	protocol, err := p2pEvent.Protocol()
	if err != nil {
		return
	}

	fmt.Println(protocol)
}
Output:

/test/v1

func (Event) To added in v0.1.19

func (e Event) To() (cid.Cid, error)

To returns a cid.Cid of the receiving node and an error.

Example
// Mocking the calls to the vm for usage in tests and playground
_cid, err := cid.Parse("QmZjBpQzRw8UovKaMoWJ3qvQrHZvErqQuXNyXNusm4XYK3")
if err != nil {
	return
}
symbols.MockData{
	To: _cid,
}.Mock()

var p2pEvent event.Event // Event for a taubyte p2p function sent by a node with id: `QmZjBpQzRw8UovKaMoWJ3qvQrHZvErqQuXNyXNusm4XYK3`

cid, err := p2pEvent.To()
if err != nil {
	return
}

fmt.Println(cid.String())
Output:

QmZjBpQzRw8UovKaMoWJ3qvQrHZvErqQuXNyXNusm4XYK3

func (Event) Write

func (e Event) Write(data []byte) error

Write writes given data and returns an error.

Example
package main

import (
	"fmt"

	symbols "bitbucket.org/taubyte/go-sdk-symbols/p2p/event"

	"bitbucket.org/taubyte/go-sdk/p2p/event"
)

func main() {
	// Mocking the calls to the vm for usage in tests and playground
	m := symbols.MockData{}.Mock()

	var p2pEvent event.Event // Event for a taubyte p2p function sent on protocol `/test/v1`

	err := p2pEvent.Write([]byte("Hello, world!"))
	if err != nil {
		return
	}

	fmt.Println(string(m.DataToSend))
}
Output:

Hello, world!

Jump to

Keyboard shortcuts

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