accounting

package
v1.0.0-rc.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Overview

Package accounting provides primitives to perform accounting operations in NeoFS.

Decimal type provides functionality to process user balances.

Example
package main

import (
	apiGoAccounting "github.com/nspcc-dev/neofs-api-go/v2/accounting"
	"github.com/nspcc-dev/neofs-sdk-go/accounting"
)

func main() {
	var val int64

	var dec accounting.Decimal
	dec.SetValue(val)
	dec.SetPrecision(8)

	// Instances can be also used to process NeoFS API V2 protocol messages. See neofs-api-go package.

	// On the client side.

	// import apiGoAccounting "github.com/nspcc-dev/neofs-api-go/v2/accounting"
	var msg apiGoAccounting.Decimal
	dec.WriteToV2(&msg)
	// *send message*

	// On the server side.
	_ = dec.ReadFromV2(msg)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decimal

type Decimal accounting.Decimal

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.

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

func (Decimal) Marshal

func (d Decimal) Marshal() []byte

Marshal encodes Decimal into a binary format of the NeoFS API protocol (Protocol Buffers with direct field order).

See also Unmarshal.

func (Decimal) Precision

func (d Decimal) Precision() uint32

Precision returns precision of the decimal number.

Zero Decimal has zero precision.

See also SetPrecision.

func (*Decimal) ReadFromV2

func (d *Decimal) ReadFromV2(m accounting.Decimal) error

ReadFromV2 reads Decimal from the accounting.Decimal message. Checks if the message conforms to NeoFS API V2 protocol.

See also WriteToV2.

func (*Decimal) SetPrecision

func (d *Decimal) SetPrecision(p uint32)

SetPrecision sets precision of the decimal number.

See also Precision.

func (*Decimal) SetValue

func (d *Decimal) SetValue(v int64)

SetValue sets value of the decimal number.

See also Value.

func (*Decimal) Unmarshal

func (d *Decimal) Unmarshal(data []byte) error

Unmarshal decodes NeoFS API protocol binary format into the Decimal (Protocol Buffers with direct field order). Returns an error describing a format violation.

See also Marshal.

func (Decimal) Value

func (d Decimal) Value() int64

Value returns value of the decimal number.

Zero Decimal has zero value.

See also SetValue.

func (Decimal) WriteToV2

func (d Decimal) WriteToV2(m *accounting.Decimal)

WriteToV2 writes Decimal to the accounting.Decimal message. The message must not be nil.

See also ReadFromV2.

Directories

Path Synopsis
Package accountingtest provides functions for convenient testing of accounting package API.
Package accountingtest provides functions for convenient testing of accounting package API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL