mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
mononoke/blobstore: don't use Buf::bytes()
to get a slice
Summary: This is currently calling `Buf::bytes()` in order to get a `&[u8]` out of `Bytes`, but this method isn't actually guaranteed to return all data in the `Buf`: https://docs.rs/bytes/0.5.6/bytes/trait.Buf.html#tymethod.bytes > Note that this can return shorter slice (this allows non-continuous internal representation) In practice this is fine because `Bytes` does in fact have a contiguous internal representation (which is why we can call `as_ref()` on it), but let's do the more correct thing here. (I happened to spot this while looking into the feasibility of a Bytes 0.5 -> Bytes 1.x upgrade, where this `bytes()` method was renamed to `chunk()`) Reviewed By: farnz Differential Revision: D28507885 fbshipit-source-id: 73e5f1ba587292f772c702127a3933ea76fceb9f
This commit is contained in:
parent
0bd512d811
commit
f5e024f889
@ -16,7 +16,7 @@ use abomonation_derive::Abomonation;
|
|||||||
use anyhow::{Error, Result};
|
use anyhow::{Error, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use auto_impl::auto_impl;
|
use auto_impl::auto_impl;
|
||||||
use bytes::{Buf, Bytes};
|
use bytes::Bytes;
|
||||||
use context::CoreContext;
|
use context::CoreContext;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
@ -229,7 +229,7 @@ impl BlobstoreBytes {
|
|||||||
let cursor = Cursor::new(bytes);
|
let cursor = Cursor::new(bytes);
|
||||||
zstd::decode_all(cursor).map_err(|_| ())?
|
zstd::decode_all(cursor).map_err(|_| ())?
|
||||||
} else {
|
} else {
|
||||||
bytes.bytes().into()
|
bytes.as_ref().into()
|
||||||
};
|
};
|
||||||
|
|
||||||
let get_data_serialisable =
|
let get_data_serialisable =
|
||||||
@ -257,7 +257,7 @@ struct BlobstoreBytesSerialisable(Vec<u8>);
|
|||||||
|
|
||||||
impl From<BlobstoreBytes> for BlobstoreBytesSerialisable {
|
impl From<BlobstoreBytes> for BlobstoreBytesSerialisable {
|
||||||
fn from(blob_bytes: BlobstoreBytes) -> Self {
|
fn from(blob_bytes: BlobstoreBytes) -> Self {
|
||||||
BlobstoreBytesSerialisable(blob_bytes.into_bytes().bytes().into())
|
BlobstoreBytesSerialisable(blob_bytes.into_bytes().as_ref().into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user