DCausse has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/254429

Change subject: [WIP] Supports schema revision id in avro binary formatter
......................................................................

[WIP] Supports schema revision id in avro binary formatter

bits related to java long encoding have been tested.
WIP: because we need to find a way to lookup the schema id

Change-Id: Icc0f92be23305e77a69b92fee4d9f9de2edda81e
---
M includes/debug/logger/monolog/AvroFormatter.php
1 file changed, 31 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/29/254429/1

diff --git a/includes/debug/logger/monolog/AvroFormatter.php 
b/includes/debug/logger/monolog/AvroFormatter.php
index 019d028..92a5f1f 100644
--- a/includes/debug/logger/monolog/AvroFormatter.php
+++ b/includes/debug/logger/monolog/AvroFormatter.php
@@ -38,6 +38,10 @@
  */
 class AvroFormatter implements FormatterInterface {
        /**
+        * @var Magic byte to encode schema revision id.
+        */
+       const MAGIC = 0x0;
+       /**
         * @var array Map from schema name to schema definition
         */
        protected $schemas;
@@ -80,6 +84,7 @@
        public function format( array $record ) {
                $this->io->truncate();
                $schema = $this->getSchema( $record['channel'] );
+               $revId = $this->getSchemaRevisionId( $record['channel'] );
                if ( $schema === null ) {
                        trigger_error( "The schema for channel 
'{$record['channel']}' is not available" );
                        return null;
@@ -92,7 +97,21 @@
                        trigger_error( "Avro failed to serialize record for 
{$record['channel']} : {$json}" );
                        return null;
                }
+               if( $revId !== null ) {
+                       return chr( self::MAGIC ) . $this->encode_long( $revId 
) . $this->io->string();
+               }
                return $this->io->string();
+       }
+
+       /**
+        * Get the writer for the named channel
+        *
+        * @var string $channel Name of the schema
+        * @return int|null
+        */
+       public function getSchemaRevisionId( $channel ) {
+               // @todo: implement
+               return null;
        }
 
        /**
@@ -136,4 +155,16 @@
                }
                return $this->schemas[$channel];
        }
+
+       /**
+        * convert an integer to a 64bits big endian long (Java compatible)
+        * NOTE: certainly only compatible with PHP 64bits
+        * @param int $id
+        * @return string the binary representation of $id
+        */
+       private function encode_long( $id ) {
+               $high   = ($id & 0xffffffff00000000) >> 32;
+               $low    = $id & 0x00000000ffffffff;
+               return pack('NN', $high, $low);
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/254429
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icc0f92be23305e77a69b92fee4d9f9de2edda81e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: DCausse <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to