⬥ ID3 encoding/decoding library in Go ⬥
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/binary"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Returns found key (int) in provided map by value (string);
|
|
|
|
// If key does not exist in map - returns -1
|
|
|
|
func GetKey(mp map[int]string, givenValue string) int {
|
|
|
|
for key, value := range mp {
|
|
|
|
if value == givenValue {
|
|
|
|
return key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decodes given integer bytes into integer
|
|
|
|
func BytesToInt(gBytes []byte) (int64, error) {
|
|
|
|
buff := bytes.NewBuffer(gBytes)
|
|
|
|
integer, err := binary.ReadVarint(buff)
|
|
|
|
if err != nil {
|
|
|
|
return 0, fmt.Errorf("could not decode integer: %s", err)
|
|
|
|
}
|
|
|
|
buff = nil
|
|
|
|
return integer, nil
|
|
|
|
}
|