From ae89b1613d5734d94ed0a55aeffda32f62463943 Mon Sep 17 00:00:00 2001 From: Ciprian Dorin Craciun Date: Tue, 21 Dec 2021 20:29:33 +0200 Subject: [PATCH] [archiver] Switch the cache from using JSON to using Gob. --- sources/cmd/archiver/archiver.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/sources/cmd/archiver/archiver.go b/sources/cmd/archiver/archiver.go index a9559b1..a6ae74f 100644 --- a/sources/cmd/archiver/archiver.go +++ b/sources/cmd/archiver/archiver.go @@ -3,6 +3,8 @@ package archiver +import "bytes" +import "encoding/gob" import "encoding/hex" import "encoding/json" import "flag" @@ -496,7 +498,7 @@ func prepareDataContent (_context *context, _pathResolved string, _pathInArchive _cacheBucket := _cacheTxn.Bucket ([]byte ("prepare")) if _cacheBucket != nil { if _dataPreparedRaw := _cacheBucket.Get ([]byte (_dataContentId)); _dataPreparedRaw != nil { - if _error := json.Unmarshal (_dataPreparedRaw, &_dataPrepared); _error != nil { + if _error := gobUnmarshal (_dataPreparedRaw, &_dataPrepared); _error != nil { AbortError (_error, "[6865d963] unexpected sources cache error!") } } @@ -571,7 +573,7 @@ func prepareDataContent (_context *context, _pathResolved string, _pathInArchive } _cacheBucket.FillPercent = 0.9 var _dataPreparedRaw []byte - if _data_0, _error := json.Marshal (_dataPrepared); _error == nil { + if _data_0, _error := gobMarshal (_dataPrepared); _error == nil { _dataPreparedRaw = _data_0 } else { AbortError (_error, "[5538658b] unexpected sources cache error!") @@ -1172,6 +1174,27 @@ func main_0 () (error) { +func gobMarshal (_object interface{}) ([]byte, error) { + _buffer := bytes.NewBuffer (nil) + _encoder := gob.NewEncoder (_buffer) + if _error := _encoder.Encode (_object); _error != nil { + return nil, _error + } + return _buffer.Bytes (), nil +} + +func gobUnmarshal (_data []byte, _object interface{}) (error) { + _buffer := bytes.NewBuffer (_data) + _encoder := gob.NewDecoder (_buffer) + if _error := _encoder.Decode (_object); _error != nil { + return _error + } + return nil +} + + + + //go:embed usage.txt var usageText string