-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*: Replace github.com/nspcc-dev/neofs-api-go/v2
module
#667
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e131cda
accounting: Fix test assert
cthulhu-rider 276e5e9
internal/proto: Fix test of zero embedded message's encoding
cthulhu-rider 7cbf4c9
internal/proto: Fix encoding of zero embedded messages
cthulhu-rider 54d1de6
proto: Add helper functions for `Message` encoding
cthulhu-rider f34803d
internal/proto: Refactor sizing and encoding of embedded repeated fields
cthulhu-rider 57e10da
proto: Test encoding of nil elements in repeated message fields
cthulhu-rider 20911e4
proto: Fix encoding of messages with nil elements in repeated fields
cthulhu-rider 213fc27
*: Refactor proto conversions of message types
cthulhu-rider 062f36b
*: Replace `github.com/nspcc-dev/neofs-api-go/v2` module
cthulhu-rider fade159
netmap/policy: Add test checking `CopyTo` clones empty sub-filter slice
cthulhu-rider File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
package accounting | ||
|
||
import ( | ||
"github.com/nspcc-dev/neofs-api-go/v2/accounting" | ||
neofsproto "github.com/nspcc-dev/neofs-sdk-go/internal/proto" | ||
protoaccounting "github.com/nspcc-dev/neofs-sdk-go/proto/accounting" | ||
) | ||
|
||
// Decimal represents decimal number for accounting operations. | ||
// | ||
// Decimal is mutually compatible with github.com/nspcc-dev/neofs-api-go/v2/accounting.Decimal | ||
// message. See ReadFromV2 / WriteToV2 methods. | ||
// Decimal is mutually compatible with [protoaccounting.Decimal] message. See | ||
// [Decimal.FromProtoMessage] / [Decimal.FromProtoMessage] methods. | ||
// | ||
// Instances can be created using built-in var declaration. | ||
// | ||
// Note that direct typecast is not safe and may result in loss of compatibility: | ||
// | ||
// _ = Decimal(accounting.Decimal{}) // not recommended | ||
type Decimal accounting.Decimal | ||
type Decimal struct { | ||
roman-khimov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val int64 | ||
prec uint32 | ||
} | ||
|
||
// ReadFromV2 reads Decimal from the accounting.Decimal message. Checks if the | ||
// message conforms to NeoFS API V2 protocol. | ||
// FromProtoMessage validates m according to the NeoFS API protocol and restores | ||
carpawell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// d from it. | ||
// | ||
// See also WriteToV2. | ||
func (d *Decimal) ReadFromV2(m accounting.Decimal) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note that temporary |
||
*d = Decimal(m) | ||
// See also [Decimal.ProtoMessage]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this, |
||
func (d *Decimal) FromProtoMessage(m *protoaccounting.Decimal) error { | ||
d.val = m.Value | ||
d.prec = m.Precision | ||
return nil | ||
} | ||
|
||
// WriteToV2 writes Decimal to the accounting.Decimal message. | ||
// The message must not be nil. | ||
// ProtoMessage converts d into message to transmit using the NeoFS API | ||
// protocol. | ||
// | ||
// See also ReadFromV2. | ||
func (d Decimal) WriteToV2(m *accounting.Decimal) { | ||
*m = (accounting.Decimal)(d) | ||
// See also [Decimal.FromProtoMessage]. | ||
func (d Decimal) ProtoMessage() *protoaccounting.Decimal { | ||
return &protoaccounting.Decimal{ | ||
Value: d.val, | ||
Precision: d.prec, | ||
} | ||
} | ||
|
||
// Value returns value of the decimal number. | ||
|
@@ -39,14 +43,14 @@ func (d Decimal) WriteToV2(m *accounting.Decimal) { | |
// | ||
// See also SetValue. | ||
func (d Decimal) Value() int64 { | ||
return (*accounting.Decimal)(&d).GetValue() | ||
return d.val | ||
} | ||
|
||
// SetValue sets value of the decimal number. | ||
// | ||
// See also Value. | ||
func (d *Decimal) SetValue(v int64) { | ||
(*accounting.Decimal)(d).SetValue(v) | ||
d.val = v | ||
} | ||
|
||
// Precision returns precision of the decimal number. | ||
|
@@ -55,25 +59,22 @@ func (d *Decimal) SetValue(v int64) { | |
// | ||
// See also SetPrecision. | ||
func (d Decimal) Precision() uint32 { | ||
return (*accounting.Decimal)(&d).GetPrecision() | ||
return d.prec | ||
} | ||
|
||
// SetPrecision sets precision of the decimal number. | ||
// | ||
// See also Precision. | ||
func (d *Decimal) SetPrecision(p uint32) { | ||
(*accounting.Decimal)(d).SetPrecision(p) | ||
d.prec = p | ||
} | ||
|
||
// Marshal encodes Decimal into a binary format of the NeoFS API protocol | ||
// (Protocol Buffers with direct field order). | ||
// | ||
// See also Unmarshal. | ||
func (d Decimal) Marshal() []byte { | ||
var m accounting.Decimal | ||
d.WriteToV2(&m) | ||
|
||
return m.StableMarshal(nil) | ||
return neofsproto.Marshal(d) | ||
} | ||
|
||
// Unmarshal decodes NeoFS API protocol binary format into the Decimal | ||
|
@@ -82,12 +83,5 @@ func (d Decimal) Marshal() []byte { | |
// | ||
// See also Marshal. | ||
func (d *Decimal) Unmarshal(data []byte) error { | ||
var m accounting.Decimal | ||
|
||
err := m.Unmarshal(data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return d.ReadFromV2(m) | ||
return neofsproto.Unmarshal(data, d) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to drop such statements since regular user is not interested in this
@roman-khimov @carpawell