add:Serialization Framework

This commit is contained in:
Christian Brier 2024-05-04 13:02:35 +02:00
parent 580e56ebbb
commit f4c70d4d30

View File

@ -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
} 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 = []