# Request

> The payload is the tag byte 22 alone; the server ignores any bytes that follow the tag.

Canonical: https://protocol.diverge.network/2.3.0/endpoints/daemons-accept/request/
Specification revision: 2.3.0

The payload of the request is exactly one byte:

```text
[22]
```

- **No parameter.** The request carries nothing after the tag. The
  identity the acceptor takes connections under is the connection's
  own, and is not stated.
- **Bytes after the tag.** A server ignores every byte that follows
  the tag. A request whose payload extends past the tag is not
  malformed.
- **Malformed.** A payload with no byte is not a request of any
  endpoint. [Endpoints](/2.3.0/endpoints/) states how a server answers a
  request it cannot read.

The request is defined by `diverge-sdk-rs/src/provider/endpoints/daemons/accept/client/request/frame.rs`:

```rust
//! What a client's request frame carries for an accept.

use crate::wire::decode::Decode;
use crate::wire::encode::{Encode, Writer};

/// Ask the provider to relay daemon connections to this daemon.
///
/// Carries nothing. The identity connectors name the daemon by is the
/// connection's, which the provider knows and the daemon does not
/// choose, so there is nothing to say beyond the asking.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct Frame;

/// This frame's tag among the scope-opening requests.
///
/// One byte at the front of the payload, which is what tells a reader
/// which request it holds. The frame layer does not discriminate them
/// — [`ClientFrame::Request`](crate::wire::frame::client::ClientFrame::Request)
/// is one type carrying bytes — so the distinction has to be in the
/// bytes, and each request owns the value that names it.
///
/// See the table in [`endpoints`](crate::provider::endpoints) for the whole
/// allocation. The values are chosen across modules that do not know
/// about each other, so the table is the only place they can be seen
/// at once.
const TAG: u8 = 22;

/// One byte, and no serialization. There is nothing to serialize.
impl Encode for Frame {
    /// [`Infallible`](std::convert::Infallible): a known byte.
    type Error = std::convert::Infallible;

    fn encode(&self, out: &mut Writer<'_>) -> Result<(), Self::Error> {
        out.extend_from_slice(&[TAG]);
        Ok(())
    }
}

impl Decode<'_> for Frame {
    /// Two ways to fail, and neither of them is a parse.
    type Error = FrameError;

    fn decode(bytes: &[u8]) -> Result<Self, Self::Error> {
        let (tag, _) = bytes.split_first().ok_or(FrameError::Empty)?;
        if *tag != TAG {
            return Err(FrameError::UnexpectedTag(*tag));
        }
        Ok(Frame)
    }
}

/// An accept request that could not be read. Anything after the tag
/// is ignored rather than refused.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FrameError {
    /// No bytes at all, so not even a tag.
    Empty,
    /// A tag naming some other request.
    UnexpectedTag(u8),
}

impl std::fmt::Display for FrameError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            FrameError::Empty => f.write_str("daemons accept request frame is empty"),
            FrameError::UnexpectedTag(tag) => write!(f, "expected daemons accept request tag {TAG}, found {tag}"),
        }
    }
}

impl std::error::Error for FrameError {}
```
