iroha icon indicating copy to clipboard operation
iroha copied to clipboard

Implement human-readable bytes in the config

Open 0x009922 opened this issue 1 year ago • 2 comments

Description

Actually implement parsing from a human-readable string for HumanBytes:

https://github.com/hyperledger/iroha/blob/964476722e2a219becaacdb3676ca058ec5748cd/config/base/src/lib.rs#L36-L38

Specification

Here is an excerpt from the config reference draft:

Bytes amount is specified as a human-readable string:

# 42 bytes
value1 = "42B"

# 1 kilobyte = 1000 bytes
value2 = "1KB"

# 1 kilobyte (binary format) = 1024 bytes
value3 = "1KiB"

# Sum of multiple
value4 = "1GB 5MB"

Iroha can parse sizes in bytes, kilobytes (K), megabytes (M), gigabytes (G), terabytes (T), and petabytes (P).

The format of suffixes:

  • {size}iB: Binary size
  • {size}B: Decimal size

I used humanfriendly Python package as a reference.

Also

0x009922 avatar Feb 18 '24 22:02 0x009922

as discussed https://github.com/hyperledger/iroha-2-docs/issues/392 I'm not sure we want to complicate config files. Simple fixed suffix on the field name should suffice IMO. We need to discuss this before proceeding

mversic avatar Feb 19 '24 08:02 mversic

I am in favor of having human-readable suffixes in config, this makes it much easier to write large values by hand.

Oftentimes, when a large value is needed, you would still end up having a comment to explain what the value actually is, like max_transfer_bytes = 1048576 # 1 MiB, so having this natively supported by the config system is better UX IMO.

Same opinion on the #4294 with the same arguments, time_value = "1h" is better than time_value_ms = 3600000 # 1 hour

DCNick3 avatar Jul 26 '24 08:07 DCNick3