Created
February 15, 2015 21:39
-
-
Save rblaze/4264b2fcd57c679d0c8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Unittest.Compat.BasicTypes (BasicTypes(..)) where | |
import qualified Bond.Imports as B' | |
import qualified Unittest.Compat.Another.Another | |
import qualified Unittest.Compat.Another.EnumType | |
import qualified Unittest.Compat.EnumType1 | |
data BasicTypes = BasicTypes{base' :: | |
Unittest.Compat.Another.Another.Another, | |
m_bool :: B'.Bool, m_str :: B'.Utf8, m_wstr :: B'.Utf16, | |
m_uint64 :: B'.Word64, m_uint16 :: B'.Word16, | |
m_uint32 :: B'.Word32, m_uint8 :: B'.Word8, m_int8 :: B'.Int8, | |
m_int16 :: B'.Maybe B'.Int16, m_int32 :: B'.Int32, | |
m_int64 :: B'.Int64, m_double :: B'.Double, m_float :: B'.Float, | |
m_enum1 :: Unittest.Compat.EnumType1.EnumType1, | |
m_enum2 :: Unittest.Compat.Another.EnumType.EnumType, | |
m_enum3 :: B'.Maybe Unittest.Compat.Another.EnumType.EnumType} | |
deriving (Show, Eq) | |
instance B'.Default BasicTypes where | |
defaultValue | |
= BasicTypes{base' = B'.defaultValue, m_bool = True, | |
m_str = B'.fromString "foo", m_wstr = B'.fromString "bar", | |
m_uint64 = 10, m_uint16 = 11, m_uint32 = 12, m_uint8 = 13, | |
m_int8 = -14, m_int16 = Nothing, m_int32 = -16, m_int64 = -17, | |
m_double = 18, m_float = 20, | |
m_enum1 = Unittest.Compat.EnumType1.enumValue3, | |
m_enum2 = Unittest.Compat.Another.EnumType.enumValue1, | |
m_enum3 = Nothing} | |
instance B'.WireType BasicTypes where | |
getWireType _ = B'.BT_STRUCT | |
instance B'.FastBinary BasicTypes where | |
fastBinaryPut v' | |
= do putStruct v' | |
B'.putStructStop | |
fastBinaryGet | |
= do b' <- B'.fastBinaryGetBase | |
B'.readFieldsWith update (B'.defaultValue{base' = b'}) | |
instance B'.FastBinaryStruct BasicTypes where | |
fastBinaryPutBase v' | |
= do putStruct v' | |
B'.putStructStopBase | |
fastBinaryGetBase | |
= do b' <- B'.fastBinaryGetBase | |
B'.readBaseFieldsWith update (B'.defaultValue{base' = b'}) | |
putStruct :: BasicTypes -> B'.Put | |
putStruct v' | |
= do B'.fastBinaryPutBase (base' v') | |
B'.unless (m_bool v' == m_bool B'.defaultValue) | |
(B'.putField 0 (m_bool v')) | |
B'.unless (m_str v' == m_str B'.defaultValue) | |
(B'.putField 2 (m_str v')) | |
B'.unless (m_wstr v' == m_wstr B'.defaultValue) | |
(B'.putField 3 (m_wstr v')) | |
B'.unless (m_uint64 v' == m_uint64 B'.defaultValue) | |
(B'.putField 10 (m_uint64 v')) | |
B'.unless (m_uint16 v' == m_uint16 B'.defaultValue) | |
(B'.putField 11 (m_uint16 v')) | |
B'.unless (m_uint32 v' == m_uint32 B'.defaultValue) | |
(B'.putField 12 (m_uint32 v')) | |
B'.unless (m_uint8 v' == m_uint8 B'.defaultValue) | |
(B'.putField 13 (m_uint8 v')) | |
B'.unless (m_int8 v' == m_int8 B'.defaultValue) | |
(B'.putField 14 (m_int8 v')) | |
B'.putMaybeField 15 (m_int16 v') | |
B'.unless (m_int32 v' == m_int32 B'.defaultValue) | |
(B'.putField 16 (m_int32 v')) | |
B'.unless (m_int64 v' == m_int64 B'.defaultValue) | |
(B'.putField 17 (m_int64 v')) | |
B'.unless (m_double v' == m_double B'.defaultValue) | |
(B'.putField 18 (m_double v')) | |
B'.unless (m_float v' == m_float B'.defaultValue) | |
(B'.putField 20 (m_float v')) | |
B'.unless (m_enum1 v' == m_enum1 B'.defaultValue) | |
(B'.putField 21 (m_enum1 v')) | |
B'.unless (m_enum2 v' == m_enum2 B'.defaultValue) | |
(B'.putField 22 (m_enum2 v')) | |
B'.putMaybeField 23 (m_enum3 v') | |
update :: | |
BasicTypes -> B'.ItemType -> B'.Word16 -> B'.Get BasicTypes | |
update v' t' 0 = fmap (\ f' -> v'{m_bool = f'}) (B'.getField t') | |
update v' t' 2 = fmap (\ f' -> v'{m_str = f'}) (B'.getField t') | |
update v' t' 3 = fmap (\ f' -> v'{m_wstr = f'}) (B'.getField t') | |
update v' t' 10 = fmap (\ f' -> v'{m_uint64 = f'}) (B'.getField t') | |
update v' t' 11 = fmap (\ f' -> v'{m_uint16 = f'}) (B'.getField t') | |
update v' t' 12 = fmap (\ f' -> v'{m_uint32 = f'}) (B'.getField t') | |
update v' t' 13 = fmap (\ f' -> v'{m_uint8 = f'}) (B'.getField t') | |
update v' t' 14 = fmap (\ f' -> v'{m_int8 = f'}) (B'.getField t') | |
update v' t' 15 | |
= fmap (\ f' -> v'{m_int16 = Just f'}) (B'.getField t') | |
update v' t' 16 = fmap (\ f' -> v'{m_int32 = f'}) (B'.getField t') | |
update v' t' 17 = fmap (\ f' -> v'{m_int64 = f'}) (B'.getField t') | |
update v' t' 18 = fmap (\ f' -> v'{m_double = f'}) (B'.getField t') | |
update v' t' 20 = fmap (\ f' -> v'{m_float = f'}) (B'.getField t') | |
update v' t' 21 = fmap (\ f' -> v'{m_enum1 = f'}) (B'.getField t') | |
update v' t' 22 = fmap (\ f' -> v'{m_enum2 = f'}) (B'.getField t') | |
update v' t' 23 | |
= fmap (\ f' -> v'{m_enum3 = Just f'}) (B'.getField t') | |
update v' t' _ | |
= do B'.skipValue t' | |
return v' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment