4 * Helper class for segmenting large cache values without relying on serializing classes
8 class SerializedValueContainer
{
9 const SCHEMA
= '__svc_schema__';
10 const SCHEMA_UNIFIED
= 'DAAIDgoKAQw'; // 64 bit UID
11 const SCHEMA_SEGMENTED
= 'CAYCDAgCDw4'; // 64 bit UID
13 const UNIFIED_DATA
= '__data__';
14 const SEGMENTED_HASHES
= '__hashes__';
17 * @param string $serialized
20 public static function newUnified( $serialized ) {
22 self
::SCHEMA
=> self
::SCHEMA_UNIFIED
,
23 self
::UNIFIED_DATA
=> $serialized
28 * @param string[] $segmentHashList Ordered list of hashes for each segment
31 public static function newSegmented( array $segmentHashList ) {
33 self
::SCHEMA
=> self
::SCHEMA_SEGMENTED
,
34 self
::SEGMENTED_HASHES
=> $segmentHashList
42 public static function isUnified( $value ) {
43 return self
::instanceOf( $value, self
::SCHEMA_UNIFIED
);
50 public static function isSegmented( $value ) {
51 return self
::instanceOf( $value, self
::SCHEMA_SEGMENTED
);
56 * @param string $schema SCHEMA_* class constant
59 private static function instanceOf( $value, $schema ) {
61 $value instanceof stdClass
&&
62 property_exists( $value, self
::SCHEMA
) &&
63 $value->{self
::SCHEMA
} === $schema