Skip to content

Commit bd25f8d

Browse files
committed
Add string representations for compression API
1 parent 9342798 commit bd25f8d

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

src/main/php/com/mongodb/io/Compression.class.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<?php namespace com\mongodb\io;
22

3+
use lang\Value;
4+
use util\{Comparison, Objects};
5+
36
/**
47
* Compression negotiation and selection.
58
*
69
* @see https://github.com/mongodb/specifications/blob/master/source/compression/OP_COMPRESSED.md
710
* @test com.mongodb.unittest.CompressionTest
811
*/
9-
class Compression {
12+
class Compression implements Value {
13+
use Comparison;
14+
1015
private static $negotiable= [];
1116
private $compressors;
1217

@@ -81,4 +86,9 @@ public function for($sections, $length) {
8186
// Currently always select the first compressor negotiated
8287
return current($this->compressors);
8388
}
89+
90+
/** @return string */
91+
public function toString() {
92+
return nameof($this).'@'.Objects::stringOf($this->compressors);
93+
}
8494
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<?php namespace com\mongodb\io;
22

3-
abstract class Compressor {
3+
use lang\Value;
4+
5+
abstract class Compressor implements Value {
46
public $id;
57

68
public abstract function compress($data);
79

810
public abstract function decompress($compressed);
911

12+
public function hashCode() { return 'C'.$this->id; }
13+
14+
public function compareTo($value) { return $value instanceof self ? $this->id <=> $value->id : 1; }
1015
}

src/main/php/com/mongodb/io/Zlib.class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ public function compress($data) {
1616
public function decompress($compressed) {
1717
return gzuncompress($compressed);
1818
}
19+
20+
/** @return string */
21+
public function toString() {
22+
return nameof($this).'(id: '.$this->id.', level: '.$this->level.')';
23+
}
1924
}

src/main/php/com/mongodb/io/Zstd.class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ public function compress($data) {
1616
public function decompress($compressed) {
1717
return zstd_uncompress($compressed);
1818
}
19+
20+
/** @return string */
21+
public function toString() {
22+
return nameof($this).'(id: '.$this->id.', level: '.$this->level.')';
23+
}
1924
}

0 commit comments

Comments
 (0)