本文整理汇总了Golang中github.com/quarnster/util/encoding/binary.BinaryReader类的典型用法代码示例。如果您正苦于以下问题:Golang BinaryReader类的具体用法?Golang BinaryReader怎么用?Golang BinaryReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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
}
开发者ID:NeoTse,项目名称:completion,代码行数:28,代码来源:encoding.go
示例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())
}
}
}
}
}
}
开发者ID:NeoTse,项目名称:completion,代码行数:31,代码来源:class_all_test.go
示例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
}
}
开发者ID:NeoTse,项目名称:completion,代码行数:9,代码来源:metadata.go
示例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
}
开发者ID:NeoTse,项目名称:completion,代码行数:10,代码来源:class.go
示例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
}
开发者ID:NeoTse,项目名称:completion,代码行数:35,代码来源:line.go
示例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
}
开发者ID:keyphact,项目名称:pso2-go,代码行数:14,代码来源:tagfile.go
示例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)
}
}
}
开发者ID:NeoTse,项目名称:completion,代码行数:22,代码来源:encoding_test.go
示例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
}
开发者ID:keyphact,项目名称:pso2-go,代码行数:22,代码来源:archive.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 (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
示例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
}
开发者ID:noname007,项目名称:completion,代码行数:24,代码来源:class.go
示例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
}
开发者ID:NeoTse,项目名称:completion,代码行数:18,代码来源:info.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
示例16: 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
示例17: Read
func (lh *lineHeader) Read(br *binary.BinaryReader) error {
start, _ := br.Seek(0, 1)
err := br.ReadInterface(&lh.Header)
if err != nil {
return err
}
if lh.is64 {
lh.header_length, err = br.Int64()
} else {
var v uint32
v, err = br.Uint32()
lh.header_length = int64(v)
}
if err != nil {
return err
}
if lh.minimum_instruction_length, err = br.Uint8(); err != nil {
return err
}
lh.maximum_operations_per_instruction = 1
// TODO:
// if lh.maximum_operations_per_instruction, err = br.Uint8(); err != nil {
// return err
// }
if err = br.ReadInterface(&lh.default_is_stmt); err != nil {
return err
} else if lh.line_base, err = br.Int8(); err != nil {
return err
} else if lh.line_range, err = br.Uint8(); err != nil {
return err
} else if lh.opcode_base, err = br.Uint8(); err != nil {
return err
}
lh.standard_opcode_lengths = make([]uint8, lh.opcode_base-1)
if err := br.ReadInterface(&lh.standard_opcode_lengths); err != nil {
return err
}
for {
var s string
if err := br.ReadInterface(&s); err != nil {
return err
} else if s == "" {
break
} else {
lh.include_directories = append(lh.include_directories, s)
}
}
for {
var f fileEntry
pos, _ := br.Seek(0, 1)
if v, err := br.Uint8(); err != nil {
return err
} else if v == '\u0000' {
break
} else {
br.Seek(pos, 0)
}
if err := br.ReadInterface(&f); err != nil {
return err
} else {
lh.file_names = append(lh.file_names, f)
}
}
var s state
s.header = lh
s.reset()
pos, _ := br.Seek(0, 1)
for (pos - 4 - start) < int64(lh.Length) {
var op DW_LNS
if err := br.ReadInterface(&op); err != nil {
return err
}
if op == 0 {
var length LEB128
if err := br.ReadInterface(&length); err != nil {
return err
}
var op2 DW_LNE
if err := br.ReadInterface(&op2); err != nil {
return err
}
s.executeLNE(op2, length-1, br)
} else {
s.execute(op, br)
}
pos, _ = br.Seek(0, 1)
}
return nil
}
开发者ID:NeoTse,项目名称:completion,代码行数:92,代码来源:line.go
示例18: execute
func (s *state) execute(op DW_LNS, br *binary.BinaryReader) error {
switch op {
case DW_LNS_copy:
s.header.matrix = append(s.header.matrix, s.lineEntry)
s.discriminator = 0
s.basic_block = false
s.prologue_end = false
s.epilogue_begin = false
case DW_LNS_advance_pc:
var advance LEB128
if err := br.ReadInterface(&advance); err != nil {
return err
}
s.advance(uint(advance))
case DW_LNS_advance_line:
var delta SLEB128
if err := br.ReadInterface(&delta); err != nil {
return err
}
s.line += int(delta)
case DW_LNS_set_file:
var arg LEB128
if err := br.ReadInterface(&arg); err != nil {
return err
}
s.file = int(arg)
case DW_LNS_set_column:
var arg LEB128
if err := br.ReadInterface(&arg); err != nil {
return err
}
s.column = int(arg)
case DW_LNS_negate_stmt:
s.is_stmt = !s.is_stmt
case DW_LNS_set_basic_block:
s.basic_block = true
case DW_LNS_fixed_advance_pc:
var arg uint16
if err := br.ReadInterface(&arg); err != nil {
return err
}
s.address += uint64(arg)
s.op_index = 0
case DW_LNS_set_prologue_end:
s.prologue_end = true
case DW_LNS_set_epilogue_begin:
s.epilogue_begin = true
case DW_LNS_set_isa:
var arg LEB128
if err := br.ReadInterface(&arg); err != nil {
return err
}
s.isa = int(arg)
case DW_LNS_const_add_pc:
op = 255
fallthrough
default:
if uint8(op) > s.header.opcode_base {
op2 := int(uint8(op) - s.header.opcode_base)
advance := op2 / int(s.header.line_range)
line := (int(op2) % int(s.header.line_range)) + int(s.header.line_base)
s.line += line
s.advance(uint(advance))
s.header.matrix = append(s.header.matrix, s.lineEntry)
s.discriminator = 0
s.epilogue_begin = false
s.prologue_end = false
s.basic_block = false
}
}
return nil
}
开发者ID:NeoTse,项目名称:completion,代码行数:73,代码来源:line.go
示例19: Create
func (m *MetadataUtil) Create(br *binary.BinaryReader, v interface{}) error {
t := reflect.ValueOf(v)
if t.Kind() != reflect.Ptr {
return errors.New(fmt.Sprintf("Expected a pointer not %s", t.Kind()))
}
v2 := t.Elem()
name := v2.Type().Name()
if name == "StringIndex" {
size := m.StringHeap.RowSize
index, err := m.ReadIndex(br, uint(size))
if err != nil {
return err
}
data := m.StringHeap.data[index:m.StringHeap.Rows]
for i := range data {
if data[i] == '\u0000' {
data = data[:i]
break
}
}
v2.SetString(string(data))
} else if name == "Guid" {
size := m.GuidHeap.RowSize
if index, err := m.ReadIndex(br, uint(size)); err != nil {
return err
} else if index != 0 {
index = (index - 1) * 16
g := Guid(m.GuidHeap.data[index : index+16])
v2.Set(reflect.ValueOf(g))
}
} else if strings.HasSuffix(name, "EncodedIndex") {
size, err := m.Size(v2.Type())
if err != nil {
return err
}
idx, err := m.ReadIndex(br, size)
if err != nil {
return err
}
var (
tables = enc_lut[idx_name_lut[name]]
b = util.Bits(len(tables))
mask = uint32(0xffff << b)
tbl = idx &^ mask
ti ConcreteTableIndex
)
idx = idx >> b
ti.index = idx
ti.table = tables[int(tbl)]
ti.metadataUtil = m
v2.Set(reflect.ValueOf(&ti))
} else if strings.HasSuffix(name, "Index") {
size, err := m.Size(v2.Type())
if err != nil {
return err
}
var ti ConcreteTableIndex
if ti.index, err = m.ReadIndex(br, size); err != nil {
return err
}
if name == "BlobIndex" {
ti.table = id_Blob
} else {
ti.table = idx_name_lut[name]
}
ti.metadataUtil = m
v2.Set(reflect.ValueOf(&ti))
} else {
if v2.Kind() != reflect.Struct {
return br.ReadInterface(v)
}
for i := 0; i < v2.NumField(); i++ {
f := v2.Field(i)
a := f.Addr()
if err := m.Create(br, a.Interface()); err != nil {
return err
}
}
}
return nil
}
开发者ID:NeoTse,项目名称:completion,代码行数:83,代码来源:metadata.go
示例20: parseModelEntryVSET
func parseModelEntryVSET(entry *ModelEntry) error {
reader := binary.BinaryReader{Reader: entry.Data, Endianess: binary.LittleEndian}
var err error
unk, err := reader.Uint16()
count, err := reader.Uint16()
fmt.Printf("Count: %04x\n", count)
fmt.Printf("Unk: %04x\n", unk)
for i := uint16(0); i < count && err == nil; i++ {
var identifier uint16
identifier, err = reader.Uint16()
var data []uint8
if err != nil {
break
}
if identifier&0x8000 != 0 { // Size is fucked up
var sz, unk uint8
unk, err = reader.Uint8()
var size uint16
if unk == 0x10 {
size, err = reader.Uint16()
} else if unk == 0x08 {
sz, err = reader.Uint8()
size = uint16(sz)
} else {
return errors.New("Unknown size flag")
}
fmt.Printf("Oh %02x, %04x\n", unk, size)
x := 2
data = make([]uint8, x*int(size+1))
} else if identifier&0x0900 != 0 { // and 0x0900
data = make([]uint8, 4)
} else if identifier&0x0600 == 0x0600 { // and 0x0600
data = make([]uint8, 2)
} else if identifier&0xff00 != 0 {
fmt.Printf("what the fuck is %04x\n", identifier&0xff00)
//break
}
_, err = util.ReadN(entry.Data, data)
fmt.Printf("\t\t%04x (%08x): %x\n", identifier, len(data), data)
}
if _, err = entry.Data.Read(make([]uint8, 1)); err != io.EOF {
return errors.New("Expected EOF")
}
if err == io.EOF {
return nil
}
return err
}
开发者ID:keyphact,项目名称:pso2-go,代码行数:61,代码来源:model.go
注:本文中的github.com/quarnster/util/encoding/binary.BinaryReader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论