git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/object/attribute.go (about)

     1  package object
     2  
     3  import (
     4  	"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
     5  )
     6  
     7  // Attribute represents v2-compatible object attribute.
     8  type Attribute object.Attribute
     9  
    10  // NewAttributeFromV2 wraps v2 Attribute message to Attribute.
    11  //
    12  // Nil object.Attribute converts to nil.
    13  func NewAttributeFromV2(aV2 *object.Attribute) *Attribute {
    14  	return (*Attribute)(aV2)
    15  }
    16  
    17  // NewAttribute creates and initializes blank Attribute.
    18  //
    19  // Works similar as NewAttributeFromV2(new(Attribute)).
    20  //
    21  // Defaults:
    22  //   - key: "";
    23  //   - value: "".
    24  func NewAttribute() *Attribute {
    25  	return NewAttributeFromV2(new(object.Attribute))
    26  }
    27  
    28  // Key returns key to the object attribute.
    29  func (a *Attribute) Key() string {
    30  	return (*object.Attribute)(a).GetKey()
    31  }
    32  
    33  // SetKey sets key to the object attribute.
    34  func (a *Attribute) SetKey(v string) {
    35  	(*object.Attribute)(a).SetKey(v)
    36  }
    37  
    38  // Value return value of the object attribute.
    39  func (a *Attribute) Value() string {
    40  	return (*object.Attribute)(a).GetValue()
    41  }
    42  
    43  // SetValue sets value of the object attribute.
    44  func (a *Attribute) SetValue(v string) {
    45  	(*object.Attribute)(a).SetValue(v)
    46  }
    47  
    48  // ToV2 converts Attribute to v2 Attribute message.
    49  //
    50  // Nil Attribute converts to nil.
    51  func (a *Attribute) ToV2() *object.Attribute {
    52  	return (*object.Attribute)(a)
    53  }
    54  
    55  // Marshal marshals Attribute into a protobuf binary form.
    56  func (a *Attribute) Marshal() ([]byte, error) {
    57  	return (*object.Attribute)(a).StableMarshal(nil), nil
    58  }
    59  
    60  // Unmarshal unmarshals protobuf binary representation of Attribute.
    61  func (a *Attribute) Unmarshal(data []byte) error {
    62  	return (*object.Attribute)(a).Unmarshal(data)
    63  }
    64  
    65  // MarshalJSON encodes Attribute to protobuf JSON format.
    66  func (a *Attribute) MarshalJSON() ([]byte, error) {
    67  	return (*object.Attribute)(a).MarshalJSON()
    68  }
    69  
    70  // UnmarshalJSON decodes Attribute from protobuf JSON format.
    71  func (a *Attribute) UnmarshalJSON(data []byte) error {
    72  	return (*object.Attribute)(a).UnmarshalJSON(data)
    73  }