8use Shellbox\RPC\RpcClient;
16 private RpcClient $rpcClient;
17 private string $locale;
21 [
'service' =>
'icu-collation' ] );
22 $this->locale = $locale;
36 private static function encode( $strings ) {
38 foreach ( $strings as $s ) {
39 $ret .= sprintf(
"%08x", strlen( $s ) ) . $s;
50 private static function decode( $blob ) {
53 while ( $p < strlen( $blob ) ) {
54 $len = intval( substr( $blob, $p, 8 ), 16 );
56 $ret[] = substr( $blob, $p, $len );
64 if ( !count( $strings ) ) {
67 $blob = $this->rpcClient->call(
69 [ self::class,
'doGetSortKeys' ],
72 self::encode( array_values( $strings ) )
75 'classes' => [ parent::class, self::class ],
80 array_keys( $strings ),
88 throw new RuntimeException( __METHOD__ .
': not implemented' );
99 $mainCollator = Collator::create( $locale );
100 if ( !$mainCollator ) {
101 throw new RuntimeException(
"Invalid ICU locale specified for collation: $locale" );
105 foreach ( self::decode( $blob ) as $string ) {
106 $ret[] = $mainCollator->getSortKey( $string );
108 return self::encode( $ret );
113class_alias( RemoteIcuCollation::class,
'RemoteIcuCollation' );