| 52 | } |
| 53 | |
| 54 | int RocksDbStream::write(const uint8_t *value, int size) { |
| 55 | gsl_Expects(size >= 0); |
| 56 | if (!write_enable_) { |
| 57 | return -1; |
| 58 | } |
| 59 | if (size == 0) { |
| 60 | return 0; |
| 61 | } |
| 62 | if (!IsNullOrEmpty(value)) { |
| 63 | auto opendb = db_->open(); |
| 64 | if (!opendb) { |
| 65 | return -1; |
| 66 | } |
| 67 | rocksdb::Slice slice_value((const char *) value, size); |
| 68 | rocksdb::Status status; |
| 69 | size_ += size; |
| 70 | if (batch_ != nullptr) { |
| 71 | status = batch_->Merge(path_, slice_value); |
| 72 | } else { |
| 73 | rocksdb::WriteOptions opts; |
| 74 | opts.sync = true; |
| 75 | status = opendb->Merge(opts, path_, slice_value); |
| 76 | } |
| 77 | if (status.ok()) { |
| 78 | return size; |
| 79 | } else { |
| 80 | return -1; |
| 81 | } |
| 82 | } else { |
| 83 | return -1; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | int RocksDbStream::read(uint8_t *buf, int buflen) { |
| 88 | gsl_Expects(buflen >= 0); |
nothing calls this directly
no test coverage detected