mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 16:50:18 +01:00
LevelDB needs re-coding of positions with zero components.
This commit is contained in:
parent
de9f738306
commit
35d05ba9c8
22
coords.go
Normal file
22
coords.go
Normal file
@ -0,0 +1,22 @@
|
||||
// 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)
|
||||
}
|
@ -64,6 +64,13 @@ func (ldb *LevelDBBackend) keyExists(key []byte) (exists bool, err error) {
|
||||
|
||||
func (ldb *LevelDBBackend) Store(hash, key, value []byte) (exists bool, err error) {
|
||||
|
||||
var pos int64
|
||||
if pos, err = bytes2pos(key); err != nil {
|
||||
return
|
||||
}
|
||||
// Re-code it to make LevelDB happy.
|
||||
key = pos2bytes(pos)
|
||||
|
||||
if exists, err = ldb.keyExists(key); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ package main
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
@ -113,10 +112,6 @@ func (sqlb *SqliteBackend) txStmt(stmt *sql.Stmt) *sql.Stmt {
|
||||
return stmt
|
||||
}
|
||||
|
||||
func bytes2pos(key []byte) (pos int64, err error) {
|
||||
return strconv.ParseInt(string(key), 10, 64)
|
||||
}
|
||||
|
||||
func (sqlb *SqliteBackend) Fetch(hash, key []byte) (data []byte, err error) {
|
||||
var pos int64
|
||||
if pos, err = bytes2pos(key); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user