trust_dns_proto/xfer/
serial_message.rs1use std::net::SocketAddr;
9
10use crate::error::ProtoResult;
11use crate::op::Message;
12
13pub struct SerialMessage {
15 message: Vec<u8>,
17 addr: SocketAddr,
18}
19
20impl SerialMessage {
21 pub fn new(message: Vec<u8>, addr: SocketAddr) -> Self {
23 Self { message, addr }
24 }
25
26 pub fn bytes(&self) -> &[u8] {
28 &self.message
29 }
30
31 pub fn addr(&self) -> SocketAddr {
33 self.addr
34 }
35
36 pub fn into_parts(self) -> (Vec<u8>, SocketAddr) {
38 self.into()
39 }
40
41 pub fn from_parts(message: Vec<u8>, addr: SocketAddr) -> Self {
43 (message, addr).into()
44 }
45
46 pub fn to_message(&self) -> ProtoResult<Message> {
48 Message::from_vec(&self.message)
49 }
50}
51
52impl From<(Vec<u8>, SocketAddr)> for SerialMessage {
53 fn from((message, addr): (Vec<u8>, SocketAddr)) -> Self {
54 Self { message, addr }
55 }
56}
57
58impl From<SerialMessage> for (Vec<u8>, SocketAddr) {
59 fn from(msg: SerialMessage) -> Self {
60 let SerialMessage { message, addr } = msg;
61 (message, addr)
62 }
63}