oid

package
v1.0.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: Apache-2.0 Imports: 10 Imported by: 65

Documentation

Overview

Package oid provides primitives to work with object identification in NeoFS.

Address type is used for global object identity inside the NeoFS network, while ID represents identity within a fixed container.

Using package types in an application is recommended to potentially work with different protocol versions with which these types are compatible.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	// contains filtered or unexported fields
}

Address represents global object identifier in NeoFS network. Each object belongs to exactly one container and is uniquely addressed within the container.

Address is mutually compatible with github.com/nspcc-dev/neofs-api-go/v2/refs.Address message. See ReadFromV2 / WriteToV2 methods.

Instances can be created using built-in var declaration.

func (Address) Container

func (x Address) Container() cid.ID

Container returns unique identifier of the NeoFS object container.

Zero Address has zero container ID, which is incorrect according to NeoFS API protocol.

See also SetContainer.

func (*Address) DecodeString

func (x *Address) DecodeString(s string) error

DecodeString decodes string into Address according to NeoFS API protocol. Returns an error if s is malformed.

See also DecodeString.

func (Address) EncodeToString

func (x Address) EncodeToString() string

EncodeToString encodes Address into NeoFS API protocol string: concatenation of the string-encoded container and object IDs delimited by a slash.

See also DecodeString.

func (Address) MarshalJSON

func (x Address) MarshalJSON() ([]byte, error)

MarshalJSON encodes Address into a JSON format of the NeoFS API protocol (Protocol Buffers JSON).

See also UnmarshalJSON.

func (Address) Object

func (x Address) Object() ID

Object returns unique identifier of the object in the container identified by Container().

Zero Address has zero object ID, which is incorrect according to NeoFS API protocol.

See also SetObject.

func (*Address) ReadFromV2

func (x *Address) ReadFromV2(m refs.Address) error

ReadFromV2 reads Address from the refs.Address message. Returns an error if the message is malformed according to the NeoFS API V2 protocol.

See also WriteToV2.

func (*Address) SetContainer

func (x *Address) SetContainer(id cid.ID)

SetContainer sets unique identifier of the NeoFS object container.

See also Container.

func (*Address) SetObject

func (x *Address) SetObject(id ID)

SetObject sets unique identifier of the object in the container identified by Container().

See also Object.

func (Address) String

func (x Address) 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 Address into NeoFS protocol string.

func (*Address) UnmarshalJSON

func (x *Address) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes NeoFS API protocol JSON format into the Address (Protocol Buffers JSON). Returns an error describing a format violation.

See also MarshalJSON.

func (Address) WriteToV2

func (x Address) WriteToV2(m *refs.Address)

WriteToV2 writes Address to the refs.Address message. The message must not be nil.

See also ReadFromV2.

type ID

type ID [sha256.Size]byte

ID represents NeoFS object identifier in a container.

ID is mutually compatible with github.com/nspcc-dev/neofs-api-go/v2/refs.ObjectID 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:

_ = ID([32]byte{}) // not recommended

func (ID) CalculateIDSignature

func (id ID) CalculateIDSignature(key ecdsa.PrivateKey) (neofscrypto.Signature, error)

CalculateIDSignature signs object id with provided key.

func (*ID) Decode

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

Decode decodes src bytes into ID.

Decode expects that src has 32 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.

See also Encode.

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.

See also DecodeString.

func (ID) Encode

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

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

Zero ID is all zeros.

See also Decode.

func (ID) EncodeToString

func (id ID) EncodeToString() string

EncodeToString encodes ID into NeoFS API protocol string.

Zero ID is base58 encoding of 32 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.

func (ID) Marshal

func (id ID) Marshal() ([]byte, error)

Marshal marshals ID into a protobuf binary form.

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON encodes ID to protobuf JSON format.

func (*ID) ReadFromV2

func (id *ID) ReadFromV2(m refs.ObjectID) error

ReadFromV2 reads ID from the refs.ObjectID message. Returns an error if the message is malformed according to the NeoFS API V2 protocol.

See also WriteToV2.

func (*ID) SetSHA256

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

SetSHA256 sets object identifier value to SHA256 checksum.

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.

func (*ID) Unmarshal

func (id *ID) Unmarshal(data []byte) error

Unmarshal unmarshals protobuf binary representation of ID.

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes ID from protobuf JSON format.

func (ID) WriteToV2

func (id ID) WriteToV2(m *refs.ObjectID)

WriteToV2 writes ID to the refs.ObjectID message. The message must not be nil.

See also ReadFromV2.

Directories

Path Synopsis
Package oidtest provides functions for convenient testing of oid package API.
Package oidtest provides functions for convenient testing of oid package API.

Jump to

Keyboard shortcuts

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