// ParseBase58 parses a base58 []byte into a snowflake ID
347909
func ParseBase58(b []byte) (ID, error) {

	var id int64

	for i := range b {
		if decodeBase58Map[b[i]] == 0xFF {
			return -1, ErrInvalidBase58
		}
		id = id*58 + int64(decodeBase58Map[b[i]])
	}

	return ID(id), nil
}
516378
func DecodeBase64(s string) (int, error) {
	n := 0
	for _, c := range s {
		n *= 36
		i := strings.IndexRune(base64Chars, c)
		if i == -1 {
			return 0, errInvalidBase64
		}
		n += i
	}
	return n, nil
}
389976
func (entity *BaseEntity) InitBaseEntityParser() {
	entity.On = true
	entity.Visible = true
	entity.Init(map[int]core.TypeParser{
		5:  core.NewStringTypeParserToVar(&entity.Handle),
		6:  core.NewStringTypeParserToVar(&entity.LineTypeName),
		8:  core.NewStringTypeParserToVar(&entity.LayerName),
		48: core.NewFloatTypeParserToVar(&entity.LineTypeScale),
		60: core.NewIntTypeParser(func(value int) {
			entity.Visible = value == 0
		}),
		62: core.NewIntTypeParser(func(value int) {
			if value < 0 {
				entity.On = false
				value = -value
			}
			entity.Color = value
		}),
		67: core.NewIntTypeParser(func(value int) {
			entity.Space = Space(value)
		}),
		284: core.NewIntTypeParser(func(value int) {
			entity.ShadowMode = ShadowMode(value)
		}),
		330: core.NewStringTypeParserToVar(&entity.Owner),
		370: core.NewIntTypeParserToVar(&entity.LineWeight),
		410: core.NewStringTypeParserToVar(&entity.LayoutTabName),

		420: core.NewIntTypeParser(func(value int) {
			entity.TrueColor = core.TrueColor(value)
		}),
		430: core.NewStringTypeParserToVar(&entity.ColorName),
		440: core.NewIntTypeParserToVar(&entity.Transparency),
	})
}
32987
func parseInt64(d []byte) (n int64) {
	if len(d) == 0 {
		return -1
	}
	for _, dec := range d {
		if dec < asciiZero || dec > asciiNine {
			return -1
		}
		n = n*10 + (int64(dec) - asciiZero)
	}
	return n
}
313861
func ParseConfig(bs []byte, services []string) (*Config, error) {

	if bs == nil {
		return nil, nil
	}

	var result Config

	if err := util.Unmarshal(bs, &result); err != nil {
		return nil, err
	}

	return &result, result.validateAndInjectDefaults(services)
}
48215
func EncodeBase64(n int) string {
	var buf [16]byte
	size := 0
	for {
		buf[size] = base64Chars[n%36]
		size++
		if n < 36 {
			break
		}
		n /= 36
	}
	end := size - 1
	for i := 0; i < end; i++ {
		b := buf[i]
		buf[i] = buf[end]
		buf[end] = b
		end--
	}
	return string(buf[:size])
}
537108
func Md5Base64_32(data string) string {
	md5String := Md5Signature(data)

	return base64.StdEncoding.EncodeToString([]byte(md5String))
}
680394
func ParseUID(value string) (uint32, error) {
	uid, err := strconv.ParseUint(value, 10, 32)
	if err != nil {
		return 0, vterrors.Wrap(err, "bad tablet uid")
	}
	return uint32(uid), nil
}
1332660
func ParseObjectType(value string) (typ ObjectType, err error) {
	switch value {
	case "commit":
		typ = CommitObject
	case "tree":
		typ = TreeObject
	case "blob":
		typ = BlobObject
	case "tag":
		typ = TagObject
	case "ofs-delta":
		typ = OFSDeltaObject
	case "ref-delta":
		typ = REFDeltaObject
	default:
		err = ErrInvalidType
	}
	return
}
620758
func decodeBase64(s string) ([]byte, error) {
	for i := 0; i < len(s)%4; i++ {
		s += "="
	}
	return base64.URLEncoding.DecodeString(s)
}
859935
func ParseBase2Bytes(s string) (Base2Bytes, error) {
	n, err := ParseUnit(s, bytesUnitMap)
	if err != nil {
		n, err = ParseUnit(s, oldBytesUnitMap)
	}
	return Base2Bytes(n), err
}
780420
func parseAnnotationsUint32(a map[string]string, key string, def uint32) uint32 {
	if v, ok := a[key]; ok {
		countu, err := strconv.ParseUint(v, 10, 32)
		if err == nil {
			v := uint32(countu)
			return v
		}
		logrus.WithFields(logrus.Fields{
			logfields.OCIAnnotation: key,
			logfields.Value:         v,
			logfields.ExpectedType:  logfields.Uint32,
			logrus.ErrorKey:         err,
		}).Warning("annotation could not be parsed")
	}
	return def
}
40539
func (p *WebPage) RenderBase64(format string) (string, error) {
	var resp struct {
		ReturnValue string `json:"returnValue"`
	}
	if err := p.ref.process.doJSON("POST", "/webpage/RenderBase64", map[string]interface{}{"ref": p.ref.id, "format": format}, &resp); err != nil {
		return "", err
	}
	return resp.ReturnValue, nil
}
805159
func parseInt64(d []byte) (n int64) {
	if len(d) == 0 {
		return -1
	}
	for _, dec := range d {
		if dec < ascii_0 || dec > ascii_9 {
			return -1
		}
		n = n*10 + (int64(dec) - ascii_0)
	}
	return n
}
854775
func ParseBytesSize(size string) (int64, error) {
	parts := strings.SplitN(strings.TrimSpace(size), " ", 2)
	memory, err := strconv.ParseFloat(parts[0], 64)
	if err != nil {
		return -1, err
	}
	if factor, ok := binaryMap2[parts[1]]; !ok {
		return -1, fmt.Errorf("Invalid size unit %q for %q", parts[1], size)
	} else {
		return int64(memory * float64(factor)), nil
	}
}
996329
func Encode58(inp []byte) string {
	num := new(big.Int).SetBytes(inp)
	buf := make([]byte, 0, len(inp))
	base := big.NewInt(int64(58))
	rem := new(big.Int)
	quo := new(big.Int)

	for num.Sign() != 0 {
		num, rem = quo.QuoRem(num, base, rem)
		c := alphabet[rem.Uint64()]
		buf = append(buf, c)
	}

	// Pad leading zeros...
	for _, c := range inp {
		if c == 0x0 {
			buf = append(buf, alphabet[0])
		} else {
			// Stop adding padding after the first nonzero byte.
			break
		}
	}
	reverseBuf(buf)

	return string(buf)
}
157178
func ParseConfig(raw []byte, id string) (*Config, error) {
	var result Config
	if err := util.Unmarshal(raw, &result); err != nil {
		return nil, err
	}
	return &result, result.validateAndInjectDefaults(id)
}