types

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MulanPSL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Contract:

1. Nil

<obj href="obix:Nil" null="true"/>

2. Range

<list href="/enums/OffSlowFast" is="obix:Range">
	<obj name="off" displayName="Off"/>
	<obj name="slow" displayName="Slow Speed"/>
	<obj name="fast" displayName="Fast Speed"/>
</list>

<list href="/enums/OnOff" is="obix:Range">
	<obj name="true" displayName="On"/>
	<obj name="false" displayName="Off"/>
</list>

3. Weekday

<enum href="obix:Weekday" range="#Range">
	<list href="#Range" is="obix:Range">
		<obj name="sunday" />
		<obj name="monday" />
		<obj name="tuesday" />
		<obj name="wednesday" />
		<obj name="thursday" />
		<obj name="friday" />
		<obj name="saturday" />
	</list>
</enum>

4. Month

<enum href="obix:Month" range="#Range">
	<list href="#Range" is="obix:Range">
		<obj name="january" />
		<obj name="febuary" />
		<obj name="march" />
		<obj name="april" />
		<obj name="may" />
		<obj name="june" />
		<obj name="july" />
		<obj name="august" />
		<obj name="september" />
		<obj name="october" />
		<obj name="november" />
		<obj name="december" />
	</list>
</enum>

Index

Constants

View Source
const (
	// xml 标准头
	XMLHeader = `<?xml version="1.0" encoding="UTF-8"?>` + "\n"
	// obix 头
	XMLStylesheet = `<?xml-stylesheet type='text/xsl' href='/obix/xsl'?>` + "\n"
	// 命名空间
	XMLNamespace = `http://obix.org/ns/schema/1.0`
)
View Source
const (
	Nanosecond  Reltime = 1
	Microsecond         = 1000 * Nanosecond
	Millisecond         = 1000 * Microsecond
	Second              = 1000 * Millisecond
	Minute              = 60 * Second
	Hour                = 60 * Minute
	Day                 = 24 * Hour
)

Variables

View Source
var (
	StatusDisabled     = Status("disabled")
	StatusFault        = Status("fault")
	StatusDown         = Status("down")
	StatusUnackedAlerm = Status("unackedAlerm")
	StatusAlarm        = Status("alarm")
	StatusUnacked      = Status("unacked")
	StatusOverridden   = Status("overridden")
	StatusOk           = Status("ok")
	StatusUnknown      = Status("unknown")
)

Functions

This section is empty.

Types

type AbsTime

type AbsTime struct {

	// the lexical space for abstime: '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)
	Val string `xml:"val,attr"`
	Min int64  `xml:"min,attr,omitempty" json:",omitempty"`
	Max int64  `xml:"max,attr,omitempty" json:",omitempty"`
	Tz  string `xml:"tz,attr" json:",omitempty"`

	*Object `xml:",omitempty"`
}

AbsTime 时间

type Bool

type Bool struct {
	Val   bool   `xml:"val,attr"`
	Range string `xml:"range,attr,omitempty" json:",omitempty"`

	*Object `xml:",omitempty"`
}

Bool 布尔值

type Date

type Date struct {

	// the lexical space for date is: '-'? yyyy '-' mm '-' dd
	Val string `xml:"val,attr"`
	// Min is date
	// XMLGregorianCalendar
	Min string `xml:"min,attr,omitempty" json:",omitempty"`
	// Max is date
	Max string `xml:"max,attr,omitempty" json:",omitempty"`
	Tz  string `xml:"tz,attr" json:",omitempty"`

	*Object `xml:",omitempty"`
}

Date 日期

type Enum

type Enum struct {
	Val   string `xml:"val,attr,omitempty"`
	Range string `xml:"range,attr,omitempty" json:",omitempty"`

	*Object `xml:",omitempty"`
}

Enum 枚举值

type Err

type Err struct {
	*Object `xml:",omitempty"`
}

func (*Err) Error added in v1.0.0

func (e *Err) Error() string

type Feed

type Feed struct {
	In string `xml:"in,attr,omitempty" json:",omitempty"`
	Of string `xml:"of,attr,omitempty"`

	*Object `xml:",omitempty"`
}

type Int

type Int struct {
	// XMLName xml.Name `xml:"int"`
	// obix定义为BigInteger
	Val  int64  `xml:"val,attr,omitempty"`
	Unit string `xml:"unit,attr,omitempty" json:",omitempty"`
	Min  string `xml:"min,attr,omitempty" json:",omitempty"`
	// Max is date
	Max string `xml:"max,attr,omitempty" json:",omitempty"`

	*Object `xml:",omitempty"`
}

