1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
use byteorder::LittleEndian; use crate::decode::{Decode, DecodeError}; use crate::encode::Encode; use crate::io::{Buf, BufMut}; use crate::mysql::protocol::Type; use crate::mysql::types::MySqlTypeMetadata; use crate::mysql::MySql; use crate::types::HasSqlType; impl HasSqlType<u8> for MySql { #[inline] fn metadata() -> MySqlTypeMetadata { MySqlTypeMetadata::unsigned(Type::TINY) } } impl Encode<MySql> for u8 { fn encode(&self, buf: &mut Vec<u8>) { buf.push(*self); } } impl Decode<MySql> for u8 { fn decode(buf: &[u8]) -> Result<Self, DecodeError> { Ok(buf[0]) } } impl HasSqlType<u16> for MySql { #[inline] fn metadata() -> MySqlTypeMetadata { MySqlTypeMetadata::unsigned(Type::SHORT) } } impl Encode<MySql> for u16 { fn encode(&self, buf: &mut Vec<u8>) { buf.put_u16::<LittleEndian>(*self); } } impl Decode<MySql> for u16 { fn decode(mut buf: &[u8]) -> Result<Self, DecodeError> { buf.get_u16::<LittleEndian>().map_err(Into::into) } } impl HasSqlType<u32> for MySql { #[inline] fn metadata() -> MySqlTypeMetadata { MySqlTypeMetadata::unsigned(Type::LONG) } } impl Encode<MySql> for u32 { fn encode(&self, buf: &mut Vec<u8>) { buf.put_u32::<LittleEndian>(*self); } } impl Decode<MySql> for u32 { fn decode(mut buf: &[u8]) -> Result<Self, DecodeError> { buf.get_u32::<LittleEndian>().map_err(Into::into) } } impl HasSqlType<u64> for MySql { #[inline] fn metadata() -> MySqlTypeMetadata { MySqlTypeMetadata::unsigned(Type::LONGLONG) } } impl Encode<MySql> for u64 { fn encode(&self, buf: &mut Vec<u8>) { buf.put_u64::<LittleEndian>(*self); } } impl Decode<MySql> for u64 { fn decode(mut buf: &[u8]) -> Result<Self, DecodeError> { buf.get_u64::<LittleEndian>().map_err(Into::into) } }