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
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

type_bytes.go 865B

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