bc_envelope/format/
hex.rs1use dcbor::prelude::*;
2
3use crate::{Envelope, FormatContextOpt};
4
5#[derive(Clone, Default)]
6pub struct HexFormatOpts<'a> {
7 annotate: bool,
8 context: FormatContextOpt<'a>,
9}
10
11impl<'a> From<HexFormatOpts<'a>> for dcbor::HexFormatOpts<'a> {
12 fn from(opts: HexFormatOpts<'a>) -> Self {
13 dcbor::HexFormatOpts::default()
14 .annotate(opts.annotate)
15 .context(opts.context.into())
16 }
17}
18
19impl<'a> HexFormatOpts<'a> {
20 pub fn annotate(mut self, annotate: bool) -> Self {
22 self.annotate = annotate;
23 self
24 }
25
26 pub fn context(mut self, context: FormatContextOpt<'a>) -> Self {
28 self.context = context;
29 self
30 }
31}
32
33impl Envelope {
34 pub fn hex_opt<'a>(&self, opts: HexFormatOpts<'a>) -> String {
39 let cbor: CBOR = self.clone().into();
40 let hex_opts: dcbor::HexFormatOpts<'a> = opts.into();
41 cbor.hex_opt(&hex_opts)
42 }
43
44 pub fn hex(&self) -> String {
51 self.hex_opt(HexFormatOpts::default().annotate(true))
52 }
53}