storj/pkg/pb/BandwidthUtils.go
Bill Thorp 60946c2024
make bandwidth agreements sensible: without []byte's (#1152)
removed []byte's from bandwidth agreement protocol buffers
2019-01-28 14:45:25 -05:00

61 lines
1.6 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package pb
import (
"bytes"
reflect "reflect"
proto "github.com/gogo/protobuf/proto"
"github.com/zeebo/errs"
)
var (
//ErrRenter wraps errors related to renter bandwidth allocations
ErrRenter = errs.Class("Renter agreement")
//ErrPayer wraps errors related to payer bandwidth allocations
ErrPayer = errs.Class("Payer agreement")
)
//Equal compares two Protobuf messages via serialization
func Equal(msg1, msg2 proto.Message) bool {
//reflect.DeepEqual and proto.Equal don't seem work in all cases
//todo: see how slow this is compared to custom equality checks
if msg1 == nil {
return msg2 == nil
}
if reflect.TypeOf(msg1) != reflect.TypeOf(msg2) {
return false
}
msg1Bytes, err := proto.Marshal(msg1)
if err != nil {
return false
}
msg2Bytes, err := proto.Marshal(msg1)
if err != nil {
return false
}
return bytes.Compare(msg1Bytes, msg2Bytes) == 0
}
//SetCerts updates the certs field, completing the auth.SignedMsg interface
func (m *PayerBandwidthAllocation) SetCerts(certs [][]byte) {
m.Certs = certs
}
//SetSignature updates the signature field, completing the auth.SignedMsg interface
func (m *PayerBandwidthAllocation) SetSignature(signature []byte) {
m.Signature = signature
}
//SetCerts updates the certs field, completing the auth.SignedMsg interface
func (m *RenterBandwidthAllocation) SetCerts(certs [][]byte) {
m.Certs = certs
}
//SetSignature updates the signature field, completing the auth.SignedMsg interface
func (m *RenterBandwidthAllocation) SetSignature(signature []byte) {
m.Signature = signature
}