plugin

package
v0.0.0-...-e20ecb9 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2019 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package plugin contains message codecs, method codecs and channel implementations which allow plugins to communicate between the flutter framework and the host (Go).

go-flutter/plugin is frozen, the API should not much change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicMessageChannel

type BasicMessageChannel struct {
	// contains filtered or unexported fields
}

BasicMessageChannel presents named channel for communicating with the Flutter application using basic, asynchronous message passing.

Messages are encoded into binary before being sent, and binary messages / received are decoded into. The MessageCodec used must be compatible with the one used by the Flutter application. This can be achieved by creating a BasicMessageChannel counterpart of this channel on the Dart side. See: https://docs.flutter.io/flutter/services/BasicMessageChannel-class.html

The static Go type of messages sent and received is interface{}, but only values supported by the specified MessageCodec can be used.

The logical identity of the channel is given by its name. Identically named channels will interfere with each other's communication.

func NewBasicMessageChannel

func NewBasicMessageChannel(messenger BinaryMessenger, channelName string, codec MessageCodec) *BasicMessageChannel

NewBasicMessageChannel creates a BasicMessageChannel.

Call Handle or HandleFunc on the returned BasicMessageChannel to provide the channel with a handler for incoming messages.

func (*BasicMessageChannel) Handle

func (b *BasicMessageChannel) Handle(handler BasicMessageHandler)

Handle registers a message handler on this channel for receiving messages sent from the Flutter application.

Consecutive calls override any existing handler registration for (the name of) this channel.

When given nil as handler, any incoming message on this channel will be handled silently by sending a nil reply which triggers the dart MissingPluginException exception.

func (*BasicMessageChannel) HandleFunc

func (b *BasicMessageChannel) HandleFunc(f func(message interface{}) (reply interface{}, err error))

HandleFunc is a shorthand for b.Handle(BasicMessageHandlerFunc(f))

func (*BasicMessageChannel) Send

func (b *BasicMessageChannel) Send(message interface{}) error

Send encodes and sends the specified message to the Flutter application without waiting for a reply.

func (*BasicMessageChannel) SendWithReply

func (b *BasicMessageChannel) SendWithReply(message interface{}) (reply interface{}, err error)

SendWithReply encodes and sends the specified message to the Flutter application and returns the reply, or an error.

NOTE: If no value are returned by the handler setted in the setMessageHandler flutter method, the function will wait forever. In case you don't want to wait for reply, use Send or launch the function in a goroutine.

type BasicMessageHandler

type BasicMessageHandler interface {
	HandleMessage(message interface{}) (reply interface{}, err error)
}

BasicMessageHandler defines the interfece for a basic message handler.

type BasicMessageHandlerFunc

type BasicMessageHandlerFunc func(message interface{}) (reply interface{}, err error)

The BasicMessageHandlerFunc type is an adapter to allow the use of ordinary functions as basic message handlers. If f is a function with the appropriate signature, BasicMessageHandlerFunc(f) is a BasicMessageHandler that calls f.

func (BasicMessageHandlerFunc) HandleMessage

func (f BasicMessageHandlerFunc) HandleMessage(message interface{}) (reply interface{}, err error)

HandleMessage calls f(message).

type BinaryCodec

type BinaryCodec struct{}

BinaryCodec implements a MessageCodec using unencoded binary messages, represented as byte slices.

func (BinaryCodec) DecodeMessage

func (BinaryCodec) DecodeMessage(data []byte) (message interface{}, err error)

DecodeMessage decodes binary data into binary data.

func (BinaryCodec) EncodeMessage

func (BinaryCodec) EncodeMessage(message interface{}) ([]byte, error)

EncodeMessage expects message to be a slice of bytes.

type BinaryMessenger

type BinaryMessenger interface {
	// SendWithReply sends a binary message to the Flutter application.
	SendWithReply(channel string, binaryMessage []byte) (binaryReply []byte, err error)

	// Send sends a binary message to the Flutter application without
	// expecting a reply.
	Send(channel string, binaryMessage []byte) (err error)

	// SetChannelHandler registers a handler to be invoked when the Flutter
	// application sends a message to its host platform on given channel.
	//
	// Registration overwrites any previous registration for the same channel
	// name. Use nil as handler to deregister.
	SetChannelHandler(channel string, handler ChannelHandlerFunc)
}

BinaryMessenger defines a bidirectional binary messenger.

type ChannelHandlerFunc

type ChannelHandlerFunc func(binaryMessage []byte, r ResponseSender) (err error)

ChannelHandlerFunc describes the function that handles binary messages sent on a channel. For each message, ResponseSender.Send must be called once.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error implement the Go error interface, can be thrown from a go-flutter method channel plugin to return custom error codes. Normal Go error can also be used, the error code will default to "error".

func NewError

func NewError(code string, err error) *Error

NewError create an error with an specific error code.

func (*Error) Error

func (e *Error) Error() string

Error is needed to comply with the Golang error interface.

type EventChannel

type EventChannel struct {
	// contains filtered or unexported fields
}

EventChannel provides way for flutter applications and hosts to communicate using event streams. It must be used with a codec, for example the StandardMethodCodec.

func NewEventChannel

func NewEventChannel(messenger BinaryMessenger, channelName string, methodCodec MethodCodec) (channel *EventChannel)

NewEventChannel creates a new event channel

func (*EventChannel) Handle

func (e *EventChannel) Handle(handler StreamHandler)

Handle registers a StreamHandler for a event channel.

Consecutive calls override any existing handler registration. When given nil as handler, the previously registered handler for a method is unregistrered.

When no handler is registered for a method, it will be handled silently by sending a nil reply which triggers the dart MissingPluginException exception.

type EventSink

type EventSink struct {
	sync.Mutex
	// contains filtered or unexported fields
}

EventSink defines the interface for producers of events to send message to Flutter. StreamHandler act as a clients of EventSink for sending events.

func (*EventSink) EndOfStream

func (es *EventSink) EndOfStream()

EndOfStream consumes end of stream.

func (*EventSink) Error

func (es *EventSink) Error(errorCode string, errorMessage string, errorDetails interface{})

Error consumes an error event.

func (*EventSink) Success

func (es *EventSink) Success(event interface{})

Success consumes a successful event.

type FlutterError

type FlutterError struct {
	Code    string
	Message string
	Details interface{}
}

FlutterError is returned to indicate that a Flutter method invocation failed on the Flutter side.

func (FlutterError) Error

func (e FlutterError) Error() string

Error returns a string describing the FlutterError

type JSONMethodCodec

type JSONMethodCodec struct{}

JSONMethodCodec implements a MethodCodec using JSON for message encoding.

func (JSONMethodCodec) DecodeEnvelope

func (j JSONMethodCodec) DecodeEnvelope(envelope []byte) (result interface{}, err error)

DecodeEnvelope decodes the specified result envelope from binary. Returns a FlutterError as error if provided envelope represents an error, otherwise returns the result as a json.RawMessage

func (JSONMethodCodec) DecodeMethodCall

func (j JSONMethodCodec) DecodeMethodCall(data []byte) (methodCall MethodCall, err error)

DecodeMethodCall decodes the MethodCall from binary. Nore that the MethodCall arguments are not fully parsed, they are always a json.RawMessage and must be decoded by the MethodHandler. Returns an error on invalid data.

func (JSONMethodCodec) EncodeErrorEnvelope

func (j JSONMethodCodec) EncodeErrorEnvelope(code string, message string, details interface{}) (data []byte, err error)

EncodeErrorEnvelope encodes an error result into a binary envelope. The specified error code, human-readable error message, and error details correspond to the fields of Flutter's PlatformException.

func (JSONMethodCodec) EncodeMethodCall

func (j JSONMethodCodec) EncodeMethodCall(methodCall MethodCall) (data []byte, err error)

EncodeMethodCall encodes the MethodCall into binary Returns an error on invalid MethodCall arguments.

func (JSONMethodCodec) EncodeSuccessEnvelope

func (j JSONMethodCodec) EncodeSuccessEnvelope(result interface{}) (data []byte, err error)

EncodeSuccessEnvelope encodes a successful result into a binary envelope. The result value must be encodable in JSON.

type MessageCodec

type MessageCodec interface {
	// EncodeMessage encodes a message to a slice of bytes.
	EncodeMessage(message interface{}) (binaryMessage []byte, err error)
	// DecodeMessage decodes a slice of bytes to a message.
	DecodeMessage(binaryMessage []byte) (message interface{}, err error)
}

MessageCodec defines a message encoding/decoding mechanism.

type MessageTypeError

type MessageTypeError struct {
	// contains filtered or unexported fields
}

MessageTypeError is returned when a MessageCodec implementation is asked to encode a message of the wrong type.

func (MessageTypeError) Error

func (e MessageTypeError) Error() string

Error returns a string describing the MessageTypeError

type MethodCall

type MethodCall struct {
	Method    string
	Arguments interface{}
}

MethodCall describes a method invocation.

type MethodChannel

type MethodChannel struct {
	// contains filtered or unexported fields
}

MethodChannel provides way for flutter applications and hosts to communicate. It must be used with a codec, for example the StandardMethodCodec. For more information please read https://flutter.dev/docs/development/platform-integration/platform-channels

