1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
//------------------------------------------------------------------------------
// GxB_deserialize_type_name: return the name of a type
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#include "GB.h"
#include "GB_serialize.h"
// GxB_deserialize_type_name extracts the type_name of the GrB_Type of the
// GrB_Matrix or GrB_Vector held in a serialized blob. On input, type_name
// must point to a user-owned char array of size at least GxB_MAX_NAME_LEN (it
// must not point into the blob itself). On output, type_name will contain a
// null-terminated string with the corresponding C type name. If the blob
// holds a matrix of a built-in type, the name is returned as "bool" for
// GrB_BOOL, "uint8_t" for GrB_UINT8, "float complex" for GxB_FC32, etc.
GrB_Info GxB_deserialize_type_name // return the type name of a blob
(
// output:
char *type_name, // name of the type (char array of size at least
// GxB_MAX_NAME_LEN, owned by the user application).
// input, not modified:
const void *blob, // the blob
GrB_Index blob_size // size of the blob
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
GB_WHERE1 ("GxB_deserialize_type_name (type_name, blob, blob_size)") ;
GB_RETURN_IF_NULL (type_name) ;
GB_RETURN_IF_NULL (blob) ;
if (blob_size < GB_BLOB_HEADER_SIZE)
{
// blob is invalid
return (GrB_INVALID_OBJECT) ;
}
//--------------------------------------------------------------------------
// get the blob header
//--------------------------------------------------------------------------
size_t s = 0 ;
GB_BLOB_READ (blob_size2, uint64_t) ;
GB_BLOB_READ (typecode, int32_t) ;
if (blob_size2 != blob_size)
{
// blob is invalid
return (GrB_INVALID_OBJECT) ;
}
//--------------------------------------------------------------------------
// get the type_name from the built-in type or the blob
//--------------------------------------------------------------------------
if (typecode >= GB_BOOL_code && typecode < GB_UDT_code)
{
// blob has a built-in type; the name is not in the blob
GrB_Type blob_type = GB_code_type ((GB_Type_code) typecode, NULL) ;
ASSERT (blob_type != NULL) ;
memcpy (type_name, blob_type->name, GxB_MAX_NAME_LEN) ;
}
else if (typecode == GB_UDT_code)
{
// blob has a user-defined type
if (blob_size < GB_BLOB_HEADER_SIZE + GxB_MAX_NAME_LEN)
{
// blob is invalid
return (GrB_INVALID_OBJECT) ;
}
// get the name of the user type from the blob
memcpy (type_name, ((GB_void *) blob) + GB_BLOB_HEADER_SIZE,
GxB_MAX_NAME_LEN) ;
}
else
{
// blob is invalid
return (GrB_INVALID_OBJECT) ;
}
// this should already be in the blob, but set it to null just in case
type_name [GxB_MAX_NAME_LEN-1] = '\0' ;
//--------------------------------------------------------------------------
// return result
//--------------------------------------------------------------------------
#pragma omp flush
return (GrB_SUCCESS) ;
}
|