Skip to content

Commit 2682b85

Browse files
committed
Rename project from simple-binary-builder (sbb) to build-a-file (baf)
1 parent 6e39a8e commit 2682b85

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
# Simple Binary Builder
1+
# Build-A-File
22

3-
Simple Binary Builder (SBB) is a framework that makes it easy to create custom binary file formats and assemble your data into them.
3+
Build-A-File (BAF) is a framework that makes it easy to create custom binary file formats and assemble your data into them.
44

5-
It was originally created to easily build binary data files for games targeting Amiga and other retro systems. However, SBB can be used for any general purpose. It was born as an internal-only tool, so it's a bit rough around the edges, but if you follow the rules then it gets the job done. :)
5+
It was originally created to easily build binary data files for games targeting Amiga and other retro systems. However, BAF can be used for any general purpose. It was born as an internal-only tool, so it's a bit rough around the edges, but if you follow the rules then it gets the job done. :)
66

7-
SBB is a one-way tool: It takes source data and builds it into a binary file. If you want to reverse-engineer existing binary files into an ORM, check out [Mr. Crowbar](https://github.com/moralrecordings/mrcrowbar), which inspired this project (and is probably much more well-written).
7+
BAF is a one-way tool: It takes source data and builds it into a binary file. If you want to reverse-engineer existing binary files into an ORM, check out [Mr. Crowbar](https://github.com/moralrecordings/mrcrowbar), which inspired this project (and is probably much more well-written).
88

99
## Requirements
1010

11-
SBB requires Python 3.12 or higher.
11+
BAF requires Python 3.12 or higher.
1212

1313
## Examples
1414

1515
### Basic example
1616

17-
With SBB, data structures are defined using `Block`s. Create a class that derives from `Block`, then annotate some property names, and a datatype for each property.
17+
With BAF, data structures are defined using `Block`s. Create a class that derives from `Block`, then annotate some property names, and a datatype for each property.
1818

19-
In your TOML file, create some corresponding entries with the same names as your properties. When you load the TOML file to your `Block` class, SBB will automatically fill in all the properties with the data from the TOML file.
19+
In your TOML file, create some corresponding entries with the same names as your properties. When you load the TOML file to your `Block` class, BAF will automatically fill in all the properties with the data from the TOML file.
2020

21-
Notice we have one property, `name_length`, that isn't in the TOML. That's because we want to programmatically give this a value, rather than define it in the TOML. To do this, create a setter method called `set_name_length()`. If SBB finds a setter method called `set_<property_name>`, it will use that to fill in the data with whatever value you return.
21+
Notice we have one property, `name_length`, that isn't in the TOML. That's because we want to programmatically give this a value, rather than define it in the TOML. To do this, create a setter method called `set_name_length()`. If BAF finds a setter method called `set_<property_name>`, it will use that to fill in the data with whatever value you return.
2222

2323
Whatever data is given to the parent `Block` (in this case, the `dict` generated from our TOML file), that will also be passed to the setter method. So, if you need that data to determine your value, you can use it.
2424

2525
`example.py`:
2626

2727
```py
28-
import sbb
29-
from sbb.datatypes import *
28+
import baf
29+
from baf.datatypes import *
3030

3131

3232
class Level(Block):
@@ -39,7 +39,7 @@ class Level(Block):
3939
return self.name.size()
4040

4141

42-
level = sbb.build_toml('example.toml', Level)
42+
level = baf.build_toml('example.toml', Level)
4343
level_bytes = level.to_bytes()
4444
print(level_bytes.hex())
4545
# Write file to disk
@@ -68,7 +68,7 @@ You can nest `Block`s to create more complex data structures.
6868

6969
In this example, `Level` has two properties, `header` and `data`, which are each a `Block` of their own. The TOML file reflects this.
7070

71-
Remember that we're passing `Level` to `sbb.build_toml()`, which is how `Level` is specified as the top-level block.
71+
Remember that we're passing `Level` to `baf.build_toml()`, which is how `Level` is specified as the top-level block.
7272

7373
```py
7474
class LevelHeader(Block):
@@ -110,7 +110,7 @@ height = 128
110110

111111
In the above example, you'll notice that `name_length` is set using `self.name.size()`, and `data_offset` is set using `self.data.offset()`. These two functions work on any datatype, and you can use them in your setter without worrying about the order in which data is built.
112112

113-
Behind the scenes, SBB uses some aggressive reflection to figure out which properties have dependencies on others. For example, to figure out `data_offset`, SBB needs to know the size of `header`, so it builds `header` first. If there is a circular dependency, you will get an error.
113+
Behind the scenes, BAF uses some aggressive reflection to figure out which properties have dependencies on others. For example, to figure out `data_offset`, BAF needs to know the size of `header`, so it builds `header` first. If there is a circular dependency, you will get an error.
114114

115115
### `Array`
116116

@@ -156,11 +156,11 @@ spawn_y = 56
156156

157157
### Visualizer
158158

159-
After getting our `Level` object with `sbb.build_toml()`, we can use `sbb.visualize()` to view a tree of our file format.
159+
After getting our `Level` object with `baf.build_toml()`, we can use `baf.visualize()` to view a tree of our file format.
160160

161161
```py
162-
level = sbb.build_toml('visualizer_example.toml', Level)
163-
tree = sbb.visualize(level)
162+
level = baf.build_toml('visualizer_example.toml', Level)
163+
tree = baf.visualize(level)
164164
print(tree)
165165
```
166166

@@ -266,9 +266,9 @@ background_path = "images/background.png"
266266

267267
### Custom datatypes
268268

269-
You can build on top of SBB with custom datatypes that suit your purposes.
269+
You can build on top of BAF with custom datatypes that suit your purposes.
270270

271-
For example, SBB doesn't have a built-in `Bool` datatype because `bool` can have different implementations depending on the platform. It's easy to define your own.
271+
For example, BAF doesn't have a built-in `Bool` datatype because `bool` can have different implementations depending on the platform. It's easy to define your own.
272272

273273
```py
274274
class Bool(U8):
@@ -291,7 +291,7 @@ has_boss = true
291291

292292
Below is an example of a custom `List` datatype which combines item count, item offsets, and item data.
293293

294-
SBB ignores the annotations in the base `List` class—it only cares about those in the derived `Rooms` and `Spritesheets` classes. Notice how `items` contains a different `Array` type in `Rooms` and `Spritesheets`.
294+
BAF ignores the annotations in the base `List` class—it only cares about those in the derived `Rooms` and `Spritesheets` classes. Notice how `items` contains a different `Array` type in `Rooms` and `Spritesheets`.
295295

296296
```py
297297
class List(Block):
@@ -329,7 +329,7 @@ class Spritesheets(List):
329329

330330
### Overriding `__init__()`
331331

332-
You can override `__init__()` if you need to do something highly specific with your data that SBB can't handle automatically. Fill in whatever data you want manually, and then call `super().__init__(parent, data)` at the end (don't forget this step). SBB will kick in and build any remaining data based on your TOML.
332+
You can override `__init__()` if you need to do something highly specific with your data that BAF can't handle automatically. Fill in whatever data you want manually, and then call `super().__init__(parent, data)` at the end (don't forget this step). BAF will kick in and build any remaining data based on your TOML.
333333

