Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
liber
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
liber
Commits
bc535848
Commit
bc535848
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
use Gob for database blobs, to avoid loss of numerical precision on uint64 with JSON
parent
c2b68b72
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
database.go
+7
-7
7 additions, 7 deletions
database.go
with
7 additions
and
7 deletions
database.go
+
7
−
7
View file @
bc535848
...
...
@@ -4,7 +4,7 @@ import (
"bytes"
cryptorand
"crypto/rand"
"encoding/binary"
"encoding/
json
"
"encoding/
gob
"
"errors"
"math/rand"
"os"
...
...
@@ -196,7 +196,7 @@ func (db *Database) GetBookFiles(bookid BookId) ([]*File, error) {
var
out
[]
*
File
for
it
.
Seek
(
start
);
it
.
Valid
()
&&
bytes
.
Compare
(
it
.
Key
(),
end
)
<
0
;
it
.
Next
()
{
var
filepath
string
if
json
.
Unmarshal
(
it
.
Value
()
,
&
filepath
)
==
nil
{
if
gob
.
NewDecoder
(
bytes
.
NewReader
(
it
.
Value
()
))
.
Decode
(
&
filepath
)
==
nil
{
if
file
,
err
:=
db
.
GetFile
(
filepath
);
err
==
nil
{
out
=
append
(
out
,
file
)
}
...
...
@@ -212,7 +212,7 @@ func (db *Database) Get(bucket, key []byte, obj interface{}) error {
if
err
!=
nil
{
return
err
}
return
json
.
Unmarshal
(
data
,
obj
)
return
gob
.
NewDecoder
(
bytes
.
NewReader
(
data
))
.
Decode
(
obj
)
}
func
(
db
*
Database
)
PutBook
(
b
*
Book
)
error
{
...
...
@@ -237,15 +237,15 @@ func (db *Database) PutFile(f *File) error {
}
func
(
db
*
Database
)
Put
(
bucket
,
key
[]
byte
,
obj
interface
{})
error
{
data
,
err
:=
json
.
Marshal
(
obj
)
if
err
!=
nil
{
var
buf
bytes
.
Buffer
if
err
:=
gob
.
NewEncoder
(
&
buf
)
.
Encode
(
obj
);
err
!=
nil
{
return
err
}
wo
:=
levigo
.
NewWriteOptions
()
defer
wo
.
Close
()
return
db
.
leveldb
.
Put
(
wo
,
bktToKey
(
bucket
,
key
),
data
)
return
db
.
leveldb
.
Put
(
wo
,
bktToKey
(
bucket
,
key
),
buf
.
Bytes
()
)
}
func
(
db
*
Database
)
DeleteBook
(
bookid
BookId
)
error
{
...
...
@@ -303,7 +303,7 @@ func (i *DatabaseIterator) Id() BookId {
}
func
(
i
*
DatabaseIterator
)
Value
(
obj
interface
{})
error
{
return
json
.
Unmarshal
(
i
.
iter
.
Value
()
,
obj
)
return
gob
.
NewDecoder
(
bytes
.
NewReader
(
i
.
iter
.
Value
()
))
.
Decode
(
obj
)
}
// Scan an entire bucket.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment