mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-17 23:58:17 +01:00
23 lines
510 B
Go
23 lines
510 B
Go
|
// 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.
|
||
|
|
||
|
package main
|
||
|
|
||
|
import "strconv"
|
||
|
|
||
|
// Returns database pos as a byte slice.
|
||
|
func pos2bytes(pos int64) []byte {
|
||
|
buf := make([]byte, 8, 8)
|
||
|
for i := 7; i >= 0; i-- {
|
||
|
buf[i] = byte(pos & 0xff)
|
||
|
pos >>= 8
|
||
|
}
|
||
|
return buf
|
||
|
}
|
||
|
|
||
|
// Constructs a database key out of byte slice.
|
||
|
func bytes2pos(key []byte) (pos int64, err error) {
|
||
|
return strconv.ParseInt(string(key), 10, 64)
|
||
|
}
|