2014-08-04 17:10:19 +02:00
|
|
|
// Copyright 2014 by Sascha L. Teichmann
|
|
|
|
// Use of this source code is governed by the MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2014-08-16 16:06:42 +02:00
|
|
|
package common
|
2014-08-04 17:10:19 +02:00
|
|
|
|
2014-08-16 17:41:54 +02:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
)
|
2014-08-04 17:10:19 +02:00
|
|
|
|
|
|
|
// Constructs a database key out of byte slice.
|
2014-08-16 16:06:42 +02:00
|
|
|
func DecodePosFromBytes(key []byte) (pos int64, err error) {
|
2014-08-04 17:10:19 +02:00
|
|
|
return strconv.ParseInt(string(key), 10, 64)
|
|
|
|
}
|
2014-08-16 17:41:54 +02:00
|
|
|
|
|
|
|
// Encode a block pos to byte slice.
|
|
|
|
func EncodePosToBytes(key int64) []byte {
|
2014-08-17 12:08:26 +02:00
|
|
|
return []byte(strconv.FormatInt(key, 10))
|
2014-08-16 17:41:54 +02:00
|
|
|
}
|