3 Commits

Author SHA1 Message Date
Adrian Zürcher
285a2add53 add new convert function 2025-04-29 08:21:40 +02:00
Adrian Zürcher
72d0d56868 add type for type conversion 2025-04-29 08:16:45 +02:00
Adrian Zürcher
ea4461fd7e add value to subscribtion 2025-04-29 07:57:43 +02:00
2 changed files with 38 additions and 1 deletions

View File

@@ -1,10 +1,46 @@
package models package models
import "github.com/google/uuid" import (
"fmt"
"github.com/google/uuid"
"github.com/tecamino/tecamino-json_data/utils"
)
type Publish struct { type Publish struct {
Event string `json:"event,omitempty"` Event string `json:"event,omitempty"`
Uuid uuid.UUID `json:"uuid,omitempty"` Uuid uuid.UUID `json:"uuid,omitempty"`
Path string `json:"path,omitempty"` Path string `json:"path,omitempty"`
Type Type `json:"type,omitempty"`
Value any `json:"value,omitempty"` Value any `json:"value,omitempty"`
} }
func (p *Publish) ConvertValue() any {
switch p.Type {
case BIT:
return utils.BoolFrom(p.Value)
case BYS:
return utils.Int8From(p.Value)
case BYU:
return utils.Uint8From(p.Value)
case WOS:
return utils.Int16From(p.Value)
case WOU:
return utils.Uint16From(p.Value)
case DWS:
return utils.Int32From(p.Value)
case DWU:
return utils.Uint32From(p.Value)
case LOS:
return utils.Int64From(p.Value)
case LOU:
return utils.Uint64From(p.Value)
case F32:
return utils.Float32From(p.Value)
case F64:
return utils.Float64From(p.Value)
case STR:
return fmt.Sprintf("%v", p.Value)
}
return nil
}

View File

@@ -6,6 +6,7 @@ type Subscribe struct {
Uuid uuid.UUID `json:"uuid,omitempty"` Uuid uuid.UUID `json:"uuid,omitempty"`
Path string `json:"path,omitempty"` Path string `json:"path,omitempty"`
Depth uint `json:"depth,omitempty"` Depth uint `json:"depth,omitempty"`
Value any `json:"value,omitempty"`
Drivers *Drivers `json:"drivers,omitempty"` Drivers *Drivers `json:"drivers,omitempty"`
Driver string `json:"driver,omitempty"` Driver string `json:"driver,omitempty"`
OnCreate bool `json:"onCreate,omitempty"` OnCreate bool `json:"onCreate,omitempty"`