IntegerType
IIntegerType is a interface for features of integer types.
/// <summary>Integer type description</summary>
public interface IIntegerType : INumberType, IUnitProvider, INumberMinMax<BigInteger>
{
/// <summary>Properties for all integer types.</summary>
public new static class Property
{
/// <summary>Protobuf <see cref="Avalanche.IntegerEncoding"/>: FixedSize, VariableSize, ZigZag</summary>
public const string IntegerEncoding = nameof(Avalanche.IntegerEncoding);
}
}
/// <summary>Description of number type features</summary>
public interface INumberType : IValueType
{
/// <summary>The number of unique digits in positional number system.</summary>
int? Radix { get; set; }
/// <summary>
/// Precision of significand digits in units of <see cref="Radix"/>.
///
/// This is mantissa for floating point types, and integer digits for integer types.
/// For fixed points, the sum of <see cref="IFloatingPointType.IntegerPrecision"/> and <see cref="IFloatingPointType.FractionPrecision"/>.
///
/// Null if not valid for the number type.
/// </summary>
int? SignificandPrecision { get; set; }
/// <summary>Is number type signed.</summary>
bool Signed { get; set; }
}
/// <summary>Provides Unit property.</summary>
public interface IUnitProvider
{
/// <summary>Unit property, e.g. "m/s".</summary>
string? Unit { get; set; }
}
IDataType └── IValueType └── INumberType └── IIntegerType
IntegerType is the default implementation.
IIntegerType datatype = new IntegerType
{
Name = Identities.CreateName("uint16").SetReadOnly(),
Properties = { },
Description = "",
Unassignable = true,
Referable = true,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
Signed = false,
SignificandPrecision = 16,
Radix = 2
}.SetReadOnly();
uint16 : IIntegerType { Base = 2, SignificandPrecision = 16, Signed = False, Nullable = True, Referable = True, Description = "", Annotations = [], MinValue = 0, MaxValue = 65536 }
IntegerTypeRequest is request for an integer type when sub-requests are needed.
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
IntegerTypeRequest request = new IntegerTypeRequest
{
Name = Identities.CreateName("uint16").SetReadOnly(),
Properties = new Dictionary<string, string> { },
Unassignable = false,
Referable = null,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
Signed = false,
SignificandPrecision = 16,
Radix = 2
};
// Query
IIntegerType datatype = service.GetRequired<IRequestFor<IIntegerType>, IIntegerType>(request);
DataTypeRequest(DtoTarget.Integer) is a request for integer type by Type. (Avalanche.DataType.Dto.dll)
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
DataTypeRequest request = new(DtoTarget.Integer(typeof(int)));
// Request
IIntegerType datatype = service.GetRequired<DataTypeRequest, IIntegerType>(request);
int : IIntegerType { Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -2147483648, MaxValue = 2147483647 }
DataTypes facade contains type definitions for .NET types.
WriteLine(DataTypes.Bool.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.SByte.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Byte.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Int16.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.UInt16.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Int32.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.UInt32.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Int64.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.UInt64.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.BigInteger.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
bool : IIntegerType { Base = 2, SignificandPrecision = 1, Signed = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = 0, MaxValue = 1 } sbyte : IIntegerType { Base = 2, SignificandPrecision = 8, Signed = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -128, MaxValue = 127 } byte : IIntegerType { Base = 2, SignificandPrecision = 8, Signed = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = 0, MaxValue = 255 } short : IIntegerType { Base = 2, SignificandPrecision = 16, Signed = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -32768, MaxValue = 32767 } ushort : IIntegerType { Base = 2, SignificandPrecision = 16, Signed = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = 0, MaxValue = 65535 } int : IIntegerType { Base = 2, SignificandPrecision = 32, Signed = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -2147483648, MaxValue = 2147483647 } uint : IIntegerType { Base = 2, SignificandPrecision = 32, Signed = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = 0, MaxValue = 4294967295 } long : IIntegerType { Base = 2, SignificandPrecision = 64, Signed = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = -9223372036854775808, MaxValue = 9223372036854775807 } ulong : IIntegerType { Base = 2, SignificandPrecision = 64, Signed = False, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0, MinValue = 0, MaxValue = 18446744073709551615 } BigInteger : IIntegerType { Base = 2, Signed = True, Nullable = False, Referable = False, Annotations = [], DefaultValue = 0 }
Properties
Key | Type | Description |
---|---|---|
IntegerEncoding | "FixedSize", "VariableSize", "ZigZag" | Protobuf encoding. |
Full Example
Full example
using System.Collections.Generic;
using System.Numerics;
using Avalanche.DataType;
using Avalanche.Identity;
using Avalanche.Service;
using Avalanche.Utilities;
using static System.Console;
public class integertype
{
public static void Run()
{
{
// <01>
IIntegerType datatype = new IntegerType
{
Name = Identities.CreateName("uint16").SetReadOnly(),
Properties = { },
Description = "",
Unassignable = true,
Referable = true,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
Signed = false,
SignificandPrecision = 16,
Radix = 2
}.SetReadOnly();
// </01>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <03>
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
IntegerTypeRequest request = new IntegerTypeRequest
{
Name = Identities.CreateName("uint16").SetReadOnly(),
Properties = new Dictionary<string, string> { },
Unassignable = false,
Referable = null,
MinValue = (BigInteger?)0,
MaxValue = (BigInteger?)65536,
Signed = false,
SignificandPrecision = 16,
Radix = 2
};
// Query
IIntegerType datatype = service.GetRequired<IRequestFor<IIntegerType>, IIntegerType>(request);
// </03>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <04>
// Create service
IService service = Services.Create(Avalanche.DataType.Dto.Module.Instance);
// Create request
DataTypeRequest request = new(DtoTarget.Integer(typeof(int)));
// Request
IIntegerType datatype = service.GetRequired<DataTypeRequest, IIntegerType>(request);
// </04>
// Print
WriteLine(datatype.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
}
{
// <05>
WriteLine(DataTypes.Bool.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.SByte.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Byte.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Int16.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.UInt16.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Int32.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.UInt32.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.Int64.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.UInt64.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
WriteLine(DataTypes.BigInteger.Instance.PrintTree(format: DataTypePrintTreeExtensions.PrintFormat.DefaultLong));
// </05>
}
}
}