Int 整数

type List

type List struct {
	Of  string `xml:"of,attr,omitempty"`
	Min int    `xml:"min,attr,omitempty" json:",omitempty"`
	Max int    `xml:"max,attr,omitempty" json:",omitempty"`

	*Object `xml:",omitempty"`
}

List order objGroup

type Obj

type Obj struct {
	XMLName xml.Name   `json:"-"`
	Type    ObjectType `xml:"-" `
	// Object的具体类型包含:
	//	- Object
	//	- Bool
	//	- Str
	//	- Ref
	//	- Real
	//	- RelTime
	//	- AbsTime
	//	- Date
	//	- Err
	//	- Feed
	//	- List
	//	- Uri
	//	- Op
	//	- Int
	//	- Enum
	//	- Time
	Object XMLObject `xml:"-"`
}

Obj 是和服务器交互时进行 XML 序列化和反序列化使用的数据类型 每个点位返回的结果对应着一个数据类型, 可以使用Obj.AssertXxx进行断言 如: AssertBool/AssertErr

func NewObj added in v0.0.8

func NewObj(typ ObjectType, v XMLObject, opts ...ObjOptions) *Obj

NewObj 创建新的Obj, 在发送数据时, 使用该函数可以生成符合xml序列化的的数据类型 typ指定的类型应当和v是同一个类型, 但实现上并没有判断 opts参数目前可以指定xml命名空间, 如: WithNamespace(XMLNamespace)

func (*Obj) AssertAbsTime added in v1.0.0

func (o *Obj) AssertAbsTime() *AbsTime

AssertAbsTime 断言AbsTime

func (*Obj) AssertBool added in v1.0.0

func (o *Obj) AssertBool() *Bool

AssertBool 断言Bool

func (*Obj) AssertDate added in v1.0.0

func (o *Obj) AssertDate() *Date

AssertBool 断言Bool

func (*Obj) AssertEnum added in v1.0.0

func (o *Obj) AssertEnum() *Enum

AssertEnum 断言Enum

func (*Obj) AssertErr added in v1.0.0

func (o *Obj) AssertErr() *Err

AssertBool 断言Bool

func (*Obj) AssertFeed added in v1.0.0

func (o *Obj) AssertFeed() *Feed

AssertFeed 断言Feed

func (*Obj) AssertInt added in v1.0.0

func (o *Obj) AssertInt() *Int

AssertInt 断言Int

func (*Obj) AssertList added in v1.0.0

func (o *Obj) AssertList() *List

AssertList 断言List

func (*Obj) AssertObject added in v1.0.0

func (o *Obj) AssertObject() *Object

AssertObject 断言Object

func (*Obj) AssertOp added in v1.0.0

func (o *Obj) AssertOp() *Op

AssertOp 断言Op

func (*Obj) AssertReal added in v1.0.0

func (o *Obj) AssertReal() *Real

AssertReal 断言Real

func (*Obj) AssertRef added in v1.0.0

func (o *Obj) AssertRef() *Ref

AssertRef 断言Ref

func (*Obj) AssertRelTime added in v1.0.0

func (o *Obj) AssertRelTime() *RelTime

AssertRelTime 断言RelTime

func (*Obj) AssertStr added in v1.0.0

func (o *Obj) AssertStr() *Str

AssertStr 断言Str

func (*Obj) AssertTime added in v1.0.0

func (o *Obj) AssertTime() *Time

AssertTime 断言Time

func (*Obj) AssertUri added in v1.0.0

func (o *Obj) AssertUri() *Uri

AssertUri 断言Uri

func (*Obj) IsErr added in v0.0.8

func (o *Obj) IsErr() bool

func (Obj) MarshalXML added in v0.0.8

func (o Obj) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML 实现xml序列化

func (*Obj) UnmarshalXML added in v0.0.8

func (o *Obj) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML 实现xml反序列化

type ObjOptions added in v0.0.8

type ObjOptions func(*Obj)

func WithNamespace added in v0.0.8

func WithNamespace(s string) ObjOptions

type Object added in v0.0.8

