use bytes::BytesMut;
use obs_proto::obs::v1::{Severity, Tier};
use crate::{envelope::FieldMeta, metric::MetricEmitter};
pub trait Sealed {}
#[allow(missing_debug_implementations)]
pub trait EventSchemaErased: Sealed + Send + Sync + 'static {
fn full_name(&self) -> &'static str;
fn schema_hash(&self) -> u64;
fn tier(&self) -> Tier;
fn default_sev(&self) -> Severity;
fn fields(&self) -> &'static [FieldMeta];
fn spans_paired_with(&self) -> Option<&'static str> {
None
}
fn project_metrics(
&self,
payload: &[u8],
emitter: &mut dyn MetricEmitter,
) -> Result<(), DecodeError> {
super::payload_decode::project_metrics_default(payload, self.fields(), emitter)
}
fn decode_to_arrow_struct(
&self,
payload: &[u8],
builder: &mut dyn ArrowStructBuilder,
) -> Result<(), DecodeError> {
super::payload_decode::decode_to_arrow_struct_default(payload, self.fields(), builder)
}
fn decode_to_otlp_kv(
&self,
payload: &[u8],
out: &mut Vec<(&'static str, OtlpValue)>,
) -> Result<(), DecodeError> {
super::payload_decode::decode_to_otlp_kv_default(payload, self.fields(), out)
}
fn render_json(
&self,
payload: &[u8],
out: &mut serde_json::Map<String, serde_json::Value>,
) -> Result<(), DecodeError> {
super::payload_decode::render_json_default(payload, self.fields(), out)
}
fn scrub_for_log<'a>(
&self,
payload: &'a [u8],
scratch: &'a mut BytesMut,
) -> Result<&'a [u8], ScrubError> {
super::scrubber::scrub_payload(payload, self.fields(), scratch)
}
fn otel_attribute_view(&self) -> &'static OtelAttributeView {
&EMPTY_OTEL_VIEW
}
}
pub trait ArrowStructBuilder: Send {
fn append_null(&mut self);
fn append_str(&mut self, name: &'static str, value: &str) {
let _ = (name, value);
}
fn append_i64(&mut self, name: &'static str, value: i64) {
let _ = (name, value);
}
fn append_u64(&mut self, name: &'static str, value: u64) {
let _ = (name, value);
}
fn append_f64(&mut self, name: &'static str, value: f64) {
let _ = (name, value);
}
fn append_bool(&mut self, name: &'static str, value: bool) {
let _ = (name, value);
}
fn append_bytes(&mut self, name: &'static str, value: &[u8]) {
let _ = (name, value);
}
fn append_field_null(&mut self, name: &'static str) {
let _ = name;
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum OtlpValue {
String(String),
Int(i64),
Double(f64),
Bool(bool),
Bytes(Vec<u8>),
}
#[derive(Debug, Default)]
#[non_exhaustive]
pub struct OtelAttributeView {
pub event_name: &'static str,
pub constant_attrs: &'static [(&'static str, &'static str)],
}
static EMPTY_OTEL_VIEW: OtelAttributeView = OtelAttributeView {
event_name: "",
constant_attrs: &[],
};
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum DecodeError {
#[error("payload truncated at offset {0}")]
Truncated(usize),
#[error("unknown wire-tag {0}")]
UnknownTag(u32),
#[error("invariant violated: {0}")]
Invariant(&'static str),
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ScrubError {
#[error("payload re-encode failed at field {0}")]
ReencodeFailed(&'static str),
}