// CalculateDiskSizeInMB returns the number of MB in the human readable string
776388
func CalculateDiskSizeInMB(humanReadableDiskSize string) int {
	diskSize, err := units.FromHumanSize(humanReadableDiskSize)
	if err != nil {
		glog.Errorf("Invalid disk size: %v", err)
	}
	return int(diskSize / units.MB)
}
312931
func messageSizeToBitLength(messageSize int) int {
	bytes := float64(messageSize)
	header := math.Ceil(math.Floor(math.Log2(bytes)+1) / 8.0)
	return int(header)
}
111539
func (s *EstimatedResourceSize) SetEstimatedSizeInBytes(v float64) *EstimatedResourceSize {
	s.EstimatedSizeInBytes = &v
	return s
}
466615
func (blk *MeasurementBlock) bytes() int {
	var b int
	// Do not count contents of blk.data or blk.hashData because they reference into an external []byte
	b += int(unsafe.Sizeof(*blk))
	return b
}
945203
func parseSizeInBytes(sizeStr string) uint {
	sizeStr = strings.TrimSpace(sizeStr)
	lastChar := len(sizeStr) - 1
	multiplier := uint(1)

	if lastChar > 0 {
		if sizeStr[lastChar] == 'b' || sizeStr[lastChar] == 'B' {
			if lastChar > 1 {
				switch unicode.ToLower(rune(sizeStr[lastChar-1])) {
				case 'k':
					multiplier = 1 << 10
					sizeStr = strings.TrimSpace(sizeStr[:lastChar-1])
				case 'm':
					multiplier = 1 << 20
					sizeStr = strings.TrimSpace(sizeStr[:lastChar-1])
				case 'g':
					multiplier = 1 << 30
					sizeStr = strings.TrimSpace(sizeStr[:lastChar-1])
				default:
					multiplier = 1
					sizeStr = strings.TrimSpace(sizeStr[:lastChar])
				}
			}
		}
	}

	size := cast.ToInt(sizeStr)
	if size < 0 {
		size = 0
	}

	return safeMul(uint(size), multiplier)
}
595882
func (api *CDROMAPI) SortBySize(reverse bool) *CDROMAPI {
	api.sortBy("SizeMB", reverse)
	return api
}
1190313
func (c Config) MaxLogSizeMB() int {
	// Value has already been validated.
	val, _ := utils.ParseSize(c.mustString(MaxLogsSize))
	return int(val)
}
126527
func (m *MACCommandBlock) Size() (int, error) {
	var count int
	for _, mc := range m.MACCommands {
		b, err := mc.MarshalBinary()
		if err != nil {
			return 0, errors.Wrap(err, "marshal binary error")
		}
		count += len(b)
	}
	return count, nil
}
854775
func ParseBytesSize(size string) (int64, error) {
	parts := strings.SplitN(strings.TrimSpace(size), " ", 2)
	memory, err := strconv.ParseFloat(parts[0], 64)
	if err != nil {
		return -1, err
	}
	if factor, ok := binaryMap2[parts[1]]; !ok {
		return -1, fmt.Errorf("Invalid size unit %q for %q", parts[1], size)
	} else {
		return int64(memory * float64(factor)), nil
	}
}
478188
func (api *DiskAPI) WithSizeGib(size int) *DiskAPI {
	api.FilterBy("SizeMB", size*1024)
	return api
}
795817
func dbCollectionSizeToInt(result bson.M, collectionName string) (int, error) {
	size, ok := result["size"]
	if !ok {
		logger.Warningf("mongo collStats did not return a size field for %q", collectionName)
		// this wasn't considered an error in the past, just treat it as size 0
		return 0, nil
	}
	if asint, ok := size.(int); ok {
		if asint < 0 {
			return 0, errors.Errorf("mongo collStats for %q returned a negative value: %v", collectionName, size)
		}
		return asint, nil
	}
	if asint64, ok := size.(int64); ok {
		// 2billion megabytes is 2 petabytes, which is outside our range anyway.
		if asint64 > math.MaxInt32 {
			return math.MaxInt32, nil
		}
		if asint64 < 0 {
			return 0, errors.Errorf("mongo collStats for %q returned a negative value: %v", collectionName, size)
		}
		return int(asint64), nil
	}
	return 0, errors.Errorf(
		"mongo collStats for %q did not return an int or int64 for size, returned %T: %v",
		collectionName, size, size)
}
668795
func (s *UpdateFileSystemOutput) SetSizeInBytes(v *FileSystemSize) *UpdateFileSystemOutput {
	s.SizeInBytes = v
	return s
}
148455
func (s *InstanceSnapshot) SetSizeInGb(v int64) *InstanceSnapshot {
	s.SizeInGb = &v
	return s
}
627043
func (s *BulkService) estimateSizeInBytes(r BulkableRequest) int64 {
	lines, _ := r.Source()
	size := 0
	for _, line := range lines {
		// +1 for the \n
		size += len(line) + 1
	}
	return int64(size)
}
594174
func (se *SizingEncoder) WriteBytes(value []byte) {
	se.WriteInt32(int32(len(value)))
	se.size += len(value)
}
387584
func (s *ImageDetail) SetImageSizeInBytes(v int64) *ImageDetail {
	s.ImageSizeInBytes = &v
	return s
}
832221
func numChunks(b []byte) int {
	lenB := len(b)
	if lenB <= ChunkSize {
		return 1
	}
	return len(b)/chunkedDataLen + 1
}