Skip to content

Commit

Permalink
BACKUP
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Dec 13, 2024
1 parent 22f5589 commit ca23744
Show file tree
Hide file tree
Showing 74 changed files with 3,075 additions and 4,550 deletions.
12 changes: 2 additions & 10 deletions accounting/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package accounting
import (
neofsproto "github.com/nspcc-dev/neofs-sdk-go/internal/proto"
protoaccounting "github.com/nspcc-dev/neofs-sdk-go/proto/accounting"
"google.golang.org/protobuf/proto"
)

// Decimal represents decimal number for accounting operations.
Expand Down Expand Up @@ -75,7 +74,7 @@ func (d *Decimal) SetPrecision(p uint32) {
//
// See also Unmarshal.
func (d Decimal) Marshal() []byte {
return neofsproto.MarshalMessage(d.ProtoMessage())
return neofsproto.Marshal(d)
}

// Unmarshal decodes NeoFS API protocol binary format into the Decimal
Expand All @@ -84,12 +83,5 @@ func (d Decimal) Marshal() []byte {
//
// See also Marshal.
func (d *Decimal) Unmarshal(data []byte) error {
var m protoaccounting.Decimal

err := proto.Unmarshal(data, &m)
if err != nil {
return err
}

return d.FromProtoMessage(&m)
return neofsproto.Unmarshal(data, d)
}
5 changes: 4 additions & 1 deletion checksum/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Checksum struct {

// Type represents the enumeration
// of checksum types.
type Type uint32
type Type int32

const (
Unknown Type = iota // Deprecated: use 0 instead.
Expand Down Expand Up @@ -99,6 +99,9 @@ func NewFromData(typ Type, data []byte) (Checksum, error) {
//
// See also [Checksum.ProtoMessage].
func (c *Checksum) FromProtoMessage(m *refs.Checksum) error {
if m.Type < 0 {
return fmt.Errorf("negative type %d", m.Type)
}
if len(m.Sum) == 0 {
return errors.New("missing value")
}
Expand Down
6 changes: 3 additions & 3 deletions checksum/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ func TestChecksumDecodingFailures(t *testing.T) {
}

func TestNew(t *testing.T) {
typ := checksum.Type(rand.Uint32())
typ := checksum.Type(rand.Int31())
val := make([]byte, 128)
//nolint:staticcheck
rand.Read(val)
cs := checksum.New(typ, val)
require.Equal(t, typ, cs.Type())
require.Equal(t, val, cs.Value())

otherTyp := checksum.Type(rand.Uint32())
otherTyp := checksum.Type(rand.Int31())
otherVal := make([]byte, 128)
//nolint:staticcheck
rand.Read(otherVal)
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestNewFromHash(t *testing.T) {
h.Write([]byte("Hello, world!"))
hb := []byte{32, 94, 4, 138}

typ := checksum.Type(rand.Uint32())
typ := checksum.Type(rand.Int31())
cs := checksum.NewFromHash(typ, h)
require.Equal(t, typ, cs.Type())
require.Equal(t, hb, cs.Value())
Expand Down
Loading

0 comments on commit ca23744

Please sign in to comment.