Chinmoy, note that datatypes like Unsigned32,Address (V4 or V6) and most of the subscriber id related AVPs have predefined length. You don't have to do anything there - unlike you are developing your own Diameter library.
String fields (UTF8, OctetString) are of variable length, so application has to initiate both the data as well as the length properly. But depending on the usage, in the application you can always define an upper limit (for programming purpose). For example, for hostname (Origin-Hostname, Destination-Hostname), probably 256 bytes will be OK.
When you receive a PDU, AVP length is part of the header, so to the extent possible, you should not make any assumptions about the length, but extract it from the PDU.