Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ProtobufSerializer.php

function ProtobufSerializer::postProcessJsonEnumValues

Workaround until protobuf exposes `FormatEnumsAsIntegers` option.

[JSON Protobuf Encoding](https://opentelemetry.io/docs/specs/otlp/#json-protobuf-encoding): > Values of enum fields MUST be encoded as integer values.

See also

https://github.com/open-telemetry/opentelemetry-php/issues/978

https://github.com/protocolbuffers/protobuf/pull/12707

File

vendor/open-telemetry/exporter-otlp/ProtobufSerializer.php, line 103

Class

ProtobufSerializer
@internal @psalm-type SUPPORTED_CONTENT_TYPES = ContentTypes::PROTOBUF|ContentTypes::JSON|ContentTypes::NDJSON

Namespace

OpenTelemetry\Contrib\Otlp

Code

private static function postProcessJsonEnumValues(Message $message, string $payload) : string {
    $pool = DescriptorPool::getGeneratedPool();
    $desc = $pool->getDescriptorByClassName($message::class);
    if (!$desc instanceof Descriptor) {
        return $payload;
    }
    $data = json_decode($payload);
    unset($payload);
    self::traverseDescriptor($data, $desc);
    return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal