Ongy / netlink-hs

Netlink communication for Haskell
BSD 3-Clause "New" or "Revised" License
2 stars 7 forks source link

support generics #9

Open teto opened 5 years ago

teto commented 5 years ago

It would be cool if we could have Ghc.Generics support to allow the generation of Convertable's getGet/getPut. It can be very tedious to write this code otherwise.

something like

class Convertable a where
  getGet :: MessageType -> Get a -- ^get a 'Get' function for the static data
  getPut :: a -> Put -- ^get a 'Put' function for the static data

  -- inspired by 
  default getGet :: (Generic a) => MessageType -> Get a
  getGet = genericGetGet

  default getGet :: (Generic a) => MessageType -> Put
  getGet = genericGetPut
teto commented 5 years ago

Here is some attempts https://github.com/Ongy/netlink-hs/compare/master...teto:master assuming the data is an instance of Serialize. But it fails in many cases with errors such as


        daemon: DiagCong error too few bytes
        From:       demandInput

        CallStack (from HasCallStack):
        error, called at IDiag.hs:449:37 in main:IDiag

    or

        "Unknown encoding for constructor"
        (Whend dealing with CongInfo)

    or
        Error too few bytes