Difference between revisions of "Truxton artifact get offset"

From truxwiki.com
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 17: Line 17:
 
=Sample=
 
=Sample=
 
<source lang="C" highlight="12">
 
<source lang="C" highlight="12">
void create_artifact(void)
+
void create_artifact( void )
 
{
 
{
 
   uint64_t truxton = truxton_create();
 
   uint64_t truxton = truxton_create();
  
   uint64_t artifact = truxton_artifact_create(truxton);
+
   uint64_t artifact = truxton_artifact_create( truxton );
  
 
   truxton_artifact_set_name( artifact, "Ducky Momo Server" );
 
   truxton_artifact_set_name( artifact, "Ducky Momo Server" );
 
   truxton_artifact_set_offset( artifact, 42 );
 
   truxton_artifact_set_offset( artifact, 42 );
   truxton_artifact_save( artifact);
+
   truxton_artifact_save( artifact );
 
   truxton_artifact_tag( artifact, "Too Young", "Yes, yes I am", 1 );
 
   truxton_artifact_tag( artifact, "Too Young", "Yes, yes I am", 1 );
  
Line 32: Line 32:
 
   printf( "Artifact offset is%" PRIu64 "\n", offset );
 
   printf( "Artifact offset is%" PRIu64 "\n", offset );
  
   truxton_artifact_destroy(artifact);
+
   truxton_artifact_destroy( artifact );
   truxton_destroy(truxton);
+
   truxton_destroy( truxton );
 
}
 
}
 
</source>
 
</source>
 +
 +
The <code>PRIu64</code> in the sample code above is a standard way of [https://en.wikipedia.org/wiki/C_data_types#Printf_and_scanf_format_specifiers formatting] a 64-bit unsigned integer in C.
 +
Over the years, different compilers on different operating systems used different format specifiers for things, these <code>PRI</code> macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.

Latest revision as of 04:31, 13 February 2021

This tells you the offset into the object where the raw bytes that make up the artifact begin. This corresponds to the [Offset] column of the [Entity] table in the database.

Syntax

uint64_t truxton_artifact_get_offset( uint64_t artifact_handle );

Parameters

artifact_handle

The artifact instance. This handle comes from calling truxton_artifact_create().

Return value

The offset into the parent object where the raw artifact begins.

Sample

void create_artifact( void )
{
   uint64_t truxton = truxton_create();

   uint64_t artifact = truxton_artifact_create( truxton );

   truxton_artifact_set_name( artifact, "Ducky Momo Server" );
   truxton_artifact_set_offset( artifact, 42 );
   truxton_artifact_save( artifact );
   truxton_artifact_tag( artifact, "Too Young", "Yes, yes I am", 1 );

   uint64_t offset = truxton_artifact_get_offset( offset );

   printf( "Artifact offset is%" PRIu64 "\n", offset );

   truxton_artifact_destroy( artifact );
   truxton_destroy( truxton );
}

The PRIu64 in the sample code above is a standard way of formatting a 64-bit unsigned integer in C. Over the years, different compilers on different operating systems used different format specifiers for things, these PRI macros, along with some tricky string concatenation the compilers perform for you, allow you to maintain a single code base without a bunch of macro magic.