type Object struct {
	XMLName xml.Name `json:"-"`
	// Xmlns             string `xml:"xmlns,attr,omitempty"`
	XsiSchemaLocation string `xml:"xsi:schemaLocation,attr,omitempty" json:",omitempty"`
	XmlnsXsi          string `xml:"xmlns:xsi,attr,omitempty" json:",omitempty"`
	SchemaLocation    string `xml:"schemaLocation,attr,omitempty" json:",omitempty"`
	Xsi               string `xml:"xsi,attr,omitempty" json:",omitempty"`
	Name              string `xml:"name,attr,omitempty" json:",omitempty"`
	// Href is URI
	Href string `xml:"href,attr,omitempty" json:",omitempty"`
	Is   string `xml:"is,attr,omitempty" json:",omitempty"`
	// Icon is URI
	Icon        string `xml:"icon,attr,omitempty" json:",omitempty"`
	Display     string `xml:"display,attr,omitempty" json:",omitempty"`
	DisplayName string `xml:"displayName,attr,omitempty" json:",omitempty"`
	Status      string `xml:"status,attr,omitempty" json:",omitempty"`
	Writable    bool   `xml:"writable,attr,omitempty" json:",omitempty"`
	Null        bool   `xml:"null,attr,omitempty" json:",omitempty"`

	// 子元素list
	Objects  []*Object  `xml:"obj,omitempty" json:",omitempty"`
	AbsTimes []*AbsTime `xml:"abstime,omitempty" json:",omitempty"`
	Bools    []*Bool    `xml:"bool,omitempty" json:",omitempty"`
	Dates    []*Date    `xml:"date,omitempty" json:",omitempty"`
	Enums    []*Enum    `xml:"enum,omitempty" json:",omitempty"`
	Errs     []*Err     `xml:"err,omitempty" json:",omitempty"`
	Feeds    []*Feed    `xml:"feed,omitempty" json:",omitempty"`
	Ints     []*Int     `xml:"int,omitempty" json:",omitempty"`
	Lists    []*List    `xml:"list,omitempty" json:",omitempty"`
	Ops      []*Op      `xml:"op,omitempty" json:",omitempty"`
	Reals    []*Real    `xml:"real,omitempty" json:",omitempty"`
	Refs     []*Ref     `xml:"ref,omitempty" json:",omitempty"`
	RelTimes []*RelTime `xml:"reltime,omitempty" json:",omitempty"`
	Strs     []*Str     `xml:"str,omitempty" json:",omitempty"`
	Uris     []*Uri     `xml:"uri,omitempty" json:",omitempty"`
	Times    []*Time    `xml:"time,omitempty" json:",omitempty"`
}

Object obix的对象基类, 一般不直接使用, 而是使用 Bool, Str etc...

func (*Object) GetAbsTime added in v0.0.8

func (o *Object) GetAbsTime(name string) *AbsTime

GetAbsTime 获取子元素中指定的AbsTime

func (*Object) GetBool added in v0.0.8

func (o *Object) GetBool(name string) *Bool

GetBool 获取子元素中指定的Bool

func (*Object) GetDate added in v0.0.8

func (o *Object) GetDate(name string) *Date

GetDate 获取子元素中指定的Date

func (*Object) GetEnum added in v0.0.8

func (o *Object) GetEnum(name string) *Enum

GetEnum 获取子元素中指定的Enum

func (*Object) GetErr added in v0.0.8

func (o *Object) GetErr(name string) *Err

GetErr 获取子元素中指定的Err

func (*Object) GetFeed added in v0.0.8

func (o *Object) GetFeed(name string) *Feed

GetFeed 获取子元素中指定的Feed

func (*Object) GetInt added in v0.0.8

func (o *Object) GetInt(name string) *Int

GetInt 获取子元素中指定的Int

func (*Object) GetList added in v0.0.8

func (o *Object) GetList(name string) *List

GetList 获取子元素中指定的List

func (*Object) GetObject added in v0.0.8

func (o *Object) GetObject(name string) *Object

GetObject 获取子元素中指定的Object

func (*Object) GetOp added in v0.0.8

func (o *Object) GetOp(name string) *Op

GetOp 获取子元素中指定的Op

func (*Object) GetReal added in v0.0.8

func (o *Object) GetReal(name string) *Real

GetReal 获取子元素中指定的Real

func (*Object) GetRef added in v0.0.8

func (o *Object) GetRef(name string) *Ref

GetRef 获取子元素中指定的Ref

func (*Object) GetRelTime added in v0.0.8

func (o *Object) GetRelTime(name string) *RelTime

GetRelTime 获取子元素中指定的Reltime

func (*Object) GetStr added in v0.0.8

func (o *Object) GetStr(name string) *Str

