mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Fix bug in wrapper, remove deprecated code
This commit is contained in:
parent
a1e3817fd0
commit
35ab2be6a0
3 changed files with 14 additions and 70 deletions
|
@ -1,16 +1,10 @@
|
|||
package record
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type TestRecord struct {
|
||||
Base
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func (tm *TestRecord) Lock() {
|
||||
tm.lock.Lock()
|
||||
}
|
||||
|
||||
func (tm *TestRecord) Unlock() {
|
||||
tm.lock.Unlock()
|
||||
sync.Mutex
|
||||
}
|
||||
|
|
|
@ -37,27 +37,19 @@ func NewRawWrapper(database, key string, data []byte) (*Wrapper, error) {
|
|||
offset += n
|
||||
|
||||
newMeta := &Meta{}
|
||||
if len(metaSection) == 34 && metaSection[4] == 0 {
|
||||
// TODO: remove in 2020
|
||||
// backward compatibility:
|
||||
// format would byte shift and populate metaSection[4] with value > 0 (would naturally populate >0 at 07.02.2106 07:28:15)
|
||||
// this must be gencode without format
|
||||
_, err = newMeta.GenCodeUnmarshal(metaSection)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not unmarshal meta section: %s", err)
|
||||
}
|
||||
} else {
|
||||
_, err = dsd.Load(metaSection, newMeta)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not unmarshal meta section: %s", err)
|
||||
}
|
||||
_, err = dsd.Load(metaSection, newMeta)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not unmarshal meta section: %s", err)
|
||||
}
|
||||
|
||||
format, n, err := varint.Unpack8(data[offset:])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get dsd format: %s", err)
|
||||
var format uint8 = dsd.NONE
|
||||
if !newMeta.IsDeleted() {
|
||||
format, n, err = varint.Unpack8(data[offset:])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get dsd format: %s", err)
|
||||
}
|
||||
offset += n
|
||||
}
|
||||
offset += n
|
||||
|
||||
return &Wrapper{
|
||||
Base{
|
||||
|
|
|
@ -2,10 +2,7 @@ package record
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/safing/portbase/container"
|
||||
)
|
||||
|
||||
func TestWrapper(t *testing.T) {
|
||||
|
@ -54,43 +51,4 @@ func TestWrapper(t *testing.T) {
|
|||
if !bytes.Equal(testData, wrapper2.Data) {
|
||||
t.Error("marshal mismatch")
|
||||
}
|
||||
|
||||
// test new format
|
||||
oldRaw, err := oldWrapperMarshalRecord(wrapper, wrapper)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
wrapper3, err := NewRawWrapper("test", "a", oldRaw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(testData, wrapper3.Data) {
|
||||
t.Error("marshal mismatch")
|
||||
}
|
||||
}
|
||||
|
||||
func oldWrapperMarshalRecord(w *Wrapper, r Record) ([]byte, error) {
|
||||
if w.Meta() == nil {
|
||||
return nil, errors.New("missing meta")
|
||||
}
|
||||
|
||||
// version
|
||||
c := container.New([]byte{1})
|
||||
|
||||
// meta
|
||||
metaSection, err := w.meta.GenCodeMarshal(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.AppendAsBlock(metaSection)
|
||||
|
||||
// data
|
||||
dataSection, err := w.Marshal(r, JSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.Append(dataSection)
|
||||
|
||||
return c.CompileData(), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue