cid

package
v1.0.0-rc.13 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: Apache-2.0 Imports: 5 Imported by: 90

Documentation

Overview

Package cid provides primitives to work with container identification in NeoFS.

Index

Constants

View Source
const Size = sha256.Size

Size is the size of an ID in bytes.

Variables

View Source
var ErrZero = errors.New("zero container ID")

ErrZero is an error returned on zero ID encounter.

Functions

This section is empty.

Types

type ID

type ID [Size]byte

ID represents NeoFS container identifier. Zero ID is usually prohibited, see docs for details.

ID implements built-in comparable interface.

ID is mutually compatible with refs.ContainerID message. See ID.FromProtoMessage / ID.ProtoMessage methods.

func DecodeBytes

func DecodeBytes(b []byte) (ID, error)

DecodeBytes creates new ID and makes ID.Decode.

func DecodeString

func DecodeString(s string) (ID, error)

DecodeString creates new ID and makes ID.DecodeString.

func NewFromMarshalledContainer

func NewFromMarshalledContainer(b []byte) ID

NewFromMarshalledContainer returns new ID calculated from the given NeoFS container encoded into Protocol Buffers V3 with ascending order of fields by number. It's callers responsibility to ensure the format of b. See [container.Container.Marshal].

func (*ID) Decode

func (id *ID) Decode(src []byte) error

Decode decodes src bytes into ID. Use DecodeBytes to decode src into a new ID.

Decode expects that src has Size bytes length. If the input is malformed, Decode returns an error describing format violation. In this case ID remains unchanged.

Decode doesn't mutate src.

func (*ID) DecodeString

func (id *ID) DecodeString(s string) error

DecodeString decodes string into ID according to NeoFS API protocol. Returns an error if s is malformed. Use DecodeString to decode s into a new ID.

See also DecodeString.

func (ID) Encode

func (id ID) Encode(dst []byte)

Encode encodes ID into Size bytes of dst. Panics if dst length is less than Size.

Zero ID is all zeros.

See also Decode. Deprecated: use id[:] instead.

func (ID) EncodeToString

func (id ID) EncodeToString() string

EncodeToString encodes ID into NeoFS API protocol string.

Zero ID is base58 encoding of Size zeros.

See also DecodeString.

func (ID) Equals

func (id ID) Equals(id2 ID) bool

Equals defines a comparison relation between two ID instances.

Note that comparison using '==' operator is not recommended since it MAY result in loss of compatibility. Deprecated: ID is comparable.

func (*ID) FromBinary

func (id *ID) FromBinary(cnr []byte)

FromBinary calculates identifier of the binary-encoded container in CAS of the NeoFS containers and writes it into id.

See also [container.Container.CalculateID], [container.Container.AssertID]. Deprecated: use [NewFromContainerBinary].

func (*ID) FromProtoMessage

func (id *ID) FromProtoMessage(m *refs.ContainerID) error

FromProtoMessage validates m according to the NeoFS API protocol and restores id from it.

See also ID.ProtoMessage.

func (ID) IsZero

func (id ID) IsZero() bool

IsZero checks whether ID is zero.

func (ID) ProtoMessage

func (id ID) ProtoMessage() *refs.ContainerID

ProtoMessage converts id into message to transmit using the NeoFS API protocol.

See also ID.FromProtoMessage.

func (*ID) SetSHA256

func (id *ID) SetSHA256(v [sha256.Size]byte)

SetSHA256 sets container identifier value to SHA256 checksum of container structure. Deprecated: use direct assignment instead.

func (ID) String

func (id ID) String() string

String implements fmt.Stringer.

String is designed to be human-readable, and its format MAY differ between SDK versions. String MAY return same result as EncodeToString. String MUST NOT be used to encode ID into NeoFS protocol string.

Directories

Path Synopsis
Package cidtest provides functions for convenient testing of cid package API.
Package cidtest provides functions for convenient testing of cid package API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