GetStr 获取子元素中指定的Str

func (*Object) GetTime added in v0.0.8

func (o *Object) GetTime(name string) *Time

GetTime 获取子元素中指定的Time

func (*Object) GetUri added in v0.0.8

func (o *Object) GetUri(name string) *Uri

GetUri 获取子元素中指定的Uri

func (*Object) ReplaceAttr added in v0.0.8

func (o *Object) ReplaceAttr()

ReplaceAttr 替换部分参数以便生成包含命名空间的属性

type ObjectType added in v0.0.8

type ObjectType string

ObjectType 对象类型

const (
	ObjectTypeAbsTime ObjectType = "abstime"
	ObjectTypeBool    ObjectType = "bool"
	ObjectTypeDate    ObjectType = "date"
	ObjectTypeEnum    ObjectType = "enum"
	ObjectTypeErr     ObjectType = "err"
	ObjectTypeFeed    ObjectType = "Feed"
	ObjectTypeInt     ObjectType = "int"
	ObjectTypeList    ObjectType = "list"
	ObjectTypeObj     ObjectType = "obj"
	ObjectTypeOp      ObjectType = "op"
	ObjectTypeReal    ObjectType = "real"
	ObjectTypeRef     ObjectType = "ref"
	ObjectTypeRelTime ObjectType = "reltime"
	ObjectTypeStr     ObjectType = "str"
	ObjectTypeTime    ObjectType = "time"
	ObjectTypeUri     ObjectType = "uri"
)

type Op

type Op struct {
	In  string `xml:"in,attr,omitempty" json:",omitempty"`
	Out string `xml:"out,attr,omitempty" json:",omitempty"`

	*Object `xml:",omitempty"`
}

type Real

type Real struct {
	Val       float64 `xml:"val,attr,omitempty"`
	Unit      string  `xml:"unit,attr,omitempty" json:",omitempty"`
	Min       string  `xml:"min,attr,omitempty" json:",omitempty"`
	Max       string  `xml:"max,attr,omitempty" json:",omitempty"`
	Precision int     `xml:"precision,attr,omitempty" json:",omitempty"`

	*Object `xml:",omitempty"`
}

type Ref

type Ref struct {
	*Object `xml:",omitempty"`
}

type RelTime

type RelTime struct {
	Val string `xml:"val,attr,omitempty"`
	// XMLGregorianCalendar
	Min string `xml:"min,attr,omitempty" json:",omitempty"`
	Max string `xml:"max,attr,omitempty" json:",omitempty"`

	*Object `xml:",omitempty"`
}

RelTime obix data type

type Reltime

type Reltime time.Duration

func ParseReltime

func ParseReltime(s string) (Reltime, error)

ParseReltime parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "P0D", "P2D" or "-P2D". Valid time units are "S", "M", "H", "D". copy from stdlib

func (Reltime) String

func (d Reltime) String() string

String returns a string representing the duration in the form "72h3m0.5s". Leading zero units are omitted. As a special case, durations less than one second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading digit is non-zero. The zero duration formats as 0s.

type Status

type Status string

func (Status) MarshalXML

func (a Status) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Status) UnmarhshalXML

func (a *Status) UnmarhshalXML(d *xml.Decoder, start xml.StartElement) error

type Str

type Str struct {
	// XMLName xml.Name `xml:"str"`
	// Val is URI
	Val string `xml:"val,attr,omitempty"`
	// Min is date
	Min int16 `xml:"min,attr,omitempty" json:",omitempty"`
	// Max is date
	Max int16 `xml:"max,attr,omitempty" json:",omitempty"`

	*Object `xml:",omitempty"`
}

type Time

type Time struct {

	// the lexical space for time: hh ':' mm ':' ss ('.' s+)?
	Val string `xml:"val,attr,omitempty"`
	// Min XMLGregorianCalendar
	Min string `xml:"min,attr,omitempty" json:",omitempty"`
	// Max XMLGregorianCalendar
	Max string `xml:"max,attr,omitempty" json:",omitempty"`
	Tz  string `xml:"tz,attr" json:",omitempty"`

	*Object `xml:",omitempty"`
}

type Uri

type Uri struct {
	// XMLName xml.Name `xml:"uri"`
	// Val is URI
	Val string `xml:"val,attr,omitempty"`

	*Object `xml:",omitempty"`
}

type XMLObject added in v0.0.8

type XMLObject interface {
	// 替换属性方法
	ReplaceAttr()
}

Jump to

Keyboard shortcuts

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