!"#$%&'()*+,-./0123456789 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z {|}~ A(c) 2010 Simon Meier (c) 2010 Jasper van der JeugtBSD3-style (see LICENSE)$Leon Smith <leon@melding-monads.com> experimentaltested on GHC onlyNone%A write of a bounded number of bytes.When defining a function write :: a -> Write for some ao, then it is important to ensure that the bound on the number of bytes written is data-independent. Formally, 4 forall x y. getBound (write x) = getBound (write y)LThe idea is that this data-independent bound is specified such that the compiler can optimize the check, if there are enough free bytes in the buffer, to a single subtraction between the pointer to the next free byte and the pointer to the end of the buffer with this constant bound of the maximal number of bytes to be written.>Changing a sequence of bytes starting from the given pointer. ns are the most primitive buffer manipulation. In most cases, you don't use the explicitely but as part of a ;, which also tells how many bytes will be changed at most. Extract the  action of a write. Run the  action of a write. @Extract the maximal number of bytes that this write could write. Extract the maximal number of bytes that this write could write in any case. Assumes that the bound of the write is data-independent.  pokeN size io- creates a write that denotes the writing of size( bytes to a buffer using the IO action io . Note that io MUST write EXACTLY size bytes to the buffer! exactWrite size ioW creates a bounded write that can later be converted to a builder that writes exactly size bytes. Note that io MUST write EXACTLY size bytes to the buffer!boundedWrite size write creates a bounded write from a write that does not write more than size bytes.writeLiftIO io write creates a write executes the io3 action to compute the value that is then written.writeIf p wTrue wFalse x creates a  with a  equal to wTrue x, if p x and equal to wFalse x# otherwise. The bound of this new ) is the maximum of the bounds for either :. This yields a data independent bound, if the bound for wTrue and wFalse is already data independent.Compare the value to a test value and use the first write action for the equal case and the second write action for the non-equal case.WTODO: Test this. It might well be too difficult to use. FIXME: Better name required!A write combinator useful to build decision trees for deciding what value to write with a constant bound on the maximal number of bytes written.'Create a builder that execute a single . Construct a . writing a list of data one element at a time.Write a storable value.AA builder that serializes a storable value. No alignment is done.A builder that serializes a list of storable values by writing them consecutively. No alignment is done. Parsing information needs to be provided externally. 'Name of caller: for debugging purposes.      (c) 2013 Leon P SmithBSD3&Leon P Smith <leon@melding-monads.com> experimentalNone(c) 2013 Leon P SmithBSD3&Leon P Smith <leon@melding-monads.com> experimentalNone4Write a UTF-8 encoded Unicode character to a buffer.O(1)9. Serialize a Unicode character using the UTF-8 encoding.O(n). Serialize a Unicode  using the UTF-8 encoding.O(n). Serialize a value by )ing it and UTF-8 encoding the resulting . O(n). Serialize a strict Unicode  value using the UTF-8 encoding.!O(n). Serialize a lazy Unicode  value using the UTF-8 encoding. ! ! ! !(c) 2013 Leon P SmithBSD3&Leon P Smith <leon@melding-monads.com> experimentalNone"2Write the lower 8-bits of a character to a buffer.#O(1),. Serialize the lower 8-bits of a character.$O(n):. Serialize the lower 8-bits of all characters of a string%O(n). Serialize a value by Aing it and serializing the lower 8-bits of the resulting string.&O(n)B. Serialize the lower 8-bits of all characters in the strict text.'O(n)@. Serialize the lower 8-bits of all characters in the lazy text."#$%&'"#$%&'"#$%&'"#$%&'(c) 2013 Leon P SmithBSD3&Leon P Smith <leon@melding-monads.com> experimentalNone(FWrite a HTML escaped and UTF-8 encoded Unicode character to a bufffer.)O(1).F Serialize a HTML escaped Unicode character using the UTF-8 encoding.*O(n)#. Serialize a HTML escaped Unicode  using the UTF-8 encoding.+O(n). Serialize a value by Aing it and then, HTML escaping and UTF-8 encoding the resulting .,O(n)*. Serialize a HTML escaped strict Unicode ! value using the UTF-8 encoding.-O(n)#. Serialize a HTML escaped Unicode  using the UTF-8 encoding.()*+,-  !()*+,-()*+,-()*+,-(c) 2013 Leon P SmithBSD3&Leon P Smith <leon@melding-monads.com> experimentalNone .Write a strict  to a buffer./ Create a 2 denoting the same sequence of bytes as a strict . The  inserts large \s directly, but copies small ones to ensure that the generated chunks are large on average.0 Construct a  that copies the strict Js, if it is smaller than the treshold, and inserts it directly otherwise. For example, fromByteStringWith 1024 copies strict s whose size is less or equal to 1kb, and inserts them directly otherwise. This implies that the average chunk-size of the generated lazy { may be as low as 513 bytes, as there could always be just a single byte between the directly inserted 1025 byte, strict s.1 Construct a  that copies the strict .Use this function to create s from smallish (<= 4kb) 's or if you need to guarantee that the 1 is not shared with the chunks generated by the .2 Construct a  that always inserts the strict  directly as a chunk.kThis implies flushing the output buffer, even if it contains just a single byte. You should therefore use 2 only for large (> 8kb) ^s. Otherwise, the generated chunks are too fragmented to be processed efficiently afterwards.3 Create a 0 denoting the same sequence of bytes as a lazy . The " inserts large chunks of the lazy \ directly, but copies small ones to ensure that the generated chunks are large on average.4 Construct a ( that uses the thresholding strategy of 0 for each chunk of the lazy .5 Construct a  that copies the lazy .6 Construct a % that inserts all chunks of the lazy  directly. ./0 Maximal number of bytes to copy.Strict  to serialize. Resulting .123456 ./0123456 ./0123456 ./0123456(c) 2013 Simon MeierBSD3&Leon P Smith <leon@melding-monads.com> experimentalNone;Write a CRLF sequence.Execute a write6Length of the hex-string required to encode the given .7ETransform a builder such that it uses chunked HTTP transfer encoding.8The zero-length chunk  '0\r\n\r\n'0 signaling the termination of the data transfer. 787878 78 (c) 2013 Leon P SmithBSD3&Leon P Smith <leon@melding-monads.com> experimentalNone!9Write a single byte.:Write a  in big endian format.;Write a  in big endian format.<Write a  in big endian format.=Write a  in little endian format.>Write a  in big endian format.?Write a  in little endian format.@Write a single native machine . The a is written in host order, host endian form, for the machine you're on. On a 64 bit machine the  is an 8 byte value, on a 32 bit machine, 4 bytes. Values written this way are not portable to different endian or word sized machines, without conversion.AWrite a * in native host order and host endianness.BWrite a * in native host order and host endianness.CWrite a * in native host order and host endianness.DSerialize a single byte.ESerialize a list of bytes.F Serialize a  in big endian format.G Serialize a  in big endian format.H Serialize a  in big endian format.ISerialize a list of s in big endian format.JSerialize a list of s in big endian format.KSerialize a list of s in big endian format.L Serialize a  in little endian format.MSerialize a list of s in little endian format.N Serialize a  in little endian format.OSerialize a list of s in little endian format.PSerialize a list of s in little endian format.QSerialize a list of s in little endian format.R"Serialize a single native machine . The e is serialized in host order, host endian form, for the machine you're on. On a 64 bit machine the  is an 8 byte value, on a 32 bit machine, 4 bytes. Values written this way are not portable to different endian or word sized machines, without conversion.SWrite a * in native host order and host endianness.TWrite a * in native host order and host endianness.UWrite a * in native host order and host endianness.VSerialize a list of s. See R for usage considerations.WWrite a list of +s in native host order and host endianness.XWrite a list of +s in native host order and host endianness.YWrite a * in native host order and host endianness.!9:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY!9:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY!9:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY!9:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY (c) 2013 Leon P SmithBSD3&Leon P Smith <leon@melding-monads.com> experimentalNone!ZWrite a single signed byte.[ Write an  in big endian format.\ Write an  in big endian format.] Write an  in big endian format.^ Write an  in little endian format._ Write an  in little endian format.` Write an  in little endian format.aWrite a single native machine . The a is written in host order, host endian form, for the machine you're on. On a 64 bit machine the  is an 8 byte value, on a 32 bit machine, 4 bytes. Values written this way are not portable to different endian or integer sized machines, without conversion.b Write an * in native host order and host endianness.c Write an * in native host order and host endianness.d Write an * in native host order and host endianness.eSerialize a single byte.fSerialize a list of bytes.g Serialize an  in big endian format.h Serialize an  in big endian format.i Serialize an  in big endian format.jSerialize a list of s in big endian format.kSerialize a list of s in big endian format.lSerialize a list of s in big endian format.m Serialize an  in little endian format.n Serialize an  in little endian format.o Serialize an  in little endian format.pSerialize a list of s in little endian format.qSerialize a list of s in little endian format.rSerialize a list of s in little endian format.s"Serialize a single native machine . The e is serialized in host order, host endian form, for the machine you're on. On a 64 bit machine the  is an 8 byte value, on a 32 bit machine, 4 bytes. Values written this way are not portable to different endian or integer sized machines, without conversion.t Write an * in native host order and host endianness.u Write an * in native host order and host endianness.v Write an * in native host order and host endianness.wSerialize a list of s. See s for usage considerations.xWrite a list of +s in native host order and host endianness.yWrite a list of +s in native host order and host endianness.zWrite a list of +s in native host order and host endianness.!Z[\]^_`abcdefghijklmnopqrstuvwxyz!Z[\]^_`abcdefghijklmnopqrstuvwxyz!Z[\]^_`abcdefghijklmnopqrstuvwxyz!Z[\]^_`abcdefghijklmnopqrstuvwxyz(c) 2013 Leon P SmithBSD3&Leon P Smith <leon@melding-monads.com> experimentalNoneBEPack the chunks of a lazy bytestring into a single strict bytestring.{Run the builder to construct a strict bytestring containing the sequence of bytes denoted by the builder. This is done by first serializing to a lazy bytestring and then packing its chunks to a appropriately sized strict bytestring. ,toByteString = packChunks . toLazyByteString Note that { is a Monoid homomorphism. ntoByteString mempty == mempty toByteString (x `mappend` y) == toByteString x `mappend` toByteString yTHowever, in the second equation, the left-hand-side is generally faster to execute.aDefault size (~32kb) for the buffer that becomes a chunk of the output stream once it is filled.|toByteStringIOWith bufSize io b runs the builder b% with a buffer of at least the size bufSize and executes the  action io whenever the buffer is full. Compared to ~ this function requires less allocation, as the output buffer is only allocated once at the start of the serialization and whenever something bigger than the current buffer size has to be copied into the buffer, which should happen very seldomly for the default buffer size of 32kb. Hence, the pressure on the garbage collector is reduced, which can be an advantage when building long sequences of bytes.~Run a  with the given buffer sizes.&Use this function for integrating the ; type with other libraries that generate lazy bytestrings.!Note that the builders should guarantee that on average the desired chunk size is attained. Builders may decide to start a new buffer and not completely fill the existing buffer, if this is faster. However, they should not spill too much of the buffer, if they cannot compensate for it.\FIXME: Note that the following paragraphs are not entirely correct as of blaze-builder-0.4:A call 4toLazyByteStringWith bufSize minBufSize firstBufSizel will generate a lazy bytestring according to the following strategy. First, we allocate a buffer of size  firstBufSizeF and start filling it. If it overflows, we allocate a buffer of size  minBufSize~ and copy the first buffer to it in order to avoid generating a too small chunk. Finally, every next buffer will be of size bufSize'. This, slow startup strategy is required to achieve good speed for short (<200 bytes) resulting bytestrings, as for them the allocation cost is of a large buffer cannot be compensated. Moreover, this strategy also allows us to avoid spilling too much memory for short resulting bytestrings.Note that setting firstBufSize >= minBufSizeg implies that the first buffer is no longer copied but allocated and filled directly. Hence, setting firstBufSize = bufSize> means that all chunks will use an underlying buffer of size bufSizeE. This is recommended, if you know that you always output more than  minBufSize bytes.Run a Write to produce a strict . This is equivalent to ({ .  fromWrite)M, but is more efficient because it uses just one appropriately-sized buffer.{|}GBuffer size (upper bounds the number of bytes forced per call to the  action).G action to execute per full buffer, which is referenced by a strict . to run. Resulting  action.~4Buffer size (upper-bounds the resulting chunk size).1This parameter is ignored as of blaze-builder-0.4NSize of the first buffer to be used and copied for larger resulting sequencesBuilder to run.9Lazy bytestring to output after the builder is finished.Resulting lazy bytestringZ./01234569:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~~{|}{|}~   !"#$%&'()*+,-()*+,-./0123456789:;<=> ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~    blaze-builder-0.4.0.0Blaze.ByteString.Builder'Blaze.ByteString.Builder.Internal.Write%Blaze.ByteString.Builder.Compat.Write"Blaze.ByteString.Builder.Char.Utf8Blaze.ByteString.Builder.Char8"Blaze.ByteString.Builder.Html.Utf8#Blaze.ByteString.Builder.ByteStringBlaze.ByteString.Builder.HTTPBlaze.ByteString.Builder.WordBlaze.ByteString.Builder.Intbytestring-0.10.4.0Data.ByteString.BuildertoLazyByteString Data.ByteString.Builder.InternalflushBuilderWritePokerunPokegetPokerunWritegetBound getBound'pokeN exactWrite boundedWrite writeLiftIOwriteIfwriteEq writeOrderingwriteOrd fromWritefromWriteSingleton fromWriteList writeStorable fromStorable fromStorableswritePrimFixedwritePrimBounded writeCharfromChar fromStringfromShowfromText fromLazyTextwriteHtmlEscapedCharfromHtmlEscapedCharfromHtmlEscapedStringfromHtmlEscapedShowfromHtmlEscapedTextfromHtmlEscapedLazyTextwriteByteStringfromByteStringfromByteStringWithcopyByteStringinsertByteStringfromLazyByteStringfromLazyByteStringWithcopyLazyByteStringinsertLazyByteStringchunkedTransferEncodingchunkedTransferTerminator writeWord8 writeWord16be writeWord32be writeWord64be writeWord16le writeWord32le writeWord64le writeWordhostwriteWord16hostwriteWord32hostwriteWord64host fromWord8 fromWord8s fromWord16be fromWord32be fromWord64be fromWord32sbe fromWord16sbe fromWord64sbe fromWord16le fromWord32le fromWord64le fromWord16sle fromWord32sle fromWord64sle fromWordhostfromWord16hostfromWord32hostfromWord64host fromWordshostfromWord16shostfromWord32shostfromWord64shost writeInt8 writeInt16be writeInt32be writeInt64be writeInt16le writeInt32le writeInt64le writeInthostwriteInt16hostwriteInt32hostwriteInt64hostfromInt8 fromInt8s fromInt16be fromInt32be fromInt64be fromInt32sbe fromInt16sbe fromInt64sbe fromInt16le fromInt32le fromInt64le fromInt16sle fromInt32sle fromInt64sle fromInthost fromInt16host fromInt32host fromInt64host fromIntshostfromInt16shostfromInt32shostfromInt64shost toByteStringtoByteStringIOtoByteStringIOWithtoLazyByteStringWithwriteToByteString $fMonoidWrite $fMonoidPokebaseGHC.BaseStringGHC.ShowShow text-1.2.0.4Data.Text.InternalTextData.Text.Internal.LazycharUtf8HtmlEscapedData.ByteString.Internal ByteStringData.ByteString.Lazy.Internal writeCRLF execWriteword32HexLengthGHC.WordWord32 shiftr_w32pokeWord32HexNiterationsUntilZerowriteWord32HexWord16Word64ghc-prim GHC.TypesWordGHC.IntInt16Int32Int64Int packChunksdefaultBufferSizeIO