#Region "Microsoft.VisualBasic::7a6673f4ff508ea3a66ea8fae7ffcb1c, Google.Protobuf\Reflection\FieldCollection.vb"
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see .
' /********************************************************************************/
' Summaries:
' Class FieldCollection
'
' Constructor: (+1 Overloads) Sub New
' Function: ByJsonName, InDeclarationOrder, InFieldNumberOrder
'
'
' /********************************************************************************/
#End Region
Namespace Google.Protobuf.Reflection
'''
''' A collection to simplify retrieving the field accessor for a particular field.
'''
Public NotInheritable Class FieldCollection
Private ReadOnly messageDescriptor As MessageDescriptor
Friend Sub New(messageDescriptor As MessageDescriptor)
Me.messageDescriptor = messageDescriptor
End Sub
'''
''' Returns the fields in the message as an immutable list, in the order in which they
''' are declared in the source .proto file.
'''
Public Function InDeclarationOrder() As IList(Of FieldDescriptor)
Return messageDescriptor.fieldsInDeclarationOrder
End Function
'''
''' Returns the fields in the message as an immutable list, in ascending field number
''' order. Field numbers need not be contiguous, so there is no direct mapping from the
''' index in the list to the field number; to retrieve a field by field number, it is better
''' to use the indexer.
'''
Public Function InFieldNumberOrder() As IList(Of FieldDescriptor)
Return messageDescriptor.fieldsInNumberOrder
End Function
' TODO: consider making this public in the future. (Being conservative for now...)
'''
''' Returns a read-only dictionary mapping the field names in this message as they're available
''' in the JSON representation to the field descriptors. For example, a field foo_bar
''' in the message would result two entries, one with a key fooBar and one with a key
''' foo_bar, both referring to the same field.
'''
Friend Function ByJsonName() As IDictionary(Of String, FieldDescriptor)
Return messageDescriptor.jsonFieldMap
End Function
'''
''' Retrieves the descriptor for the field with the given number.
'''
''' Number of the field to retrieve the descriptor for
''' The accessor for the given field
''' The message descriptor does not contain a field
''' with the given number
Default Public ReadOnly Property Item(number As Integer) As FieldDescriptor
Get
Dim fieldDescriptor = messageDescriptor.FindFieldByNumber(number)
If fieldDescriptor Is Nothing Then
Throw New KeyNotFoundException("No such field number")
End If
Return fieldDescriptor
End Get
End Property
'''
''' Retrieves the descriptor for the field with the given name.
'''
''' Name of the field to retrieve the descriptor for
''' The descriptor for the given field
''' The message descriptor does not contain a field
''' with the given name
Default Public ReadOnly Property Item(name As String) As FieldDescriptor
Get
Dim fieldDescriptor = messageDescriptor.FindFieldByName(name)
If fieldDescriptor Is Nothing Then
Throw New KeyNotFoundException("No such field name")
End If
Return fieldDescriptor
End Get
End Property
End Class
End Namespace