From a2fd0105217926fe13b9bc84679b855f3af4b533 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Fri, 5 Jul 2024 17:43:33 +0800 Subject: [PATCH 1/2] llgo:rust:sled:a working demo --- _rsdemo/sled/sled.go | 9 ++++--- rust/sled/sled.go | 63 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/_rsdemo/sled/sled.go b/_rsdemo/sled/sled.go index 2a49d8bc..282ead09 100644 --- a/_rsdemo/sled/sled.go +++ b/_rsdemo/sled/sled.go @@ -6,11 +6,12 @@ import ( ) func main() { - //c.Printf(c.Str("helloworld\n")) var valueLen c.Ulong - conf := &sled.SledConfig{} - conf.SetPath(c.Str("./db.sled")) - db := conf.OpenDB() + conf := sled.CreateConfig() + path := c.Str("./db") + copyPath := c.Strdup(path) + pathConfig := conf.SetPath(copyPath) + db := pathConfig.OpenDb() db.Set(c.Str("key"), 3, c.Str("value"), 5) value := db.Get(c.Str("key"), 3, &valueLen) c.Printf(c.Str("value: %s\n"), value) diff --git a/rust/sled/sled.go b/rust/sled/sled.go index 92071d26..e9c3ddce 100644 --- a/rust/sled/sled.go +++ b/rust/sled/sled.go @@ -15,21 +15,56 @@ type SledDb struct { Unused [8]byte } -//llgo:link (*SledConfig).SetPath C.sled_config_set_path -func (conf *SledConfig) SetPath(char *c.Char) *SledConfig { - return nil -} +// Create a new configuration +// llgo:link CreateConfig C.sled_create_config +func CreateConfig() *SledConfig { return nil } -//llgo:link (*SledConfig).OpenDB C.sled_open_db -func (conf *SledConfig) OpenDB() *SledDb { - return nil -} +// Free a configuration +// llgo:link (*SledConfig).FreeConfig C.sled_free_config +func (conf *SledConfig) FreeConfig() {} -//llgo:link (*SledDb).Set C.sled_set -func (db *SledDb) Set(key *c.Char, keyLen c.Ulong, value *c.Char, valueLen c.Ulong) { -} +// Set the configured file path +// llgo:link (*SledConfig).SetPath C.sled_config_set_path +func (conf *SledConfig) SetPath(path *c.Char) *SledConfig { return nil } -//llgo:link (*SledDb).Get C.sled_get -func (db *SledDb) Get(key *c.Char, keyLen c.Ulong, valLen *c.Ulong) *c.Char { - return nil +// Set the configured cache capacity in bytes +// llgo:link (*SledConfig).SetCacheCapacity C.sled_config_set_cache_capacity +func (conf *SledConfig) SetCacheCapacity(capacity c.Ulong) *SledConfig { return nil } + +// Configure the use of the zstd compression library +// llgo:link (*SledConfig).UseCompression C.sled_config_use_compression +func (conf *SledConfig) UseCompression(use_compression c.Char) *SledConfig { return nil } + +// Set the configured IO buffer flush interval in milliseconds +// llgo:link (*SledConfig).SetFlushEveryMs C.sled_config_flush_every_ms +func (conf *SledConfig) SetFlushEveryMs(flush_every c.Int) *SledConfig { return nil } + +// Open a sled lock-free log-structured tree +// llgo:link (*SledConfig).OpenDb C.sled_open_db +func (conf *SledConfig) OpenDb() *SledDb { return nil } + +// Close a sled lock-free log-structured tree +// llgo:link (*SledDb).Close C.sled_close +func (db *SledDb) Close() {} + +// Free a buffer originally allocated by sled +// llgo:link FreeBuf C.sled_free_buf +func FreeBuf(buf *c.Char, sz c.Ulong) {} + +// Set a key to a value +// llgo:link (*SledDb).Set C.sled_set +func (db *SledDb) Set(key *c.Char, keylen c.Ulong, val *c.Char, vallen c.Ulong) {} + +// Get the value of a key +// llgo:link (*SledDb).Get C.sled_get +func (db *SledDb) Get(key *c.Char, keylen c.Ulong, vallen *c.Ulong) *c.Char { return nil } + +// Delete the value of a key +// llgo:link (*SledDb).Del C.sled_del +func (db *SledDb) Del(key *c.Char, keylen c.Ulong) {} + +// Compare and swap +// llgo:link (*SledDb).CompareAndSwap C.sled_compare_and_swap +func (db *SledDb) CompareAndSwap(key *c.Char, keylen c.Ulong, old_val *c.Char, old_vallen c.Ulong, new_val *c.Char, new_vallen c.Ulong, actual_val **c.Char, actual_vallen *c.Ulong) c.Char { + return 0 } From 60f8fe6f41243a146202cd4a292b5269fc745a4c Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Tue, 9 Jul 2024 09:39:44 +0800 Subject: [PATCH 2/2] llgo/rust/sled:rename struct --- rust/sled/sled.go | 50 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/rust/sled/sled.go b/rust/sled/sled.go index e9c3ddce..e68b25ac 100644 --- a/rust/sled/sled.go +++ b/rust/sled/sled.go @@ -7,64 +7,64 @@ const ( LLGoPackage = "link: $(pkg-config --libs sled); -lsled" ) -type SledConfig struct { +type Config struct { Unused [8]byte } -type SledDb struct { +type DB struct { Unused [8]byte } // Create a new configuration // llgo:link CreateConfig C.sled_create_config -func CreateConfig() *SledConfig { return nil } +func CreateConfig() *Config { return nil } // Free a configuration -// llgo:link (*SledConfig).FreeConfig C.sled_free_config -func (conf *SledConfig) FreeConfig() {} +// llgo:link (*Config).FreeConfig C.sled_free_config +func (conf *Config) FreeConfig() {} // Set the configured file path -// llgo:link (*SledConfig).SetPath C.sled_config_set_path -func (conf *SledConfig) SetPath(path *c.Char) *SledConfig { return nil } +// llgo:link (*Config).SetPath C.sled_config_set_path +func (conf *Config) SetPath(path *c.Char) *Config { return nil } // Set the configured cache capacity in bytes -// llgo:link (*SledConfig).SetCacheCapacity C.sled_config_set_cache_capacity -func (conf *SledConfig) SetCacheCapacity(capacity c.Ulong) *SledConfig { return nil } +// llgo:link (*Config).SetCacheCapacity C.sled_config_set_cache_capacity +func (conf *Config) SetCacheCapacity(capacity c.Ulong) *Config { return nil } // Configure the use of the zstd compression library -// llgo:link (*SledConfig).UseCompression C.sled_config_use_compression -func (conf *SledConfig) UseCompression(use_compression c.Char) *SledConfig { return nil } +// llgo:link (*Config).UseCompression C.sled_config_use_compression +func (conf *Config) UseCompression(use_compression c.Char) *Config { return nil } // Set the configured IO buffer flush interval in milliseconds -// llgo:link (*SledConfig).SetFlushEveryMs C.sled_config_flush_every_ms -func (conf *SledConfig) SetFlushEveryMs(flush_every c.Int) *SledConfig { return nil } +// llgo:link (*Config).SetFlushEveryMs C.sled_config_flush_every_ms +func (conf *Config) SetFlushEveryMs(flush_every c.Int) *Config { return nil } // Open a sled lock-free log-structured tree -// llgo:link (*SledConfig).OpenDb C.sled_open_db -func (conf *SledConfig) OpenDb() *SledDb { return nil } +// llgo:link (*Config).OpenDb C.sled_open_db +func (conf *Config) OpenDb() *DB { return nil } // Close a sled lock-free log-structured tree -// llgo:link (*SledDb).Close C.sled_close -func (db *SledDb) Close() {} +// llgo:link (*DB).Close C.sled_close +func (db *DB) Close() {} // Free a buffer originally allocated by sled // llgo:link FreeBuf C.sled_free_buf func FreeBuf(buf *c.Char, sz c.Ulong) {} // Set a key to a value -// llgo:link (*SledDb).Set C.sled_set -func (db *SledDb) Set(key *c.Char, keylen c.Ulong, val *c.Char, vallen c.Ulong) {} +// llgo:link (*DB).Set C.sled_set +func (db *DB) Set(key *c.Char, keylen c.Ulong, val *c.Char, vallen c.Ulong) {} // Get the value of a key -// llgo:link (*SledDb).Get C.sled_get -func (db *SledDb) Get(key *c.Char, keylen c.Ulong, vallen *c.Ulong) *c.Char { return nil } +// llgo:link (*DB).Get C.sled_get +func (db *DB) Get(key *c.Char, keylen c.Ulong, vallen *c.Ulong) *c.Char { return nil } // Delete the value of a key -// llgo:link (*SledDb).Del C.sled_del -func (db *SledDb) Del(key *c.Char, keylen c.Ulong) {} +// llgo:link (*DB).Del C.sled_del +func (db *DB) Del(key *c.Char, keylen c.Ulong) {} // Compare and swap -// llgo:link (*SledDb).CompareAndSwap C.sled_compare_and_swap -func (db *SledDb) CompareAndSwap(key *c.Char, keylen c.Ulong, old_val *c.Char, old_vallen c.Ulong, new_val *c.Char, new_vallen c.Ulong, actual_val **c.Char, actual_vallen *c.Ulong) c.Char { +// llgo:link (*DB).CompareAndSwap C.sled_compare_and_swap +func (db *DB) CompareAndSwap(key *c.Char, keylen c.Ulong, old_val *c.Char, old_vallen c.Ulong, new_val *c.Char, new_vallen c.Ulong, actual_val **c.Char, actual_vallen *c.Ulong) c.Char { return 0 }