Commit 210779c0 authored by Jaromil's avatar Jaromil
Browse files

zencode when cast string dictionary to another encoding

internal cast in heap only available for string objects and tables:
when for instance a base64 is imported as a string, it can be
re-decoded internally (cast)
parent b9d0e93e
......@@ -511,3 +511,23 @@ end)
-- have(target)
-- ACK[target] = deepmap(function(v) if trim(v) == '' then return nil end, ACK[target])
-- end)
When("create the '' cast of strings in ''", function(conv, source)
ZEN.assert(ZEN.CODEC[source], "Object has no codec: "..source)
ZEN.assert(ZEN.CODEC[source].encoding == 'string', "Object has no string encoding: "..source)
empty(conv)
local src = have(source)
local enc = input_encoding(conv)
if luatype(src) == 'table' then
ACK[conv] = deepmap(function(v)
local s = OCTET.to_string(v)
ZEN.assert(enc.check(s), "Object value is not a "..conv..": "..source)
return enc.fun( s )
end, src)
else
local s = OCTET.to_string(src)
ZEN.assert(enc.check(s), "Object value is not a "..conv..": "..source)
ACK[conv] = enc.fun(s)
end
new_codec(conv, {encoding = conv})
end)
......@@ -29,14 +29,41 @@ cat <<EOF | save when stringnum.json
{
"api": "http://3.68.108.18/api/v1/blocks/latest",
"path": "blocks/",
"height": 102
"latest": {
"result": {
"height": 102
}
}
}
EOF
cat <<EOF | zexe append_number_try.zen -a stringnum.json
Given I have a 'string dictionary' named 'latest'
and I have a 'string' named 'path'
When I pickup from path 'latest.result.height'
and I append 'height' to 'path'
Then print the 'path'
EOF
cat <<EOF | save when string-mpack.json
{
"newblock": {
"newblock-mpack": "haZudW1iZXLHAAAACk1IZ3hNV0psTnepdGltZXN0YW1wxwAAAA5NSGcyTWpkaVlUa3dPQapwYXJlbnRIYXNoxwAAAFhNSGd6TUdJell6YzBOR0k0WkRsaVlqTXdZak00TURRMllXWTFPRGhpWVRsbFpEWTRaamRsTjJaalpEa3pOV0U0WXpRNE5UWmlPR0ZoWXpBek5HVTBOak5opGhhc2jHAAAAWE1IZzVZekF3WW1ZeU9ESmpObVk1WTJGaE1XRTVaamM0Tmpaak1UaGxNbVpsWkRneVpUWTVNREkzTlRWaE16a3hNMlkxT0RKbFpXSXhaV1psT0dZM05EbGqqYmxvY2tjaGFpboSkdHlwZccAAAALWlhSb1pYSmxkVzCkaHR0cMcAAAAgYUhSMGNEb3ZMemM0TGpRM0xqTTRMakl5TXpvNE5UUTGid3PHAAAAHmQzTTZMeTgzT0M0ME55NHpPQzR5TWpNNk9EVTBOZ6RuYW1lxwAAAAtabUZpWTJoaGFXNA==",
"txid": "dd445fed8ab124ab0c38720db060b730ddcf4c3fe71b3668eacf9505cd17da8f"
},
"version": "2.0",
"id": "20cfe258df01bf6c634b6b79329b20ef7f5bdf69e6c319b06adb44ac9a4b6c67"
}
EOF
cat <<EOF | zexe append_number.zen -a stringnum.json
Given I have a 'string' named 'api'
and a 'string' named 'path'
and a 'number' named 'height'
When I append 'height' to 'path'
Then print 'path'
cat <<EOF | zexe base64-string-cast.zen -a string-mpack.json
Given I have a 'string dictionary' named 'newblock'
When I pickup from path 'newblock.newblock-mpack'
When I create the 'base64' cast of strings in 'newblock-mpack'
and I create the 'contents' decoded from mpack 'base64'
Then print the 'contents' as 'string'
EOF
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment