Descriptor.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // Protocol Buffers - Google's data interchange format
  3. // Copyright 2017 Google Inc. All rights reserved.
  4. //
  5. // Use of this source code is governed by a BSD-style
  6. // license that can be found in the LICENSE file or at
  7. // https://developers.google.com/open-source/licenses/bsd
  8. namespace Google\Protobuf;
  9. use Google\Protobuf\Internal\GetPublicDescriptorTrait;
  10. class Descriptor
  11. {
  12. use GetPublicDescriptorTrait;
  13. private $internal_desc;
  14. /**
  15. * @internal
  16. */
  17. public function __construct($internal_desc)
  18. {
  19. $this->internal_desc = $internal_desc;
  20. }
  21. /**
  22. * @return string Full protobuf message name
  23. */
  24. public function getFullName()
  25. {
  26. return trim($this->internal_desc->getFullName(), ".");
  27. }
  28. /**
  29. * @return string PHP class name
  30. */
  31. public function getClass()
  32. {
  33. return $this->internal_desc->getClass();
  34. }
  35. /**
  36. * @param int $index Must be >= 0 and < getFieldCount()
  37. * @return FieldDescriptor
  38. */
  39. public function getField($index)
  40. {
  41. return $this->getPublicDescriptor($this->internal_desc->getFieldByIndex($index));
  42. }
  43. /**
  44. * @return int Number of fields in message
  45. */
  46. public function getFieldCount()
  47. {
  48. return count($this->internal_desc->getField());
  49. }
  50. /**
  51. * @param int $index Must be >= 0 and < getOneofDeclCount()
  52. * @return OneofDescriptor
  53. */
  54. public function getOneofDecl($index)
  55. {
  56. return $this->getPublicDescriptor($this->internal_desc->getOneofDecl()[$index]);
  57. }
  58. /**
  59. * @return int Number of oneofs in message
  60. */
  61. public function getOneofDeclCount()
  62. {
  63. return count($this->internal_desc->getOneofDecl());
  64. }
  65. /**
  66. * @return int Number of real oneofs in message
  67. */
  68. public function getRealOneofDeclCount()
  69. {
  70. return $this->internal_desc->getRealOneofDeclCount();
  71. }
  72. }