binary icon indicating copy to clipboard operation
binary copied to clipboard

Calculate the length of a Builder without executing it

Open kolmodin opened this issue 13 years ago • 0 comments

In the ELF format, there are absolute offsets pointing to positions after the offset. Thus, calculating this offset requires knowing the length of several Builders, including the length of the Builder that will contain the offset itself.

With the current API and a naive approach that would force the Builders into lazy ByteStrings, you'd end up with <>.

One simple solution, suggested by Joe Hendrix, is to wrap the Builder in a type that contains the Builder and it's length.

data SizedBuilder = SB Int64 Builder

length (SB l _) = l … + additional methods exported by Data.Binary.Builder

This API could be exposed from Data.Binary.Builder.Sized.

kolmodin avatar Apr 12 '12 09:04 kolmodin