binary

package
v0.0.0-...-54cfa85 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package binary provide functionality for encoding Go types into OPC UA binary representation as defined by [IEC-62541](https://webstore.iec.ch/webstore/webstore.nsf/mysearchajax?Openform&key=62541). Encode and decode functionality only aims to fully handle types that are defined in the uatype package, and can not be expected to handle all Go types. As an example, int and uint types without a bit size suffix are deliberately not handled.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidBitLength = errors.New("bit length not in range 1-8")
	ErrInvalidLength    = errors.New("length don't match length field value")
	ErrInvalidTag       = errors.New("invalid struct tag")
	ErrNotSetable       = errors.New("value must be a pointer")
	ErrUnknownType      = errors.New("can not handle type")
)

Common errors that may be returned as the cause for EncoderError and DecoderError.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal encodes v into the OPC UA Binary Encoding format, and returns it as a slice of bytes.

func SetDebugLogger

func SetDebugLogger(l guma.Logger)

SetDebugLogger sets a debug logger for this package.

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal parses the OPC UA binary encoded data into the value pointed to by v.

Types

type BitLengther

type BitLengther interface {
	BitLength() int
}

BitLengther is implemented by types that should be encoded into, or has been decoded from, a certain number of bits.

type Decoder

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

A Decoder reads and decodes OPC UA Binary content from an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder initializes a Decoder for r.

func (Decoder) BytesRead

func (dec Decoder) BytesRead() int

BytesRead return the number of bytes read since initialization.

func (*Decoder) Decode

func (dec *Decoder) Decode(v interface{}) (err error)

Decode reads the next OPC UA binary encoded value from it's input stream and stores it in the value pointed to by v.

type DecoderError

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

DecoderError provides a way of getting the logical path to where in a nested data structure a decoder error occurred.

func (DecoderError) Cause

func (err DecoderError) Cause() error

Cause returns the original error.

func (DecoderError) Error

func (err DecoderError) Error() string

Error returns a human readable description of the error.

func (DecoderError) Path

func (err DecoderError) Path() []interface{}

Path returns the error path.

type Encoder

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

An Encoder writes OPC UA Binary content to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder takes a writer object where OPC UA data will be written on calls to Encode.

func (*Encoder) BytesWritten

func (enc *Encoder) BytesWritten() int64

BytesWritten returns the number of bytes written since the BinaryEncoder was initialized.

func (*Encoder) Encode

func (enc *Encoder) Encode(v interface{}) (err error)

Encode encodes uatype structs into a binary representation used for transfer.

type EncoderError

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

EncoderError provides a way of getting the logical path to where in a nested data structure an encoder error occurred.

func (EncoderError) Cause

func (err EncoderError) Cause() error

Cause returns the original error.

func (EncoderError) Error

func (err EncoderError) Error() string

Error returns a human readable description of the error.

func (EncoderError) Path

func (err EncoderError) Path() []interface{}

Path returns the error path.

Jump to

Keyboard shortcuts

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