forked from TrueCloudLab/frostfs-api-go
[#19] subnet: Drop related types and fields
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
bd44a3f47b
commit
ff6d8db741
23 changed files with 171 additions and 1484 deletions
|
@ -1,10 +1,5 @@
|
|||
package refs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type OwnerID struct {
|
||||
val []byte
|
||||
}
|
||||
|
@ -45,10 +40,6 @@ type Signature struct {
|
|||
scheme SignatureScheme
|
||||
}
|
||||
|
||||
type SubnetID struct {
|
||||
value uint32
|
||||
}
|
||||
|
||||
type Version struct {
|
||||
major, minor uint32
|
||||
}
|
||||
|
@ -178,56 +169,6 @@ func (s *Signature) SetScheme(scheme SignatureScheme) {
|
|||
s.scheme = scheme
|
||||
}
|
||||
|
||||
func (s *SubnetID) SetValue(id uint32) {
|
||||
s.value = id
|
||||
}
|
||||
|
||||
func (s *SubnetID) GetValue() uint32 {
|
||||
if s != nil {
|
||||
return s.value
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// MarshalText encodes SubnetID into text format according to NeoFS API V2 protocol:
|
||||
// value in base-10 integer string format.
|
||||
//
|
||||
// Implements encoding.TextMarshaler.
|
||||
func (s *SubnetID) MarshalText() ([]byte, error) {
|
||||
num := s.GetValue() // NPE safe, returns zero on nil (zero subnet)
|
||||
|
||||
return []byte(strconv.FormatUint(uint64(num), 10)), nil
|
||||
}
|
||||
|
||||
// UnmarshalText decodes SubnetID from the text according to NeoFS API V2 protocol:
|
||||
// should be base-10 integer string format with bitsize = 32.
|
||||
//
|
||||
// Returns strconv.ErrRange if integer overflows uint32.
|
||||
//
|
||||
// Must not be called on nil.
|
||||
//
|
||||
// Implements encoding.TextUnmarshaler.
|
||||
func (s *SubnetID) UnmarshalText(txt []byte) error {
|
||||
num, err := strconv.ParseUint(string(txt), 10, 32)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid numeric value: %w", err)
|
||||
}
|
||||
|
||||
s.value = uint32(num)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsZeroSubnet returns true iff the SubnetID refers to zero subnet.
|
||||
func IsZeroSubnet(id *SubnetID) bool {
|
||||
return id.GetValue() == 0
|
||||
}
|
||||
|
||||
// MakeZeroSubnet makes the SubnetID to refer to zero subnet.
|
||||
func MakeZeroSubnet(id *SubnetID) {
|
||||
id.SetValue(0)
|
||||
}
|
||||
|
||||
func (v *Version) GetMajor() uint32 {
|
||||
if v != nil {
|
||||
return v.major
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue