parx-rs 0.1.0

Parx format Rust library
Documentation
/*
 * Copyright 2026 PARX Authors
 *
 * 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.
 */

//! Error types for PARX operations.

use thiserror::Error;

/// Result type for PARX operations.
pub type Result<T> = std::result::Result<T, ParxError>;

/// Errors that can occur when reading or writing PARX files.
#[derive(Error, Debug)]
pub enum ParxError {
    /// Invalid magic bytes in header or trailer.
    #[error("invalid magic: expected PARX, got {0:?}")]
    InvalidMagic([u8; 4]),

    /// Unsupported PARX format version.
    #[error("unsupported version: {major}.{minor}")]
    UnsupportedVersion { major: u8, minor: u8 },

    /// File is too small to contain valid PARX data.
    #[error("file too small: {size} bytes, minimum is {minimum}")]
    FileTooSmall { size: usize, minimum: usize },

    /// CRC32C checksum mismatch for manifest.
    #[error("manifest CRC32C mismatch: expected {expected:#010x}, got {actual:#010x}")]
    ManifestChecksumMismatch { expected: u32, actual: u32 },

    /// CRC32C checksum mismatch for footer payload.
    #[error("footer checksum mismatch")]
    FooterChecksumMismatch,

    #[error("page index checksum mismatch")]
    PageIndexChecksumMismatch,

    /// Failed to decode protobuf manifest.
    #[error("failed to decode manifest: {0}")]
    ManifestDecode(#[from] prost::DecodeError),

    /// Invalid offset or length in manifest.
    #[error("invalid payload bounds: offset {offset}, length {length}, file size {file_size}")]
    InvalidPayloadBounds {
        offset: u64,
        length: u64,
        file_size: u64,
    },

    /// Invalid format (JSON parsing, etc).
    #[error("invalid format: {0}")]
    InvalidFormat(String),

    /// Compression or decompression error.
    #[error("compression error: {0}")]
    CompressionError(String),

    /// Bundle-specific errors.
    #[error("invalid bundle magic: expected PRXB, got {0:?}")]
    InvalidBundleMagic([u8; 4]),

    /// Invalid Parquet file magic bytes.
    #[error("invalid Parquet magic bytes (expected PAR1, got {0:?})")]
    InvalidParquetMagic([u8; 4]),

    /// Parquet footer length exceeds file size.
    #[error("Parquet footer length {footer_len} exceeds file size {file_size}")]
    InvalidParquetFooterLength { footer_len: u64, file_size: u64 },

    /// I/O error (e.g., reading a file from disk).
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),
}