How to know where number of inputs field ends in a transaction if it is not a fixedsize field?
A Varint is a Variable Length Integer, and can be up to 9 bytes in total

It is usually only one byte, which can represent numbers 0-252. 253-255 (0xFD-0xFF) are used as markers for the next three lengths.

Marker    Payload
None      1 byte of integer data
0xFD      0xFD followed by two bytes of integer data
0xFE      0xFE followed by four bytes of integer data
0xFF      0xFF followed by eight byes of integer data


Each marker indicates how to interpret the upcoming bytes.