package bin

import (
	
)

// Buffer implements low level binary (de-)serialization for TL.
type Buffer struct {
	Buf []byte
}

// Encode wrapper.
func ( *Buffer) ( Encoder) error {
	return .Encode()
}

// Decode wrapper.
func ( *Buffer) ( Decoder) error {
	return .Decode()
}

// ResetN resets buffer and expands it to fit n bytes.
func ( *Buffer) ( int) {
	.Buf = append(.Buf[:0], make([]byte, )...)
}

// Expand expands buffer to add n bytes.
func ( *Buffer) ( int) {
	.Buf = append(.Buf, make([]byte, )...)
}

// Skip moves cursor for next n bytes.
func ( *Buffer) ( int) {
	.Buf = .Buf[:]
}

// Read implements io.Reader.
func ( *Buffer) ( []byte) ( int,  error) {
	if len() == 0 {
		return 0, nil
	}
	if len(.Buf) == 0 {
		return 0, io.EOF
	}
	 = copy(, .Buf)
	.Buf = .Buf[:]
	return , nil
}

// Copy returns new copy of buffer.
func ( *Buffer) () []byte {
	return append([]byte{}, .Buf...)
}

// Raw returns internal byte slice.
func ( Buffer) () []byte {
	return .Buf
}

// Len returns length of internal buffer.
func ( Buffer) () int {
	return len(.Buf)
}

// ResetTo sets internal buffer exactly to provided value.
//
// Buffer will retain buf, so user should not modify or read it
// concurrently.
func ( *Buffer) ( []byte) {
	.Buf = 
}