Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interface{} values #8

Open
leewz opened this issue Oct 31, 2018 · 0 comments
Open

interface{} values #8

leewz opened this issue Oct 31, 2018 · 0 comments

Comments

@leewz
Copy link

leewz commented Oct 31, 2018

I tried to decode a MapType which had interface keys and values.

I was able to decode it with these additions.

type.py:

class GoInterface(GoType):
    typeid = INTERFACE
    zero = None  # Seems to work.
    def __init__(self, loader):
        self._loader = loader
    
    def decode(self, buf):
        typename, buf = GoString.decode(buf)
        # A nil value has an empty typename. What does that mean?
        typeid, buf = GoInt.decode(buf)
        segment, buf = self._loader._read_segment(buf)
        zero, segment = GoUint.decode(segment)  #What's this about?
        assert zero == 0, 'illegal delta for singleton: %s' % zero
        value, segment = self._loader.decode_value(typeid, segment)
        assert segment == b'', 'trailing data in segment: %s' % list(segment)
        return value, buf

loader.py:

from .types import (INTERFACE, GoInterface)

class Loader:
    def __init__(self):
        # ...
        interface_type = GoInterface(self)
        self.types[INTERFACE] = interface_type
        # ...

However, I don't know if this code only works for my own case (being new to Go), and I don't know if I made the right choices, such as inheriting from GoType. I am also uncomfortable with discarding the typename information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant