Skip to content

kv::adapter should use Buffer #4479

Closed

Description

@Xuanwo

kv::adapter still users Bytes in many places, we should migrate to Buffer instead.

  • We should use Buffer as Reader

type Reader = Bytes;
type BlockingReader = Bytes;

  • We should use QueueBuf as Writer

pub struct KvWriter<S> {
kv: Arc<S>,
path: String,
buffer: FlexBuffer,
}

  • We should return Buffer in get and blocking_get

/// Get a key from service.
///
/// - return `Ok(None)` if this key is not exist.
async fn get(&self, path: &str) -> Result<Option<Vec<u8>>>;
/// The blocking version of get.
fn blocking_get(&self, path: &str) -> Result<Option<Vec<u8>>> {
let _ = path;
Err(Error::new(
ErrorKind::Unsupported,
"kv adapter doesn't support this operation",
)
.with_operation("kv::Adapter::blocking_get"))
}

  • We should accept Buffer in set and blocking_set

async fn set(&self, path: &str, value: &[u8]) -> Result<()>;
/// The blocking version of set.
fn blocking_set(&self, path: &str, value: &[u8]) -> Result<()> {
let _ = (path, value);
Err(Error::new(
ErrorKind::Unsupported,
"kv adapter doesn't support this operation",
)
.with_operation("kv::Adapter::blocking_set"))
}

This might affect many services, please feel free to link to this issue.

Activity

  1. self-assigned this
    on Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions