Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

type_bytes.go 768B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package config
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/alecthomas/units"
  6. )
  7. type TypeBytes struct {
  8. value uint
  9. }
  10. func (c *TypeBytes) UnmarshalText(data []byte) error {
  11. if len(data) == 0 {
  12. return nil
  13. }
  14. value, err := units.ParseStrictBytes(strings.ToUpper(string(data)))
  15. if err != nil {
  16. return fmt.Errorf("incorrect bytes value: %w", err)
  17. }
  18. if value < 0 {
  19. return fmt.Errorf("%d should be positive number", value)
  20. }
  21. c.value = uint(value)
  22. return nil
  23. }
  24. func (c TypeBytes) MarshalText() ([]byte, error) {
  25. return []byte(c.String()), nil
  26. }
  27. func (c TypeBytes) String() string {
  28. return units.ToString(int64(c.value), 1024, "ib", "b")
  29. }
  30. func (c TypeBytes) Value(defaultValue uint) uint {
  31. if c.value == 0 {
  32. return defaultValue
  33. }
  34. return c.value
  35. }