// UnmarshalText take a string of format time.RFC3339 and marshals it into the TimeWrapper value (Kdbx v3.1)
// On Kdbx v4 it calculates the time with given seconds via data byte array (base64 encoded)
552178
func (tw *TimeWrapper) UnmarshalText(data []byte) error {
	var formatted bool
	// Check for RFC string (KDBX 3.1), if it fail try with KDBX 4
	t, err := time.Parse(time.RFC3339, string(data))
	if err != nil {
		// KDBX v4
		// In version 4 the time is a base64 timestamp of seconds passed since 1/1/0001
		var buf int64

		decoded := make([]byte, base64.StdEncoding.DecodedLen(len(data)))
		_, err = base64.StdEncoding.Decode(decoded, data)
		if err != nil {
			return err
		}
		if err := binary.Read(bytes.NewReader(decoded), binary.LittleEndian, &buf); err != nil {
			return err
		}

		// Count since year 0
		t = time.Date(0, 1, 1, 0, 0, 0, 0, time.UTC)
		for {
			if buf < intLimit {
				t = t.Add(time.Duration(buf) * time.Second)
				break
			} else {
				t = t.Add(time.Duration(intLimit) * time.Second)
				buf -= intLimit
			}
		}
		formatted = false
	} else {
		formatted = true
	}
	*tw = TimeWrapper{
		Formatted: formatted,
		Time:      t,
	}
	return nil
}
65378
func (c *Cid) UnmarshalText(text []byte) error {
	decodedCid, err := Decode(string(text))
	if err != nil {
		return err
	}
	c.str = decodedCid.str
	return nil
}
889323
func (t *Time) UnmarshalJSON(value []byte) (err error) {
	v := strings.Trim(string(value), "\"")

	if v == "" {
		t.Time = time.Time{}

		return
	}

	timestamp, err := strconv.ParseInt(v, 10, 64)

	if err != nil {
		return
	}

	t.Time = time.Unix(timestamp, 0)

	return
}
112602
func (l *LocalDevices) UnmarshalText(value []byte) error {

	m := ldRX.FindSubmatch(value)
	lm := len(m)

	if lm < 3 {
		return goof.WithField("value", string(value), "invalid LocalDevices")
	}

	l.Driver = string(m[1])
	l.DeviceMap = map[string]string{}

	for _, p := range bytes.Split(m[2], commaByteSep) {
		pp := bytes.Split(p, colonByteSep)
		if len(pp) < 2 {
			continue
		}
		l.DeviceMap[string(pp[0])] = string(pp[1])
	}

	return nil
}
19459
func (timestamp *Timestamp) UnmarshalJSON(data []byte) error {
	t, err := time.Parse(timestampFormat, string(data))
	if err != nil {
		return err
	}

	*timestamp = Timestamp(t)
	return nil
}
942787
func (s *UUID) UnmarshalText(text []byte) error {
	var ss []string
	for _, x := range strings.Split(string(text), ",") {
		ss = append(ss, strings.TrimSpace(x))
	}
	us, err := strSliceToUUIDSlice(ss)
	if err != nil {
		return errors.WithStack(err)
	}
	*s = us
	return nil
}
994040
func (p *PHYPayload) UnmarshalText(text []byte) error {
	b, err := base64.StdEncoding.DecodeString(string(text))
	if err != nil {
		return err
	}
	return p.UnmarshalBinary(b)
}
1012579
func (v *Feature) UnmarshalText(value []byte) error {
	switch s := string(value); s {
	case "SERVICE_GENERATOR":
		*v = FeatureServiceGenerator
		return nil
	default:
		val, err := strconv.ParseInt(s, 10, 32)
		if err != nil {
			return fmt.Errorf("unknown enum value %q for %q: %v", s, "Feature", err)
		}
		*v = Feature(val)
		return nil
	}
}
139227
func (d *Duration) UnmarshalText(text []byte) error {
	// Ignore if there is no value set.
	if len(text) == 0 {
		return nil
	}

	// Otherwise parse as a duration formatted string.
	duration, err := time.ParseDuration(string(text))
	if err != nil {
		return err
	}

	// Set duration and return.
	*d = Duration(duration)
	return nil
}
211176
func (co *ChangeOption) UnmarshalText(b []byte) error {
	s := strings.ToLower(strings.Trim(string(b), `"`))
	switch s {
	case strings.ToLower(string(RestartAllOnInstanceChanged)), strings.ToLower(string(RestartAllOnInstanceZeroDown)):
		*co = ChangeOption(s)
	case "":
		*co = DefaultChangeOption
	default:
		return errors.New("Invalid ChangeOption: " + s)
	}
	return nil
}
1239751
func (eui *EUI64) UnmarshalText(data []byte) error {
	parsed, err := ParseEUI64(string(data))
	if err != nil {
		return err
	}
	*eui = EUI64(parsed)
	return nil
}
750364
func (t *Token) UnmarshalText(data []byte) error {

	number := uint64(0)
	idx := 0.0
	chars := []byte(Base62)

	charsLength := float64(len(chars))
	tokenLength := float64(len(data))

	if tokenLength > MaxTokenLength {
		return ErrTokenTooBig
	} else if tokenLength < MinTokenLength {
		return ErrTokenTooSmall
	}

	for _, c := range data {
		power := tokenLength - (idx + 1)
		index := bytes.IndexByte(chars, c)
		if index < 0 {
			return ErrInvalidCharacter
		}
		number += uint64(index) * uint64(math.Pow(charsLength, power))
		idx++
	}

	// the token was successfully decoded
	*t = Token(number)
	return nil
}
812044
func (u *UUID) UnmarshalText(text []byte) (err error) {
	if len(text) < 32 {
		err = fmt.Errorf("uuid: UUID string too short: %s", text)
		return
	}

	t := text[:]
	braced := false

	if bytes.Equal(t[:9], urnPrefix) {
		t = t[9:]
	} else if t[0] == '{' {
		braced = true
		t = t[1:]
	}

	b := u[:]

	for i, byteGroup := range byteGroups {
		if i > 0 {
			if t[0] != '-' {
				err = fmt.Errorf("uuid: invalid string format")
				return
			}
			t = t[1:]
		}

		if len(t) < byteGroup {
			err = fmt.Errorf("uuid: UUID string too short: %s", text)
			return
		}

		if i == 4 && len(t) > byteGroup &&
			((braced && t[byteGroup] != '}') || len(t[byteGroup:]) > 1 || !braced) {
			err = fmt.Errorf("uuid: UUID string too long: %s", text)
			return
		}

		_, err = hex.Decode(b[:byteGroup/2], t[:byteGroup])
		if err != nil {
			return
		}

		t = t[byteGroup:]
		b = b[byteGroup/2:]
	}

	return
}
414793
func (t *Timestamp) UnmarshalJSON(data []byte) error {
	strValue := string(data)
	strValue = strings.Replace(strValue, `"`, ``, -1)
	if strings.Contains(strValue, ".") {
		components := strings.Split(strValue, ".")
		if integerValue, integerErr := strconv.ParseInt(components[0], 10, 64); integerErr == nil {
			t.time = time.Unix(integerValue, 0)
			t.uuid = components[1]
		}
	}

	if integerValue, integerErr := strconv.ParseInt(strValue, 10, 64); integerErr == nil {
		t.time = time.Unix(integerValue, 0)
	}

	return nil
}
64638
func (d *Duration) UnmarshalText(text []byte) error {
	if text == nil {
		*d = 0
		return nil
	}

	var (
		out  time.Duration
		sign time.Duration = 1
	)
	match := durationRegexp.FindStringSubmatch(string(text))
	if match == nil || strings.Join(match[2:6], "") == "" {
		return fmt.Errorf("invalid duration (%s)", text)
	}
	if match[1] == "-" {
		sign = -1
	}
	if match[2] != "" {
		y, err := strconv.Atoi(match[2])
		if err != nil {
			return fmt.Errorf("invalid duration years (%s): %s", text, err)
		}
		out += time.Duration(y) * year
	}
	if match[3] != "" {
		m, err := strconv.Atoi(match[3])
		if err != nil {
			return fmt.Errorf("invalid duration months (%s): %s", text, err)
		}
		out += time.Duration(m) * month
	}
	if match[4] != "" {
		d, err := strconv.Atoi(match[4])
		if err != nil {
			return fmt.Errorf("invalid duration days (%s): %s", text, err)
		}
		out += time.Duration(d) * day
	}
	if match[5] != "" {
		match := durationTimeRegexp.FindStringSubmatch(match[5])
		if match == nil {
			return fmt.Errorf("invalid duration (%s)", text)
		}
		if match[1] != "" {
			h, err := strconv.Atoi(match[1])
			if err != nil {
				return fmt.Errorf("invalid duration hours (%s): %s", text, err)
			}
			out += time.Duration(h) * time.Hour
		}
		if match[2] != "" {
			m, err := strconv.Atoi(match[2])
			if err != nil {
				return fmt.Errorf("invalid duration minutes (%s): %s", text, err)
			}
			out += time.Duration(m) * time.Minute
		}
		if match[3] != "" {
			s, err := strconv.ParseFloat(match[3], 64)
			if err != nil {
				return fmt.Errorf("invalid duration seconds (%s): %s", text, err)
			}
			out += time.Duration(s * float64(time.Second))
		}
	}

	*d = Duration(sign * out)
	return nil
}
251585
func (m *RelaxedTime) UnmarshalText(text []byte) error {
	if len(text) == 0 {
		*m = RelaxedTime(time.Time{})
		return nil
	}
	t, err1 := time.Parse(time.RFC3339, string(text))
	if err1 == nil {
		t = t.Round(time.Millisecond)
		*m = RelaxedTime(t)
		return nil
	}

	t, err2 := time.Parse(time.RFC3339Nano, string(text))
	if err2 == nil {
		t = t.Round(time.Millisecond)
		*m = RelaxedTime(t)
		return nil
	}

	t, err2 = time.Parse("2006-01-02T15:04:05.999999999", string(text))
	if err2 == nil {
		t = t.Round(time.Millisecond)
		*m = RelaxedTime(t)
		return nil
	}

	return err1
}
398858
func (i *HexOrDecimal64) UnmarshalText(input []byte) error {
	int, ok := ParseUint64(string(input))
	if !ok {
		return fmt.Errorf("invalid hex or decimal integer %q", input)
	}
	*i = HexOrDecimal64(int)
	return nil
}