Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ListenToProtocol = func(protocol string, response *byte, responseSize uint32) (error errno.Error) { return errno.ErrorNone }
View Source
var ListenToProtocolSize = func(protocol string, responseSize *uint32) (error errno.Error) { return errno.ErrorNone }
View Source
var NewCommand = func(protocol, command string, id *Command) (error errno.Error) { return errno.ErrorNone }
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command uint32
A p2p command
func (Command) Send ¶
Send returns the command response and an error, used to send data over p2p on given protocol and command.
Example ¶
package main import ( "fmt" "bitbucket.org/taubyte/go-sdk/event" "bitbucket.org/taubyte/go-sdk/p2p/node" ) func main() { service := node.New("/test/v1") // Instantiate a command `someCommand` to protocol `/test/v1` command, err := service.Command("someCommand") if err != nil { return } // Send the command with data []byte("Hello, world!") response, err := command.Send([]byte("Hello, world!")) if err != nil { return } // A function representing the call executed by the above command _ = func(e event.Event) uint32 { p2pEvent, err := e.P2P() if err != nil { return 1 } data, err := p2pEvent.Data() if err != nil { return 1 } if string(data) == "Hello, world!" { p2pEvent.Write([]byte("Hello from the other side!")) return 0 } return 1 } fmt.Println(response) }
Output: Hello from the other side!
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
A p2p service with on a given protocol
Example ¶
package main import ( "fmt" "bitbucket.org/taubyte/go-sdk/p2p/node" ) func main() { // Instantiate a service with protocol `/test/v1` service := node.New("/test/v1") fmt.Println(service.Protocol()) }
Output: /test/v1
func (*Service) Command ¶
Command returns a p2p Command and an error Used for sending a given command on a protocol
func (*Service) Listen ¶
Listen returns the projectProtocol and an error. Asks a node to listen on a protocol, and returns the protocol the node is set to listen on.
Example ¶
package main import ( "fmt" "bitbucket.org/taubyte/go-sdk/p2p/node" ) func main() { service := node.New("/test/v1") projectProtocol, err := service.Listen() if err != nil { return } fmt.Println(projectProtocol) }
Output: hash(project + service)/test/v1
Click to show internal directories.
Click to hide internal directories.