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

     1  //
     2  // Copyright (C) 2020-2023 IOTech Ltd
     3  //
     4  // SPDX-License-Identifier: Apache-2.0
     5  
     6  package models
     7  
     8  type BaseReading struct {
     9  	Id           string
    10  	Origin       int64
    11  	DeviceName   string
    12  	ResourceName string
    13  	ProfileName  string
    14  	ValueType    string
    15  	Units        string
    16  	Tags         map[string]any
    17  }
    18  
    19  type BinaryReading struct {
    20  	BaseReading `json:",inline"`
    21  	BinaryValue []byte
    22  	MediaType   string
    23  }
    24  
    25  type SimpleReading struct {
    26  	BaseReading `json:",inline"`
    27  	Value       string
    28  }
    29  
    30  type ObjectReading struct {
    31  	BaseReading `json:",inline"`
    32  	ObjectValue interface{}
    33  }
    34  
    35  // Reading is an abstract interface to be implemented by BinaryReading/SimpleReading
    36  type Reading interface {
    37  	GetBaseReading() BaseReading
    38  }
    39  
    40  // Implement GetBaseReading() method in order for BinaryReading and SimpleReading, ObjectReading structs to implement the
    41  // abstract Reading interface and then be used as a Reading.
    42  // Also, the Reading interface can access the BaseReading fields.
    43  // This is Golang's way to implement inheritance.
    44  func (b BinaryReading) GetBaseReading() BaseReading { return b.BaseReading }
    45  func (s SimpleReading) GetBaseReading() BaseReading { return s.BaseReading }
    46  func (o ObjectReading) GetBaseReading() BaseReading { return o.BaseReading }