use std::io::{Read, Write};
use crate::encoding::*;
impl SimpleBinaryEncodable for bool {
fn byte_len(&self) -> usize {
1
}
fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
write_u8(stream, if *self { 1 } else { 0 })
}
}
impl SimpleBinaryDecodable for bool {
fn decode<S: Read + ?Sized>(
stream: &mut S,
_decoding_options: &DecodingOptions,
) -> EncodingResult<Self> {
Ok(read_u8(stream)? == 1)
}
}
impl SimpleBinaryEncodable for i8 {
fn byte_len(&self) -> usize {
1
}
fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
write_u8(stream, *self as u8)
}
}
impl SimpleBinaryDecodable for i8 {
fn decode<S: Read + ?Sized>(
stream: &mut S,
_decoding_options: &DecodingOptions,
) -> EncodingResult<Self> {
Ok(read_u8(stream)? as i8)
}
}
impl SimpleBinaryEncodable for u8 {
fn byte_len(&self) -> usize {
1
}
fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
write_u8(stream, *self)
}
}
impl SimpleBinaryDecodable for u8 {
fn decode<S: Read + ?Sized>(
stream: &mut S,
_decoding_options: &DecodingOptions,
) -> EncodingResult<Self> {
read_u8(stream)
}
}
impl SimpleBinaryEncodable for i16 {
fn byte_len(&self) -> usize {
2
}
fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
write_i16(stream, *self)
}
}
impl SimpleBinaryDecodable for i16 {
fn decode<S: Read + ?Sized>(
stream: &mut S,
_decoding_options: &DecodingOptions,
) -> EncodingResult<Self> {
read_i16(stream)
}
}
impl SimpleBinaryEncodable for u16 {
fn byte_len(&self) -> usize {
2
}
fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
write_u16(stream, *self)
}
}
impl SimpleBinaryDecodable for u16 {
fn decode<S: Read + ?Sized>(
stream: &mut S,
_decoding_options: &DecodingOptions,
) -> EncodingResult<Self> {
read_u16(stream)
}
}
impl SimpleBinaryEncodable for i32 {
fn byte_len(&self) -> usize {
4
}
fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
write_i32(stream, *self)
}
}
impl SimpleBinaryDecodable for i32 {
fn decode<S: Read + ?Sized>(
stream: &mut S,
_decoding_options: &DecodingOptions,
) -> EncodingResult<Self> {
read_i32(stream)
}
}
impl SimpleBinaryEncodable for u32 {
fn byte_len(&self) -> usize {
4
}
fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
write_u32(stream, *self)
}
}
impl SimpleBinaryDecodable for u32 {
fn decode<S: Read + ?Sized>(
stream: &mut S,
_decoding_options: &DecodingOptions,
) -> EncodingResult<Self> {
read_u32(stream)
}
}
impl SimpleBinaryEncodable for i64 {
fn byte_len(&self) -> usize {
8
}
fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
write_i64(stream, *self)
}
}
impl SimpleBinaryDecodable for i64 {
fn decode<S: Read + ?Sized>(
stream: &mut S,
_decoding_options: &DecodingOptions,
) -> EncodingResult<Self> {
read_i64(stream)
}
}
impl SimpleBinaryEncodable for u64 {
fn byte_len(&self) -> usize {
8
}
fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
write_u64(stream, *self)
}
}
impl SimpleBinaryDecodable for u64 {
fn decode<S: Read + ?Sized>(
stream: &mut S,
_decoding_options: &DecodingOptions,
) -> EncodingResult<Self> {
read_u64(stream)
}
}
impl SimpleBinaryEncodable for f32 {
fn byte_len(&self) -> usize {
4
}
fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
write_f32(stream, *self)
}
}
impl SimpleBinaryDecodable for f32 {
fn decode<S: Read + ?Sized>(
stream: &mut S,
_decoding_options: &DecodingOptions,
) -> EncodingResult<Self> {
read_f32(stream)
}
}
impl SimpleBinaryEncodable for f64 {
fn byte_len(&self) -> usize {
8
}
fn encode<S: Write + ?Sized>(&self, stream: &mut S) -> EncodingResult<()> {
write_f64(stream, *self)
}
}
impl SimpleBinaryDecodable for f64 {
fn decode<S: Read + ?Sized>(
stream: &mut S,
_decoding_options: &DecodingOptions,
) -> EncodingResult<Self> {
read_f64(stream)
}
}