ServiceHost.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Nacos\Protobuf;
  12. use Hyperf\Contract\JsonDeSerializable;
  13. use JsonSerializable;
  14. class ServiceHost implements JsonDeSerializable, JsonSerializable
  15. {
  16. public function __construct(
  17. public string $instanceId,
  18. public string $ip,
  19. public int $port,
  20. public float $weight,
  21. public bool $healthy,
  22. public bool $enabled,
  23. public bool $ephemeral,
  24. public string $clusterName,
  25. public string $serviceName,
  26. public array $metadata,
  27. public int $instanceHeartBeatTimeOut,
  28. public int $instanceHeartBeatInterval,
  29. public string $instanceIdGenerator,
  30. public int $ipDeleteTimeout
  31. ) {
  32. }
  33. public static function jsonDeSerialize(mixed $data): static
  34. {
  35. return new static(
  36. $data['instanceId'] ?? '',
  37. $data['ip'],
  38. $data['port'],
  39. $data['weight'],
  40. $data['healthy'],
  41. $data['enabled'],
  42. $data['ephemeral'],
  43. $data['clusterName'],
  44. $data['serviceName'],
  45. $data['metadata'],
  46. $data['instanceHeartBeatTimeOut'],
  47. $data['instanceHeartBeatInterval'],
  48. $data['instanceIdGenerator'] ?? '',
  49. $data['ipDeleteTimeout'],
  50. );
  51. }
  52. public function jsonSerialize(): mixed
  53. {
  54. return [
  55. 'instanceId' => $this->instanceId,
  56. 'ip' => $this->ip,
  57. 'port' => $this->port,
  58. 'weight' => $this->weight,
  59. 'healthy' => $this->healthy,
  60. 'enabled' => $this->enabled,
  61. 'ephemeral' => $this->ephemeral,
  62. 'clusterName' => $this->clusterName,
  63. 'serviceName' => $this->serviceName,
  64. 'metadata' => $this->metadata,
  65. 'instanceHeartBeatTimeOut' => $this->instanceHeartBeatTimeOut,
  66. 'instanceHeartBeatInterval' => $this->instanceHeartBeatInterval,
  67. 'instanceIdGenerator' => $this->instanceIdGenerator,
  68. 'ipDeleteTimeout' => $this->ipDeleteTimeout,
  69. ];
  70. }
  71. }