Beispiel #1
0
        private void SerializeType(BitWriter bitWriter, ulong value, int bitLength)
        {
            var bytes = BitConverter.GetBytes((uint)value).Reverse().ToArray();

            bitWriter.WriteBits(bytes, bitLength, offset: 32 - bitLength);
        }
Beispiel #2
0
        private void SerializeType(BitWriter bitWriter, Guid value)
        {
            var bytes = value.ToByteArray();

            bitWriter.WriteBytes(bytes);
        }
Beispiel #3
0
 private void SerializeType(BitWriter bitWriter, bool value)
 {
     bitWriter.WriteBit(value);
 }
Beispiel #4
0
        private void SerializeType(BitWriter bitWriter, double value)
        {
            var bytes = BitConverter.GetBytes((float)value).Reverse().ToArray();

            bitWriter.WriteBits(bytes, length: 31, offset: 1); // cut off sign bit because it's always positive
        }
Beispiel #5
0
        private void SerializeType(BitWriter bitWriter, string value)
        {
            var bytes = FloEncoding.GetBytes(value, onlyCharacters: true);

            bitWriter.WriteBits(bytes, value.Length * 5);
        }
 private void SerializeType(BitWriter bitWriter, ulong value)
 {
     SerializeType(bitWriter, (object)((uint)value));
 }
 private void SerializeType(BitWriter bitWriter, double value)
 {
     SerializeType(bitWriter, (object)((float)value));
 }
        private void SerializeType(BitWriter bitWriter, string value, bool onlyCharacters = false)
        {
            var bytes = FloEncoding.GetBytes(value, onlyCharacters);

            bitWriter.WriteBits(bytes, value.Length * (onlyCharacters ? 5 : 6));
        }
        private byte[] SerializeType(IotDevice obj)
        {
            var bitWriter = new BitWriter();

            var id            = Guid.Parse(obj.Id).ToString("N");
            var statusMessage = obj.StatusMessage.Replace(" ", string.Empty);

            bitWriter.WriteBit(string.Equals(obj.Name, _name, StringComparison.Ordinal) && string.Equals(id, _id, StringComparison.Ordinal));
            bitWriter.WriteBit(string.Equals(statusMessage, _statusMessage, StringComparison.Ordinal));
            bitWriter.WriteBit(_selfCheckPassed == obj.SelfCheckPassed);
            bitWriter.WriteBit(_serviceModeEnabled == obj.ServiceModeEnabled);
            bitWriter.WriteBit(_uptimeInSeconds == obj.UptimeInSeconds);
            bitWriter.WriteBit(IsEqual(_pressure, obj.Pressure.Value));
            bitWriter.WriteBit(IsEqual(_temperature, obj.Temperature.Value));
            bitWriter.WriteBit(IsEqual(_distance, obj.Distance.Value));

            if (!string.Equals(obj.Name, _name, StringComparison.Ordinal))
            {
                SerializeType(bitWriter, obj.Name, onlyCharacters: true);
                _name = obj.Name;
            }

            if (!string.Equals(id, _id, StringComparison.Ordinal))
            {
                SerializeType(bitWriter, id);
                _id = id;
            }

            if (!string.Equals(statusMessage, _statusMessage, StringComparison.Ordinal))
            {
                SerializeType(bitWriter, statusMessage, onlyCharacters: true);
                _statusMessage = statusMessage;
            }

            if (_selfCheckPassed != obj.SelfCheckPassed)
            {
                SerializeType(bitWriter, obj.SelfCheckPassed);
                _selfCheckPassed = obj.SelfCheckPassed;
            }

            if (_serviceModeEnabled != obj.ServiceModeEnabled)
            {
                SerializeType(bitWriter, obj.ServiceModeEnabled);
                _serviceModeEnabled = obj.ServiceModeEnabled;
            }

            if (_uptimeInSeconds != obj.UptimeInSeconds)
            {
                SerializeType(bitWriter, obj.UptimeInSeconds);
                _uptimeInSeconds = obj.UptimeInSeconds;
            }

            if (!IsEqual(_pressure, obj.Pressure.Value))
            {
                SerializeType(bitWriter, obj.Pressure.Value);
                _pressure = obj.Pressure.Value;
            }

            if (!IsEqual(_temperature, obj.Temperature.Value))
            {
                SerializeType(bitWriter, obj.Temperature.Value);
                _temperature = obj.Temperature.Value;
            }

            if (!IsEqual(_distance, obj.Distance.Value))
            {
                SerializeType(bitWriter, obj.Distance.Value);
                _distance = obj.Distance.Value;
            }

            var bytes = bitWriter.ToArray();

            return(bytes);
        }