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

     1  package container
     2  
     3  import (
     4  	container "github.com/TrueCloudLab/frostfs-api-go/v2/container/grpc"
     5  	"github.com/TrueCloudLab/frostfs-api-go/v2/rpc/message"
     6  	protoutil "github.com/TrueCloudLab/frostfs-api-go/v2/util/proto"
     7  )
     8  
     9  const (
    10  	attributeKeyField   = 1
    11  	attributeValueField = 2
    12  
    13  	containerVersionField    = 1
    14  	containerOwnerField      = 2
    15  	containerNonceField      = 3
    16  	containerBasicACLField   = 4
    17  	containerAttributesField = 5
    18  	containerPlacementField  = 6
    19  
    20  	putReqBodyContainerField = 1
    21  	putReqBodySignatureField = 2
    22  
    23  	putRespBodyIDField = 1
    24  
    25  	deleteReqBodyIDField        = 1
    26  	deleteReqBodySignatureField = 2
    27  
    28  	getReqBodyIDField = 1
    29  
    30  	getRespBodyContainerField = 1
    31  	getRespBodySignatureField = 2
    32  	getRespBodyTokenField     = 3
    33  
    34  	listReqBodyOwnerField = 1
    35  
    36  	listRespBodyIDsField = 1
    37  
    38  	setEACLReqBodyTableField     = 1
    39  	setEACLReqBodySignatureField = 2
    40  
    41  	getEACLReqBodyIDField = 1
    42  
    43  	getEACLRespBodyTableField     = 1
    44  	getEACLRespBodySignatureField = 2
    45  	getEACLRespBodyTokenField     = 3
    46  
    47  	usedSpaceAnnounceEpochField     = 1
    48  	usedSpaceAnnounceCIDField       = 2
    49  	usedSpaceAnnounceUsedSpaceField = 3
    50  
    51  	usedSpaceReqBodyAnnouncementsField = 1
    52  )
    53  
    54  func (a *Attribute) StableMarshal(buf []byte) []byte {
    55  	if a == nil {
    56  		return []byte{}
    57  	}
    58  
    59  	if buf == nil {
    60  		buf = make([]byte, a.StableSize())
    61  	}
    62  
    63  	var offset int
    64  
    65  	offset += protoutil.StringMarshal(attributeKeyField, buf[offset:], a.key)
    66  	protoutil.StringMarshal(attributeValueField, buf[offset:], a.val)
    67  
    68  	return buf
    69  }
    70  
    71  func (a *Attribute) StableSize() (size int) {
    72  	if a == nil {
    73  		return 0
    74  	}
    75  
    76  	size += protoutil.StringSize(attributeKeyField, a.key)
    77  	size += protoutil.StringSize(attributeValueField, a.val)
    78  
    79  	return size
    80  }
    81  
    82  func (a *Attribute) Unmarshal(data []byte) error {
    83  	return message.Unmarshal(a, data, new(container.Container_Attribute))
    84  }
    85  
    86  func (c *Container) StableMarshal(buf []byte) []byte {
    87  	if c == nil {
    88  		return []byte{}
    89  	}
    90  
    91  	if buf == nil {
    92  		buf = make([]byte, c.StableSize())
    93  	}
    94  
    95  	var offset int
    96  
    97  	offset += protoutil.NestedStructureMarshal(containerVersionField, buf[offset:], c.version)
    98  	offset += protoutil.NestedStructureMarshal(containerOwnerField, buf[offset:], c.ownerID)
    99  	offset += protoutil.BytesMarshal(containerNonceField, buf[offset:], c.nonce)
   100  	offset += protoutil.UInt32Marshal(containerBasicACLField, buf[offset:], c.basicACL)
   101  
   102  	for i := range c.attr {
   103  		offset += protoutil.NestedStructureMarshal(containerAttributesField, buf[offset:], &c.attr[i])
   104  	}
   105  
   106  	protoutil.NestedStructureMarshal(containerPlacementField, buf[offset:], c.policy)
   107  
   108  	return buf
   109  }
   110  
   111  func (c *Container) StableSize() (size int) {
   112  	if c == nil {
   113  		return 0
   114  	}
   115  
   116  	size += protoutil.NestedStructureSize(containerVersionField, c.version)
   117  	size += protoutil.NestedStructureSize(containerOwnerField, c.ownerID)
   118  	size += protoutil.BytesSize(containerNonceField, c.nonce)
   119  	size += protoutil.UInt32Size(containerBasicACLField, c.basicACL)
   120  
   121  	for i := range c.attr {
   122  		size += protoutil.NestedStructureSize(containerAttributesField, &c.attr[i])
   123  	}
   124  
   125  	size += protoutil.NestedStructureSize(containerPlacementField, c.policy)
   126  
   127  	return size
   128  }
   129  
   130  func (c *Container) Unmarshal(data []byte) error {
   131  	return message.Unmarshal(c, data, new(container.Container))
   132  }
   133  
   134  func (r *PutRequestBody) StableMarshal(buf []byte) []byte {
   135  	if r == nil {
   136  		return []byte{}
   137  	}
   138  
   139  	if buf == nil {
   140  		buf = make([]byte, r.StableSize())
   141  	}
   142  
   143  	var offset int
   144  
   145  	offset += protoutil.NestedStructureMarshal(putReqBodyContainerField, buf[offset:], r.cnr)
   146  	protoutil.NestedStructureMarshal(putReqBodySignatureField, buf[offset:], r.sig)
   147  
   148  	return buf
   149  }
   150  
   151  func (r *PutRequestBody) StableSize() (size int) {
   152  	if r == nil {
   153  		return 0
   154  	}
   155  
   156  	size += protoutil.NestedStructureSize(putReqBodyContainerField, r.cnr)
   157  	size += protoutil.NestedStructureSize(putReqBodySignatureField, r.sig)
   158  
   159  	return size
   160  }
   161  
   162  func (r *PutRequestBody) Unmarshal(data []byte) error {
   163  	return message.Unmarshal(r, data, new(container.PutRequest_Body))
   164  }
   165  
   166  func (r *PutResponseBody) StableMarshal(buf []byte) []byte {
   167  	if r == nil {
   168  		return []byte{}
   169  	}
   170  
   171  	if buf == nil {
   172  		buf = make([]byte, r.StableSize())
   173  	}
   174  
   175  	protoutil.NestedStructureMarshal(putRespBodyIDField, buf, r.cid)
   176  
   177  	return buf
   178  }
   179  
   180  func (r *PutResponseBody) StableSize() (size int) {
   181  	if r == nil {
   182  		return 0
   183  	}
   184  
   185  	size += protoutil.NestedStructureSize(putRespBodyIDField, r.cid)
   186  
   187  	return size
   188  }
   189  
   190  func (r *PutResponseBody) Unmarshal(data []byte) error {
   191  	return message.Unmarshal(r, data, new(container.PutResponse_Body))
   192  }
   193  
   194  func (r *DeleteRequestBody) StableMarshal(buf []byte) []byte {
   195  	if r == nil {
   196  		return []byte{}
   197  	}
   198  
   199  	if buf == nil {
   200  		buf = make([]byte, r.StableSize())
   201  	}
   202  
   203  	var offset int
   204  
   205  	offset += protoutil.NestedStructureMarshal(deleteReqBodyIDField, buf[offset:], r.cid)
   206  	protoutil.NestedStructureMarshal(deleteReqBodySignatureField, buf[offset:], r.sig)
   207  
   208  	return buf
   209  }
   210  
   211  func (r *DeleteRequestBody) StableSize() (size int) {
   212  	if r == nil {
   213  		return 0
   214  	}
   215  
   216  	size += protoutil.NestedStructureSize(deleteReqBodyIDField, r.cid)
   217  	size += protoutil.NestedStructureSize(deleteReqBodySignatureField, r.sig)
   218  
   219  	return size
   220  }
   221  
   222  func (r *DeleteRequestBody) Unmarshal(data []byte) error {
   223  	return message.Unmarshal(r, data, new(container.DeleteRequest_Body))
   224  }
   225  
   226  func (r *DeleteResponseBody) StableMarshal(buf []byte) []byte {
   227  	return nil
   228  }
   229  
   230  func (r *DeleteResponseBody) StableSize() (size int) {
   231  	return 0
   232  }
   233  
   234  func (r *DeleteResponseBody) Unmarshal([]byte) error {
   235  	return nil
   236  }
   237  
   238  func (r *GetRequestBody) StableMarshal(buf []byte) []byte {
   239  	if r == nil {
   240  		return []byte{}
   241  	}
   242  
   243  	if buf == nil {
   244  		buf = make([]byte, r.StableSize())
   245  	}
   246  
   247  	protoutil.NestedStructureMarshal(getReqBodyIDField, buf, r.cid)
   248  
   249  	return buf
   250  }
   251  
   252  func (r *GetRequestBody) StableSize() (size int) {
   253  	if r == nil {
   254  		return 0
   255  	}
   256  
   257  	size += protoutil.NestedStructureSize(getReqBodyIDField, r.cid)
   258  
   259  	return size
   260  }
   261  
   262  func (r *GetRequestBody) Unmarshal(data []byte) error {
   263  	return message.Unmarshal(r, data, new(container.GetRequest_Body))
   264  }
   265  
   266  func (r *GetResponseBody) StableMarshal(buf []byte) []byte {
   267  	if r == nil {
   268  		return []byte{}
   269  	}
   270  
   271  	if buf == nil {
   272  		buf = make([]byte, r.StableSize())
   273  	}
   274  
   275  	var offset int
   276  
   277  	offset += protoutil.NestedStructureMarshal(getRespBodyContainerField, buf, r.cnr)
   278  	offset += protoutil.NestedStructureMarshal(getRespBodySignatureField, buf[offset:], r.sig)
   279  	protoutil.NestedStructureMarshal(getRespBodyTokenField, buf[offset:], r.token)
   280  
   281  	return buf
   282  }
   283  
   284  func (r *GetResponseBody) StableSize() (size int) {
   285  	if r == nil {
   286  		return 0
   287  	}
   288  
   289  	size += protoutil.NestedStructureSize(getRespBodyContainerField, r.cnr)
   290  	size += protoutil.NestedStructureSize(getRespBodySignatureField, r.sig)
   291  	size += protoutil.NestedStructureSize(getRespBodyTokenField, r.token)
   292  
   293  	return size
   294  }
   295  
   296  func (r *GetResponseBody) Unmarshal(data []byte) error {
   297  	return message.Unmarshal(r, data, new(container.GetResponse_Body))
   298  }
   299  
   300  func (r *ListRequestBody) StableMarshal(buf []byte) []byte {
   301  	if r == nil {
   302  		return []byte{}
   303  	}
   304  
   305  	if buf == nil {
   306  		buf = make([]byte, r.StableSize())
   307  	}
   308  
   309  	protoutil.NestedStructureMarshal(listReqBodyOwnerField, buf, r.ownerID)
   310  
   311  	return buf
   312  }
   313  
   314  func (r *ListRequestBody) StableSize() (size int) {
   315  	if r == nil {
   316  		return 0
   317  	}
   318  
   319  	size += protoutil.NestedStructureSize(listReqBodyOwnerField, r.ownerID)
   320  
   321  	return size
   322  }
   323  
   324  func (r *ListRequestBody) Unmarshal(data []byte) error {
   325  	return message.Unmarshal(r, data, new(container.ListRequest_Body))
   326  }
   327  
   328  func (r *ListResponseBody) StableMarshal(buf []byte) []byte {
   329  	if r == nil {
   330  		return []byte{}
   331  	}
   332  
   333  	if buf == nil {
   334  		buf = make([]byte, r.StableSize())
   335  	}
   336  
   337  	var offset int
   338  
   339  	for i := range r.cidList {
   340  		offset += protoutil.NestedStructureMarshal(listRespBodyIDsField, buf[offset:], &r.cidList[i])
   341  	}
   342  
   343  	return buf
   344  }
   345  
   346  func (r *ListResponseBody) StableSize() (size int) {
   347  	if r == nil {
   348  		return 0
   349  	}
   350  
   351  	for i := range r.cidList {
   352  		size += protoutil.NestedStructureSize(listRespBodyIDsField, &r.cidList[i])
   353  	}
   354  
   355  	return size
   356  }
   357  
   358  func (r *ListResponseBody) Unmarshal(data []byte) error {
   359  	return message.Unmarshal(r, data, new(container.ListResponse_Body))
   360  }
   361  
   362  func (r *SetExtendedACLRequestBody) StableMarshal(buf []byte) []byte {
   363  	if r == nil {
   364  		return []byte{}
   365  	}
   366  
   367  	if buf == nil {
   368  		buf = make([]byte, r.StableSize())
   369  	}
   370  
   371  	var offset int
   372  
   373  	offset += protoutil.NestedStructureMarshal(setEACLReqBodyTableField, buf[offset:], r.eacl)
   374  	protoutil.NestedStructureMarshal(setEACLReqBodySignatureField, buf[offset:], r.sig)
   375  
   376  	return buf
   377  }
   378  
   379  func (r *SetExtendedACLRequestBody) StableSize() (size int) {
   380  	if r == nil {
   381  		return 0
   382  	}
   383  
   384  	size += protoutil.NestedStructureSize(setEACLReqBodyTableField, r.eacl)
   385  	size += protoutil.NestedStructureSize(setEACLReqBodySignatureField, r.sig)
   386  
   387  	return size
   388  }
   389  
   390  func (r *SetExtendedACLRequestBody) Unmarshal(data []byte) error {
   391  	return message.Unmarshal(r, data, new(container.SetExtendedACLRequest_Body))
   392  }
   393  
   394  func (r *SetExtendedACLResponseBody) StableMarshal(buf []byte) []byte {
   395  	return nil
   396  }
   397  
   398  func (r *SetExtendedACLResponseBody) StableSize() (size int) {
   399  	return 0
   400  }
   401  
   402  func (r *SetExtendedACLResponseBody) Unmarshal([]byte) error {
   403  	return nil
   404  }
   405  
   406  func (r *GetExtendedACLRequestBody) StableMarshal(buf []byte) []byte {
   407  	if r == nil {
   408  		return []byte{}
   409  	}
   410  
   411  	if buf == nil {
   412  		buf = make([]byte, r.StableSize())
   413  	}
   414  
   415  	protoutil.NestedStructureMarshal(getEACLReqBodyIDField, buf, r.cid)
   416  
   417  	return buf
   418  }
   419  
   420  func (r *GetExtendedACLRequestBody) StableSize() (size int) {
   421  	if r == nil {
   422  		return 0
   423  	}
   424  
   425  	size += protoutil.NestedStructureSize(getEACLReqBodyIDField, r.cid)
   426  
   427  	return size
   428  }
   429  
   430  func (r *GetExtendedACLRequestBody) Unmarshal(data []byte) error {
   431  	return message.Unmarshal(r, data, new(container.GetExtendedACLRequest_Body))
   432  }
   433  
   434  func (r *GetExtendedACLResponseBody) StableMarshal(buf []byte) []byte {
   435  	if r == nil {
   436  		return []byte{}
   437  	}
   438  
   439  	if buf == nil {
   440  		buf = make([]byte, r.StableSize())
   441  	}
   442  
   443  	var offset int
   444  
   445  	offset += protoutil.NestedStructureMarshal(getEACLRespBodyTableField, buf[offset:], r.eacl)
   446  	offset += protoutil.NestedStructureMarshal(getEACLRespBodySignatureField, buf[offset:], r.sig)
   447  	protoutil.NestedStructureMarshal(getEACLRespBodyTokenField, buf[offset:], r.token)
   448  
   449  	return buf
   450  }
   451  
   452  func (r *GetExtendedACLResponseBody) StableSize() (size int) {
   453  	if r == nil {
   454  		return 0
   455  	}
   456  
   457  	size += protoutil.NestedStructureSize(getEACLRespBodyTableField, r.eacl)
   458  	size += protoutil.NestedStructureSize(getEACLRespBodySignatureField, r.sig)
   459  	size += protoutil.NestedStructureSize(getEACLRespBodyTokenField, r.token)
   460  
   461  	return size
   462  }
   463  
   464  func (r *GetExtendedACLResponseBody) Unmarshal(data []byte) error {
   465  	return message.Unmarshal(r, data, new(container.GetExtendedACLResponse_Body))
   466  }
   467  
   468  func (a *UsedSpaceAnnouncement) StableMarshal(buf []byte) []byte {
   469  	if a == nil {
   470  		return []byte{}
   471  	}
   472  
   473  	if buf == nil {
   474  		buf = make([]byte, a.StableSize())
   475  	}
   476  
   477  	var offset int
   478  
   479  	offset += protoutil.UInt64Marshal(usedSpaceAnnounceEpochField, buf[offset:], a.epoch)
   480  	offset += protoutil.NestedStructureMarshal(usedSpaceAnnounceCIDField, buf[offset:], a.cid)
   481  	protoutil.UInt64Marshal(usedSpaceAnnounceUsedSpaceField, buf[offset:], a.usedSpace)
   482  
   483  	return buf
   484  }
   485  
   486  func (a *UsedSpaceAnnouncement) StableSize() (size int) {
   487  	if a == nil {
   488  		return 0
   489  	}
   490  
   491  	size += protoutil.UInt64Size(usedSpaceAnnounceEpochField, a.epoch)
   492  	size += protoutil.NestedStructureSize(usedSpaceAnnounceCIDField, a.cid)
   493  	size += protoutil.UInt64Size(usedSpaceAnnounceUsedSpaceField, a.usedSpace)
   494  
   495  	return size
   496  }
   497  
   498  func (a *UsedSpaceAnnouncement) Unmarshal(data []byte) error {
   499  	return message.Unmarshal(a, data, new(container.AnnounceUsedSpaceRequest_Body_Announcement))
   500  }
   501  
   502  func (r *AnnounceUsedSpaceRequestBody) StableMarshal(buf []byte) []byte {
   503  	if r == nil {
   504  		return []byte{}
   505  	}
   506  
   507  	if buf == nil {
   508  		buf = make([]byte, r.StableSize())
   509  	}
   510  
   511  	var offset int
   512  
   513  	for i := range r.announcements {
   514  		offset += protoutil.NestedStructureMarshal(usedSpaceReqBodyAnnouncementsField, buf[offset:], &r.announcements[i])
   515  	}
   516  
   517  	return buf
   518  }
   519  
   520  func (r *AnnounceUsedSpaceRequestBody) StableSize() (size int) {
   521  	if r == nil {
   522  		return 0
   523  	}
   524  
   525  	for i := range r.announcements {
   526  		size += protoutil.NestedStructureSize(usedSpaceReqBodyAnnouncementsField, &r.announcements[i])
   527  	}
   528  
   529  	return size
   530  }
   531  
   532  func (r *AnnounceUsedSpaceRequestBody) Unmarshal(data []byte) error {
   533  	return message.Unmarshal(r, data, new(container.AnnounceUsedSpaceRequest_Body))
   534  }
   535  
   536  func (r *AnnounceUsedSpaceResponseBody) StableMarshal(buf []byte) []byte {
   537  	return nil
   538  }
   539  
   540  func (r *AnnounceUsedSpaceResponseBody) StableSize() (size int) {
   541  	return 0
   542  }
   543  
   544  func (r *AnnounceUsedSpaceResponseBody) Unmarshal([]byte) error {
   545  	return nil
   546  }