{"action":"opened","issue":{"url":"https://api.github.com/repos/dmendel/bindata/issues/75","repository_url":"https://api.github.com/repos/dmendel/bindata","labels_url":"https://api.github.com/repos/dmendel/bindata/issues/75/labels{/name}","comments_url":"https://api.github.com/repos/dmendel/bindata/issues/75/comments","events_url":"https://api.github.com/repos/dmendel/bindata/issues/75/events","html_url":"https://github.com/dmendel/bindata/issues/75","id":165426440,"number":75,"title":"Understanding how to access fields from different classes","user":{"login":"peterjmorgan","id":132468,"avatar_url":"https://avatars.githubusercontent.com/u/132468?v=3","gravatar_id":"","url":"https://api.github.com/users/peterjmorgan","html_url":"https://github.com/peterjmorgan","followers_url":"https://api.github.com/users/peterjmorgan/followers","following_url":"https://api.github.com/users/peterjmorgan/following{/other_user}","gists_url":"https://api.github.com/users/peterjmorgan/gists{/gist_id}","starred_url":"https://api.github.com/users/peterjmorgan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterjmorgan/subscriptions","organizations_url":"https://api.github.com/users/peterjmorgan/orgs","repos_url":"https://api.github.com/users/peterjmorgan/repos","events_url":"https://api.github.com/users/peterjmorgan/events{/privacy}","received_events_url":"https://api.github.com/users/peterjmorgan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-13T21:31:18Z","updated_at":"2016-07-13T21:31:18Z","closed_at":null,"body":"I have a use case where I need to read a field in one class (ChunkFile) and access it other classes (lots, actually - but ChunkHdr is an example) I think I'm missing something abstract here:\r\n\r\n#!/usr/bin/env ruby\r\n\r\n%w[bindata rbkb pry].each {|x| require x}\r\n\r\nclass ChunkHdr < BinData::Record\r\n  # shouldn't need blendian, use lambda\r\n  choice :max_chunks, :selection => :blendian do\r\n    uint32be \"big\"\r\n    uint32le \"little\"\r\n  end\r\n  choice :num_chunks, :selection => :blendian do\r\n    uint32be \"big\"\r\n    uint32le \"little\"\r\n  end\r\nend\r\n\r\n\r\nclass ChunkFile < BinData::Record\r\n  endian :big\r\n\r\n  uint32 :magic, :length => 4\r\n\r\n  big = [:string, {:value => \"big\"}]\r\n  little = [:string, {:value => \"little\"}]\r\n  choices = {0xC5C6CBC3=>little, :default=>big}\r\n\r\n  choice :blendian, :choices => choices, :selection => :magic\r\n  chunk_hdr :header\r\nend\r\n\r\nif $0 == __FILE__\r\n  cf = ChunkFile.new\r\n\r\n  # test chunkfile\r\n  magic = BinData::Uint32be.new\r\n  magic.assign(3318139843)\r\n\r\n  #test chunkhdr\r\n  maxchunks = BinData::Uint32be.new(10)\r\n  numchunks = BinData::Uint32be.new(10)\r\n\r\n  cur = \"#{magic.to_binary_s} + #{maxchunks.to_binary_s} + #{numchunks.to_binary_s}\"\r\n  cf.read(cur)\r\n  \r\n  binding.pry\r\nend\r\n\r\nPython's construct module has the concept of context to do this. I feel like this has to be done in BinData but I'm not understanding how.\r\n\r\nAny help is greatly appreciated!"}}
{"actor":{"display_login":"peterjmorgan"}}