vendor/google.golang.org/protobuf/internal/filedesc/desc_init.go
changeset 260 445e01aede7e
parent 256 6d9efbef00a9
equal deleted inserted replaced
259:db4911b0c721 260:445e01aede7e
     8 	"sync"
     8 	"sync"
     9 
     9 
    10 	"google.golang.org/protobuf/encoding/protowire"
    10 	"google.golang.org/protobuf/encoding/protowire"
    11 	"google.golang.org/protobuf/internal/genid"
    11 	"google.golang.org/protobuf/internal/genid"
    12 	"google.golang.org/protobuf/internal/strs"
    12 	"google.golang.org/protobuf/internal/strs"
    13 	pref "google.golang.org/protobuf/reflect/protoreflect"
    13 	"google.golang.org/protobuf/reflect/protoreflect"
    14 )
    14 )
    15 
    15 
    16 // fileRaw is a data struct used when initializing a file descriptor from
    16 // fileRaw is a data struct used when initializing a file descriptor from
    17 // a raw FileDescriptorProto.
    17 // a raw FileDescriptorProto.
    18 type fileRaw struct {
    18 type fileRaw struct {
    93 
    93 
    94 func (fd *File) unmarshalSeed(b []byte) {
    94 func (fd *File) unmarshalSeed(b []byte) {
    95 	sb := getBuilder()
    95 	sb := getBuilder()
    96 	defer putBuilder(sb)
    96 	defer putBuilder(sb)
    97 
    97 
    98 	var prevField pref.FieldNumber
    98 	var prevField protoreflect.FieldNumber
    99 	var numEnums, numMessages, numExtensions, numServices int
    99 	var numEnums, numMessages, numExtensions, numServices int
   100 	var posEnums, posMessages, posExtensions, posServices int
   100 	var posEnums, posMessages, posExtensions, posServices int
   101 	b0 := b
   101 	b0 := b
   102 	for len(b) > 0 {
   102 	for len(b) > 0 {
   103 		num, typ, n := protowire.ConsumeTag(b)
   103 		num, typ, n := protowire.ConsumeTag(b)
   108 			b = b[m:]
   108 			b = b[m:]
   109 			switch num {
   109 			switch num {
   110 			case genid.FileDescriptorProto_Syntax_field_number:
   110 			case genid.FileDescriptorProto_Syntax_field_number:
   111 				switch string(v) {
   111 				switch string(v) {
   112 				case "proto2":
   112 				case "proto2":
   113 					fd.L1.Syntax = pref.Proto2
   113 					fd.L1.Syntax = protoreflect.Proto2
   114 				case "proto3":
   114 				case "proto3":
   115 					fd.L1.Syntax = pref.Proto3
   115 					fd.L1.Syntax = protoreflect.Proto3
   116 				default:
   116 				default:
   117 					panic("invalid syntax")
   117 					panic("invalid syntax")
   118 				}
   118 				}
   119 			case genid.FileDescriptorProto_Name_field_number:
   119 			case genid.FileDescriptorProto_Name_field_number:
   120 				fd.L1.Path = sb.MakeString(v)
   120 				fd.L1.Path = sb.MakeString(v)
   121 			case genid.FileDescriptorProto_Package_field_number:
   121 			case genid.FileDescriptorProto_Package_field_number:
   122 				fd.L1.Package = pref.FullName(sb.MakeString(v))
   122 				fd.L1.Package = protoreflect.FullName(sb.MakeString(v))
   123 			case genid.FileDescriptorProto_EnumType_field_number:
   123 			case genid.FileDescriptorProto_EnumType_field_number:
   124 				if prevField != genid.FileDescriptorProto_EnumType_field_number {
   124 				if prevField != genid.FileDescriptorProto_EnumType_field_number {
   125 					if numEnums > 0 {
   125 					if numEnums > 0 {
   126 						panic("non-contiguous repeated field")
   126 						panic("non-contiguous repeated field")
   127 					}
   127 					}
   161 		}
   161 		}
   162 	}
   162 	}
   163 
   163 
   164 	// If syntax is missing, it is assumed to be proto2.
   164 	// If syntax is missing, it is assumed to be proto2.
   165 	if fd.L1.Syntax == 0 {
   165 	if fd.L1.Syntax == 0 {
   166 		fd.L1.Syntax = pref.Proto2
   166 		fd.L1.Syntax = protoreflect.Proto2
   167 	}
   167 	}
   168 
   168 
   169 	// Must allocate all declarations before parsing each descriptor type
   169 	// Must allocate all declarations before parsing each descriptor type
   170 	// to ensure we handled all descriptors in "flattened ordering".
   170 	// to ensure we handled all descriptors in "flattened ordering".
   171 	if numEnums > 0 {
   171 	if numEnums > 0 {
   217 			b = b[n+m:]
   217 			b = b[n+m:]
   218 		}
   218 		}
   219 	}
   219 	}
   220 }
   220 }
   221 
   221 
   222 func (ed *Enum) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
   222 func (ed *Enum) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
   223 	ed.L0.ParentFile = pf
   223 	ed.L0.ParentFile = pf
   224 	ed.L0.Parent = pd
   224 	ed.L0.Parent = pd
   225 	ed.L0.Index = i
   225 	ed.L0.Index = i
   226 
   226 
   227 	var numValues int
   227 	var numValues int
   269 			b = b[m:]
   269 			b = b[m:]
   270 		}
   270 		}
   271 	}
   271 	}
   272 }
   272 }
   273 
   273 
   274 func (md *Message) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
   274 func (md *Message) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
   275 	md.L0.ParentFile = pf
   275 	md.L0.ParentFile = pf
   276 	md.L0.Parent = pd
   276 	md.L0.Parent = pd
   277 	md.L0.Index = i
   277 	md.L0.Index = i
   278 
   278 
   279 	var prevField pref.FieldNumber
   279 	var prevField protoreflect.FieldNumber
   280 	var numEnums, numMessages, numExtensions int
   280 	var numEnums, numMessages, numExtensions int
   281 	var posEnums, posMessages, posExtensions int
   281 	var posEnums, posMessages, posExtensions int
   282 	b0 := b
   282 	b0 := b
   283 	for len(b) > 0 {
   283 	for len(b) > 0 {
   284 		num, typ, n := protowire.ConsumeTag(b)
   284 		num, typ, n := protowire.ConsumeTag(b)
   385 			b = b[m:]
   385 			b = b[m:]
   386 		}
   386 		}
   387 	}
   387 	}
   388 }
   388 }
   389 
   389 
   390 func (xd *Extension) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
   390 func (xd *Extension) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
   391 	xd.L0.ParentFile = pf
   391 	xd.L0.ParentFile = pf
   392 	xd.L0.Parent = pd
   392 	xd.L0.Parent = pd
   393 	xd.L0.Index = i
   393 	xd.L0.Index = i
   394 
   394 
   395 	for len(b) > 0 {
   395 	for len(b) > 0 {
   399 		case protowire.VarintType:
   399 		case protowire.VarintType:
   400 			v, m := protowire.ConsumeVarint(b)
   400 			v, m := protowire.ConsumeVarint(b)
   401 			b = b[m:]
   401 			b = b[m:]
   402 			switch num {
   402 			switch num {
   403 			case genid.FieldDescriptorProto_Number_field_number:
   403 			case genid.FieldDescriptorProto_Number_field_number:
   404 				xd.L1.Number = pref.FieldNumber(v)
   404 				xd.L1.Number = protoreflect.FieldNumber(v)
   405 			case genid.FieldDescriptorProto_Label_field_number:
   405 			case genid.FieldDescriptorProto_Label_field_number:
   406 				xd.L1.Cardinality = pref.Cardinality(v)
   406 				xd.L1.Cardinality = protoreflect.Cardinality(v)
   407 			case genid.FieldDescriptorProto_Type_field_number:
   407 			case genid.FieldDescriptorProto_Type_field_number:
   408 				xd.L1.Kind = pref.Kind(v)
   408 				xd.L1.Kind = protoreflect.Kind(v)
   409 			}
   409 			}
   410 		case protowire.BytesType:
   410 		case protowire.BytesType:
   411 			v, m := protowire.ConsumeBytes(b)
   411 			v, m := protowire.ConsumeBytes(b)
   412 			b = b[m:]
   412 			b = b[m:]
   413 			switch num {
   413 			switch num {
   421 			b = b[m:]
   421 			b = b[m:]
   422 		}
   422 		}
   423 	}
   423 	}
   424 }
   424 }
   425 
   425 
   426 func (sd *Service) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd pref.Descriptor, i int) {
   426 func (sd *Service) unmarshalSeed(b []byte, sb *strs.Builder, pf *File, pd protoreflect.Descriptor, i int) {
   427 	sd.L0.ParentFile = pf
   427 	sd.L0.ParentFile = pf
   428 	sd.L0.Parent = pd
   428 	sd.L0.Parent = pd
   429 	sd.L0.Index = i
   429 	sd.L0.Index = i
   430 
   430 
   431 	for len(b) > 0 {
   431 	for len(b) > 0 {
   457 	nameBuilderPool.Put(b)
   457 	nameBuilderPool.Put(b)
   458 }
   458 }
   459 
   459 
   460 // makeFullName converts b to a protoreflect.FullName,
   460 // makeFullName converts b to a protoreflect.FullName,
   461 // where b must start with a leading dot.
   461 // where b must start with a leading dot.
   462 func makeFullName(sb *strs.Builder, b []byte) pref.FullName {
   462 func makeFullName(sb *strs.Builder, b []byte) protoreflect.FullName {
   463 	if len(b) == 0 || b[0] != '.' {
   463 	if len(b) == 0 || b[0] != '.' {
   464 		panic("name reference must be fully qualified")
   464 		panic("name reference must be fully qualified")
   465 	}
   465 	}
   466 	return pref.FullName(sb.MakeString(b[1:]))
   466 	return protoreflect.FullName(sb.MakeString(b[1:]))
   467 }
   467 }
   468 
   468 
   469 func appendFullName(sb *strs.Builder, prefix pref.FullName, suffix []byte) pref.FullName {
   469 func appendFullName(sb *strs.Builder, prefix protoreflect.FullName, suffix []byte) protoreflect.FullName {
   470 	return sb.AppendFullName(prefix, pref.Name(strs.UnsafeString(suffix)))
   470 	return sb.AppendFullName(prefix, protoreflect.Name(strs.UnsafeString(suffix)))
   471 }
   471 }