当前位置: 首页>>代码示例>>Golang>>正文


Golang BinaryReader.ReadInterface方法代码示例

本文整理汇总了Golang中github.com/quarnster/util/encoding/binary.BinaryReader.ReadInterface方法的典型用法代码示例。如果您正苦于以下问题:Golang BinaryReader.ReadInterface方法的具体用法?Golang BinaryReader.ReadInterface怎么用?Golang BinaryReader.ReadInterface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/quarnster/util/encoding/binary.BinaryReader的用法示例。


在下文中一共展示了BinaryReader.ReadInterface方法的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
}
开发者ID:NeoTse,项目名称:completion,代码行数:26,代码来源:class.go

示例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
}
开发者ID:keyphact,项目名称:pso2-go,代码行数:7,代码来源:packet.go

示例3: 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
}
开发者ID:NeoTse,项目名称:completion,代码行数:35,代码来源:line.go

示例4: Read

func (dw *DW_VIRTUALITY) Read(br *binary.BinaryReader) error {
	var v LEB128
	if err := br.ReadInterface(&v); err != nil {
		return err
	}
	*dw = DW_VIRTUALITY(v)
	return nil
}
开发者ID:NeoTse,项目名称:completion,代码行数:8,代码来源:encoding.go

示例5: 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
}
开发者ID:NeoTse,项目名称:completion,代码行数:10,代码来源:class.go

示例6: 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
}
开发者ID:keyphact,项目名称:pso2-go,代码行数:14,代码来源:tagfile.go

示例7: 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
}
开发者ID:NeoTse,项目名称:completion,代码行数:18,代码来源:info.go

示例8: 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)
		}
	}
}
开发者ID:NeoTse,项目名称:completion,代码行数:22,代码来源:encoding_test.go

示例9: 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
}
开发者ID:keyphact,项目名称:pso2-go,代码行数:22,代码来源:archive.go

示例10: 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
}
开发者ID:keyphact,项目名称:pso2-go,代码行数:23,代码来源:tagfile.go

示例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
}
开发者ID:NeoTse,项目名称:completion,代码行数:23,代码来源:class.go

示例12: parse

func (m *Model) parse() (err error) {
	reader := binary.BinaryReader{Reader: m.reader, Endianess: binary.LittleEndian}

	if err = reader.ReadInterface(&m.Header); err != nil {
		return
	}

	reader.Seek(int64(m.Header.HeaderSize)-0x10, 1)

	offset := int64(m.Header.HeaderSize)
	for err == nil {
		entry := ModelEntry{}

		if err = reader.ReadInterface(&entry); err != nil {
			if err == io.EOF {
				return nil
			}
			return
		}

		entry.Data = io.NewSectionReader(util.ReaderAt(m.reader), offset+0x0c, int64(entry.Size)-0x04)
		offset += 0x08 + int64(entry.Size)

		m.Entries = append(m.Entries, entry)

		switch entry.SubType {
		case "NODE": // Bone data

		case "NODO": // More bone things

		case "VSET": // Vertex data shit
			err = parseModelEntryVSET(&entry)
		}
	}

	return
}
开发者ID:keyphact,项目名称:pso2-go,代码行数:37,代码来源:model.go

示例13: LoadAssembly

func LoadAssembly(r io.ReadSeeker) (*Assembly, error) {

	var (
		br        = binary.BinaryReader{r, binary.LittleEndian}
		err       error
		pe_offset uint32
		coff      coff_file_header
		cor20     image_cor20
		t         MetadataHeader
	)

	if _, err := r.Seek(pe_signature_offset, 0); err != nil {
		return nil, err
	}

	if pe_offset, err = br.Uint32(); err != nil {
		return nil, err
	} else if _, err := r.Seek(int64(pe_offset), 0); err != nil {
		return nil, err
	}

	if err := br.ReadInterface(&coff); err != nil {
		return nil, err
	}
	net := coff.OptionalHeader.RVAS[14]
	off := coff.VirtualToFileOffset(net.VirtualAddress)
	if _, err := br.Seek(int64(off), 0); err != nil {
		return nil, err
	}

	if err := br.ReadInterface(&cor20); err != nil {
		return nil, err
	}
	off = coff.VirtualToFileOffset(cor20.MetaData.VirtualAddress)
	if _, err := br.Seek(int64(off), 0); err != nil {
		return nil, err
	}
	if err := br.ReadInterface(&t); err != nil {
		return nil, err
	}
	if _, err := br.Seek(int64(off), 0); err != nil {
		return nil, err
	}
	md, err := t.MetadataUtil(&br)
	if err != nil {
		return nil, err
	}
	a := Assembly{*md, make(map[string]*TypeDef)}
	idx := ConcreteTableIndex{&a.MetadataUtil, 0, id_TypeDef}
	for i := uint32(0); i < a.Tables[id_TypeDef].Rows; i++ {
		idx.index = 1 + i
		if td, err := TypeDefFromIndex(&idx); err == nil {
			a.typelut[td.Name().Absolute] = td
		}
	}
	return &a, nil
}
开发者ID:NeoTse,项目名称:completion,代码行数:57,代码来源:assembly.go

示例14: 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
}
开发者ID:noname007,项目名称:completion,代码行数:24,代码来源:class.go

示例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
}
开发者ID:NeoTse,项目名称:completion,代码行数:20,代码来源:abbrev.go


注:本文中的github.com/quarnster/util/encoding/binary.BinaryReader.ReadInterface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。