/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package model

import (
	"github.com/apache/plc4x/plc4go/internal/plc4go/spi/utils"
	"github.com/apache/plc4x/plc4go/internal/plc4go/spi/values"
	api "github.com/apache/plc4x/plc4go/pkg/plc4go/values"
	"github.com/pkg/errors"
)

// Code generated by code-generation. DO NOT EDIT.

func KnxPropertyParse(readBuffer utils.ReadBuffer, propertyType KnxPropertyDataType, dataLengthInBytes uint8) (api.PlcValue, error) {
	readBuffer.PullContext("KnxProperty")
	switch {
	case propertyType == KnxPropertyDataType_PDT_CONTROL: // BOOL

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 7); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadBit("value")
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcBOOL(value), nil
	case propertyType == KnxPropertyDataType_PDT_CHAR: // SINT

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadInt8("value", 8)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcSINT(value), nil
	case propertyType == KnxPropertyDataType_PDT_UNSIGNED_CHAR: // USINT

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadUint8("value", 8)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcUSINT(value), nil
	case propertyType == KnxPropertyDataType_PDT_INT: // INT

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadInt16("value", 16)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcINT(value), nil
	case propertyType == KnxPropertyDataType_PDT_UNSIGNED_INT && dataLengthInBytes == 4: // UDINT

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadUint32("value", 32)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcUDINT(value), nil
	case propertyType == KnxPropertyDataType_PDT_UNSIGNED_INT: // UINT

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadUint16("value", 16)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcUINT(value), nil
	case propertyType == KnxPropertyDataType_PDT_KNX_FLOAT: // REAL

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadFloat32("value", true, 4, 11)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcREAL(value), nil
	case propertyType == KnxPropertyDataType_PDT_DATE: // Struct
		_map := map[string]api.PlcValue{}

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 3); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (dayOfMonth)
		dayOfMonth, _dayOfMonthErr := readBuffer.ReadUint8("dayOfMonth", 5)
		if _dayOfMonthErr != nil {
			return nil, errors.Wrap(_dayOfMonthErr, "Error parsing 'dayOfMonth' field")
		}
		_map["Struct"] = values.NewPlcUSINT(dayOfMonth)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 4); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (month)
		month, _monthErr := readBuffer.ReadUint8("month", 4)
		if _monthErr != nil {
			return nil, errors.Wrap(_monthErr, "Error parsing 'month' field")
		}
		_map["Struct"] = values.NewPlcUSINT(month)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 1); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (year)
		year, _yearErr := readBuffer.ReadUint8("year", 7)
		if _yearErr != nil {
			return nil, errors.Wrap(_yearErr, "Error parsing 'year' field")
		}
		_map["Struct"] = values.NewPlcUSINT(year)
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcStruct(_map), nil
	case propertyType == KnxPropertyDataType_PDT_TIME: // Struct
		_map := map[string]api.PlcValue{}

		// Simple Field (day)
		day, _dayErr := readBuffer.ReadUint8("day", 3)
		if _dayErr != nil {
			return nil, errors.Wrap(_dayErr, "Error parsing 'day' field")
		}
		_map["Struct"] = values.NewPlcUSINT(day)

		// Simple Field (hour)
		hour, _hourErr := readBuffer.ReadUint8("hour", 5)
		if _hourErr != nil {
			return nil, errors.Wrap(_hourErr, "Error parsing 'hour' field")
		}
		_map["Struct"] = values.NewPlcUSINT(hour)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 2); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (minutes)
		minutes, _minutesErr := readBuffer.ReadUint8("minutes", 6)
		if _minutesErr != nil {
			return nil, errors.Wrap(_minutesErr, "Error parsing 'minutes' field")
		}
		_map["Struct"] = values.NewPlcUSINT(minutes)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 2); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (seconds)
		seconds, _secondsErr := readBuffer.ReadUint8("seconds", 6)
		if _secondsErr != nil {
			return nil, errors.Wrap(_secondsErr, "Error parsing 'seconds' field")
		}
		_map["Struct"] = values.NewPlcUSINT(seconds)
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcStruct(_map), nil
	case propertyType == KnxPropertyDataType_PDT_LONG: // DINT

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadInt32("value", 32)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcDINT(value), nil
	case propertyType == KnxPropertyDataType_PDT_UNSIGNED_LONG: // UDINT

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadUint32("value", 32)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcUDINT(value), nil
	case propertyType == KnxPropertyDataType_PDT_FLOAT: // REAL

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadFloat32("value", true, 8, 23)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcREAL(value), nil
	case propertyType == KnxPropertyDataType_PDT_DOUBLE: // LREAL

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadFloat64("value", true, 11, 52)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcLREAL(value), nil
	case propertyType == KnxPropertyDataType_PDT_CHAR_BLOCK: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((10)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_POLL_GROUP_SETTINGS: // Struct
		_map := map[string]api.PlcValue{}

		// Array Field (groupAddress)
		var groupAddress []api.PlcValue
		for i := 0; i < int((2)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("groupAddress", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			groupAddress = append(groupAddress, values.NewPlcUSINT(_item))
		}

		// Simple Field (disable)
		disable, _disableErr := readBuffer.ReadBit("disable")
		if _disableErr != nil {
			return nil, errors.Wrap(_disableErr, "Error parsing 'disable' field")
		}
		_map["Struct"] = values.NewPlcBOOL(disable)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 3); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (pollingSoftNr)
		pollingSoftNr, _pollingSoftNrErr := readBuffer.ReadUint8("pollingSoftNr", 4)
		if _pollingSoftNrErr != nil {
			return nil, errors.Wrap(_pollingSoftNrErr, "Error parsing 'pollingSoftNr' field")
		}
		_map["Struct"] = values.NewPlcUSINT(pollingSoftNr)
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcStruct(_map), nil
	case propertyType == KnxPropertyDataType_PDT_SHORT_CHAR_BLOCK: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((5)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_DATE_TIME: // Struct
		_map := map[string]api.PlcValue{}

		// Simple Field (year)
		year, _yearErr := readBuffer.ReadUint8("year", 8)
		if _yearErr != nil {
			return nil, errors.Wrap(_yearErr, "Error parsing 'year' field")
		}
		_map["Struct"] = values.NewPlcUSINT(year)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 4); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (month)
		month, _monthErr := readBuffer.ReadUint8("month", 4)
		if _monthErr != nil {
			return nil, errors.Wrap(_monthErr, "Error parsing 'month' field")
		}
		_map["Struct"] = values.NewPlcUSINT(month)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 3); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (dayofmonth)
		dayofmonth, _dayofmonthErr := readBuffer.ReadUint8("dayofmonth", 5)
		if _dayofmonthErr != nil {
			return nil, errors.Wrap(_dayofmonthErr, "Error parsing 'dayofmonth' field")
		}
		_map["Struct"] = values.NewPlcUSINT(dayofmonth)

		// Simple Field (dayofweek)
		dayofweek, _dayofweekErr := readBuffer.ReadUint8("dayofweek", 3)
		if _dayofweekErr != nil {
			return nil, errors.Wrap(_dayofweekErr, "Error parsing 'dayofweek' field")
		}
		_map["Struct"] = values.NewPlcUSINT(dayofweek)

		// Simple Field (hourofday)
		hourofday, _hourofdayErr := readBuffer.ReadUint8("hourofday", 5)
		if _hourofdayErr != nil {
			return nil, errors.Wrap(_hourofdayErr, "Error parsing 'hourofday' field")
		}
		_map["Struct"] = values.NewPlcUSINT(hourofday)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 2); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (minutes)
		minutes, _minutesErr := readBuffer.ReadUint8("minutes", 6)
		if _minutesErr != nil {
			return nil, errors.Wrap(_minutesErr, "Error parsing 'minutes' field")
		}
		_map["Struct"] = values.NewPlcUSINT(minutes)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 2); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (seconds)
		seconds, _secondsErr := readBuffer.ReadUint8("seconds", 6)
		if _secondsErr != nil {
			return nil, errors.Wrap(_secondsErr, "Error parsing 'seconds' field")
		}
		_map["Struct"] = values.NewPlcUSINT(seconds)

		// Simple Field (fault)
		fault, _faultErr := readBuffer.ReadBit("fault")
		if _faultErr != nil {
			return nil, errors.Wrap(_faultErr, "Error parsing 'fault' field")
		}
		_map["Struct"] = values.NewPlcBOOL(fault)

		// Simple Field (workingDay)
		workingDay, _workingDayErr := readBuffer.ReadBit("workingDay")
		if _workingDayErr != nil {
			return nil, errors.Wrap(_workingDayErr, "Error parsing 'workingDay' field")
		}
		_map["Struct"] = values.NewPlcBOOL(workingDay)

		// Simple Field (noWd)
		noWd, _noWdErr := readBuffer.ReadBit("noWd")
		if _noWdErr != nil {
			return nil, errors.Wrap(_noWdErr, "Error parsing 'noWd' field")
		}
		_map["Struct"] = values.NewPlcBOOL(noWd)

		// Simple Field (noYear)
		noYear, _noYearErr := readBuffer.ReadBit("noYear")
		if _noYearErr != nil {
			return nil, errors.Wrap(_noYearErr, "Error parsing 'noYear' field")
		}
		_map["Struct"] = values.NewPlcBOOL(noYear)

		// Simple Field (noDate)
		noDate, _noDateErr := readBuffer.ReadBit("noDate")
		if _noDateErr != nil {
			return nil, errors.Wrap(_noDateErr, "Error parsing 'noDate' field")
		}
		_map["Struct"] = values.NewPlcBOOL(noDate)

		// Simple Field (noDayOfWeek)
		noDayOfWeek, _noDayOfWeekErr := readBuffer.ReadBit("noDayOfWeek")
		if _noDayOfWeekErr != nil {
			return nil, errors.Wrap(_noDayOfWeekErr, "Error parsing 'noDayOfWeek' field")
		}
		_map["Struct"] = values.NewPlcBOOL(noDayOfWeek)

		// Simple Field (noTime)
		noTime, _noTimeErr := readBuffer.ReadBit("noTime")
		if _noTimeErr != nil {
			return nil, errors.Wrap(_noTimeErr, "Error parsing 'noTime' field")
		}
		_map["Struct"] = values.NewPlcBOOL(noTime)

		// Simple Field (standardSummerTime)
		standardSummerTime, _standardSummerTimeErr := readBuffer.ReadBit("standardSummerTime")
		if _standardSummerTimeErr != nil {
			return nil, errors.Wrap(_standardSummerTimeErr, "Error parsing 'standardSummerTime' field")
		}
		_map["Struct"] = values.NewPlcBOOL(standardSummerTime)

		// Simple Field (qualityOfClock)
		qualityOfClock, _qualityOfClockErr := readBuffer.ReadBit("qualityOfClock")
		if _qualityOfClockErr != nil {
			return nil, errors.Wrap(_qualityOfClockErr, "Error parsing 'qualityOfClock' field")
		}
		_map["Struct"] = values.NewPlcBOOL(qualityOfClock)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 7); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcStruct(_map), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_01: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((1)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_02: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((2)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_03: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((3)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_04: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((4)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_05: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((5)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_06: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((6)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_07: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((7)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_08: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((8)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_09: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((9)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_10: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((10)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_11: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((11)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_12: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((12)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_13: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((13)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_14: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((14)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_15: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((15)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_16: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((16)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_17: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((17)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_18: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((18)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_19: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((19)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_GENERIC_20: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((20)); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_VERSION: // Struct
		_map := map[string]api.PlcValue{}

		// Simple Field (magicNumber)
		magicNumber, _magicNumberErr := readBuffer.ReadUint8("magicNumber", 5)
		if _magicNumberErr != nil {
			return nil, errors.Wrap(_magicNumberErr, "Error parsing 'magicNumber' field")
		}
		_map["Struct"] = values.NewPlcUSINT(magicNumber)

		// Simple Field (versionNumber)
		versionNumber, _versionNumberErr := readBuffer.ReadUint8("versionNumber", 5)
		if _versionNumberErr != nil {
			return nil, errors.Wrap(_versionNumberErr, "Error parsing 'versionNumber' field")
		}
		_map["Struct"] = values.NewPlcUSINT(versionNumber)

		// Simple Field (revisionNumber)
		revisionNumber, _revisionNumberErr := readBuffer.ReadUint8("revisionNumber", 6)
		if _revisionNumberErr != nil {
			return nil, errors.Wrap(_revisionNumberErr, "Error parsing 'revisionNumber' field")
		}
		_map["Struct"] = values.NewPlcUSINT(revisionNumber)
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcStruct(_map), nil
	case propertyType == KnxPropertyDataType_PDT_ALARM_INFO: // Struct
		_map := map[string]api.PlcValue{}

		// Simple Field (logNumber)
		logNumber, _logNumberErr := readBuffer.ReadUint8("logNumber", 8)
		if _logNumberErr != nil {
			return nil, errors.Wrap(_logNumberErr, "Error parsing 'logNumber' field")
		}
		_map["Struct"] = values.NewPlcUSINT(logNumber)

		// Simple Field (alarmPriority)
		alarmPriority, _alarmPriorityErr := readBuffer.ReadUint8("alarmPriority", 8)
		if _alarmPriorityErr != nil {
			return nil, errors.Wrap(_alarmPriorityErr, "Error parsing 'alarmPriority' field")
		}
		_map["Struct"] = values.NewPlcUSINT(alarmPriority)

		// Simple Field (applicationArea)
		applicationArea, _applicationAreaErr := readBuffer.ReadUint8("applicationArea", 8)
		if _applicationAreaErr != nil {
			return nil, errors.Wrap(_applicationAreaErr, "Error parsing 'applicationArea' field")
		}
		_map["Struct"] = values.NewPlcUSINT(applicationArea)

		// Simple Field (errorClass)
		errorClass, _errorClassErr := readBuffer.ReadUint8("errorClass", 8)
		if _errorClassErr != nil {
			return nil, errors.Wrap(_errorClassErr, "Error parsing 'errorClass' field")
		}
		_map["Struct"] = values.NewPlcUSINT(errorClass)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 4); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (errorcodeSup)
		errorcodeSup, _errorcodeSupErr := readBuffer.ReadBit("errorcodeSup")
		if _errorcodeSupErr != nil {
			return nil, errors.Wrap(_errorcodeSupErr, "Error parsing 'errorcodeSup' field")
		}
		_map["Struct"] = values.NewPlcBOOL(errorcodeSup)

		// Simple Field (alarmtextSup)
		alarmtextSup, _alarmtextSupErr := readBuffer.ReadBit("alarmtextSup")
		if _alarmtextSupErr != nil {
			return nil, errors.Wrap(_alarmtextSupErr, "Error parsing 'alarmtextSup' field")
		}
		_map["Struct"] = values.NewPlcBOOL(alarmtextSup)

		// Simple Field (timestampSup)
		timestampSup, _timestampSupErr := readBuffer.ReadBit("timestampSup")
		if _timestampSupErr != nil {
			return nil, errors.Wrap(_timestampSupErr, "Error parsing 'timestampSup' field")
		}
		_map["Struct"] = values.NewPlcBOOL(timestampSup)

		// Simple Field (ackSup)
		ackSup, _ackSupErr := readBuffer.ReadBit("ackSup")
		if _ackSupErr != nil {
			return nil, errors.Wrap(_ackSupErr, "Error parsing 'ackSup' field")
		}
		_map["Struct"] = values.NewPlcBOOL(ackSup)

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 5); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (locked)
		locked, _lockedErr := readBuffer.ReadBit("locked")
		if _lockedErr != nil {
			return nil, errors.Wrap(_lockedErr, "Error parsing 'locked' field")
		}
		_map["Struct"] = values.NewPlcBOOL(locked)

		// Simple Field (alarmunack)
		alarmunack, _alarmunackErr := readBuffer.ReadBit("alarmunack")
		if _alarmunackErr != nil {
			return nil, errors.Wrap(_alarmunackErr, "Error parsing 'alarmunack' field")
		}
		_map["Struct"] = values.NewPlcBOOL(alarmunack)

		// Simple Field (inalarm)
		inalarm, _inalarmErr := readBuffer.ReadBit("inalarm")
		if _inalarmErr != nil {
			return nil, errors.Wrap(_inalarmErr, "Error parsing 'inalarm' field")
		}
		_map["Struct"] = values.NewPlcBOOL(inalarm)
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcStruct(_map), nil
	case propertyType == KnxPropertyDataType_PDT_BINARY_INFORMATION: // BOOL

		// Reserved Field (Just skip the bytes)
		if _, _err := readBuffer.ReadUint8("reserved", 7); _err != nil {
			return nil, errors.Wrap(_err, "Error parsing reserved field")
		}

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadBit("value")
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcBOOL(value), nil
	case propertyType == KnxPropertyDataType_PDT_BITSET8: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((8)); i++ {
			_item, _itemErr := readBuffer.ReadBit("value")
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcBOOL(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_BITSET16: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int((16)); i++ {
			_item, _itemErr := readBuffer.ReadBit("value")
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcBOOL(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	case propertyType == KnxPropertyDataType_PDT_ENUM8: // USINT

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadUint8("value", 8)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcUSINT(value), nil
	case propertyType == KnxPropertyDataType_PDT_SCALING: // USINT

		// Simple Field (value)
		value, _valueErr := readBuffer.ReadUint8("value", 8)
		if _valueErr != nil {
			return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcUSINT(value), nil
	default: // List

		// Array Field (value)
		var value []api.PlcValue
		for i := 0; i < int(dataLengthInBytes); i++ {
			_item, _itemErr := readBuffer.ReadUint8("value", 8)
			if _itemErr != nil {
				return nil, errors.Wrap(_itemErr, "Error parsing 'value' field")
			}
			value = append(value, values.NewPlcUSINT(_item))
		}
		readBuffer.CloseContext("KnxProperty")
		return values.NewPlcList(value), nil
	}
	// TODO: add more info which type it is actually
	return nil, errors.New("unsupported type")
}

func KnxPropertySerialize(writeBuffer utils.WriteBuffer, value api.PlcValue, propertyType KnxPropertyDataType, dataLengthInBytes uint8) error {
	writeBuffer.PushContext("KnxProperty")
	switch {
	case propertyType == KnxPropertyDataType_PDT_CONTROL: // BOOL

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 7, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (value)
		if _err := writeBuffer.WriteBit("value", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_CHAR: // SINT

		// Simple Field (value)
		if _err := writeBuffer.WriteInt8("value", 8, value.GetInt8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_UNSIGNED_CHAR: // USINT

		// Simple Field (value)
		if _err := writeBuffer.WriteUint8("value", 8, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_INT: // INT

		// Simple Field (value)
		if _err := writeBuffer.WriteInt16("value", 16, value.GetInt16()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_UNSIGNED_INT && dataLengthInBytes == 4: // UDINT

		// Simple Field (value)
		if _err := writeBuffer.WriteUint32("value", 32, value.GetUint32()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_UNSIGNED_INT: // UINT

		// Simple Field (value)
		if _err := writeBuffer.WriteUint16("value", 16, value.GetUint16()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_KNX_FLOAT: // REAL

		// Simple Field (value)
		if _err := writeBuffer.WriteFloat32("value", 16, value.GetFloat32()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_DATE: // Struct

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 3, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (dayOfMonth)
		if _err := writeBuffer.WriteUint8("dayOfMonth", 5, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'dayOfMonth' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 4, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (month)
		if _err := writeBuffer.WriteUint8("month", 4, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'month' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 1, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (year)
		if _err := writeBuffer.WriteUint8("year", 7, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'year' field")
		}
	case propertyType == KnxPropertyDataType_PDT_TIME: // Struct

		// Simple Field (day)
		if _err := writeBuffer.WriteUint8("day", 3, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'day' field")
		}

		// Simple Field (hour)
		if _err := writeBuffer.WriteUint8("hour", 5, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'hour' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 2, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (minutes)
		if _err := writeBuffer.WriteUint8("minutes", 6, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'minutes' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 2, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (seconds)
		if _err := writeBuffer.WriteUint8("seconds", 6, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'seconds' field")
		}
	case propertyType == KnxPropertyDataType_PDT_LONG: // DINT

		// Simple Field (value)
		if _err := writeBuffer.WriteInt32("value", 32, value.GetInt32()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_UNSIGNED_LONG: // UDINT

		// Simple Field (value)
		if _err := writeBuffer.WriteUint32("value", 32, value.GetUint32()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_FLOAT: // REAL

		// Simple Field (value)
		if _err := writeBuffer.WriteFloat32("value", 32, value.GetFloat32()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_DOUBLE: // LREAL

		// Simple Field (value)
		if _err := writeBuffer.WriteFloat64("value", 64, value.GetFloat64()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_CHAR_BLOCK: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((10)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_POLL_GROUP_SETTINGS: // Struct

		// Array Field (groupAddress)
		for i := uint32(0); i < uint32((2)); i++ {
			groupAddress := value.GetValue("groupAddress")
			_itemErr := writeBuffer.WriteUint8("", 8, groupAddress.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}

		// Simple Field (disable)
		if _err := writeBuffer.WriteBit("disable", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'disable' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 3, uint8(0x0)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (pollingSoftNr)
		if _err := writeBuffer.WriteUint8("pollingSoftNr", 4, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'pollingSoftNr' field")
		}
	case propertyType == KnxPropertyDataType_PDT_SHORT_CHAR_BLOCK: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((5)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_DATE_TIME: // Struct

		// Simple Field (year)
		if _err := writeBuffer.WriteUint8("year", 8, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'year' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 4, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (month)
		if _err := writeBuffer.WriteUint8("month", 4, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'month' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 3, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (dayofmonth)
		if _err := writeBuffer.WriteUint8("dayofmonth", 5, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'dayofmonth' field")
		}

		// Simple Field (dayofweek)
		if _err := writeBuffer.WriteUint8("dayofweek", 3, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'dayofweek' field")
		}

		// Simple Field (hourofday)
		if _err := writeBuffer.WriteUint8("hourofday", 5, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'hourofday' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 2, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (minutes)
		if _err := writeBuffer.WriteUint8("minutes", 6, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'minutes' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 2, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (seconds)
		if _err := writeBuffer.WriteUint8("seconds", 6, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'seconds' field")
		}

		// Simple Field (fault)
		if _err := writeBuffer.WriteBit("fault", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'fault' field")
		}

		// Simple Field (workingDay)
		if _err := writeBuffer.WriteBit("workingDay", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'workingDay' field")
		}

		// Simple Field (noWd)
		if _err := writeBuffer.WriteBit("noWd", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'noWd' field")
		}

		// Simple Field (noYear)
		if _err := writeBuffer.WriteBit("noYear", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'noYear' field")
		}

		// Simple Field (noDate)
		if _err := writeBuffer.WriteBit("noDate", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'noDate' field")
		}

		// Simple Field (noDayOfWeek)
		if _err := writeBuffer.WriteBit("noDayOfWeek", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'noDayOfWeek' field")
		}

		// Simple Field (noTime)
		if _err := writeBuffer.WriteBit("noTime", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'noTime' field")
		}

		// Simple Field (standardSummerTime)
		if _err := writeBuffer.WriteBit("standardSummerTime", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'standardSummerTime' field")
		}

		// Simple Field (qualityOfClock)
		if _err := writeBuffer.WriteBit("qualityOfClock", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'qualityOfClock' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 7, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_01: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((1)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_02: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((2)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_03: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((3)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_04: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((4)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_05: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((5)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_06: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((6)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_07: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((7)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_08: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((8)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_09: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((9)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_10: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((10)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_11: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((11)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_12: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((12)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_13: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((13)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_14: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((14)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_15: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((15)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_16: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((16)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_17: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((17)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_18: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((18)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_19: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((19)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_GENERIC_20: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((20)); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_VERSION: // Struct

		// Simple Field (magicNumber)
		if _err := writeBuffer.WriteUint8("magicNumber", 5, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'magicNumber' field")
		}

		// Simple Field (versionNumber)
		if _err := writeBuffer.WriteUint8("versionNumber", 5, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'versionNumber' field")
		}

		// Simple Field (revisionNumber)
		if _err := writeBuffer.WriteUint8("revisionNumber", 6, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'revisionNumber' field")
		}
	case propertyType == KnxPropertyDataType_PDT_ALARM_INFO: // Struct

		// Simple Field (logNumber)
		if _err := writeBuffer.WriteUint8("logNumber", 8, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'logNumber' field")
		}

		// Simple Field (alarmPriority)
		if _err := writeBuffer.WriteUint8("alarmPriority", 8, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'alarmPriority' field")
		}

		// Simple Field (applicationArea)
		if _err := writeBuffer.WriteUint8("applicationArea", 8, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'applicationArea' field")
		}

		// Simple Field (errorClass)
		if _err := writeBuffer.WriteUint8("errorClass", 8, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'errorClass' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 4, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (errorcodeSup)
		if _err := writeBuffer.WriteBit("errorcodeSup", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'errorcodeSup' field")
		}

		// Simple Field (alarmtextSup)
		if _err := writeBuffer.WriteBit("alarmtextSup", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'alarmtextSup' field")
		}

		// Simple Field (timestampSup)
		if _err := writeBuffer.WriteBit("timestampSup", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'timestampSup' field")
		}

		// Simple Field (ackSup)
		if _err := writeBuffer.WriteBit("ackSup", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'ackSup' field")
		}

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 5, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (locked)
		if _err := writeBuffer.WriteBit("locked", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'locked' field")
		}

		// Simple Field (alarmunack)
		if _err := writeBuffer.WriteBit("alarmunack", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'alarmunack' field")
		}

		// Simple Field (inalarm)
		if _err := writeBuffer.WriteBit("inalarm", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'inalarm' field")
		}
	case propertyType == KnxPropertyDataType_PDT_BINARY_INFORMATION: // BOOL

		// Reserved Field (Just skip the bytes)
		if _err := writeBuffer.WriteUint8("reserved", 7, uint8(0x00)); _err != nil {
			return errors.Wrap(_err, "Error serializing reserved field")
		}

		// Simple Field (value)
		if _err := writeBuffer.WriteBit("value", value.GetBool()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_BITSET8: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((8)); i++ {
			_itemErr := writeBuffer.WriteBit("", value.GetIndex(i).GetBool())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_BITSET16: // List

		// Array Field (value)
		for i := uint32(0); i < uint32((16)); i++ {
			_itemErr := writeBuffer.WriteBit("", value.GetIndex(i).GetBool())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	case propertyType == KnxPropertyDataType_PDT_ENUM8: // USINT

		// Simple Field (value)
		if _err := writeBuffer.WriteUint8("value", 8, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	case propertyType == KnxPropertyDataType_PDT_SCALING: // USINT

		// Simple Field (value)
		if _err := writeBuffer.WriteUint8("value", 8, value.GetUint8()); _err != nil {
			return errors.Wrap(_err, "Error serializing 'value' field")
		}
	default: // List

		// Array Field (value)
		for i := uint32(0); i < uint32(dataLengthInBytes); i++ {
			_itemErr := writeBuffer.WriteUint8("", 8, value.GetIndex(i).GetUint8())
			if _itemErr != nil {
				return errors.Wrap(_itemErr, "Error serializing 'value' field")
			}
		}
	}
	writeBuffer.PopContext("KnxProperty")
	return nil
}
