ign

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(ctx context.Context, message transport.Message)

Callback is a function that will be executed after reading a message from a certain topic.

type Message

type Message struct {
	// Operation is the operation request that will be performed in the websocket server.
	//
	// auth: Authorize connection to the websocket server.
	//
	// sub: Subscribe to a certain topic.
	//
	// topics: List the available topics.
	//
	// pub: Publish to a certain topic - Not implemented yet.
	//
	// protos: Request message definitions.
	Operation string
	// Topic is the name of the topic to subscribe or publish to.
	Topic string
	// Type is the name of the ign-msgs protobuf type used to marshal/unmarshal payloads.
	Type string
	// Payload is the actual message. This message needs to be unmarshalled with protobuf before using.
	Payload string
}

Message represents a message format for Ignition Robotics websocket server communication.

func NewAuthorizationMessage

func NewAuthorizationMessage(token string) Message

NewAuthorizationMessage creates a new authorization message from the given token.

func NewMessageFromByteSlice

func NewMessageFromByteSlice(slice []byte) (*Message, error)

NewMessageFromByteSlice initializes a new message from the given slice. It returns an error if the slice is invalid

func NewPublicationMessage

func NewPublicationMessage(topic string, messageType, message string) Message

NewPublicationMessage creates a new publication message with a certain type to send to the given topic. messageType is the name of a protobuf type used to marshal the message.

func NewSubscriptionMessage

func NewSubscriptionMessage(topic string) Message

NewSubscriptionMessage creates a new subscription message from the given topic.

func (*Message) GetPayload

func (m *Message) GetPayload(out interface{}) error

GetPayload returns the message payload.

func (Message) ToByteSlice

func (m Message) ToByteSlice() []byte

ToByteSlice converts the message into a slice of bytes.

func (Message) ToSlice

func (m Message) ToSlice() []string

ToSlice converts the message into a slice.

func (Message) ToString

func (m Message) ToString() string

ToString converts the message into a string.

type PubSubTransporterMock

type PubSubTransporterMock struct {
	*mock.Mock
}

PubSubTransporterMock implements PubSubWebsocketTransporter to be used as mock for testing purposes.

func NewPubSubTransporterMock

func NewPubSubTransporterMock() *PubSubTransporterMock

NewPubSubTransporterMock initializes a new PubSubTransporterMock

func (*PubSubTransporterMock) Connect

func (m *PubSubTransporterMock) Connect() error

Connect is a mock for the Connect method.

func (*PubSubTransporterMock) Connection

func (m *PubSubTransporterMock) Connection() *websocket.Conn

Connection is a mock for the Connection method.

func (*PubSubTransporterMock) Disconnect

func (m *PubSubTransporterMock) Disconnect() error

Disconnect is a mock for the Disconnect method.

func (*PubSubTransporterMock) IsConnected

func (m *PubSubTransporterMock) IsConnected() bool

IsConnected is a mock for the IsConnected method.

func (*PubSubTransporterMock) Publish

func (m *PubSubTransporterMock) Publish(message Message) error

Publish is a mock for the Publish method.

func (*PubSubTransporterMock) Subscribe

func (m *PubSubTransporterMock) Subscribe(topic string, cb Callback) error

Subscribe is a mock for the Subscribe method.

func (*PubSubTransporterMock) Unsubscribe

func (m *PubSubTransporterMock) Unsubscribe(topic string) error

Unsubscribe is a mock for the Unsubscribe method.

type PubSubWebsocketTransporter

type PubSubWebsocketTransporter interface {
	transport.WebsocketTransporter
	Subscriber
	Publisher
}

PubSubWebsocketTransporter represents a set of methods to communicate two processes using the Publisher and Subscriber interfaces.

func NewIgnWebsocketTransporter

func NewIgnWebsocketTransporter(baseCtx context.Context, host, path, scheme, token string) (PubSubWebsocketTransporter, error)

NewIgnWebsocketTransporter initializes a new PubSubWebsocketTransporter instance using a websocketPubSubTransport implementation. It also establishes a connection to the given addr and sends an authorization message with the given token. The token should be the same as the simulation authorization token from the simulation that the transporter is attempting to connect to.

type Publisher

type Publisher interface {
	Publish(message Message) error
}

Publisher represents a set of methods that will let some process send messages to another process.

type Subscriber

type Subscriber interface {
	Subscribe(topic string, cb Callback) error
	Unsubscribe(topic string) error
}

Subscriber represents a set of methods that will let some process receive messages from another process.

Jump to

Keyboard shortcuts

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