enumDeserializeImpl ename labels
 = do sayln' $ enumDeserializeProto ename ++ " {"
      sayln' $ "  int ret = 0;"
      sayln' $ "  "
      sayln' $ "  " ++ intType IKSigned IS32 ++ " temp = 0;"
      sayln' $ "  ret = " ++ deserialize (FInt IKSigned IS32) ++ "(in, in_len, pos, &temp);"
      sayln' $ "  if (ret) return ret;"
      sayln' $ "  switch (temp) {"
      flip mapM_ labels $ \EnumLabel{ label_name = lname, label_val = lval }
        -> do sayln' $ "    case " ++ show lval ++ ":"
              sayln' $ "      *out = " ++ lname ++ ";"
              sayln' $ "      break;"
      sayln' $ "    default: ret = -1;"
      sayln' $ "  }"
      sayln' $ "  "
      sayln' $ "  return ret;"
      sayln' $ "}"
enumDeserializeImpl ename labels
 = do sayln' $ enumDeserializeProto ename ++ " {"
      sayln' $ "  int ret = 0;"
      sayln' $ "  "
      sayln' $ "  " ++ intType IKSigned IS32 ++ " temp = 0;"
      sayln' $ "  ret = " ++ deserialize (FInt IKSigned IS32) ++ "(in, in_len, pos, &temp);"
      sayln' $ "  if (ret) return ret;"
      sayln' $ "  switch (temp) {"
      flip mapM_ labels $ \EnumLabel{ label_name = lname, label_val = lval }
        -> do sayln' $ "    case " ++ show lval ++ ":"
              sayln' $ "      *out = " ++ lname ++ ";"
              sayln' $ "      break;"
      sayln' $ "    default: ret = -1;"
      sayln' $ "  }"
      sayln' $ "  "
      sayln' $ "  return ret;"
      sayln' $ "}"
enumDeserializeImpl ename labels
 = do sayln' $ enumDeserializeProto ename ++ " {"
      sayln' $ "  int ret = 0;"
      sayln' $ "  "
      sayln' $ "  " ++ intType IKSigned IS32 ++ " temp = 0;"
      sayln' $ "  ret = " ++ deserialize (FInt IKSigned IS32) ++ "(in, in_len, pos, &temp);"
      sayln' $ "  if (ret) return ret;"
      sayln' $ "  switch (temp) {"
      flip mapM_ labels $ \EnumLabel{ label_name = lname, label_val = lval }
        -> do sayln' $ "    case " ++ show lval ++ ":"
              sayln' $ "      *out = " ++ lname ++ ";"
              sayln' $ "      break;"
      sayln' $ "    default: ret = -1;"
      sayln' $ "  }"
      sayln' $ "  "
      sayln' $ "  return ret;"
      sayln' $ "}"