334334
Below, I have a list `Bobs`, but the data in the TOML needs to be processed into a more specific format before the list can be built.
335335

@@ -369,18 +369,18 @@ heights = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
369369

370370
### Errors
371371

372-
If SBB catches an exception, it will add notes to the exception containing a traceback of your data structures, so you can pinpoint what data or setter caused the issue.
372+
If BAF catches an exception, it will add notes to the exception containing a traceback of your data structures, so you can pinpoint what data or setter caused the issue.
373373

374-
SBB doesn't discard or sanitize the full Python traceback, so it's ugly by default. If you want it to look nice, catch the exception yourself and print `__notes__`, as shown below. However, the default Python exception will also show the notes at the bottom, so this is optional.
374+
BAF doesn't discard or sanitize the full Python traceback, so it's ugly by default. If you want it to look nice, catch the exception yourself and print `__notes__`, as shown below. However, the default Python exception will also show the notes at the bottom, so this is optional.
375375

376376
```py
377377
import sys
378-
import sbb
379-
from sbb.errors import BuildError
378+
import baf
379+
from baf.errors import BuildError
380380

381381

382382
try:
383-
level = sbb.build_toml('error_example.toml', Level)
383+
level = baf.build_toml('error_example.toml', Level)
384384
except BuildError as e:
385385
print(f"ERROR: {e}\nTraceback:")
386386
print('\n'.join(e.__notes__))
File renamed without changes.

sbb/datatypes.py renamed to baf/datatypes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
class DataType(ABC):
28-
'''The abstract base class of all SBB datatypes.'''
28+
'''The abstract base class of all BAF datatypes.'''
2929

3030
parent: Optional[Block]
3131

@@ -254,7 +254,7 @@ def __init__(self, parent: Optional[Block], path: str) -> None:
254254
class Empty(DataType):
255255
'''A datatype of size 0 that never generates any bytes in the output.
256256
257-
This can sometimes be useful in lieu of `None`, because SBB can parse
257+
This can sometimes be useful in lieu of `None`, because BAF can parse
258258
it.'''
259259

260260
def __init__(self, parent: Optional[Block]) -> None:
@@ -314,7 +314,7 @@ def __init__(self, parent: Optional[Block], pad_amount: int) -> None:
314314

315315
class Block(DataType):
316316
'''The base class of custom datatypes and the foundational building block
317-
of SBB.
317+
of BAF.
318318
319319
Custom datatypes deriving from `Block` can specify their data using member
320320
variable annotations, which are then automatically set using data from the
@@ -424,7 +424,7 @@ def offset_of(cls, prop_name: str) -> int:
424424
size or have already been populated with their data.
425425
426426
It's preferable to directly call `offset()` on the child object,
427-
especially in a setter method, because SBB can figure out the
427+
especially in a setter method, because BAF can figure out the
428428
dependencies needed before the offset is calculated. However, this
429429
method can be useful in edge cases where `offset()` doesn't work.'''
430430

sbb/errors.py renamed to baf/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
class BuildError(Exception):
2-
'''The base exception class used for all errors handled during the SBB
2+
'''The base exception class used for all errors handled during the BAF
33
build process.'''
44
pass
55

66

77
class DataMissingError(BuildError):
8-
'''An exception class used when SBB fails to fetch data from a `Block`,
8+
'''An exception class used when BAF fails to fetch data from a `Block`,
99
`Array`, or other datatype that has not yet been fully built.'''
1010
pass
1111

0 commit comments

Comments
 (0)