Function toPushOpcode
Creates a PUSH_BYTES_*
or PUSH_DATA_*
opcode based on the length of
the data. It does not verify data limits for the stack, as this check
belongs in the Stack and the Engine. Additionally it's useful to be able to
create exceeding data buffers with this function for testing purposes.
ubyte[] toPushOpcode
(
in const(ubyte[]) data
) pure nothrow @safe;
Parameters
Name | Description |
---|---|
data | the data to create the opcode and payload for |
Returns
a byte array containing the opcode and the payload
Example
import std .array;
import std .range;
assert(ubyte(42) .repeat(75) .array .toPushOpcode() ==
[75] ~ 42 .repeat(75) .array);
assert(ubyte(42) .repeat(255) .array .toPushOpcode() ==
[76, 255] ~ 42 .repeat(255) .array);
assert(ubyte(42) .repeat(500) .array .toPushOpcode() ==
[77, 244, 1] ~ 42 .repeat(500) .array); // little-endian form