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 ¶
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 ¶
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 ¶
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 ¶
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
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 ¶
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!
Click to show internal directories.
Click to hide internal directories.