Create constant for ut_metadata

This commit is contained in:
Ivan 2024-08-18 11:59:39 +02:00
parent 8dc8c1e35d
commit 19e944a697
2 changed files with 4 additions and 3 deletions

View file

@ -10,7 +10,7 @@ use bytes::Bytes;
use clone_to_owned::CloneToOwned; use clone_to_owned::CloneToOwned;
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
use crate::MY_EXTENDED_UT_METADATA; use crate::{EXTENDED_UT_METADATA_KEY, MY_EXTENDED_UT_METADATA};
#[derive(Deserialize, Serialize, Debug, Default)] #[derive(Deserialize, Serialize, Debug, Default)]
pub struct ExtendedHandshake<ByteBuf: Eq + std::hash::Hash> { pub struct ExtendedHandshake<ByteBuf: Eq + std::hash::Hash> {
@ -39,7 +39,7 @@ pub struct ExtendedHandshake<ByteBuf: Eq + std::hash::Hash> {
impl ExtendedHandshake<ByteBuf<'static>> { impl ExtendedHandshake<ByteBuf<'static>> {
pub fn new() -> Self { pub fn new() -> Self {
let mut features = HashMap::new(); let mut features = HashMap::new();
features.insert(ByteBuf(b"ut_metadata"), MY_EXTENDED_UT_METADATA); features.insert(ByteBuf(EXTENDED_UT_METADATA_KEY), MY_EXTENDED_UT_METADATA);
Self { Self {
m: features, m: features,
..Default::default() ..Default::default()
@ -56,7 +56,7 @@ where
} }
pub fn ut_metadata(&self) -> Option<u8> { pub fn ut_metadata(&self) -> Option<u8> {
self.get_msgid(b"ut_metadata") self.get_msgid(EXTENDED_UT_METADATA_KEY)
} }
} }

View file

@ -44,6 +44,7 @@ const MSGID_PIECE: u8 = 7;
const MSGID_CANCEL: u8 = 8; const MSGID_CANCEL: u8 = 8;
const MSGID_EXTENDED: u8 = 20; const MSGID_EXTENDED: u8 = 20;
pub const EXTENDED_UT_METADATA_KEY: &[u8] = b"ut_metadata";
pub const MY_EXTENDED_UT_METADATA: u8 = 3; pub const MY_EXTENDED_UT_METADATA: u8 = 3;
#[derive(Debug)] #[derive(Debug)]