The numbers can in fact change. Saving by name is better.
Be aware that %obj.datablock or %obj.getDataBlock().getName() will give you the datablock name,
but it only works for the host.
To get it to work client-side, you need to use the .uiname property of the datablocks (this is the name that is displayed in the brick selection dialog and in the hud)
So, to the name from a brick on the client you do
%brickName = %brick.getDatablock().uiName;
Then you save that uiname however you want.
Converting from the uiName back to a datablock id is a little trickier, but there is a built in table.
//create the table if it hasn't been created yet
if($UiNameTableCreated == false)
createUiNameTable();
//lookup the uiname in the table
%brickData = $uiNameTable[%brickName];