lance_table/
format.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright The Lance Authors
3
4use arrow_buffer::ToByteSlice;
5use snafu::location;
6use uuid::Uuid;
7
8mod fragment;
9mod index;
10mod manifest;
11
12pub use fragment::*;
13pub use index::Index;
14pub use manifest::{
15    is_detached_version, DataStorageFormat, Manifest, SelfDescribingFileReader, WriterVersion,
16    DETACHED_VERSION_MASK,
17};
18
19use lance_core::{Error, Result};
20
21/// Protobuf definitions for Lance Format
22pub mod pb {
23    #![allow(clippy::all)]
24    #![allow(non_upper_case_globals)]
25    #![allow(non_camel_case_types)]
26    #![allow(non_snake_case)]
27    #![allow(unused)]
28    #![allow(improper_ctypes)]
29    #![allow(clippy::upper_case_acronyms)]
30    #![allow(clippy::use_self)]
31    include!(concat!(env!("OUT_DIR"), "/lance.table.rs"));
32}
33
34/// These version/magic values are written at the end of manifest files (e.g. versions/1.version)
35pub const MAJOR_VERSION: i16 = 0;
36pub const MINOR_VERSION: i16 = 1;
37pub const MAGIC: &[u8; 4] = b"LANC";
38
39impl TryFrom<&pb::Uuid> for Uuid {
40    type Error = Error;
41
42    fn try_from(p: &pb::Uuid) -> Result<Self> {
43        if p.uuid.len() != 16 {
44            return Err(Error::io(
45                "Protobuf UUID is malformed".to_string(),
46                location!(),
47            ));
48        }
49        let mut buf: [u8; 16] = [0; 16];
50        buf.copy_from_slice(p.uuid.to_byte_slice());
51        Ok(Self::from_bytes(buf))
52    }
53}
54
55impl From<&Uuid> for pb::Uuid {
56    fn from(value: &Uuid) -> Self {
57        Self {
58            uuid: value.into_bytes().to_vec(),
59        }
60    }
61}