dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/dtos/resourceproperties.go (about)

     1  //
     2  // Copyright (C) 2020-2023 IOTech Ltd
     3  //
     4  // SPDX-License-Identifier: Apache-2.0
     5  
     6  package dtos
     7  
     8  import (
     9  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/models"
    10  )
    11  
    12  type ResourceProperties struct {
    13  	ValueType    string         `json:"valueType" yaml:"valueType" validate:"required,edgex-dto-value-type"`
    14  	ReadWrite    string         `json:"readWrite" yaml:"readWrite" validate:"required,oneof='R' 'W' 'RW' 'WR' ''"`
    15  	Units        string         `json:"units,omitempty" yaml:"units"`
    16  	Minimum      *float64       `json:"minimum,omitempty" yaml:"minimum"`
    17  	Maximum      *float64       `json:"maximum,omitempty" yaml:"maximum"`
    18  	DefaultValue string         `json:"defaultValue,omitempty" yaml:"defaultValue"`
    19  	Mask         *uint64        `json:"mask,omitempty" yaml:"mask"`
    20  	Shift        *int64         `json:"shift,omitempty" yaml:"shift"`
    21  	Scale        *float64       `json:"scale,omitempty" yaml:"scale"`
    22  	Offset       *float64       `json:"offset,omitempty" yaml:"offset"`
    23  	Base         *float64       `json:"base,omitempty" yaml:"base"`
    24  	Assertion    string         `json:"assertion,omitempty" yaml:"assertion"`
    25  	MediaType    string         `json:"mediaType,omitempty" yaml:"mediaType"`
    26  	Optional     map[string]any `json:"optional,omitempty" yaml:"optional"`
    27  }
    28  
    29  // ToResourcePropertiesModel transforms the ResourceProperties DTO to the ResourceProperties model
    30  func ToResourcePropertiesModel(p ResourceProperties) models.ResourceProperties {
    31  	return models.ResourceProperties{
    32  		ValueType:    p.ValueType,
    33  		ReadWrite:    p.ReadWrite,
    34  		Units:        p.Units,
    35  		Minimum:      p.Minimum,
    36  		Maximum:      p.Maximum,
    37  		DefaultValue: p.DefaultValue,
    38  		Mask:         p.Mask,
    39  		Shift:        p.Shift,
    40  		Scale:        p.Scale,
    41  		Offset:       p.Offset,
    42  		Base:         p.Base,
    43  		Assertion:    p.Assertion,
    44  		MediaType:    p.MediaType,
    45  		Optional:     p.Optional,
    46  	}
    47  }
    48  
    49  // FromResourcePropertiesModelToDTO transforms the ResourceProperties Model to the ResourceProperties DTO
    50  func FromResourcePropertiesModelToDTO(p models.ResourceProperties) ResourceProperties {
    51  	return ResourceProperties{
    52  		ValueType:    p.ValueType,
    53  		ReadWrite:    p.ReadWrite,
    54  		Units:        p.Units,
    55  		Minimum:      p.Minimum,
    56  		Maximum:      p.Maximum,
    57  		DefaultValue: p.DefaultValue,
    58  		Mask:         p.Mask,
    59  		Shift:        p.Shift,
    60  		Scale:        p.Scale,
    61  		Offset:       p.Offset,
    62  		Base:         p.Base,
    63  		Assertion:    p.Assertion,
    64  		MediaType:    p.MediaType,
    65  		Optional:     p.Optional,
    66  	}
    67  }