Module payload_gen

This module provides lazy, composable producer streams that can be considered counterparts to Archiver's consumer pipes and therefore can facilitate testing.

Description

This module provides lazy, composable producer streams that can be considered counterparts to Archiver's consumer pipes and therefore can facilitate testing

Also it comes with an implementation of binary data stream which is able to produce sufficiently large amounts of plausibly pseudorandom binary payload in a deterministic way. It also contains routines to check binary blobs via sampling

Data Types

binary_payload()

binary_payload() = {binary(), _ChunkNum::non_neg_integer(), _ChunkCnt::non_neg_integer()}

chunk_state()

abstract datatype: chunk_state()

cont()

abstract datatype: cont(Data)

payload()

payload() = {Seed::term(), Size::integer()}

stream()

stream(Data) = maybe_improper_list(Data, cont(Data)) | '?end_of_stream'

tagged_binstream()

tagged_binstream() = stream({Tag::term(), Payload::chunk_state()})

Function Index

binary_stream_gen/1Proper generator that creates a binary stream.
check_consistency/3
check_file_consistency/3
consume/1Equivalent to consume(Stream, fun (A) -> A end).
consume/2Consume all elements of the stream and feed them into a callback (e.g.
generate_chunk/2Stream of binary chunks.
generate_chunks/3Generate chunks of data and feed them into Callback
generator_fun/2First argument is a chunk number, the second one is a seed.
get_byte/2Get byte at offset N
interleave_chunks/1Take a list of payload()s and a callback function, and start producing the payloads in random order.
interleave_chunks/2Take a list of payload()s and a callback function, and start consuming the payloads in a random order.
interleave_streams/1Take a list of tagged streams and return a stream where elements of the streams are tagged and randomly interleaved.
interleaved_binary_gen/1
interleaved_list_gen/1
interleaved_streams_gen/1Equivalent to interleaved_streams_gen(10, Type).
list_to_stream/1
mb/1Return number of bytes in N megabytes.
next/1Consume one element from the stream.
retransmits/2Take an arbitrary stream and add repetitions of the elements.

Function Details

binary_stream_gen/1

binary_stream_gen(_ChunkSize::non_neg_integer()) -> proper_types:type()

Proper generator that creates a binary stream

check_consistency/3

check_consistency(X1::payload(), SampleSize::integer(), Callback::fun((integer()) -> {ok, binary()} | undefined)) -> ok

check_file_consistency/3

check_file_consistency(Payload::payload(), SampleSize::integer(), FileName::file:filename()) -> ok

consume/1

consume(Stream::stream(A)) -> [A]

Equivalent to consume(Stream, fun (A) -> A end).

consume/2

consume(Stream::stream(A), Callback::fun((A) -> Ret)) -> [Ret]

Consume all elements of the stream and feed them into a callback (e.g. brod:produce)

generate_chunk/2

generate_chunk(X1::payload(), ChunkSize::integer()) -> stream(binary_payload())

Stream of binary chunks. Limitation: both payload size and ChunkSize should be dividable by ?hash_size

generate_chunks/3

generate_chunks(Payload::payload(), ChunkSize::integer(), Callback::fun((binary()) -> A)) -> [A]

Generate chunks of data and feed them into Callback

generator_fun/2

generator_fun(N::integer(), Seed::binary()) -> binary()

First argument is a chunk number, the second one is a seed. This implementation is hardly efficient, but it was chosen for clarity reasons

get_byte/2

get_byte(N::integer(), Seed::term()) -> byte()

Get byte at offset N

interleave_chunks/1

interleave_chunks(Streams0::[{payload(), ChunkSize::non_neg_integer()}]) -> tagged_binstream()

Take a list of payload()s and a callback function, and start producing the payloads in random order. Seed is used as a tag

See also: interleave_streams/4.

interleave_chunks/2

interleave_chunks(Streams0::[payload()], ChunkSize::non_neg_integer()) -> tagged_binstream()

Take a list of payload()s and a callback function, and start consuming the payloads in a random order. Seed is used as a tag. All streams use the same chunk size

See also: interleave_streams/2.

interleave_streams/1

interleave_streams(Streams::[{Tag, stream(Data)}]) -> stream({Tag, Data})

Take a list of tagged streams and return a stream where elements of the streams are tagged and randomly interleaved.

Note: this function is more or less generic and it's compatible with this module's generate_chunks function family, as well as ets:next, lists and what not

Consider using simplified versions of this function

interleaved_binary_gen/1

interleaved_binary_gen(ChunkSize::non_neg_integer()) -> proper_types:type()

interleaved_list_gen/1

interleaved_list_gen(Type::proper_types:type()) -> proper_types:type()

interleaved_streams_gen/1

interleaved_streams_gen(Type::proper_types:type()) -> proper_types:type()

Equivalent to interleaved_streams_gen(10, Type).

list_to_stream/1

list_to_stream(L::[A]) -> stream(A)

mb/1

mb(N::integer()) -> integer()

Return number of bytes in N megabytes

next/1

next(Fun::cont(A)) -> stream(A)

Consume one element from the stream.

retransmits/2

retransmits(Stream::stream(Data), Probability::float()) -> stream(Data)

Take an arbitrary stream and add repetitions of the elements


Generated by EDoc