Groonga
Loading...
Searching...
No Matches
util.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

GRN_API grn_objgrn_inspect (grn_ctx *ctx, grn_obj *buffer, grn_obj *obj)
 Inspect specified object and produce a textual representation.
 
GRN_API grn_objgrn_inspect_indent (grn_ctx *ctx, grn_obj *buffer, grn_obj *content, const char *indent)
 
GRN_API grn_objgrn_inspect_indented (grn_ctx *ctx, grn_obj *buffer, grn_obj *obj, const char *indent)
 Inspect specified object and produce an indented textual representation.
 
GRN_API grn_objgrn_inspect_limited (grn_ctx *ctx, grn_obj *buffer, grn_obj *obj)
 Inspect specified object and produce a length-limited textual representation.
 
GRN_API grn_objgrn_inspect_name (grn_ctx *ctx, grn_obj *buffer, grn_obj *obj)
 Inspect specified object and return the name of the specified object.
 
GRN_API grn_objgrn_inspect_encoding (grn_ctx *ctx, grn_obj *buffer, grn_encoding encoding)
 Inspect the given encoding and produce its name.
 
GRN_API grn_objgrn_inspect_type (grn_ctx *ctx, grn_obj *buffer, unsigned char type)
 Inspect the given type and produce its name.
 
GRN_API grn_objgrn_inspect_query_log_flags (grn_ctx *ctx, grn_obj *buffer, unsigned int flags)
 Inspect the given query log flags and produce their names.
 
GRN_API grn_objgrn_inspect_key (grn_ctx *ctx, grn_obj *buffer, grn_obj *table, const void *key, uint32_t key_size)
 
GRN_API void grn_p (grn_ctx *ctx, grn_obj *obj)
 Print inspected text of the given object.
 
GRN_API void grn_p_geo_point (grn_ctx *ctx, grn_geo_point *point)
 Print inspected text of the given geo point.
 
GRN_API void grn_p_ii_values (grn_ctx *ctx, grn_obj *obj)
 Print inspected text of the given index column values.
 

Function Documentation

◆ grn_inspect()

GRN_API grn_obj * grn_inspect ( grn_ctx ctx,
grn_obj buffer,
grn_obj obj 
)

Inspect specified object and produce a textual representation.

Note
If obj is a GRN_TABLE_PAT_KEY table, all keys are shown. To limit output on GRN_TABLE_PAT_KEY tables, use grn_inspect_limited instead.

For example usage:

grn_obj inspected;
GRN_TEXT_INIT(&inspected, 0);
grn_inspect(ctx, &inspected, obj);
printf("%.*s\n", (int)GRN_TEXT_LEN(&inspected), GRN_TEXT_VALUE(&inspected));
GRN_OBJ_FIN(ctx, &inspected);
#define GRN_TEXT_VALUE(obj)
Definition groonga.h:2785
#define GRN_OBJ_FIN(ctx, obj)
Definition groonga.h:958
#define GRN_TEXT_INIT(obj, flags)
Definition groonga.h:2750
#define GRN_TEXT_LEN(obj)
Definition groonga.h:2786
Definition groonga.h:919
GRN_API grn_obj * grn_inspect(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj)
Inspect specified object and produce a textual representation.
Parameters
ctxThe context object.
bufferThe buffer where the inspected text will be stored.
objThe target object to inspect.
Returns
The inspected object in text.

◆ grn_inspect_encoding()

GRN_API grn_obj * grn_inspect_encoding ( grn_ctx ctx,
grn_obj buffer,
grn_encoding  encoding 
)

Inspect the given encoding and produce its name.

Since
4.0.8

For example usage:

grn_obj encoding;
GRN_TEXT_INIT(&encoding, 0);
printf("%.*s\n", (int)GRN_TEXT_LEN(&encoding), GRN_TEXT_VALUE(&encoding));
GRN_OBJ_FIN(ctx, &encoding);
@ GRN_ENC_UTF8
UTF-8 (3)
Definition groonga.h:172
GRN_API grn_obj * grn_inspect_encoding(grn_ctx *ctx, grn_obj *buffer, grn_encoding encoding)
Inspect the given encoding and produce its name.

