MCPcopy Create free account
hub / github.com/bufbuild/buf / newFile

Function newFile

private/bufpkg/bufprotosource/file.go:230–357  ·  view source on GitHub ↗

does not validation of the fileDescriptorProto - this is assumed to be done elsewhere does no duplicate checking by name - could just have maps ie importToFileImport, enumNameToEnum, etc

(inputFile InputFile, resolver protodesc.Resolver)

Source from the content-addressed store, hash-verified

228// does not validation of the fileDescriptorProto - this is assumed to be done elsewhere
229// does no duplicate checking by name - could just have maps ie importToFileImport, enumNameToEnum, etc
230func newFile(inputFile InputFile, resolver protodesc.Resolver) (*file, error) {
231 locationStore := newLocationStore(inputFile.FileDescriptorProto())
232 f := &file{
233 FileInfo: inputFile,
234 resolver: resolver,
235 fileDescriptor: inputFile.FileDescriptorProto(),
236 optionExtensionDescriptor: newOptionExtensionDescriptor(
237 inputFile.FileDescriptorProto().GetOptions(),
238 []int32{8},
239 locationStore,
240 50,
241 ),
242 edition: inputFile.FileDescriptorProto().GetEdition(),
243 }
244 descriptor := newDescriptor(
245 f,
246 locationStore,
247 )
248 f.descriptor = descriptor
249
250 if inputFile.IsSyntaxUnspecified() {
251 // if the syntax is "proto2", protoc and buf will not set the syntax
252 // field even if it was explicitly set, this is why we have
253 // IsSyntaxUnspecified
254 f.syntax = SyntaxUnspecified
255 } else {
256 switch syntaxString := f.fileDescriptor.GetSyntax(); syntaxString {
257 case "", "proto2":
258 f.syntax = SyntaxProto2
259 case "proto3":
260 f.syntax = SyntaxProto3
261 case "editions":
262 f.syntax = SyntaxEditions
263 default:
264 return nil, fmt.Errorf("unknown syntax: %q", syntaxString)
265 }
266 }
267
268 for dependencyIndex, dependency := range f.fileDescriptor.GetDependency() {
269 fileImport, err := newFileImport(
270 f.descriptor,
271 dependency,
272 getDependencyPath(dependencyIndex),
273 )
274 if err != nil {
275 return nil, err
276 }
277 f.fileImports = append(f.fileImports, fileImport)
278 }
279 for _, dependencyIndex := range f.fileDescriptor.GetPublicDependency() {
280 if int(dependencyIndex) < 0 || len(f.fileImports) <= int(dependencyIndex) {
281 return nil, fmt.Errorf("got dependency index of %d but length of imports is %d", dependencyIndex, len(f.fileImports))
282 }
283 fileImport, ok := f.fileImports[dependencyIndex].(*fileImport)
284 if !ok {
285 return nil, fmt.Errorf("could not cast %T to a *fileImport", f.fileImports[dependencyIndex])
286 }
287 fileImport.setIsPublic()

Callers 1

newFilesFunction · 0.70

Calls 15

populateEnumMethod · 0.95
populateMessageMethod · 0.95
populateServiceMethod · 0.95
populateExtensionMethod · 0.95
newLocationStoreFunction · 0.85
newDescriptorFunction · 0.85
newFileImportFunction · 0.85
getDependencyPathFunction · 0.85
setIsPublicMethod · 0.80
setIsWeakMethod · 0.80
setIsUnusedMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…