Documentation ¶
Index ¶
- Constants
- Variables
- type ArraySpec
- type BooleanSpec
- type DataType
- type DateSpec
- type DigitalSpec
- type EntityReply
- type EntityRequest
- type EnumSpec
- type Event
- type FloatSpec
- type Profile
- type Property
- type Service
- type StructSpec
- type TextSpec
- type Thing
- func (s *Thing) GenerateGoCodec(tp string) (string, error)
- func (s *Thing) Random(method string, generateAllProperty bool) ([]byte, error)
- func (s *Thing) RandomAll() ([]byte, error)
- func (s *Thing) ToEntityString() string
- func (s *Thing) ValidateEntity(thingEntity *ThingEntity) error
- func (s *Thing) ValidateEntityBytes(bs []byte) error
- func (s *Thing) ValidateEvent(identifier string, params []byte) error
- func (s *Thing) ValidateService(identifier string, params, data []byte) error
- func (s *Thing) ValidateSpec() error
- type ThingEntity
- type ThingMethod
- type Validator
- func NewArraySpec(bs []byte) (Validator, error)
- func NewBooleanSpec(bs []byte) (Validator, error)
- func NewDateSpec(bs []byte) (Validator, error)
- func NewDigitalSpec(bs []byte) (Validator, error)
- func NewEnumSpec(bs []byte) (Validator, error)
- func NewFloatSpec(bs []byte) (Validator, error)
- func NewStructSpec(bs []byte) (Validator, error)
- func NewTextSpec(bs []byte) (Validator, error)
Constants ¶
View Source
const ( MethodCellMinLength = 3 MethodCellMaxLength = 4 MethodClassifyIndex = 1 MethodActionIndex = 2 MethodActionPropertyName = "property" MethodServiceName = "service" MethodEventName = "event" )
Variables ¶
View Source
var DefaultCodecTmpl = `` /* 3088-byte string literal not displayed */
View Source
var TypeSpecRegister = map[string]func([]byte) (Validator, error){ "int": NewDigitalSpec, "long": NewDigitalSpec, "float": NewFloatSpec, "double": NewFloatSpec, "text": NewTextSpec, "enum": NewEnumSpec, "bool": NewBooleanSpec, "array": NewArraySpec, "struct": NewStructSpec, "date": NewDateSpec, }
数据类型注册表
Functions ¶
This section is empty.
Types ¶
type ArraySpec ¶
数组类型
func (*ArraySpec) ToEntityString ¶
func (*ArraySpec) ValidateSpec ¶
func (*ArraySpec) ValidateValue ¶
type BooleanSpec ¶
布尔类型
func (*BooleanSpec) Random ¶
func (s *BooleanSpec) Random() interface{}
func (*BooleanSpec) ToEntityString ¶
func (s *BooleanSpec) ToEntityString() string
func (*BooleanSpec) ValidateSpec ¶
func (s *BooleanSpec) ValidateSpec() error
func (*BooleanSpec) ValidateValue ¶
func (s *BooleanSpec) ValidateValue(value interface{}) error
type DataType ¶
type DataType struct { // 数据类型 Type string // 数据类型定义 Specs json.RawMessage Value struct { Specs Validator } }
数据类型
func (*DataType) GenerateGoType ¶
func (*DataType) ToEntityString ¶
func (*DataType) ValidateSpec ¶
func (*DataType) ValidateValue ¶
type DateSpec ¶
type DateSpec struct{}
func (*DateSpec) ToEntityString ¶
func (*DateSpec) ValidateSpec ¶
func (*DateSpec) ValidateValue ¶
type DigitalSpec ¶
type DigitalSpec struct { Max string Min string Step string Unit string UnitName string Value struct { Max int64 Min int64 Step uint64 } }
数值类型
func (*DigitalSpec) Random ¶
func (s *DigitalSpec) Random() interface{}
func (*DigitalSpec) ToEntityString ¶
func (s *DigitalSpec) ToEntityString() string
func (*DigitalSpec) ValidateSpec ¶
func (s *DigitalSpec) ValidateSpec() error
func (*DigitalSpec) ValidateValue ¶
func (s *DigitalSpec) ValidateValue(value interface{}) error
type EntityReply ¶
type EntityRequest ¶
type EnumSpec ¶
枚举类型
func (*EnumSpec) ToEntityString ¶
func (*EnumSpec) ValidateSpec ¶
func (*EnumSpec) ValidateValue ¶
type Event ¶
type Event struct { Identifier string Name string Desc string Method string Type string OutputData []*Property Value struct { OutputData map[string]*Property } }
事件
func (*Event) ParamPrefixName ¶
func (*Event) ToEntity ¶
func (s *Event) ToEntity() *ThingEntity
func (*Event) ValidateEntity ¶
func (*Event) ValidateSpec ¶
type FloatSpec ¶
type FloatSpec struct { Max string Min string Step string Unit string UnitName string Value struct { Max float64 Min float64 Step float64 } }
数值类型
func (*FloatSpec) ToEntityString ¶
func (*FloatSpec) ValidateSpec ¶
func (*FloatSpec) ValidateValue ¶
type Profile ¶
func (*Profile) ValidateSpec ¶
type Property ¶
type Property struct { AccessMode string Identifier string Name string Desc string Required bool DataType *DataType }
属性
func (*Property) ToEntityString ¶
func (*Property) ValidateSpec ¶
func (*Property) ValidateValue ¶
type Service ¶
type Service struct { Identifier string Name string Desc string Method string CallType string Required bool InputData []*Property OutputData []*Property Value struct { InputData map[string]*Property OutputData map[string]*Property } }
服务
func (*Service) ToEntity ¶
func (s *Service) ToEntity() *ThingEntity
func (*Service) ValidateEntity ¶
func (*Service) ValidateSpec ¶
type StructSpec ¶
type StructSpec struct { // Identifier Name dataType Properties []*Property Value struct { Properties map[string]*Property } }
结构体类型
func (*StructSpec) Random ¶
func (s *StructSpec) Random() interface{}
func (*StructSpec) ToEntityString ¶
func (s *StructSpec) ToEntityString() string
func (*StructSpec) ValidateSpec ¶
func (s *StructSpec) ValidateSpec() error
func (*StructSpec) ValidateValue ¶
func (s *StructSpec) ValidateValue(value interface{}) error
type TextSpec ¶
字符串类型
func (*TextSpec) ToEntityString ¶
func (*TextSpec) ValidateSpec ¶
func (*TextSpec) ValidateValue ¶
type Thing ¶
type Thing struct { Profile *Profile // 事件 Events []*Event // 服务 Services []*Service // 属性 Properties []*Property Value struct { // 事件 Events map[string]*Event // 服务 Services map[string]*Service } }
物模型
func (*Thing) ToEntityString ¶
func (*Thing) ValidateEntity ¶
func (s *Thing) ValidateEntity(thingEntity *ThingEntity) error
校验实体数据 传入为结构体
func (*Thing) ValidateEntityBytes ¶
校验实体数据, 传入实体字节数据
func (*Thing) ValidateService ¶
func (*Thing) ValidateSpec ¶
type ThingEntity ¶
type ThingEntity struct { ID string `json:"id"` // 消息ID,String类型的数字,取值范围0~4294967295,且每个消息ID在当前设备中具有唯一性。 Version string `json:"version"` // 协议版本号,目前协议版本号唯一取值为1.0。 Params json.RawMessage `json:"params,omitempty"` Method string `json:"method"` Timestamp int64 `json:"timestamp"` Code int `json:"code"` Data json.RawMessage `json:"data,omitempty"` }
type ThingMethod ¶
type ThingMethod struct { Original string Classify string // 分类: 属性, 服务, 事件 Action string // 动作: set, get, post, {tsl.identifier} IsProperty bool // 是否是属性 IsSet bool // 是否是set IsGet bool // 是否是get }
func NewThingMethod ¶
func NewThingMethod(method string) (*ThingMethod, error)
func (*ThingMethod) IsEvent ¶
func (t *ThingMethod) IsEvent() bool
func (*ThingMethod) IsService ¶
func (t *ThingMethod) IsService() bool
type Validator ¶
type Validator interface { // 校验物模型定义规范 ValidateSpec() error // 校验物模型实例值 ValidateValue(value interface{}) error // 转换为物模型实例 ToEntityString() string // 随机值生成 Random() interface{} }
校验接口
func NewArraySpec ¶
func NewBooleanSpec ¶
func NewDateSpec ¶
func NewDigitalSpec ¶
func NewEnumSpec ¶
func NewFloatSpec ¶
func NewStructSpec ¶
func NewTextSpec ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.