Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefane Fermigier
neo
Commits
3398c0af
Commit
3398c0af
authored
7 years ago
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
78681a6e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
3 deletions
+41
-3
go/neo/client/client.go
go/neo/client/client.go
+41
-3
No files found.
go/neo/client/client.go
View file @
3398c0af
...
...
@@ -21,7 +21,11 @@
package
client
import
(
"bytes"
"compress/zlib"
"context"
"crypto/sha1"
"io"
"math/rand"
"net/url"
...
...
@@ -99,6 +103,29 @@ func (c *Client) LastOid() (zodb.Oid, error) {
panic
(
"TODO"
)
}
// decompress decompresses data according to zlib encoding.
//
// out buffer, if there is enough capacity, is used for decompression destionation.
// if out has not not enough capacity a new buffer is allocated and used.
//
// return: destination buffer with full decompressed data.
func
decompress
(
in
[]
byte
,
out
[]
byte
)
([]
byte
,
error
)
{
bin
:=
bytes
.
NewReader
(
in
)
zr
,
err
:=
zlib
.
NewReader
(
bin
)
if
err
!=
nil
{
return
nil
,
err
}
defer
zr
.
Close
()
bout
:=
bytes
.
NewBuffer
(
out
)
_
,
err
=
io
.
Copy
(
bout
,
bin
)
if
err
!=
nil
{
return
nil
,
err
}
return
bout
.
Bytes
(),
nil
}
func
(
c
*
Client
)
Load
(
xid
zodb
.
Xid
)
(
data
[]
byte
,
tid
zodb
.
Tid
,
err
error
)
{
// XXX check pt is operational first? -> no if there is no data - we'll
// just won't find ready cell
...
...
@@ -115,6 +142,7 @@ func (c *Client) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error) {
if
err
!=
nil
{
panic
(
0
)
// XXX
}
defer
lclose
(
Sconn
)
req
:=
neo
.
GetObject
{
Oid
:
xid
.
Oid
}
if
xid
.
TidBefore
{
...
...
@@ -131,12 +159,22 @@ func (c *Client) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error) {
return
nil
,
0
,
err
// XXX err context
}
// TODO reply.Checksum - check sha1
// TODO reply.Compression - decompress
checksum
:=
sha1
.
Sum
(
data
)
if
checksum
!=
reply
.
Checksum
{
// XXX data corrupt
}
data
:=
resp
.
Data
if
reply
.
Compression
{
data
,
err
=
decompress
(
resp
.
Data
,
make
([]
byte
,
0
,
len
(
resp
.
Data
)))
if
err
!=
nil
{
// XXX data corrupt
}
}
// reply.NextSerial
// reply.DataSerial
return
resp
.
D
ata
,
resp
.
Serial
,
nil
return
d
ata
,
resp
.
Serial
,
nil
}
func
(
c
*
Client
)
Iterate
(
tidMin
,
tidMax
zodb
.
Tid
)
zodb
.
IStorageIterator
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment