mirror of
https://github.com/facebook/sapling.git
synced 2024-10-12 01:39:21 +03:00
rust/thrift: Replace bytes-ext with bufsize from crates.io
Summary: Removes the dependency of ////common/rust/thrift/runtime:fbthrift// on ////common/rust/bytes-ext//. This is a move toward a self-contained runtime that is easy to open source. Reviewed By: yfeldblum Differential Revision: D17891341 fbshipit-source-id: ddc53735c3ecde32e16a10bf98ae24a68aec9d82
This commit is contained in:
parent
602152c8e5
commit
63f06115c1
@ -1,8 +0,0 @@
|
||||
[package]
|
||||
name = "bytes-ext"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
error-chain = "0.11"
|
||||
bytes = "0.4"
|
@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This software may be used and distributed according to the terms of the
|
||||
* GNU General Public License found in the LICENSE file in the root
|
||||
* directory of this source tree.
|
||||
*/
|
||||
|
||||
//! Extensions for the bytes crate.
|
||||
|
||||
#![deny(warnings)]
|
||||
|
||||
mod sized;
|
||||
|
||||
pub use crate::sized::SizeCounter;
|
@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This software may be used and distributed according to the terms of the
|
||||
* GNU General Public License found in the LICENSE file in the root
|
||||
* directory of this source tree.
|
||||
*/
|
||||
|
||||
use std::usize;
|
||||
|
||||
use bytes::{Buf, BufMut, ByteOrder, IntoBuf};
|
||||
//use iovec::IoVec;
|
||||
|
||||
/// Implementation of `BufMut` to count the size of a resulting buffer
|
||||
///
|
||||
/// A "buffer" for counting the size of a resulting buffer. This effectively requires
|
||||
/// the data to be serialized twice, but with luck inlining will result in most effort used
|
||||
/// in generating actual data will be elided.
|
||||
pub struct SizeCounter(usize);
|
||||
|
||||
impl SizeCounter {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
SizeCounter(0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn size(&self) -> usize {
|
||||
self.0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn increment(&mut self, inc: usize) {
|
||||
self.0 += inc;
|
||||
}
|
||||
}
|
||||
|
||||
impl BufMut for SizeCounter {
|
||||
#[inline]
|
||||
fn remaining_mut(&self) -> usize {
|
||||
usize::MAX
|
||||
}
|
||||
|
||||
unsafe fn advance_mut(&mut self, _cnt: usize) {}
|
||||
|
||||
unsafe fn bytes_mut(&mut self) -> &mut [u8] {
|
||||
unimplemented!("SizeCounter doesn't really have a buffer")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn has_remaining_mut(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
//unsafe fn bytes_vec_mut<'a>(&'a mut self, _dst: &mut [&'a mut IoVec]) -> usize {
|
||||
// unimplemented!("SizeCounter doesn't really have a buffer")
|
||||
//}
|
||||
|
||||
#[inline]
|
||||
fn put<T: IntoBuf>(&mut self, src: T)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let buf = src.into_buf();
|
||||
self.0 += buf.remaining();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn put_slice(&mut self, src: &[u8]) {
|
||||
self.0 += src.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn put_u8(&mut self, _n: u8) {
|
||||
self.0 += 1
|
||||
}
|
||||
#[inline]
|
||||
fn put_i8(&mut self, _n: i8) {
|
||||
self.0 += 1
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn put_u16<T: ByteOrder>(&mut self, _n: u16) {
|
||||
self.0 += 2
|
||||
}
|
||||
#[inline]
|
||||
fn put_i16<T: ByteOrder>(&mut self, _n: i16) {
|
||||
self.0 += 2
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn put_u32<T: ByteOrder>(&mut self, _n: u32) {
|
||||
self.0 += 4
|
||||
}
|
||||
#[inline]
|
||||
fn put_i32<T: ByteOrder>(&mut self, _n: i32) {
|
||||
self.0 += 4
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn put_u64<T: ByteOrder>(&mut self, _n: u64) {
|
||||
self.0 += 8
|
||||
}
|
||||
#[inline]
|
||||
fn put_i64<T: ByteOrder>(&mut self, _n: i64) {
|
||||
self.0 += 8
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn put_uint<T: ByteOrder>(&mut self, _n: u64, nbytes: usize) {
|
||||
self.0 += nbytes
|
||||
}
|
||||
#[inline]
|
||||
fn put_int<T: ByteOrder>(&mut self, _n: i64, nbytes: usize) {
|
||||
self.0 += nbytes
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn put_f32<T: ByteOrder>(&mut self, _n: f32) {
|
||||
self.0 += 4
|
||||
}
|
||||
#[inline]
|
||||
fn put_f64<T: ByteOrder>(&mut self, _n: f64) {
|
||||
self.0 += 8
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
|
||||
use bytes::{BufMut, BytesMut};
|
||||
|
||||
use bytes_ext::SizeCounter;
|
||||
use bufsize::SizeCounter;
|
||||
use failure_ext::bail_err;
|
||||
use mercurial_types::delta::{Delta, Fragment};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user