net

package
v0.0.0-...-505b8b1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: Apache-2.0, EPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package net provides the Zenoh-net API in Go.

Index

Constants

View Source
const (
	// InfoPidKey is the key for the PID value in the properties
	// map returned by the Info() operation.
	InfoPidKey = C.ZN_INFO_PID_KEY

	// InfoPeerKey is the key for the peer value in the properties
	// map returned by the Info() operation.
	InfoPeerKey = C.ZN_INFO_PEER_KEY

	// InfoPeerPidKey is the key for the peer's PID value in the properties
	// map returned by the Info() operation.
	InfoPeerPidKey = C.ZN_INFO_PEER_PID_KEY

	// UserKey is the key for the (optional) user's name in the properties
	// map passed to the Login() operation.
	UserKey = C.ZN_USER_KEY

	// PasswdKey is the key for the (optional) user's password in the properties
	// map passed to the Login() operation.
	PasswdKey = C.ZN_PASSWD_KEY
)

Variables

This section is empty.

Functions

func RNameIntersect

func RNameIntersect(rname1 string, rname2 string) bool

RNameIntersect returns true if the resource name 'rname1' intersects with the resource name 'rname2'.

Types

type DataHandler

type DataHandler func(rname string, data []byte, info *DataInfo)

DataHandler will be called on reception of data matching the subscribed/stored resource. 'ranme' is the resource name of the received data. 'data' is the received data. 'info' is the DataInfo associated with the received data.

type DataInfo

type DataInfo = C.zn_data_info_t

DataInfo contains meta informations about the associated data.

func (*DataInfo) Encoding

func (info *DataInfo) Encoding() uint8

Encoding returns the encoding of the data.

func (*DataInfo) Kind

func (info *DataInfo) Kind() uint8

Kind returns the kind of the data.

func (*DataInfo) Tstamp

func (info *DataInfo) Tstamp() *Timestamp

Tstamp returns the unique timestamp at which the data has been produced

type Eval

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

Eval is a Zenoh eval

type Publisher

type Publisher = C.zn_pub_t

Publisher is a Zenoh publisher

func (*Publisher) StreamCompactData

func (p *Publisher) StreamCompactData(payload []byte) error

StreamCompactData sends data in a 'compact_data' message for the resource published by publisher 'p'. 'payload' is the data to be sent.

func (*Publisher) StreamData

func (p *Publisher) StreamData(payload []byte) error

StreamData sends data in a 'stream_data' message for the resource published by publisher 'p'. 'payload' is the data to be sent.

func (*Publisher) StreamDataWO

func (p *Publisher) StreamDataWO(payload []byte, encoding uint8, kind uint8) error

StreamDataWO sends data in a 'stream_data' message for the resource published by publisher 'p'. 'payload' is the data to be sent. 'encoding' is a metadata information associated with the published data that represents the encoding of the published data. 'kind' is a metadata information associated with the published data that represents the kind of publication.

type QueryDest

type QueryDest = C.zn_query_dest_t

QueryDest is a data structure defining which storages or evals should be destination of a query (see Session.QueryWO())

func NewQueryDest

func NewQueryDest(kind QueryDestKind) QueryDest

NewQueryDest returns a QueryDest with the specified kind

func NewQueryDestWithNb

func NewQueryDestWithNb(kind QueryDestKind, nb C.uint8_t) QueryDest

NewQueryDestWithNb returns a QueryDest with the specified kind and nb

type QueryDestKind

type QueryDestKind = C.uint8_t

QueryDestKind is the kind of a Query destination

const (
	// ZNBestMatch : the nearest complete storage/eval if there is one, all storages/evals if not.
	ZNBestMatch QueryDestKind = iota
	// ZNComplete : only complete storages/evals.
	ZNComplete QueryDestKind = iota
	// ZNAll : all storages/evals.
	ZNAll QueryDestKind = iota
	// ZNNone : no storages/evals.
	ZNNone QueryDestKind = iota
)

type QueryHandler

type QueryHandler func(rname string, predicate string, sendReplies *RepliesSender)

QueryHandler will be called on reception of query matching the stored/evaluated resource selection. The QueryHandler must provide the data matching the resource 'rname' by calling the 'sendReplies' function of the 'RepliesSender'. The 'sendReplies' function MUST be called but accepts empty data array. 'rname' is the resource name of the queried data. 'predicate' is a string provided by the querier refining the data to be provided. 'sendReplies' is a RepliesSender on which the 'sendReplies()' function MUST be called with the provided data as argument.

type RepliesSender

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

RepliesSender is used in a storage's and eval's QueryHandler() implementation to send back replies to a query.

func (*RepliesSender) SendReplies

