risingwave_connector_codec/
lib.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Encoding and decoding between external data formats and RisingWave datum (i.e., type mappings).
16
17#![allow(clippy::derive_partial_eq_without_eq)]
18#![feature(coroutines)]
19#![feature(proc_macro_hygiene)]
20#![feature(stmt_expr_attributes)]
21#![feature(box_patterns)]
22#![feature(trait_alias)]
23#![feature(box_into_inner)]
24#![feature(type_alias_impl_trait)]
25#![feature(associated_type_defaults)]
26#![feature(impl_trait_in_assoc_type)]
27#![feature(iter_from_coroutine)]
28#![feature(if_let_guard)]
29#![feature(iterator_try_collect)]
30#![feature(try_blocks)]
31#![feature(error_generic_member_access)]
32#![feature(negative_impls)]
33#![feature(register_tool)]
34#![feature(assert_matches)]
35#![register_tool(rw)]
36#![recursion_limit = "256"]
37
38pub mod common;
39/// Converts JSON/AVRO/Protobuf data to RisingWave datum.
40/// The core API is [`decoder::Access`].
41pub mod decoder;
42
43pub use apache_avro::schema::Schema as AvroSchema;
44pub use apache_avro::types::{Value as AvroValue, ValueKind as AvroValueKind};
45pub use risingwave_pb::plan_common::ColumnDesc;
46pub struct JsonSchema(pub serde_json::Value);
47impl JsonSchema {
48    pub fn parse_str(schema: &str) -> anyhow::Result<Self> {
49        use anyhow::Context;
50
51        let value = serde_json::from_str(schema).context("failed to parse json schema")?;
52        Ok(Self(value))
53    }
54
55    pub fn parse_bytes(schema: &[u8]) -> anyhow::Result<Self> {
56        use anyhow::Context;
57
58        let value = serde_json::from_slice(schema).context("failed to parse json schema")?;
59        Ok(Self(value))
60    }
61}