fix: Fix connection interface binding, JSON lease DB
This commit is contained in:
46
pkg/types/json.go
Normal file
46
pkg/types/json.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
util "github.com/adrianokf/go-dhcp/pkg/util"
|
||||
)
|
||||
|
||||
func (txid *TxId) UnmarshalText(text []byte) (err error) {
|
||||
result, err := strconv.ParseUint(string(text), 16, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
copy(txid[:], util.U32ToByte(uint32(result)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (id TxId) MarshalText() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf("%x", id)), nil
|
||||
}
|
||||
|
||||
func (addr *Ipv4Addr) UnmarshalText(text []byte) (err error) {
|
||||
ip := net.ParseIP(string(text))
|
||||
fmt.Println(ip)
|
||||
if ip == nil {
|
||||
return fmt.Errorf("could not parse IP address: '%s'", text)
|
||||
}
|
||||
*addr = Ipv4AddrFromNetIP(ip)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (addr Ipv4Addr) MarshalText() ([]byte, error) {
|
||||
return addr.ToNetIPv4().MarshalText()
|
||||
}
|
||||
|
||||
func (addr HwAddr) MarshalText() ([]byte, error) {
|
||||
return []byte(addr.String()), nil
|
||||
}
|
||||
|
||||
func (addr *HwAddr) UnmarshalText(text []byte) (err error) {
|
||||
*addr, err = HwAddrFromString(string(text))
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user