add:Serialization Framework
This commit is contained in:
parent
580e56ebbb
commit
f4c70d4d30
@ -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
|
||||
|
||||
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 = []
|
||||
|
Loading…
Reference in New Issue
Block a user