Add impl Value for IpAddr
@@ -6,6 +6,7 @@ use num_bigint::BigInt;
use std::borrow::Cow;
use std::collections::HashMap;
use std::convert::TryInto;
+use std::net::IpAddr;
use thiserror::Error;
use uuid::Uuid;
@@ -350,6 +351,23 @@ impl Value for Vec<u8> {
}
}
+impl Value for IpAddr {
+ fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig> {
+ match self {
+ IpAddr::V4(addr) => {
+ buf.put_i32(4);
+ buf.extend_from_slice(&addr.octets());
+ }
+ IpAddr::V6(addr) => {
+ buf.put_i32(16);
+ buf.extend_from_slice(&addr.octets());
+ }
+ }
+
+ Ok(())
+ }
+}
+
impl Value for String {
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig> {
<&str as Value>::serialize(&self.as_str(), buf)
