Ejemplo n.º 1
0
 /**
  * Computes hash of \Google\Protobuf\FileDescriptorProto
  *
  * @param object $object
  * @param string|resource $algoOrCtx
  * @param bool $raw
  *
  * @return string|void
  */
 public static function hash($object, $algoOrCtx = 'md5', $raw = FALSE)
 {
     if (is_string($algoOrCtx)) {
         $ctx = hash_init($algoOrCtx);
     } else {
         $ctx = $algoOrCtx;
     }
     if (isset($object->name)) {
         hash_update($ctx, 'name');
         hash_update($ctx, (string) $object->name);
     }
     if (isset($object->package)) {
         hash_update($ctx, 'package');
         hash_update($ctx, (string) $object->package);
     }
     if (isset($object->dependency)) {
         hash_update($ctx, 'dependency');
         foreach ($object->dependency instanceof \Traversable ? $object->dependency : (array) $object->dependency as $v0) {
             hash_update($ctx, (string) $v0);
         }
     }
     if (isset($object->publicDependency)) {
         hash_update($ctx, 'publicDependency');
         foreach ($object->publicDependency instanceof \Traversable ? $object->publicDependency : (array) $object->publicDependency as $v0) {
             hash_update($ctx, (string) $v0);
         }
     }
     if (isset($object->weakDependency)) {
         hash_update($ctx, 'weakDependency');
         foreach ($object->weakDependency instanceof \Traversable ? $object->weakDependency : (array) $object->weakDependency as $v0) {
             hash_update($ctx, (string) $v0);
         }
     }
     if (isset($object->messageType)) {
         hash_update($ctx, 'messageType');
         foreach ($object->messageType instanceof \Traversable ? $object->messageType : (array) $object->messageType as $v0) {
             DescriptorProtoMeta::hash($v0, $ctx);
         }
     }
     if (isset($object->enumType)) {
         hash_update($ctx, 'enumType');
         foreach ($object->enumType instanceof \Traversable ? $object->enumType : (array) $object->enumType as $v0) {
             EnumDescriptorProtoMeta::hash($v0, $ctx);
         }
     }
     if (isset($object->service)) {
         hash_update($ctx, 'service');
         foreach ($object->service instanceof \Traversable ? $object->service : (array) $object->service as $v0) {
             ServiceDescriptorProtoMeta::hash($v0, $ctx);
         }
     }
     if (isset($object->extension)) {
         hash_update($ctx, 'extension');
         foreach ($object->extension instanceof \Traversable ? $object->extension : (array) $object->extension as $v0) {
             FieldDescriptorProtoMeta::hash($v0, $ctx);
         }
     }
     if (isset($object->options)) {
         hash_update($ctx, 'options');
         FileOptionsMeta::hash($object->options, $ctx);
     }
     if (isset($object->sourceCodeInfo)) {
         hash_update($ctx, 'sourceCodeInfo');
         SourceCodeInfoMeta::hash($object->sourceCodeInfo, $ctx);
     }
     if (isset($object->syntax)) {
         hash_update($ctx, 'syntax');
         hash_update($ctx, (string) $object->syntax);
     }
     if (is_string($algoOrCtx)) {
         return hash_final($ctx, $raw);
     } else {
         return null;
     }
 }
Ejemplo n.º 2
0
 /**
  * Computes hash of \Google\Protobuf\DescriptorProto
  *
  * @param object $object
  * @param string|resource $algoOrCtx
  * @param bool $raw
  *
  * @return string|void
  */
 public static function hash($object, $algoOrCtx = 'md5', $raw = FALSE)
 {
     if (is_string($algoOrCtx)) {
         $ctx = hash_init($algoOrCtx);
     } else {
         $ctx = $algoOrCtx;
     }
     if (isset($object->name)) {
         hash_update($ctx, 'name');
         hash_update($ctx, (string) $object->name);
     }
     if (isset($object->field)) {
         hash_update($ctx, 'field');
         foreach ($object->field instanceof \Traversable ? $object->field : (array) $object->field as $v0) {
             FieldDescriptorProtoMeta::hash($v0, $ctx);
         }
     }
     if (isset($object->extension)) {
         hash_update($ctx, 'extension');
         foreach ($object->extension instanceof \Traversable ? $object->extension : (array) $object->extension as $v0) {
             FieldDescriptorProtoMeta::hash($v0, $ctx);
         }
     }
     if (isset($object->nestedType)) {
         hash_update($ctx, 'nestedType');
         foreach ($object->nestedType instanceof \Traversable ? $object->nestedType : (array) $object->nestedType as $v0) {
             DescriptorProtoMeta::hash($v0, $ctx);
         }
     }
     if (isset($object->enumType)) {
         hash_update($ctx, 'enumType');
         foreach ($object->enumType instanceof \Traversable ? $object->enumType : (array) $object->enumType as $v0) {
             EnumDescriptorProtoMeta::hash($v0, $ctx);
         }
     }
     if (isset($object->extensionRange)) {
         hash_update($ctx, 'extensionRange');
         foreach ($object->extensionRange instanceof \Traversable ? $object->extensionRange : (array) $object->extensionRange as $v0) {
             ExtensionRangeMeta::hash($v0, $ctx);
         }
     }
     if (isset($object->oneofDecl)) {
         hash_update($ctx, 'oneofDecl');
         foreach ($object->oneofDecl instanceof \Traversable ? $object->oneofDecl : (array) $object->oneofDecl as $v0) {
             OneofDescriptorProtoMeta::hash($v0, $ctx);
         }
     }
     if (isset($object->options)) {
         hash_update($ctx, 'options');
         MessageOptionsMeta::hash($object->options, $ctx);
     }
     if (isset($object->reservedRange)) {
         hash_update($ctx, 'reservedRange');
         foreach ($object->reservedRange instanceof \Traversable ? $object->reservedRange : (array) $object->reservedRange as $v0) {
             ReservedRangeMeta::hash($v0, $ctx);
         }
     }
     if (isset($object->reservedName)) {
         hash_update($ctx, 'reservedName');
         foreach ($object->reservedName instanceof \Traversable ? $object->reservedName : (array) $object->reservedName as $v0) {
             hash_update($ctx, (string) $v0);
         }
     }
     if (is_string($algoOrCtx)) {
         return hash_final($ctx, $raw);
     } else {
         return null;
     }
 }