avsej
August 15, 2016, 1:42pm
61
You should not invoke encoder, you have to specify reference to the encoder implementation. try
$couchBucket->setTranscoder("couchbase_default_encoder", function($bytes, $flags, $datatype) {
if ($flags == 0) {
$flags = COUCHBASE_CFFMT_JSON;
} //$flags == 0
return couchbase_default_decoder($bytes, $flags, $datatype);
});
avsej
August 15, 2016, 1:46pm
62
To verify, you have to upsert/get the value
<?php
$cluster = new CouchbaseCluster("couchbase://localhost");
$bucket = $cluster->openBucket("default");
$COUCHBASE_DEFAULT_DECOPTS = array(
'jsonassoc' => true
);
$bucket->setTranscoder(
// encoder($value) -> array($bytes, $flags, $datatype)
"couchbase_default_encoder",
// decoder($bytes, $flags, $datatype) -> $value
function ($bytes, $flags, $datatype) {
if ($flags == 0) {
$flags = COUCHBASE_CFFMT_JSON;
}
return couchbase_default_decoder($bytes, $flags, $datatype);
}
);
var_dump($bucket->upsert("foo_json_flags", array("foo" => array("nested" => "bar"))));
var_dump($bucket->get("foo_json_flags"));
object(CouchbaseMetaDoc)#5 (5) {
["error"]=>
NULL
["value"]=>
NULL
["flags"]=>
NULL
["cas"]=>
string(9) "scj1gu8es"
["token"]=>
NULL
}
object(CouchbaseMetaDoc)#5 (5) {
["error"]=>
NULL
["value"]=>
array(1) {
["foo"]=>
array(1) {
["nested"]=>
string(3) "bar"
}
}
["flags"]=>
int(33554438)
["cas"]=>
string(9) "scj1gu8es"
["token"]=>
NULL
}
srm
August 15, 2016, 2:08pm
63
Try :
return \couchbase_default_decoder($bytes, $flags, $datatype);
avsej
August 15, 2016, 2:09pm
64
I wonder if it is enough something like
$bucket->setTranscoder(\couchbase_default_encoder, ...
srm
August 15, 2016, 2:12pm
65
If EdanBrooke is in a namespace he sould put \ before couchbase_default_encoder and couchbase_default_decoder
avsej
August 15, 2016, 2:14pm
66
I assumed he is verifying on some minimal examples with CLI, but okay. Any way to provide implementation would work, but not invocation of actual encoder.