Skip to main content

risingwave_connector_codec/
lib.rs

1// Copyright 2024 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#![feature(proc_macro_hygiene)]
18#![feature(stmt_expr_attributes)]
19#![feature(error_generic_member_access)]
20#![feature(register_tool)]
21#![register_tool(rw)]
22#![recursion_limit = "256"]
23
24pub mod common;
25/// Converts JSON/AVRO/Protobuf data to RisingWave datum.
26/// The core API is [`decoder::Access`].
27pub mod decoder;
28
29pub use apache_avro::schema::Schema as AvroSchema;
30pub use apache_avro::types::{Value as AvroValue, ValueKind as AvroValueKind};
31pub use risingwave_pb::plan_common::ColumnDesc;
32pub struct JsonSchema(pub serde_json::Value);
33impl JsonSchema {
34    pub fn parse_str(schema: &str) -> anyhow::Result<Self> {
35        use anyhow::Context;
36
37        let value = serde_json::from_str(schema).context("failed to parse json schema")?;
38        Ok(Self(value))
39    }
40
41    pub fn parse_bytes(schema: &[u8]) -> anyhow::Result<Self> {
42        use anyhow::Context;
43
44        let value = serde_json::from_slice(schema).context("failed to parse json schema")?;
45        Ok(Self(value))
46    }
47}