42 lines
882 B
Go
42 lines
882 B
Go
package grpcall
|
|
|
|
import (
|
|
"encoding/base64"
|
|
|
|
"github.com/jhump/protoreflect/desc"
|
|
)
|
|
|
|
type FileDescriptorSorter []*desc.FileDescriptor
|
|
|
|
func (this FileDescriptorSorter) Len() int {
|
|
return len(this)
|
|
}
|
|
|
|
func (this FileDescriptorSorter) Less(i, j int) bool {
|
|
return this[i].GetName() < this[j].GetName()
|
|
}
|
|
|
|
func (this FileDescriptorSorter) Swap(i, j int) {
|
|
this[i], this[j] = this[j], this[i]
|
|
}
|
|
|
|
var base64s = []*base64.Encoding{base64.StdEncoding, base64.URLEncoding, base64.RawStdEncoding, base64.RawURLEncoding}
|
|
|
|
func metadata_decode(val string) (string, error) {
|
|
var firstErr error
|
|
var b []byte
|
|
// we are lenient and can accept any of the flavors of base64 encoding
|
|
for _, d := range base64s {
|
|
var err error
|
|
b, err = d.DecodeString(val)
|
|
if err != nil {
|
|
if firstErr == nil {
|
|
firstErr = err
|
|
}
|
|
continue
|
|
}
|
|
return string(b), nil
|
|
}
|
|
return "", firstErr
|
|
}
|