user_json.go 618 B

1234567891011121314151617181920212223242526272829
  1. // +build json
  2. package vmess
  3. import (
  4. "encoding/json"
  5. "github.com/v2ray/v2ray-core/common/uuid"
  6. )
  7. func (u *User) UnmarshalJSON(data []byte) error {
  8. type rawUser struct {
  9. IdString string `json:"id"`
  10. EmailString string `json:"email"`
  11. LevelByte byte `json:"level"`
  12. AlterIdCount uint16 `json:"alterId"`
  13. }
  14. var rawUserValue rawUser
  15. if err := json.Unmarshal(data, &rawUserValue); err != nil {
  16. return err
  17. }
  18. id, err := uuid.ParseString(rawUserValue.IdString)
  19. if err != nil {
  20. return err
  21. }
  22. *u = *NewUser(NewID(id), UserLevel(rawUserValue.LevelByte), rawUserValue.AlterIdCount)
  23. return nil
  24. }