fields

package
v0.0.0-...-9a529fd Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2017 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunUnsafeCode

func RunUnsafeCode(vm *otto.Otto, code string, timeOut time.Duration) (value otto.Value, err error)

Types

type Adapter

type Adapter interface {
	core.AppClient
	Storage() AppStorage
	SubscribeDownlink(handler core.HandlerServer) error
}

Adapter represents the interface of an application

func NewAdapter

func NewAdapter(ctx log.Interface, storage AppStorage, next mqtt.Adapter) Adapter

NewAdapter returns a new adapter that processes binary payload to fields

type AppStorage

type AppStorage interface {
	SetFunctions(eui types.AppEUI, functions *Functions) error
	GetFunctions(eui types.AppEUI) (*Functions, error)
	Reset() error
	Close() error
}

AppStorage provides storage for applications

func ConnectRedis

func ConnectRedis(addr string, db int64) (AppStorage, error)

ConnectRedis connects to Redis using the specified options

type Functions

type Functions struct {
	// Decoder is a JavaScript function that accepts the payload as byte array and
	// returns an object containing the decoded values
	Decoder string
	// Converter is a JavaScript function that accepts the data as decoded by
	// Decoder and returns an object containing the converted values
	Converter string
	// Validator is a JavaScript function that validates the data is converted by
	// Converter and returns a boolean value indicating the validity of the data
	Validator string
}

Functions decodes, converts and validates payload using JavaScript functions

func (*Functions) Convert

func (f *Functions) Convert(data map[string]interface{}) (map[string]interface{}, error)

Convert converts the values in the specified map to a another map using the Converter function. If the Converter function is not set, this function returns the data as-is

func (*Functions) Decode

func (f *Functions) Decode(payload []byte) (map[string]interface{}, error)

Decode decodes the payload using the Decoder function into a map

func (*Functions) Process

func (f *Functions) Process(payload []byte) (map[string]interface{}, bool, error)

Process decodes the specified payload, converts it and test the validity

func (*Functions) Validate

func (f *Functions) Validate(data map[string]interface{}) (bool, error)

Validate validates the values in the specified map using the Validator function. If the Validator function is not set, this function returns true

Jump to

Keyboard shortcuts

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