Open thechile opened 7 years ago
This looks like mostly likely a bug in this library -- there is an internal data structure on each Message called @set_fields
which looks like it is somehow not getting initialized. I'll see if I can come up with a small repro case.
Ah actually I tracked it down but it's not what I stated above. The DNSRR
message has a field defined as optional uint32 class = 3;
, which ends up overriding the ruby built-in method class
causing havoc at runtime.
I think ideally this library would detect when a conflict like this occurs... I'm not sure what the best way to handle it is, though. Maybe just rename the field to add a prefix underscore, so it ends up being _class
or something like that? That seems potentially confusing but I'm not sure what a better option would be.
In the meantime, can you rename this field in your proto definition? That will work around the problem.
OK, many thanks for identifying the problem. I can create issue for DNS server repo and suggest change of name for that field but i don't know if they will be interested in fixing or accepting a PR if i send.
I think it would be quicker to update this library. If you can point me in direction of culprit code i can try for PR ?
Thinking about it more, Message
is really a value type and we should treat it as such, so we should allow methods like .class
to be defined without mangling them. We should also inherit from BasicObject
now that ruby has such a concept (this library was originally written for ruby 1.8).
That said, there's quite a few places where code will have to change -- I see around 18 calls to self.class
in message.rb, along with a few calls in text_parser.ry and field.rb too. That'd be awesome if you're up for tackling it, but it'll be a larger change. It will probably be a week or two before I can tackle it myself.
One other workaround for now would be to rename the field in just your local .proto
or just the .pb.rb
file -- the field names don't actually matter in serialized data, so you'll still be able to interact with code that uses the unchanged definition.
OK thanks.. for quick win i deleted the class
field from proto since it's not really useful to me and everything now works. Perfect.
I don't know if my Ruby knowledge is sufficient to realise the needed changes but if i get time i'll take a punt.. if you don't get PR within a week then know i failed miserably and will need your help.
haha, totally understand
Hi
I am using this proto https://github.com/PowerDNS/pdns/blob/master/pdns/dnsmessage.proto which i compiled to give me the following
.rb.
But when i receive
DNSResponse
events from the DNS server it get errors e.g.This only happens when i receive an event with one or more
DNSRR
entries.. when there are none it works OK.For example a message produced on the source that works is
And one that fails is
Can you suggest please if this is a problem with the compiled protobuf definition or maybe a bug ?
thank you.