func (rs *RepliesSender) SendReplies(replies []Resource)

SendReplies sends the replies to a query in a storage or eval. This operation should be called in the implementation of a QueryHandler

type ReplyHandler

type ReplyHandler func(reply *ReplyValue)

ReplyHandler is a function to pass as argument to 'Session.Query()' or 'Session.QueryWO()'. It will be called on reception of replies to the query sent by 'Session.Query()' or 'Session.QueryWO()'. 'reply' is the actual reply.

type ReplyKind

type ReplyKind = C.char

ReplyKind is the kind of a ReplyValue

const (
	// ZNStorageData : a reply with data from a storage
	ZNStorageData ReplyKind = iota
	// ZNStorageFinal : a final reply from a storage (without data)
	ZNStorageFinal ReplyKind = iota
	// ZNEvalData : a reply with data from an eval
	ZNEvalData ReplyKind = iota
	// ZNEvalFinal : a final reply from an eval (without data)
	ZNEvalFinal ReplyKind = iota
	// ZNReplyFinal : the final reply (without data)
	ZNReplyFinal ReplyKind = iota
)

type ReplyValue

type ReplyValue = C.zn_reply_value_t

ReplyValue is a data structure containing one of the replies to a query (see ReplyHandler).

func (*ReplyValue) Data

func (r *ReplyValue) Data() []byte

Data returns the received data when Kind() equals ZNStorageData or ZNEvalData. Otherwise, it returns null

func (*ReplyValue) Info

func (r *ReplyValue) Info() DataInfo

Info returns some meta information about the received data when Kind() equals ZNStorageData or ZNEvalData.

func (*ReplyValue) Kind

func (r *ReplyValue) Kind() ReplyKind

Kind returns the Reply message kind. It can be one of the following: ZNStorageData, ZNStorageFinal, ZNEvalData, ZNEvalFinal or ZNReplyFinal.

func (*ReplyValue) RName

func (r *ReplyValue) RName() string

RName returns the resource name of the received data when Kind() equals ZNStorageData or ZNEvalData

func (*ReplyValue) RSN

func (r *ReplyValue) RSN() uint64

RSN returns the sequence number of the reply from the identified storage or eval when Kind() equals ZNStorageData, ZNStorageFinal, ZNEvalData or ZNEvalFinal

func (*ReplyValue) SrcID

func (r *ReplyValue) SrcID() []byte

SrcID returns the unique identifier of the storage or eval that sent the reply when Kind() equals ZNStorageData, ZNStorageFinal, ZNEvalData or ZNEvalFinal

type Resource

type Resource struct {
	RName    string
	Data     []byte
	Encoding uint8
	Kind     uint8
}

Resource is a Zenoh resource with a name and a value (data).

type Session

type Session = C.zn_session_t

Session is the C session type

func Open

func Open(locator *string, properties map[int][]byte) (*Session, error)

Open opens a zenoh-net session. 'locator' is a pointer to a string representing the network endpoint to which establish the session. A typical locator looks like this : "tcp/127.0.0.1:7447".

If 'locator' is "nil", 'open' will scout and try to establish the session automatically.

'properties' is a map of properties that will be used to establish and configure the zenoh session.

'properties' will typically contain the username and password informations needed to establish the zenoh session with a secured infrastructure.
It can be set to "nil".

Return a handle to the zenoh session.

func (*Session) Close

func (s *Session) Close() error

Close the zenoh-net session 'z'.

func (*Session) DeclareEval

func (s *Session) DeclareEval(resource string, handler QueryHandler) (*Eval, error)

DeclareEval declares an eval able to provide data matching the provided resource name 'resource'. 'resource' is the resource to evaluate. 'handler' is the callback function that will be called each time a query for data matching the evaluated resource name 'resource' is received. The 'handler' function MUST call the provided 'sendReplies' function with the resulting data. 'sendReplies'can be called with an empty array. Return a zenoh-net eval.

func (*Session) DeclarePublisher

func (s *Session) DeclarePublisher(resource string) (*Publisher, error)

DeclarePublisher declares a publication for resource name 'resource'. 'resource' is the resource name to publish. Return a zenoh publisher.

func (*Session) DeclareStorage

func (s *Session) DeclareStorage(resource string, dataHandler DataHandler, queryHandler QueryHandler) (*Storage, error)

DeclareStorage declares a storage for all data matching the provided resource name 'resource'. 'resource' is the resource selection to store. 'dataHandler' is the callback function that will be called each time a data matching the stored resource name 'resource' is received. 'queryHandler' is the callback function that will be called each time a query for data matching the stored resource name 'resource' is received. The 'queryHandler' function MUST call the provided 'RepliesSender.SendReplies()' function with the resulting data. 'RepliesSender.SendReplies()' can be called with an empty array. Return a zenoh storage.

func (*Session) DeclareSubscriber

func (s *Session) DeclareSubscriber(resource string, mode SubMode, dataHandler DataHandler) (*Subscriber, error)

DeclareSubscriber declares a subscription for all published data matching the provided resource name 'resource'. 'resource' is the resource name to subscribe to. 'mode' is the subscription mode. 'dataHandler' is the callback function that will be called each time a data matching the subscribed resource name 'resource' is received. Return a zenoh subscriber.

func (*Session) Info

func (s *Session) Info() map[int][]byte

Info returns a map of properties containing various informations about the established zenoh-net session.

func (*Session) Query

func (s *Session) Query(resource string, predicate string, replyHandler ReplyHandler) error

Query queries data matching resource name 'resource'. 'resource' is the resource to query. 'predicate' is a string that will be propagated to the storages and evals that should provide the queried data. It may allow them to filter, transform and/or compute the queried data. 'replyHandler' is the callback function that will be called on reception of the replies of the query.

func (*Session) QueryWO

func (s *Session) QueryWO(resource string, predicate string, replyHandler ReplyHandler, destStorages QueryDest, destEvals QueryDest) error

QueryWO queries data matching resource name 'resource'. 'resource' is the resource to query. 'predicate' is a string that will be propagated to the storages and evals that should provide the queried data. It may allow them to filter, transform and/or compute the queried data. 'replyHandler' is the callback function that will be called on reception of the replies of the query. 'destStorages' indicates which matching storages should be destination of the query. 'destEvals' indicates which matching evals should be destination of the query.

func (*Session) UndeclareEval

func (s *Session) UndeclareEval(e *Eval) error

UndeclareEval undeclares the eval 'e'.

func (*Session) UndeclarePublisher

func (s *Session) UndeclarePublisher(p *Publisher) error

UndeclarePublisher undeclares the publication 'p'.

func (*Session) UndeclareStorage

func (s *Session) UndeclareStorage(sto *Storage) error

UndeclareStorage undeclares the storage 's'.

func (*Session) UndeclareSubscriber

func (s *Session) UndeclareSubscriber(sub *Subscriber) error

UndeclareSubscriber undeclares the subscription 's'.

func (*Session) WriteData

func (s *Session) WriteData(resource string, payload []byte) error

WriteData sends data in a 'write_data' message for the resource 'resource'. 'resource' is the resource name of the data to be sent. 'payload' is the data to be sent.

func (*Session) WriteDataWO

func (s *Session) WriteDataWO(resource string, payload []byte, encoding uint8, kind uint8) error

WriteDataWO sends data in a 'write_data' message for the resource 'resource'. 'resource' is the resource name of the data to be sent. 'payload' is the data to be sent. 'encoding' is a metadata information associated with the published data that represents the encoding of the published data. 'kind' is a metadata information associated with the published data that represents the kind of publication.

type Storage

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

Storage is a Zenoh storage

type SubMode

type SubMode = C.zn_sub_mode_t

SubMode is a Subscriber mode

func NewSubMode

func NewSubMode(kind SubModeKind) SubMode

NewSubMode returns a SubMode with the specified kind

func NewSubModeWithTime

func NewSubModeWithTime(kind SubModeKind, origin C.ulong, period C.ulong, duration C.ulong) SubMode

NewSubModeWithTime returns a SubMode with the specified kind and temporal properties

type SubModeKind

type SubModeKind = C.uint8_t

SubModeKind is the kind of a Subscriber mode

const (
	// ZNPushMode : push mode for subscriber
	ZNPushMode SubModeKind = iota + 1
	// ZNPullMode : pull mode for subscriber
	ZNPullMode SubModeKind = iota + 1
	// ZNPeriodicPushMode : periodic push mode for subscriber
	ZNPeriodicPushMode SubModeKind = iota + 1
	// ZNPeriodicPullMode : periodic pull mode for subscriber
	ZNPeriodicPullMode SubModeKind = iota + 1
)

type Subscriber

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

Subscriber is a Zenoh subscriber

func (*Subscriber) Pull

func (s *Subscriber) Pull() error

Pull data for the `ZPullMode` or `ZPeriodicPullMode` subscription 's'. The pulled data will be provided by calling the 'dataHandler' function provided to the `DeclareSubscriber` function.

type Timestamp

type Timestamp = zcore.Timestamp

Timestamp is data structure representing a unique timestamp.

type ZError

type ZError = zcore.ZError

ZError reports an error that occurred in zenoh.

Jump to

Keyboard shortcuts

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