2016-01-15 06:43:06 -05:00
|
|
|
// +build json
|
|
|
|
|
2016-02-03 05:58:42 -05:00
|
|
|
package protocol
|
2016-01-15 06:43:06 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core/common/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (u *User) UnmarshalJSON(data []byte) error {
|
|
|
|
type rawUser struct {
|
|
|
|
IdString string `json:"id"`
|
|
|
|
EmailString string `json:"email"`
|
2016-01-20 11:31:43 -05:00
|
|
|
LevelByte byte `json:"level"`
|
2016-01-18 19:21:07 -05:00
|
|
|
AlterIdCount uint16 `json:"alterId"`
|
2016-01-15 06:43:06 -05:00
|
|
|
}
|
|
|
|
var rawUserValue rawUser
|
|
|
|
if err := json.Unmarshal(data, &rawUserValue); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
id, err := uuid.ParseString(rawUserValue.IdString)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-01-20 11:31:43 -05:00
|
|
|
*u = *NewUser(NewID(id), UserLevel(rawUserValue.LevelByte), rawUserValue.AlterIdCount)
|
2016-01-15 06:43:06 -05:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|