本文整理汇总了Golang中github.com/quarnster/util/encoding/binary.BinaryReader类的典型用法代码示例。如果您正苦于以下问题:Golang BinaryReader类的具体用法?Golang BinaryReader怎么用?Golang BinaryReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: String
func (a *attribute_info) String(c *ConstantPool) (ret string) {
ret = c.Lut(a.Attribute_name_index).String()
switch n := c.Lut(a.Attribute_name_index).String(); n {
case "Signature", "SourceFile":
ret += "="
br := binary.BinaryReader{bytes.NewReader(a.Info), binary.BigEndian}
if i16, err := br.Uint16(); err != nil {
ret += err.Error()
} else {
ret += c.Lut(u2(i16)).String()
}
case "Code":
ret += " ("
var cl Code_attribute
br := binary.BinaryReader{bytes.NewReader(a.Info), binary.BigEndian}
if err := br.ReadInterface(&cl); err != nil {
ret += err.Error()
} else {
for _, a2 := range cl.Attributes {
ret += fmt.Sprintf(" %s", c.Lut(a2.Attribute_name_index))
}
}
ret += " )"
}
return ret
}
示例2: PacketToBinary
func PacketToBinary(p *Packet, i interface{}) (interface{}, error) {
reader := binary.BinaryReader{Reader: util.Seeker(bytes.NewBuffer(p.Data)), Endianess: binary.LittleEndian}
err := reader.ReadInterface(i)
return i, err
}
示例3: Read
func (l *SLEB128) Read(br *binary.BinaryReader) error {
var (
curr LEB128
shift LEB128
v uint8
err error
)
for {
v, err = br.Uint8()
if err != nil {
return err
}
br := v&0x80 == 0
v = v & 0x7f
curr |= LEB128(v) << shift
shift += 7
if br {
break
}
}
const size = 64
if (shift < size) && v&0x40 != 0 {
curr |= -(1 << shift)
}
*l = SLEB128(curr)
return nil
}
示例4: testparse
func testparse(c *Class, members []member_info, method bool, t *testing.T) {
for i := range members {
var p descriptors.DESCRIPTORS
desc := c.Constant_pool.Lut(members[i].Descriptor_index).String()
if !p.Parse(desc) || p.RootNode().Range.End() != len(desc) {
t.Errorf("Failed to parse descriptor: %s\n%s\n%s", p.Error(), desc, p.RootNode())
}
var p2 signatures.SIGNATURES
for _, attr := range members[i].Attributes {
if c.Constant_pool.Lut(attr.Attribute_name_index).String() == "Signature" {
br := binary.BinaryReader{bytes.NewReader(attr.Info), binary.BigEndian}
if i16, err := br.Uint16(); err != nil {
t.Error(err)
} else {
sign := c.Constant_pool.Lut(u2(i16)).String()
p2.SetData(sign)
var ret bool
if method {
ret = p2.MethodTypeSignature()
} else {
ret = p2.FieldTypeSignature()
}
p2.RootNode().UpdateRange()
if !ret || p2.RootNode().Range.End() != len(sign) {
t.Errorf("Failed to parse signature: %s\n%s\n%s", p2.Error(), desc, p2.RootNode())
}
}
}
}
}
}
示例5: ReadIndex
func (m *MetadataUtil) ReadIndex(br *binary.BinaryReader, size uint) (uint32, error) {
if size != 2 {
return br.Uint32()
} else if v, e := br.Uint16(); e != nil {
return 0, e
} else {
return uint32(v), nil
}
}
示例6: NewClass
func NewClass(reader io.ReadSeeker) (*Class, error) {
r := binary.BinaryReader{reader, binary.BigEndian}
var c Class
if err := r.ReadInterface(&c); err != nil {
return nil, err
} else if c.Magic != magic {
return nil, errors.New(fmt.Sprintf("Magic isn't what's expected: %x", c.Magic))
}
return &c, nil
}
示例7: executeLNE
func (s *state) executeLNE(op DW_LNE, length LEB128, br *binary.BinaryReader) error {
switch op {
case DW_LNE_end_sequence:
s.end_sequence = true
s.header.matrix = append(s.header.matrix, s.lineEntry)
s.reset()
case DW_LNE_set_address:
var err error
if length == 8 {
s.address, err = br.Uint64()
} else {
var v uint32
v, err = br.Uint32()
s.address = uint64(v)
}
s.op_index = 0
return err
case DW_LNE_define_file:
var fe fileEntry
if err := br.ReadInterface(&fe); err != nil {
return err
} else {
s.header.file_names = append(s.header.file_names, fe)
}
case DW_LNE_set_discriminator:
var arg LEB128
if err := br.ReadInterface(&arg); err != nil {
return err
}
s.discriminator = uint(arg)
default:
panic(fmt.Errorf("%s", op))
}
return nil
}
示例8: TagRead
func TagRead(r io.ReadSeeker) (TagFileEntry, error) {
reader := binary.BinaryReader{Reader: r, Endianess: binary.LittleEndian}
var err error
var entry TagFileEntry
if err = reader.ReadInterface(&entry); err == nil {
offset, err := r.Seek(0, 1)
entry.Data = io.NewSectionReader(util.ReaderAt(r), offset, int64(entry.Size))
return entry, err
}
return TagFileEntry{}, err
}
示例9: TestLEB128Read
func TestLEB128Read(t *testing.T) {
tests := []struct {
output LEB128
input []byte
}{
{2, []byte{2}},
{127, []byte{127}},
{128, []byte{0 + 0x80, 1}},
{129, []byte{1 + 0x80, 1}},
{130, []byte{2 + 0x80, 1}},
{12857, []byte{57 + 0x80, 100}},
}
for _, test := range tests {
br := binary.BinaryReader{Reader: bytes.NewReader(test.input)}
var v LEB128
if err := br.ReadInterface(&v); err != nil {
t.Error(err)
} else if v != test.output {
t.Errorf("%d != %d", v, test.output)
}
}
}
示例10: parse
func (a *Archive) parse() (err error) {
reader := binary.BinaryReader{Reader: a.reader, Endianess: binary.LittleEndian}
if err = reader.ReadInterface(&a.header); err != nil {
return
}
entryOffset := int64(0x10)
a.entries = make([]archiveEntry, a.header.EntryCount)
for i := uint32(0); i < a.header.EntryCount; i++ {
entry := &a.entries[i]
if err = reader.ReadInterface(entry); err != nil {
return
}
entry.Data = io.NewSectionReader(util.ReaderAt(a.reader), entryOffset+int64(entry.DataOffset), int64(entry.DataSize))
entryOffset += int64(entry.DataEnd)
}
return
}
示例11: Read
func (c *ConstantPool) Read(br *binary.BinaryReader) error {
var count uint16
if err := br.ReadInterface(&count); err != nil {
return err
}
ic := int(count)
ic--
c.constants = make([]Constant, ic, ic)
for i := 0; i < len(c.constants); i++ {
cc := &c.constants[i]
cc.cp = c
if err := c.readConstant(cc, br); err != nil {
return err
}
if cc.Tag == CONSTANT_Double || cc.Tag == CONSTANT_Long {
// All 8-byte constants take up two entries in the constant_pool table of the class file.
i++
}
}
return nil
}
示例12: parse
func (f *TagFile) parse() error {
var err error
reader := binary.BinaryReader{Reader: f.reader, Endianess: binary.LittleEndian}
offset := int64(0)
var entry TagFileEntry
for err = reader.ReadInterface(&entry); err == nil; err = reader.ReadInterface(&entry) {
offset += 8
entry.Data = io.NewSectionReader(util.ReaderAt(f.reader), offset, int64(entry.Size))
f.Entries = append(f.Entries, entry)
_, err = f.reader.Seek(int64(entry.Size), 1)
offset += int64(entry.Size)
}
if err == io.EOF {
return nil
}
return err
}
示例13: String
func (a *attribute_info) String(c *ConstantPool) (ret string) {
ret = c.Lut(a.Attribute_name_index).String()
switch n := c.Lut(a.Attribute_name_index).String(); n {
case "Signature", "SourceFile":
ret += "="
br := binary.BinaryReader{Reader: bytes.NewReader(a.Info), Endianess: binary.BigEndian}
if i16, err := br.Uint16(); err != nil {
ret += err.Error()
} else {
ret += c.Lut(u2(i16)).String()
}
case "Code":
ret += " ( "
var cl Code_attribute
br := binary.BinaryReader{Reader: bytes.NewReader(a.Info), Endianess: binary.BigEndian}
if err := br.ReadInterface(&cl); err != nil {
ret += err.Error()
} else {
ret += strings.Join(sortStrings(cl.Attributes, c), " ")
}
ret += " )"
}
return ret
}
示例14: Read
func (ih *InfoHeader) Read(br *binary.BinaryReader) error {
err := br.ReadInterface(&ih.Header)
if err != nil {
return err
}
if ih.is64 {
ih.DebugAbbrevOffset, err = br.Int64()
} else {
var v uint32
v, err = br.Uint32()
ih.DebugAbbrevOffset = int64(v)
}
if err != nil {
return err
}
ih.AddressSize, err = br.Uint8()
return err
}
示例15: Read
func (ae *AbbrevEntry) Read(br *binary.BinaryReader) error {
if err := br.ReadInterface(&ae.Code); err != nil {
return err
} else if err := br.ReadInterface(&ae.Tag); err != nil {
return err
} else if err := br.ReadInterface(&ae.Children); err != nil {
return err
}
for {
var v AttributeSpecification
if err := br.ReadInterface(&v); err != nil {
return err
}
if v.Name == 0 && v.Form == 0 {
break
}
ae.Attributes = append(ae.Attributes, v)
}
return nil
}