Skip to content

Commit

Permalink
Add mem tracking primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 committed Jul 23, 2024
1 parent a388fa9 commit 2bbd882
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ pub trait Input {
/// This is called when decoding reference-based type is finished.
fn ascend_ref(&mut self) {}

/// Hook that is called before allocating memory on the heap.
fn on_before_alloc_mem(&mut self, _size: usize) -> Result<(), Error> {
Ok(())
}

/// !INTERNAL USE ONLY!
///
/// Decodes a `bytes::Bytes`.
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ mod joiner;
mod keyedvec;
#[cfg(feature = "max-encoded-len")]
mod max_encoded_len;
mod mem_tracking;

#[cfg(feature = "std")]
pub use self::codec::IoReader;
Expand Down
20 changes: 20 additions & 0 deletions src/mem_tracking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::Decode;

/// Marker trait used for identifying types that call the mem tracking hooks exposed by `Input`
/// while decoding.
pub trait DecodeWithMemTracking: Decode {}

0 comments on commit 2bbd882

Please sign in to comment.