Skip to content

Commit

Permalink
finished all attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
phith0n committed Apr 9, 2024
1 parent 06da533 commit 31e6506
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
24 changes: 24 additions & 0 deletions class/attr_module_main_class.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package class

import (
"encoding/binary"
"fmt"
"github.com/phith0n/zkar/commons"
)

// AttrModuleMainClass https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.27
type AttrModuleMainClass struct {
*AttributeBase

MainClassIndex uint16
}

func (a *AttrModuleMainClass) readInfo(stream *commons.Stream) error {
bs, err := stream.ReadN(2)
if err != nil {
return fmt.Errorf("read AttrModuleMainClass failed, no enough data in the stream")
}

a.MainClassIndex = binary.BigEndian.Uint16(bs)
return nil
}
33 changes: 33 additions & 0 deletions class/attr_module_packages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package class

import (
"encoding/binary"
"fmt"
"github.com/phith0n/zkar/commons"
)

// AttrModulePackages https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.26
type AttrModulePackages struct {
*AttributeBase

PackageIndex []uint16
}

func (a *AttrModulePackages) readInfo(stream *commons.Stream) error {
bs, err := stream.ReadN(2)
if err != nil {
return fmt.Errorf("read AttrModulePackages failed, no enough data in the stream")
}

length := binary.BigEndian.Uint16(bs)
for i := uint16(0); i < length; i++ {
bs, err = stream.ReadN(2)
if err != nil {
return fmt.Errorf("read AttrModulePackages[%d] failed, no enough data in the stream", i)
}

a.PackageIndex = append(a.PackageIndex, binary.BigEndian.Uint16(bs))
}

return nil
}

0 comments on commit 31e6506

Please sign in to comment.