For example output: Depending on encoding, it will output one of the following lines:

default(UTF-8)
none
EUC-JP
UTF-8
Shift_JIS
Latin-1
KOI8-R
unknown(encoding)
Parameters
ctxThe context object.
bufferThe buffer where the encoding name will be stored.
encodingThe encoding to inspect. Must be one of:
Returns
The inspected object's encoding name in text.

◆ grn_inspect_indent()

GRN_API grn_obj * grn_inspect_indent ( grn_ctx ctx,
grn_obj buffer,
grn_obj content,
const char *  indent 
)

◆ grn_inspect_indented()

GRN_API grn_obj * grn_inspect_indented ( grn_ctx ctx,
grn_obj buffer,
grn_obj obj,
const char *  indent 
)

Inspect specified object and produce an indented textual representation.

Since
4.0.8

This function combines grn_inspect and grn_inspect_indent. It first inspects the given obj into a temporary buffer, then prepends the given indent string to each line of that inspected text and stores the result in buffer.

Note
The indent string is only applied when the inspected text contains one or more newline characters (when the output spans multiple lines).

For example usage:

grn_obj inspected;
GRN_TEXT_INIT(&inspected, 0);
grn_inspect_indented(ctx, &inspected, obj, "***");
printf("%.*s\n", (int)GRN_TEXT_LEN(&inspected), GRN_TEXT_VALUE(&inspected));
GRN_OBJ_FIN(ctx, &inspected);
GRN_API grn_obj * grn_inspect_indented(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj, const char *indent)
Inspect specified object and produce an indented textual representation.

If obj is GRN_TABLE_PAT_KEY table, it prints like the following.

