// CodeToVarint converts an integer to a varint-encoded []byte
546093
func CodeToVarint(num int) []byte {
	buf := make([]byte, VarintSize(num))
	n := binary.PutUvarint(buf, uint64(num))
	return buf[:n]
}
389172
func (c *Connection) ReceiveTickerInterval() int64 {
	if c.hbd == nil {
		return 0
	}
	return c.hbd.rti / 1000000
}
1363627
func (c *Connection) SendTickerInterval() int64 {
	if c.hbd == nil {
		return 0
	}
	return c.hbd.sti / 1000000
}
616417
func IntToTrytes(value int64, trytesCnt int) Trytes {
	remainder := value
	if value < 0 {
		remainder = -value
	}

	var t Trytes

	for tryte := 0; tryte < trytesCnt; tryte++ {
		idx := remainder % 27
		remainder /= 27

		if idx > 13 {
			remainder += 1
		}

		if value < 0 && idx != 0 {
			idx = 27 - idx
		}

		t += string(TryteAlphabet[idx])
	}
	return t
}
538200
func (scope *Scope) AddToVars(value interface{}) string {
	_, skipBindVar := scope.InstanceGet("skip_bindvar")

	if expr, ok := value.(*expr); ok {
		exp := expr.expr
		for _, arg := range expr.args {
			if skipBindVar {
				scope.AddToVars(arg)
			} else {
				exp = strings.Replace(exp, "?", scope.AddToVars(arg), 1)
			}
		}
		return exp
	}

	scope.SQLVars = append(scope.SQLVars, value)

	if skipBindVar {
		return "?"
	}
	return scope.Dialect().BindVar(len(scope.SQLVars))
}
770088
func (r *ruleImpl) CallInternal(th *starlark.Thread, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
	newArgs := make(starlark.Tuple, 0, len(args)+1)
	newArgs = append(newArgs, starlarkstruct.FromStringDict(
		starlark.String("lucicfg.rule_ctx"),
		starlark.StringDict{
			"defaults": r.defaults,
		},
	))
	newArgs = append(newArgs, args...)
	switch res, err := r.Callable.CallInternal(th, newArgs, kwargs); {
	case err != nil:
		return nil, err
	case !isNamedStruct(res, "graph.keyset"):
		return nil, fmt.Errorf("bad rule implementation %s: must return graph.keyset, got %s", r.Callable, res.Type())
	default:
		return res, nil
	}
}
706371
func DecodeVarint(b []byte) ([]byte, int64, error) {
	v, n := binary.Varint(b)
	if n > 0 {
		return b[n:], v, nil
	}
	if n < 0 {
		return nil, 0, errors.New("value larger than 64 bits")
	}
	return nil, 0, errors.New("insufficient bytes to decode value")
}
1212345
func (p *PAM) codeToError(returnValue C.int) error {
	// Error strings are not allocated on the heap, so memory does not need
	// released.
	err := C._pam_strerror(pamHandle, p.pamh, returnValue)
	if err != nil {
		return trace.BadParameter(C.GoString(err))
	}

	return nil
}
656484
func ParseInt(value string) (int, error) {
	i, err := strconv.ParseInt(strings.TrimPrefix(value, "0x"), 16, 64)
	if err != nil {
		return 0, err
	}

	return int(i), nil
}
107228
func (f CodecFactory) DecoderToVersion(serializer runtime.Serializer, gv unversioned.GroupVersion) runtime.Decoder {
	return f.CodecForVersions(serializer, nil, []unversioned.GroupVersion{gv})
}
496102
func stringIntMapParser(rd *proto.Reader, n int64) (interface{}, error) {
	m := make(map[string]int64, n/2)
	for i := int64(0); i < n; i += 2 {
		key, err := rd.ReadString()
		if err != nil {
			return nil, err
		}

		n, err := rd.ReadIntReply()
		if err != nil {
			return nil, err
		}

		m[key] = n
	}
	return m, nil
}
750671
func codeVal(status int) string {
	code := (status - (status % 100)) / 100
	return strconv.Itoa(code) + "xx"
}
1231462
func DecodeComparableVarint(b []byte) ([]byte, int64, error) {
	if len(b) == 0 {
		return nil, 0, errors.Trace(errDecodeInsufficient)
	}
	first := b[0]
	if first >= negativeTagEnd && first <= positiveTagStart {
		return b, int64(first) - negativeTagEnd, nil
	}
	b = b[1:]
	var length int
	var v uint64
	if first < negativeTagEnd {
		length = negativeTagEnd - int(first)
		v = math.MaxUint64 // negative value has all bits on by default.
	} else {
		length = int(first) - positiveTagStart
	}
	if len(b) < length {
		return nil, 0, errors.Trace(errDecodeInsufficient)
	}
	for _, c := range b[:length] {
		v = (v << 8) | uint64(c)
	}
	if first > positiveTagStart && v > math.MaxInt64 {
		return nil, 0, errors.Trace(errDecodeInvalid)
	} else if first < negativeTagEnd && v <= math.MaxInt64 {
		return nil, 0, errors.Trace(errDecodeInvalid)
	}
	return b[length:], int64(v), nil
}
1177263
func InterfaceToValue(goval interface{}) (Value, error) {
	switch goval := goval.(type) {
	case nil:
		return NULL, nil
	case []byte:
		return MakeTrusted(VarBinary, goval), nil
	case int64:
		return NewInt64(goval), nil
	case uint64:
		return NewUint64(goval), nil
	case float64:
		return NewFloat64(goval), nil
	case string:
		return NewVarChar(goval), nil
	default:
		return NULL, fmt.Errorf("unexpected type %T: %v", goval, goval)
	}
}
1043858
func ConvertToValue(p interface{}, tagName string) interface{} {
	rv := toValue(p)
	switch rv.Kind() {
	case reflect.Struct:
		return convertFromStruct(rv.Interface(), tagName)
	case reflect.Map:
		return convertFromMap(rv, tagName)
	case reflect.Slice:
		return convertFromSlice(rv, tagName)
	case reflect.Chan:
		return nil
	case reflect.Invalid:
		return nil
	default:
		return rv.Interface()
	}
}
1249830
func (s *Redirect) SetHttpRedirectCode(v string) *Redirect {
	s.HttpRedirectCode = &v
	return s
}
715478
func CodeFromErr(err error) string {

	errToken, ok := err.(*ErrToken)
	if !ok {
		return collector.InvalidToken
	}

	return errToken.Code()
}