github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/status/marshal.go (about)

     1  package status
     2  
     3  import (
     4  	"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/message"
     5  	status "github.com/TrueCloudLab/frostfs-api-go/v2/status/grpc"
     6  	protoutil "github.com/TrueCloudLab/frostfs-api-go/v2/util/proto"
     7  )
     8  
     9  const (
    10  	_ = iota
    11  	detailIDFNum
    12  	detailValueFNum
    13  )
    14  
    15  func (x *Detail) StableMarshal(buf []byte) []byte {
    16  	if x == nil {
    17  		return []byte{}
    18  	}
    19  
    20  	if buf == nil {
    21  		buf = make([]byte, x.StableSize())
    22  	}
    23  
    24  	var offset int
    25  
    26  	offset += protoutil.UInt32Marshal(detailIDFNum, buf[offset:], x.id)
    27  	protoutil.BytesMarshal(detailValueFNum, buf[offset:], x.val)
    28  
    29  	return buf
    30  }
    31  
    32  func (x *Detail) StableSize() (size int) {
    33  	size += protoutil.UInt32Size(detailIDFNum, x.id)
    34  	size += protoutil.BytesSize(detailValueFNum, x.val)
    35  
    36  	return size
    37  }
    38  
    39  func (x *Detail) Unmarshal(data []byte) error {
    40  	return message.Unmarshal(x, data, new(status.Status_Detail))
    41  }
    42  
    43  const (
    44  	_ = iota
    45  	statusCodeFNum
    46  	statusMsgFNum
    47  	statusDetailsFNum
    48  )
    49  
    50  func (x *Status) StableMarshal(buf []byte) []byte {
    51  	if x == nil {
    52  		return []byte{}
    53  	}
    54  
    55  	if buf == nil {
    56  		buf = make([]byte, x.StableSize())
    57  	}
    58  
    59  	var offset int
    60  
    61  	offset += protoutil.UInt32Marshal(statusCodeFNum, buf[offset:], CodeToGRPC(x.code))
    62  	offset += protoutil.StringMarshal(statusMsgFNum, buf[offset:], x.msg)
    63  
    64  	for i := range x.details {
    65  		offset += protoutil.NestedStructureMarshal(statusDetailsFNum, buf[offset:], &x.details[i])
    66  	}
    67  
    68  	return buf
    69  }
    70  
    71  func (x *Status) StableSize() (size int) {
    72  	size += protoutil.UInt32Size(statusCodeFNum, CodeToGRPC(x.code))
    73  	size += protoutil.StringSize(statusMsgFNum, x.msg)
    74  
    75  	for i := range x.details {
    76  		size += protoutil.NestedStructureSize(statusDetailsFNum, &x.details[i])
    77  	}
    78  
    79  	return size
    80  }
    81  
    82  func (x *Status) Unmarshal(data []byte) error {
    83  	return message.Unmarshal(x, data, new(status.Status))
    84  }