***#<table:pat Users key:ShortText value:(nil) size:7 columns:[] \
default_tokenizer:(nil) normalizer:(nil) \
keys:["a", "b", "c", "d", "e", "f", "g"] subrec:none nodes:{
***4{0,5,0}
*** L:2{0,6,0}
*** L:1{0,7,0}
*** L:0{0,0,0}
*** R:1{0,7,0}("a")[01100001]
Parameters
ctxThe context object.
bufferThe buffer where the indented inspected text will be stored.
objThe target object to inspect.
indentThe indentation string to prepend to each line of output.
Returns
The indented inspected object in text.

◆ grn_inspect_key()

GRN_API grn_obj * grn_inspect_key ( grn_ctx ctx,
grn_obj buffer,
grn_obj table,
const void *  key,
uint32_t  key_size 
)

◆ grn_inspect_limited()

GRN_API grn_obj * grn_inspect_limited ( grn_ctx ctx,
grn_obj buffer,
grn_obj obj 
)

Inspect specified object and produce a length-limited textual representation.

Since
7.0.0

This function inspects obj into buffer, but if the full representation exceeds half of GRN_CTX_MSGSIZE, the output is truncated to that length, and "...(original length)" is appended to indicate the total size.

Note
If the inspected text length is greater than GRN_CTX_MSGSIZE/2, it will be truncated otherwise it is copied in full.

For example usage:

grn_obj inspected;
GRN_TEXT_INIT(&inspected, 0);
grn_inspect_limited(ctx, &inspected, obj);
printf("#=> %.*s\n",
(int)GRN_TEXT_LEN(&inspected),
GRN_TEXT_VALUE(&inspected));
GRN_OBJ_FIN(ctx, &buffer);
GRN_API grn_obj * grn_inspect_limited(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj)
Inspect specified object and produce a length-limited textual representation.

If obj is GRN_TABLE_PAT_KEY table, it prints truncated result as follows.

#<table:pat Users key:ShortText value:(nil) size:7 columns:[] de...(502)
Parameters
ctxThe context object.
bufferThe buffer where the truncated inspected text will be stored.
objThe target object to inspect.
Returns
The truncated inspected object in text.

◆ grn_inspect_name()

GRN_API grn_obj * grn_inspect_name ( grn_ctx ctx,
grn_obj buffer,
grn_obj obj 
)

Inspect specified object and return the name of the specified object.

This function inspects the given obj and writes its name into buffer. If obj has a name, that name is copied into buffer. Otherwise:

  • If obj's ID is a GRN_ID_NIL, the (nil) is stored in buffer.
  • If obj exists but has no name, the (anonymous:ID) is stored.

For example usage:

grn_obj name;
GRN_TEXT_INIT(&name, 0);
grn_inspect_name(ctx, &name, obj);
printf("%.*s\n", (int)GRN_TEXT_LEN(&name),
GRN_TEXT_VALUE(&name));
GRN_OBJ_FIN(ctx, &name);
GRN_API grn_obj * grn_inspect_name(grn_ctx *ctx, grn_obj *buffer, grn_obj *obj)
Inspect specified object and return the name of the specified object.

For example output: Depending on obj, it will output one of the following lines:

Users
(nil)
(anonymous:42)
Parameters
ctxThe context object.
bufferThe buffer where the inspected name will be stored.
objThe target object whose name is to be inspected.
Returns
The inspected object's name in text.

◆ grn_inspect_query_log_flags()

GRN_API grn_obj * grn_inspect_query_log_flags ( grn_ctx ctx,
grn_obj buffer,
unsigned int  flags 
)

Inspect the given query log flags and produce their names.

Since
7.0.4

For example usage:

grn_obj flags;
GRN_TEXT_INIT(&flags, 0);
unsigned int current_flags = grn_query_logger_get_flags(ctx);
grn_inspect_query_log_flags(ctx, &flags, current_flags);
printf("%.*s\n",
(int)GRN_TEXT_LEN(&flags),
GRN_TEXT_VALUE(&flags));
GRN_OBJ_FIN(ctx, &flags);
GRN_API unsigned int grn_query_logger_get_flags(grn_ctx *ctx)
GRN_API grn_obj * grn_inspect_query_log_flags(grn_ctx *ctx, grn_obj *buffer, unsigned int flags)
Inspect the given query log flags and produce their names.

For example output: Depending on flags, it will output one of the following:

NONE
CACHE
COMMAND
DESTINATION
RESULT_CODE
SCORE
SIZE

When multiple flags are set, they are displayed separated by "|".

CACHE|COMMAND|DESTINATION|RESULT_CODE|SCORE|SIZE

Available flags:

Parameters
ctxThe context object.
bufferThe buffer where the flag names will be stored.
flagsThe query log flags to inspect.
Returns
The names of the inspected query log flags as text.

◆ grn_inspect_type()

GRN_API grn_obj * grn_inspect_type ( grn_ctx ctx,
grn_obj buffer,
unsigned char  type 
)

Inspect the given type and produce its name.

Since
4.0.8

For example usage:

grn_obj type_name;
GRN_TEXT_INIT(&type_name, 0);
grn_inspect_type(ctx, &type_name, obj->header.type);
printf("%.*s\n",
(int)GRN_TEXT_LEN(&type_name),
GRN_TEXT_VALUE(&type_name));
GRN_OBJ_FIN(ctx, &type_name);
GRN_API grn_obj * grn_inspect_type(grn_ctx *ctx, grn_obj *buffer, unsigned char type)
Inspect the given type and produce its name.

For example output: Depending on type, it will output one of the following lines:

Table types:

#define GRN_TABLE_NO_KEY
Definition groonga.h:898
#define GRN_TABLE_HASH_KEY
Definition groonga.h:895
#define GRN_TABLE_PAT_KEY
Definition groonga.h:896
#define GRN_TABLE_DAT_KEY
Definition groonga.h:897

Column types:

#define GRN_COLUMN_INDEX
Definition groonga.h:902
#define GRN_COLUMN_FIX_SIZE
Definition groonga.h:900
#define GRN_COLUMN_VAR_SIZE
Definition groonga.h:901

Data container types:

#define GRN_PVECTOR
Definition groonga.h:876
#define GRN_UVECTOR
Definition groonga.h:875
#define GRN_BULK
Definition groonga.h:868
#define GRN_VECTOR
Definition groonga.h:877
#define GRN_PTR
Definition groonga.h:873

Cursor types:

#define GRN_CURSOR_TABLE_DAT_KEY
Definition groonga.h:887
#define GRN_CURSOR_TABLE_HASH_KEY
Definition groonga.h:885
#define GRN_CURSOR_COLUMN_GEO_INDEX
Definition groonga.h:890
#define GRN_CURSOR_TABLE_NO_KEY
Definition groonga.h:888
#define GRN_CURSOR_TABLE_PAT_KEY
Definition groonga.h:886
#define GRN_CURSOR_COLUMN_INDEX
Definition groonga.h:889

Other object types:

#define GRN_ACCESSOR
Definition groonga.h:880
#define GRN_QUERY
Definition groonga.h:879
#define GRN_PATSNIP
Definition groonga.h:882
#define GRN_SNIP
Definition groonga.h:881
#define GRN_PROC
Definition groonga.h:893
#define GRN_MSG
Definition groonga.h:878
#define GRN_EXPR
Definition groonga.h:894
#define GRN_STRING
Definition groonga.h:883
#define GRN_TYPE
Definition groonga.h:892
#define GRN_DB
Definition groonga.h:899
#define GRN_VOID
Definition groonga.h:863

Unknown types:

(unknown: 0x42)

Where 0x42 is an example of the hexadecimal value for unknown types.

Parameters
ctxThe context object.
bufferThe buffer where the type name will be stored.
typeThe type to inspect. This is typically obtained from an grn_obj_header::type.
Returns
The inspected object's type name in text.

◆ grn_p()

GRN_API void grn_p ( grn_ctx ctx,
grn_obj obj 
)

Print inspected text of the given object.

Since
4.0.8

For example usage:

grn_p(ctx, obj);
GRN_API void grn_p(grn_ctx *ctx, grn_obj *obj)
Print inspected text of the given object.

If obj is a ShortText type, it prints output like:

#<type ShortText size:4096 type:var_size>
Parameters
ctxThe context object.
objThe object to inspect and print.

◆ grn_p_geo_point()

GRN_API void grn_p_geo_point ( grn_ctx ctx,
grn_geo_point point 
)

Print inspected text of the given geo point.

Since
4.0.8

This function inspects the given point and prints the result directly to stdout. It internally creates a WGS84 geo point object from the provided grn_geo_point structure and prints its inspected representation.

For example usage:

point.latitude = ((40 * 60 * 60) + (42 * 60) + 46) * 1000;
point.longitude = ((-74 * 60 * 60) + (0 * 60) + 22) * 1000;
grn_p_geo_point(ctx, &point);
Definition geo.h:26
int32_t longitude
Definition geo.h:28
int32_t latitude
Definition geo.h:27
GRN_API void grn_p_geo_point(grn_ctx *ctx, grn_geo_point *point)
Print inspected text of the given geo point.

If point indicates New York City, it prints output like:

[(524290,18) ((0, 8, 44, 290),(0, 0, 0, 18)) \
[00000000 00000000 00000000 10000000 00000000 00000000 00000001 00001100]]
Parameters
ctxThe context object.
pointThe geo point to inspect and print.

◆ grn_p_ii_values()

GRN_API void grn_p_ii_values ( grn_ctx ctx,
grn_obj obj 
)

Print inspected text of the given index column values.

Since
4.0.8

For example usage:

grn_p_ii_values(ctx, index_column);
GRN_API void grn_p_ii_values(grn_ctx *ctx, grn_obj *obj)
Print inspected text of the given index column values.

If obj is an index column, it prints output like:

[
#<"!"
elements:[
{status:available, rid:1, sid:1, pos:0, tf:1, weight:0, rest:1},
{status:available, rid:2, sid:1, pos:0, tf:1, weight:0, rest:1}
]
>,
...
# ]
Parameters
ctxThe context object.
objThe index column to inspect and print.