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
- Variables
- type AbsTime
- type Bool
- type Date
- type Enum
- type Err
- type Feed
- type Int
- type List
- type Obj
- func (o *Obj) AssertAbsTime() *AbsTime
- func (o *Obj) AssertBool() *Bool
- func (o *Obj) AssertDate() *Date
- func (o *Obj) AssertEnum() *Enum
- func (o *Obj) AssertErr() *Err
- func (o *Obj) AssertFeed() *Feed
- func (o *Obj) AssertInt() *Int
- func (o *Obj) AssertList() *List
- func (o *Obj) AssertObject() *Object
- func (o *Obj) AssertOp() *Op
- func (o *Obj) AssertReal() *Real
- func (o *Obj) AssertRef() *Ref
- func (o *Obj) AssertRelTime() *RelTime
- func (o *Obj) AssertStr() *Str
- func (o *Obj) AssertTime() *Time
- func (o *Obj) AssertUri() *Uri
- func (o *Obj) IsErr() bool
- func (o Obj) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (o *Obj) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- type ObjOptions
- type Object
- func (o *Object) GetAbsTime(name string) *AbsTime
- func (o *Object) GetBool(name string) *Bool
- func (o *Object) GetDate(name string) *Date
- func (o *Object) GetEnum(name string) *Enum
- func (o *Object) GetErr(name string) *Err
- func (o *Object) GetFeed(name string) *Feed
- func (o *Object) GetInt(name string) *Int
- func (o *Object) GetList(name string) *List
- func (o *Object) GetObject(name string) *Object
- func (o *Object) GetOp(name string) *Op
- func (o *Object) GetReal(name string) *Real
- func (o *Object) GetRef(name string) *Ref
- func (o *Object) GetRelTime(name string) *RelTime
- func (o *Object) GetStr(name string) *Str
- func (o *Object) GetTime(name string) *Time
- func (o *Object) GetUri(name string) *Uri
- func (o *Object) ReplaceAttr()
- type ObjectType
- type Op
- type Real
- type Ref
- type RelTime
- type Reltime
- type Status
- type Str
- type Time
- type Uri
- type XMLObject
Constants ¶
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` )
const ( Nanosecond Reltime = 1 Microsecond = 1000 * Nanosecond Millisecond = 1000 * Microsecond Second = 1000 * Millisecond Minute = 60 * Second Hour = 60 * Minute Day = 24 * Hour )
Variables ¶
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 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
AssertAbsTime 断言AbsTime
func (*Obj) AssertObject ¶ added in v1.0.0
AssertObject 断言Object
func (*Obj) AssertRelTime ¶ added in v1.0.0
AssertRelTime 断言RelTime
func (Obj) MarshalXML ¶ added in v0.0.8
MarshalXML 实现xml序列化
func (*Obj) UnmarshalXML ¶ added in v0.0.8
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
GetAbsTime 获取子元素中指定的AbsTime
func (*Object) GetRelTime ¶ added in v0.0.8
GetRelTime 获取子元素中指定的Reltime
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 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 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 ¶
func ParseReltime ¶
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 ¶
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 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"` }