runtime: add dharma-required functions to el_runtime.c and runtime/*.el
Add the following functions that dharma registry calls but were missing from the El runtime: el_runtime.c (consumed by the old build system via released SDK): - list_len, list_get — aliases for el_list_len/el_list_get (handlers.el) - json_array_push — append pre-encoded element to JSON array string - now_millis, unix_timestamp_ms, time_now_ms — ms-since-epoch aliases - log_info, log_warn — structured stderr log helpers - config — reads config from environment (alias for getenv) - http_patch — HTTP PATCH with Content-Type: application/json - http_post_engram — HTTP POST with optional X-API-Key header - http_get_engram — HTTP GET with optional X-API-Key header - str_to_bytes — encode string as JSON byte array [72,101,...] - bytes_to_str — decode JSON byte array back to string - hash_sha256 — SHA-256 hex digest using built-in sha256 impl runtime/*.el (consumed by the new build system): - http.el: http_patch, http_post_engram, http_get_engram - time.el: now_millis, unix_timestamp_ms, time_now_ms - env.el: config, log_info, log_warn, list_len, list_get - json.el: json_array_push, bytes_to_str - string.el: str_to_bytes, hash_sha256 (via __sha256_hex seed) el_seed.h / el_seed.c: - __sha256_hex primitive with self-contained SHA-256 implementation
This commit is contained in:
@@ -876,3 +876,32 @@ fn str_join(parts: [String], sep: String) -> String {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// ── DHARMA byte encoding (str_to_bytes) ──────────────────────────────────────
|
||||
//
|
||||
// str_to_bytes — encode a string as a JSON array of unsigned byte values.
|
||||
// "hi" -> "[104,105]"
|
||||
// Used by db.el to store content in Engram JSON nodes as a byte array.
|
||||
// Note: bytes_to_str (the inverse) is defined in json.el because it depends
|
||||
// on json_array_get_string which is defined there.
|
||||
fn str_to_bytes(s: String) -> String {
|
||||
let n: Int = __str_len(s)
|
||||
if n == 0 { return "[]" }
|
||||
let result: String = "["
|
||||
let i: Int = 0
|
||||
while i < n {
|
||||
let b: Int = __str_char_at(s, i)
|
||||
if i > 0 { result = __str_concat_raw(result, ",") }
|
||||
result = __str_concat_raw(result, __int_to_str(b))
|
||||
i = i + 1
|
||||
}
|
||||
return __str_concat_raw(result, "]")
|
||||
}
|
||||
|
||||
// ── Cryptographic hashing ─────────────────────────────────────────────────────
|
||||
|
||||
// hash_sha256 — return the SHA-256 hex digest of a string.
|
||||
// Delegates to the __sha256_hex seed primitive.
|
||||
fn hash_sha256(s: String) -> String {
|
||||
return __sha256_hex(s)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user