plugin

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2019 License: BSD-3-Clause Imports: 11 Imported by: 46

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 in active development. API's must be considered alpha/unstable and may be changed at any time.

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, name string, codec MessageCodec) *BasicMessageChannel

NewBasicMessageChannel creates a BasicMessageChannel.

Call Handle or HandleFunc on the returned BasicMessageChannel to provide the channel with a handler for incomming 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{}) (reply interface{}, err error)

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

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 {
	// Send sends a binary message to the Flutter application.
	Send(channel string, binaryMessage []byte) (binaryReply []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) (binaryReply []byte, err error)

ChannelHandlerFunc describes the function that handles binary messages sent on a channel.

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) Handle

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

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, 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.

func (*MethodChannel) HandleFunc

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

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

func (*MethodChannel) InvokeMethod

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

InvokeMethod sends a methodcall to the binary messenger and waits for a result.

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 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 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