code: def write_var_int(self, value, little_endian=True):
          
          if not isinstance(value, int):
              raise SDKException(ErrorCode.param_err('%s not int type.' % value))
  
          if value < 0:
              raise SDKException(ErrorCode.param_err('%d too small.' % value))
  
          elif value < 0xfd:
              return self.write_byte(value)
  
          elif value <= 0xffff:
              self.write_byte(0xfd)
              return self.write_uint16(value, little_endian)
  
          elif value <= 0xFFFFFFFF:
              self.write_byte(0xfe)
              return self.write_uint32(value, little_endian)
  
          else:
              self.write_byte(0xff)
              return self.write_uint64(value, little_endian)
docs: Write an integer value in a space saving way to the stream.
  
          Args:
              value (int):
              little_endian (bool): specify the endianness. (Default) Little endian.
  
          Raises:
              SDKException: if `value` is not of type int.
              SDKException: if `value` is < 0.
  
          Returns:
              int: the number of bytes written.