tsl

package
v0.0.0-...-648f786 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

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

type ArraySpec struct {
	Size  string
	Item  *DataType
	Value struct {
		Size int
	}
}

数组类型

func (*ArraySpec) Random

func (s *ArraySpec) Random() interface{}

func (*ArraySpec) ToEntityString

func (s *ArraySpec) ToEntityString() string

func (*ArraySpec) ValidateSpec

func (s *ArraySpec) ValidateSpec() error

func (*ArraySpec) ValidateValue

func (s *ArraySpec) ValidateValue(value interface{}) error

type BooleanSpec

type BooleanSpec struct {
	FalseValue string `json:"0"`
	TrueValue  string `json:"1"`
}

布尔类型

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) DefaultValueString

func (s *DataType) DefaultValueString() string

默认值

func (*DataType) GenerateGoType

func (s *DataType) GenerateGoType() string

func (*DataType) Random

func (s *DataType) Random() interface{}

func (*DataType) ToEntityString

func (s *DataType) ToEntityString() string

func (*DataType) ValidateSpec

func (s *DataType) ValidateSpec() error

func (*DataType) ValidateValue

func (s *DataType) ValidateValue(value interface{}) error

type DateSpec

type DateSpec struct{}

func (*DateSpec) Random

func (s *DateSpec) Random() interface{}

func (*DateSpec) ToEntityString

func (s *DateSpec) ToEntityString() string

func (*DateSpec) ValidateSpec

func (s *DateSpec) ValidateSpec() error

func (*DateSpec) ValidateValue

func (s *DateSpec) ValidateValue(value interface{}) error

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 EntityReply struct {
	ID        string          `json:"id"` // 消息ID,String类型的数字,取值范围0~4294967295,且每个消息ID在当前设备中具有唯一性。
	Code      int             `json:"code"`
	Data      json.RawMessage `json:"data,omitempty"`
	Method    string          `json:"method"`
	Timestamp int64           `json:"timestamp"`
}

type EntityRequest

type EntityRequest 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"`
}

type EnumSpec

type EnumSpec struct {
	Specs map[string]string
	Value struct {
		Specs map[int]string
	}
}

枚举类型

func (*EnumSpec) Random

func (s *EnumSpec) Random() interface{}

func (*EnumSpec) ToEntityString

func (s *EnumSpec) ToEntityString() string

func (*EnumSpec) ValidateSpec

func (s *EnumSpec) ValidateSpec() error

func (*EnumSpec) ValidateValue

func (s *EnumSpec) ValidateValue(value interface{}) error

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) ConstName

func (s *Event) ConstName() string

func (*Event) ParamPrefixName

func (s *Event) ParamPrefixName() string

func (*Event) Random

func (s *Event) Random(generateAllProperty bool) (*ThingEntity, error)

func (*Event) ToEntity

func (s *Event) ToEntity() *ThingEntity

func (*Event) ValidateEntity

func (s *Event) ValidateEntity(outputData []byte) error

func (*Event) ValidateSpec

func (s *Event) ValidateSpec() error

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) Random

func (s *FloatSpec) Random() interface{}

func (*FloatSpec) ToEntityString

func (s *FloatSpec) ToEntityString() string

func (*FloatSpec) ValidateSpec

func (s *FloatSpec) ValidateSpec() error

func (*FloatSpec) ValidateValue

func (s *FloatSpec) ValidateValue(value interface{}) error

type Profile

type Profile struct {
	ProductKey string
	DeviceName string
}

func (*Profile) ValidateSpec

func (s *Profile) ValidateSpec() error

type Property

type Property struct {
	AccessMode string
	Identifier string
	Name       string
	Desc       string
	Required   bool
	DataType   *DataType
}

属性

func (*Property) Random

func (s *Property) Random() interface{}

func (*Property) ToEntityString

func (s *Property) ToEntityString() string

func (*Property) ValidateSpec

func (s *Property) ValidateSpec() error

func (*Property) ValidateValue

func (s *Property) ValidateValue(value interface{}) error

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) Random

func (s *Service) Random(generateAllProperty bool) (*ThingEntity, error)

func (*Service) ToEntity

func (s *Service) ToEntity() *ThingEntity

func (*Service) ValidateEntity

func (s *Service) ValidateEntity(inputData, outputData []byte) error

func (*Service) ValidateSpec

func (s *Service) ValidateSpec() error

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

type TextSpec struct {
	Length string
	Value  struct {
		Length int
	}
}

字符串类型

func (*TextSpec) Random

func (s *TextSpec) Random() interface{}

func (*TextSpec) ToEntityString

func (s *TextSpec) ToEntityString() string

func (*TextSpec) ValidateSpec

func (s *TextSpec) ValidateSpec() error

func (*TextSpec) ValidateValue

func (s *TextSpec) ValidateValue(value interface{}) error

type Thing

type Thing struct {
	Profile *Profile
	// 事件
	Events []*Event
	// 服务
	Services []*Service
	// 属性
	Properties []*Property
	Value      struct {
		// 事件
		Events map[string]*Event
		// 服务
		Services map[string]*Service
	}
}

物模型

func NewThing

func NewThing(bs []byte) (*Thing, error)

NewThing

func (*Thing) GenerateGoCodec

func (s *Thing) GenerateGoCodec(tp string) (string, error)

func (*Thing) Random

func (s *Thing) Random(method string, generateAllProperty bool) ([]byte, error)

func (*Thing) RandomAll

func (s *Thing) RandomAll() ([]byte, error)

随机生成物模型实体数据

func (*Thing) ToEntityString

func (s *Thing) ToEntityString() string

func (*Thing) ValidateEntity

func (s *Thing) ValidateEntity(thingEntity *ThingEntity) error

校验实体数据 传入为结构体

func (*Thing) ValidateEntityBytes

func (s *Thing) ValidateEntityBytes(bs []byte) error

校验实体数据, 传入实体字节数据

func (*Thing) ValidateEvent

func (s *Thing) ValidateEvent(identifier string, params []byte) error

func (*Thing) ValidateService

func (s *Thing) ValidateService(identifier string, params, data []byte) error

func (*Thing) ValidateSpec

func (s *Thing) ValidateSpec() error

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 NewArraySpec(bs []byte) (Validator, error)

func NewBooleanSpec

func NewBooleanSpec(bs []byte) (Validator, error)

func NewDateSpec

func NewDateSpec(bs []byte) (Validator, error)

func NewDigitalSpec

func NewDigitalSpec(bs []byte) (Validator, error)

func NewEnumSpec

func NewEnumSpec(bs []byte) (Validator, error)

func NewFloatSpec

func NewFloatSpec(bs []byte) (Validator, error)

func NewStructSpec

func NewStructSpec(bs []byte) (Validator, error)

func NewTextSpec

func NewTextSpec(bs []byte) (Validator, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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