Skip to content

Commit

Permalink
Merge pull request tecbot#150 from jialeicui/rocksdb_get_options_from…
Browse files Browse the repository at this point in the history
…_string

add wrapper for GetOptionsFromString
  • Loading branch information
tecbot authored May 19, 2019
2 parents 28ce0c0 + 2280d59 commit 8e5cf18
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package gorocksdb
// #include "rocksdb/c.h"
// #include "gorocksdb.h"
import "C"
import "unsafe"
import (
"errors"
"unsafe"
)

// CompressionType specifies the block compression.
// DB contents are stored in a set of blocks, each of which holds a
Expand Down Expand Up @@ -82,6 +85,30 @@ func NewNativeOptions(c *C.rocksdb_options_t) *Options {
return &Options{c: c}
}

// GetOptionsFromString creates a Options object from existing opt and string.
// If base is nil, a default opt create by NewDefaultOptions will be used as base opt.
func GetOptionsFromString(base *Options, optStr string) (*Options, error) {
if base == nil {
base = NewDefaultOptions()
defer base.Destroy()
}

var (
cErr *C.char
cOptStr = C.CString(optStr)
)
defer C.free(unsafe.Pointer(cOptStr))

newOpt := NewDefaultOptions()
C.rocksdb_get_options_from_string(base.c, cOptStr, newOpt.c, &cErr)
if cErr != nil {
defer C.free(unsafe.Pointer(cErr))
return nil, errors.New(C.GoString(cErr))
}

return newOpt, nil
}

// -------------------
// Parameters that affect behavior

Expand Down

0 comments on commit 8e5cf18

Please sign in to comment.