14
"google.golang.org/protobuf/internal/errors"
15
"google.golang.org/protobuf/reflect/protoreflect"
16
"google.golang.org/protobuf/runtime/protoiface"
23
func (Export) LegacyEnumName(ed protoreflect.EnumDescriptor) string {
24
return legacyEnumName(ed)
29
func (Export) LegacyMessageTypeOf(m protoiface.MessageV1, name protoreflect.FullName) protoreflect.MessageType {
30
if mv := (Export{}).protoMessageV2Of(m); mv != nil {
31
return mv.ProtoReflect().Type()
33
return legacyLoadMessageType(reflect.TypeOf(m), name)
39
func (Export) UnmarshalJSONEnum(ed protoreflect.EnumDescriptor, b []byte) (protoreflect.EnumNumber, error) {
41
var name protoreflect.Name
42
if err := json.Unmarshal(b, &name); err != nil {
43
return 0, errors.New("invalid input for enum %v: %s", ed.FullName(), b)
45
ev := ed.Values().ByName(name)
47
return 0, errors.New("invalid value for enum %v: %s", ed.FullName(), name)
49
return ev.Number(), nil
51
var num protoreflect.EnumNumber
52
if err := json.Unmarshal(b, &num); err != nil {
53
return 0, errors.New("invalid input for enum %v: %s", ed.FullName(), b)
61
func (Export) CompressGZIP(in []byte) (out []byte) {
63
var gzipHeader = [10]byte{0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff}
66
var blockHeader [5]byte
67
const maxBlockSize = math.MaxUint16
68
numBlocks := 1 + len(in)/maxBlockSize
71
var gzipFooter [8]byte
72
binary.LittleEndian.PutUint32(gzipFooter[0:4], crc32.ChecksumIEEE(in))
73
binary.LittleEndian.PutUint32(gzipFooter[4:8], uint32(len(in)))
76
out = make([]byte, 0, len(gzipHeader)+len(blockHeader)*numBlocks+len(in)+len(gzipFooter))
77
out = append(out, gzipHeader[:]...)
78
for blockHeader[0] == 0 {
79
blockSize := maxBlockSize
80
if blockSize > len(in) {
84
binary.LittleEndian.PutUint16(blockHeader[1:3], uint16(blockSize))
85
binary.LittleEndian.PutUint16(blockHeader[3:5], ^uint16(blockSize))
86
out = append(out, blockHeader[:]...)
87
out = append(out, in[:blockSize]...)
90
out = append(out, gzipFooter[:]...)