This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-06
Channels
- # announcements (33)
- # babashka (13)
- # babashka-sci-dev (23)
- # beginners (94)
- # calva (105)
- # cider (37)
- # circleci (1)
- # clj-kondo (45)
- # cljs-dev (59)
- # cljsrn (2)
- # clojure (145)
- # clojure-czech (1)
- # clojure-europe (19)
- # clojure-nl (18)
- # clojure-norway (13)
- # clojure-portugal (1)
- # clojure-uk (5)
- # clojurescript (19)
- # community-development (2)
- # conjure (3)
- # copenhagen-clojurians (1)
- # core-async (34)
- # data-science (6)
- # datomic (25)
- # emacs (43)
- # fulcro (19)
- # graalvm (7)
- # graalvm-mobile (12)
- # graphql (10)
- # honeysql (3)
- # hyperfiddle (3)
- # improve-getting-started (2)
- # interop (20)
- # kaocha (3)
- # lsp (16)
- # meander (7)
- # off-topic (22)
- # other-languages (14)
- # portal (15)
- # releases (1)
- # rewrite-clj (2)
- # ring (1)
- # shadow-cljs (119)
- # spacemacs (19)
- # sql (65)
- # testing (4)
- # tools-deps (11)
- # xtdb (29)
Does anyone know any C# libraries that allow to serialize into EDN? I found this but it doesn't seem to serialize: https://www.nuget.org/packages?q=extensible+data+notation https://www.nuget.org/packages/EdnParser/
use std::ffi::{CStr, CString};
use libc;
use edn_format;
use edn_format::{ParserErrorWithContext, Value};
#[no_mangle]
pub extern "C" fn edn_integer_new(value: libc::c_long) -> *mut edn_format::Value {
Box::into_raw(Box::new(edn_format::Value::Integer(value as i64)))
}
#[no_mangle]
pub extern "C" fn edn_string_new(value: *const libc::c_char) -> *mut edn_format::Value {
let c_string = unsafe { CStr::from_ptr(value) };
Box::into_raw(Box::new(edn_format::Value::String(
c_string
.to_str()
.unwrap()
.to_string()
)))
}
#[no_mangle]
pub extern "C" fn edn_value_free(value: *mut edn_format::Value) {
if !value.is_null() {
unsafe { Box::from_raw(value); }
}
}
#[no_mangle]
pub extern "C" fn edn_parse(value: *const libc::c_char, out: *mut *mut edn_format::Value) -> libc::c_int {
let c_string = unsafe { CStr::from_ptr(value) };
let str = c_string
.to_str()
.unwrap();
let parse = edn_format::parse_str(str);
match parse {
Ok(value) => {
unsafe { *out = Box::into_raw(Box::new(value)) };
0
}
Err(_) => {
-1
}
}
}
#[no_mangle]
pub extern "C" fn edn_display(value: *const edn_format::Value) {
println!("{}", edn_format::emit_str(unsafe { value.as_ref().unwrap() }))
}
>>> from ctypes import *
>>> dll = cdll.LoadLibrary("libedn_format_c.dylib")
>>> dll.edn_string_new.argtypes = [ c_char_p ]
>>> dll.edn_string_new.restype = c_void_p
>>> dll.edn_display.argtypes = [ c_void_p ]
>>> dll.edn_display.restype = None
>>> s = dll.edn_string_new(b"abc")
>>> dll.edn_display(s)
"abc"
Yes but what I was looking for is something ready-made 😄 But thanks ;D
>>> timeit.timeit(lambda: dll.edn_parse(b"{:a 12 :abc [1 2 {:a 3}]}"), number=10000) / 10000
3.068520799999419e-06
which language?
oh, python
I see the b