func NewMethodChannel

func NewMethodChannel(messenger BinaryMessenger, channelName string, methodCodec MethodCodec) (channel *MethodChannel)

NewMethodChannel creates a new method channel

func (*MethodChannel) CatchAllHandle

func (m *MethodChannel) CatchAllHandle(handler MethodHandler)

CatchAllHandle registers a default method handler. When no Handle are found, the handler provided in CatchAllHandle will be used. If no CatchAllHandle is provided, a MissingPluginException exception is sent when no handler is registered for a method name.

Consecutive calls override any existing handler registration for (the name of) this method. When given nil as handler, the previously registered handler for a method is unregistered.

The argument of the HandleMethod function of the MethodHandler interface is a MethodCall struct instead of MethodCall.Arguments

func (*MethodChannel) CatchAllHandleFunc

func (m *MethodChannel) CatchAllHandleFunc(f func(arguments interface{}) (reply interface{}, err error))

CatchAllHandleFunc is a shorthand for m.CatchAllHandle(MethodHandlerFunc(f))

The argument of the function f is a MethodCall struct instead of MethodCall.Arguments

func (*MethodChannel) ClearAllHandle

func (m *MethodChannel) ClearAllHandle()

ClearAllHandle clear all the handlers registered by Handle\HandleFunc and HandleSync\HandleFuncSync. ClearAllHandle dose not clear the handler registered by CatchAllHandle\CatchAllHandleFunc

func (*MethodChannel) Handle

func (m *MethodChannel) Handle(methodName string, handler MethodHandler)

Handle registers a method handler for method calls with given name.

Consecutive calls override any existing handler registration for (the name of) this method. When given nil as handler, the previously registered handler for a method is unregistered.

When no handler is registered for a method, it will be handled silently by sending a nil reply which triggers the dart MissingPluginException exception.

func (*MethodChannel) HandleFunc

func (m *MethodChannel) HandleFunc(methodName string, f func(arguments interface{}) (reply interface{}, err error))

HandleFunc is a shorthand for m.Handle("name", MethodHandlerFunc(f))

The argument of the function f is an interface corresponding to the MethodCall.Arguments values

func (*MethodChannel) HandleFuncSync

func (m *MethodChannel) HandleFuncSync(methodName string, f func(arguments interface{}) (reply interface{}, err error))

HandleFuncSync is a shorthand for m.HandleSync("name", MethodHandlerFunc(f))

The argument of the function f is an interface corresponding to the MethodCall.Arguments values

func (*MethodChannel) HandleSync

func (m *MethodChannel) HandleSync(methodName string, handler MethodHandler)

HandleSync is like Handle, but messages for given method are handled synchronously.

func (*MethodChannel) InvokeMethod

func (m *MethodChannel) InvokeMethod(name string, arguments interface{}) error

InvokeMethod sends a methodcall to the binary messenger without waiting for a reply.

func (*MethodChannel) InvokeMethodWithReply

func (m *MethodChannel) InvokeMethodWithReply(name string, arguments interface{}) (result interface{}, err error)

InvokeMethodWithReply sends a methodcall to the binary messenger and wait for a reply.

NOTE: If no value are returned by the handler setted in the setMethodCallHandler flutter method, the function will wait forever. In case you don't want to wait for reply, use InvokeMethod or launch the function in a goroutine.

type MethodCodec

type MethodCodec interface {
	// EncodeMethodCall encodes the MethodCall into binary
	// Returns an error on invalid MethodCall arguments.
	EncodeMethodCall(methodCall MethodCall) (data []byte, err error)

	// DecodeMethodCal decodes the MethodCall from binary.
	// Returns an error on invalid data.
	DecodeMethodCall(data []byte) (methodCall MethodCall, err error)

	/// Encodes a successful [result] into a binary envelope.
	EncodeSuccessEnvelope(result interface{}) (data []byte, err error)

	// EncodeErrorEnvelope encodes an error result into a binary envelope.
	// The specified error code, human-readable error message, and error
	// details correspond to the fields of Flutter's PlatformException.
	EncodeErrorEnvelope(code string, message string, details interface{}) (data []byte, err error)

	// DecodeEnvelope decodes the specified result [envelope] from binary.
	// Returns a FlutterError as error if provided envelope represents an error,
	// otherwise returns the enveloped result.
	DecodeEnvelope(envelope []byte) (result interface{}, err error)
}

MethodCodec describes a codec for method calls and enveloped results.

type MethodHandler

type MethodHandler interface {
	// HandleMethod is called whenever an incoming
	HandleMethod(arguments interface{}) (reply interface{}, err error)
}

MethodHandler defines the interface for a method handler.

type MethodHandlerFunc

type MethodHandlerFunc func(arguments interface{}) (reply interface{}, err error)

The MethodHandlerFunc type is an adapter to allow the use of ordinary functions as method handlers. If f is a function with the appropriate signature, MethodHandlerFunc(f) is a MethodHandler that calls f.

func (MethodHandlerFunc) HandleMethod

func (f MethodHandlerFunc) HandleMethod(arguments interface{}) (reply interface{}, err error)

HandleMethod calls f(arguments).

type ResponseSender

type ResponseSender interface {
	// Send may return before the message was passed to the flutter side.
	Send(binaryReply []byte)
}

ResponseSender defines the interface that must be implemented by a messenger to handle replies on on message. It is an error to call Send multiple times on the same ResponseSender.

type StandardMessageCodec

type StandardMessageCodec struct{}

StandardMessageCodec implements a MessageCodec using the Flutter standard binary encoding.

This codec tries to stay compatible with the corresponding StandardMessageCodec on the Dart side. See: https://docs.flutter.io/flutter/services/StandardMessageCodec-class.html

Supported messages are acyclic values of these forms:

nil
bool
byte
int32, int64
float64
*big.Int
string
[]byte, []int32, []int64, []float64
[]interface{} of supported values
map[interface{}]interface{} with supported keys and values

On the Dart side, these values are represented as follows:

null: null
bool: bool
byte, int8, int16, int32, int64: int
float32, float64: double
string: String
[]byte: Uint8List
[]int32: Int32List
[]int64: Int64List
[]float64: Float64List
[]interface{}: List
map[interface{}]interface{}: Map

*big.Int's are represented in Dart as strings with the hexadecimal representation of the integer's value.

func (StandardMessageCodec) DecodeMessage

func (s StandardMessageCodec) DecodeMessage(data []byte) (message interface{}, err error)

DecodeMessage decodes binary data into a standard message

func (StandardMessageCodec) EncodeMessage

func (s StandardMessageCodec) EncodeMessage(message interface{}) ([]byte, error)

EncodeMessage encodes message to bytes using the Flutter standard message encoding. message is expected to be comprised of supported types. See `type StandardMessageCodec`.

type StandardMethodCodec

type StandardMethodCodec struct {
	// contains filtered or unexported fields
}

StandardMethodCodec implements a MethodCodec using the Flutter standard binary encoding.

This codec tries to stay compatible with the corresponding StandardMethodCodec on the Dart side. See https://docs.flutter.io/flutter/services/StandardMethodCodec-class.html

Values supported as method arguments and result payloads are those supported by StandardMessageCodec.

func (StandardMethodCodec) DecodeEnvelope

func (s StandardMethodCodec) DecodeEnvelope(envelope []byte) (result interface{}, err error)

DecodeEnvelope fulfils the MethodCodec interface.

func (StandardMethodCodec) DecodeMethodCall

func (s StandardMethodCodec) DecodeMethodCall(data []byte) (methodCall MethodCall, err error)

DecodeMethodCall fulfils the MethodCodec interface.

func (StandardMethodCodec) EncodeErrorEnvelope

func (s StandardMethodCodec) EncodeErrorEnvelope(code string, message string, details interface{}) (data []byte, err error)

EncodeErrorEnvelope fulfils the MethodCodec interface.

func (StandardMethodCodec) EncodeMethodCall

func (s StandardMethodCodec) EncodeMethodCall(methodCall MethodCall) (data []byte, err error)

EncodeMethodCall fulfils the MethodCodec interface.

func (StandardMethodCodec) EncodeSuccessEnvelope

func (s StandardMethodCodec) EncodeSuccessEnvelope(result interface{}) (data []byte, err error)

EncodeSuccessEnvelope fulfils the MethodCodec interface.

type StreamHandler

type StreamHandler interface {
	// OnListen handles a request to set up an event stream.
	OnListen(arguments interface{}, sink *EventSink)
	// OnCancel handles a request to tear down the most recently created event
	// stream.
	OnCancel(arguments interface{})
}

StreamHandler defines the interface for a stream handler setup and tear-down requests.

type StringCodec

type StringCodec struct{}

StringCodec implements a MessageCodec using UTF-8 encoded string messages.

func (StringCodec) DecodeMessage

func (StringCodec) DecodeMessage(data []byte) (message interface{}, err error)

DecodeMessage decodes binary data into a string message.

func (StringCodec) EncodeMessage

func (StringCodec) EncodeMessage(message interface{}) ([]byte, error)

EncodeMessage expects message to be a string.

Jump to

Keyboard shortcuts

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