/* Copyright 2010-2015 MongoDB Inc.
*
* 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.
*/
using System;
using System.IO;
namespace MongoDB.Bson.IO
{
///
/// Represents a byte buffer (backed by various means depending on the implementation).
///
public interface IByteBuffer : IDisposable
{
// properties
///
/// Gets the capacity.
///
///
/// The capacity.
///
int Capacity { get; }
///
/// Gets a value indicating whether this instance is read only.
///
///
/// true if this instance is read only; otherwise, false.
///
bool IsReadOnly { get; }
///
/// Gets or sets the length.
///
///
/// The length.
///
int Length { get; set; }
// methods
///
/// Access the backing bytes directly. The returned ArraySegment will point to the desired position and contain
/// as many bytes as possible up to the next chunk boundary (if any). If the returned ArraySegment does not
/// contain enough bytes for your needs you will have to call ReadBytes instead.
///
/// The position.
///
/// An ArraySegment pointing directly to the backing bytes for the position.
///
ArraySegment AccessBackingBytes(int position);
///
/// Clears the specified bytes.
///
/// The position.
/// The count.
void Clear(int position, int count);
///
/// Ensure that the buffer has a minimum capacity. Depending on the buffer allocation strategy
/// calling this method may result in a higher capacity than the minimum (but never lower).
///
/// The minimum capacity.
void EnsureCapacity(int minimumCapacity);
///
/// Gets a slice of this buffer.
///
/// The position of the start of the slice.
/// The length of the slice.
/// A slice of this buffer.
IByteBuffer GetSlice(int position, int length);
///
/// Makes this buffer read only.
///
void MakeReadOnly();
///
/// Gets a byte.
///
/// The position.
/// A byte.
byte GetByte(int position);
///
/// Gets bytes.
///
/// The position.
/// The destination.
/// The destination offset.
/// The count.
void GetBytes(int position, byte[] destination, int offset, int count);
///
/// Sets a byte.
///
/// The position.
/// The value.
void SetByte(int position, byte value);
///
/// Sets bytes.
///
/// The position.
/// The bytes.
/// The offset.
/// The count.
void SetBytes(int position, byte[] source, int offset, int count);
}
}