Lib zlib
Console program108 lines of .st181 lines of generated C
47 bytes packed into 17, unpacked 47 (rc 0 = Z_OK 0): hello hello hello hello hello hello hello hello CRC-32 3106698858, version known: true
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
standard = "c11"
}
}
lib_provider {
C_lang = {
source = "StructOp/c"
version = "@latest"
}
Zip = {
source = "C/zlib"
version = "@latest"
}
}
}main.st
# zlib through the provider structop bind writes: compress a text, check its CRC-32,
# and get the text back.
ability "value" "input" {
type = Bytes
size = 64
}
data "value" "input" {
of = ability.value.input
}
ability "value" "packed" {
type = Bytes
size = 128
}
data "value" "packed" {
of = ability.value.packed
}
ability "value" "unpacked" {
type = Bytes
size = 64
}
data "value" "unpacked" {
of = ability.value.unpacked
}
ability "value" "rc" {
type = Int32
}
data "value" "rc" {
of = ability.value.rc
}
ability "value" "crc" {
type = UInt64
}
data "value" "crc" {
of = ability.value.crc
}
ability "value" "version" {
type = String
size = 32
}
data "value" "version" {
of = ability.value.version
}
ability "set" "Fill" {
target = ability.value.input
value = bytes("hello hello hello hello hello hello hello hello")
}
ability "compress" "Pack" {
target = ability.value.packed
source = ability.value.input
result = ability.value.rc
}
ability "uncompress" "Unpack" {
target = ability.value.unpacked
source = ability.value.packed
result = ability.value.rc
}
ability "crc32" "Check" {
crc = 0
buf = ability.value.input
result = ability.value.crc
}
ability "zlibVersion" "Version" {
result = ability.value.version
}
ability "print" "Show" {
message = "${length(data.value.input.current)} bytes packed into ${length(data.value.packed.current)}, unpacked ${length(data.value.unpacked.current)} (rc ${data.value.rc.current} = Z_OK ${const.Z_OK}): ${text(data.value.unpacked.current)}"
}
ability "print" "Crc" {
message = "CRC-32 ${data.value.crc.current}, version known: ${length(data.value.version.current) > 0}"
}Input, plan and generated C#
bind/zlib.bind.st · hints for structop bind
bind/zlib.bind.st · hints for structop bind
bind "zlib" {
header = "zlib.h"
package = "zlib"
prefix = ["compress", "uncompress", "crc32", "zlibVersion", "Z_"]
}structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.value.input
+ ability.value.packed
+ ability.value.unpacked
+ ability.value.rc
+ ability.value.crc
+ ability.value.version
+ ability.set.Fill
+ ability.compress.Pack
+ ability.uncompress.Unpack
+ ability.crc32.Check
+ ability.zlibVersion.Version
+ ability.print.Show
+ ability.print.Crc
Plan: 1 to add, 0 to change, 0 to destroy.Generated main.c
To inspect this generated file, select C in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runTry it
structop bind bind/zlib.bind.st # from the repository root
cd lib-zlib # a folder holding the .st files above
structop init
structop plan
structop apply