diff --git a/src/ClassFile.hs b/src/ClassFile.hs index d5322a1..08f2038 100644 --- a/src/ClassFile.hs +++ b/src/ClassFile.hs @@ -30,6 +30,7 @@ import Data.Word import Data.Int +import Data.ByteString data ConstantInfo = ClassInfo Word16 | FieldRefInfo Word16 Word16 @@ -48,15 +49,45 @@ data MemberInfo = MemberInfo { } deriving Show data ClassFile = ClassFile { - magic :: Word32, - minorVersion :: Word16, - majorVersion :: Word16, constantPool :: [ConstantInfo], accessFlags :: Word16, thisClass :: Word16, - superClass :: Word16, - interfaces :: [Word16], fields :: [MemberInfo], methods :: [MemberInfo], attributes :: [Attribute] -} deriving Show \ No newline at end of file +} deriving Show + +class Serializable a where + serialize :: a -> [Word8] -> [Word8] + +instance Serializable ClassFile where + serialize :: ClassFile -> [Word8] -> [Word8] + serialize classfile buffer = buffer ++ [0xC0, 0xFE, 0xBA, 0xBE] + ++ [0, 0] + ++ [0, 49] + ++ [0, 1] + ++ [0, 1] + ++ [0, 0] + ++ [0, 0] + ++ [0, 0] + ++ [0, 0] + ++ [0, 0] + ++ [0, 0] + + + + +example = ClassFile{ + constantPool, + accessFlags, + thisClass, + fields, + methods, + attributes + } where + constantPool = [] + accessFlags = 1 + thisClass = 0 + fields = [] + methods = [] + attributes = []