The TaggedBlockWriter uses context managers to handle the hierarchical structure of .rm files. Data written inside these blocks is buffered and then written out with the appropriate length and header information once the block is exited.
Top-level Blocks
Use write_block(block_type, min_version, current_version) to create a top-level block. This method ensures that all writes within the with scope are accumulated and then written with a length prefix and versioning metadata.
Subblocks
Use write_subblock(index) to create a subblock associated with a specific index. This is commonly used for complex types like strings or LWW (Last-Write-Wins) values. The subblock is written with a TagType.Length4 tag and a length prefix.
Note: You cannot nest a top-level block inside another top-level block; attempting to do so will raise an UnexpectedBlockError.
# Example of nesting subblocks within a top-level block
with writer.write_block(block_type=1, min_version=1, current_version=1):
with writer.write_subblock(index=10):
writer.write_bool(1, True)