Using maps in protobuf v2 - protocol-buffers
Currently I am using protobuf version 2 in my project. So far all of the messages are working great; however I have hit a road block trying to use the 'map' keyword.
The TLDR usage behind needing the map, is that I want to pass some JSON key/value pairs to my server to do a lookup, and potential log of data to a server (which uses a JSON message interface).
I am currently using the backwards compatibility method that is recommend on the docs page: https://developers.google.com/protocol-buffers/docs/proto#maps
What I would like to understand is why is the following declaration of my message (using maps) failing to compile? I am using the following veriosn of the protoc compiler: '# protoc --version => libprotoc 2.6.1'
message MapFieldEntry {
optional string key = 1;
optional string value = 2;
}
message Lookup {
repeated MapFieldEntry map_field = 1;
map<string, string> test_map = 2;
}
The error I receive is as follows (the errors don't make sense to me considering the documentation of the map feature):
Expected "required", "optional", or "repeated".
Expected field name.
I have tried adding syntax="proto2"; at the top, but I still get the error.
Edit:
Just as a note; the issue I am having is regarding the second argument of the Lookup message. The first argument is what I am currently using as a work around.
I found someone else with a similar issue on git:
https://github.com/google/protobuf/issues/799
The response is:
The maps syntax is only supported starting from v3.0.0. The "proto2"
in the doc is referring to the syntax version, not protobuf release
version. v3.0.0 supports both proto2 syntax and proto3 syntax while
v2.6.1 only supports proto2 syntax. For all users, it's recommended to
use v3.0.0-beta-1 instead of v2.6.1.
So it looks like to fix your problem, you should use protoc 3, instead of 2.6.1.
And keep your syntax=proto2 at the top of your file to precise this is the proto2 syntax that you use.
Could you try and let me know if this work? this is an interesting question as the official doc does not mention it.
Related
Kamailio 4.4 seturi Only Accepts Explicit Strings?
I've been working at implementing a simple serial forking described in the TM module's documentation (the Q values are stored as a priority weight in a mysql table) where my proxy is querying a database to determine to what domain to forward to. I've verified through extensive use of xlog that a variable I'm using to build the new URI to use with seturi is getting everything correctly. I use an append_branch call in a subsequent while loop iterating over my sql query results, which doesn't have any problems with taking a very similarly formatted parameter. However, when I go to restart Kamailio it simply gripes at me that a string is expected. The line it corresponds to from console is just the seturi call. I've tried casting as a string, but that doesn't seem to be part of 4.4 (or my syntax is wrong). I've thought about building the URI strings and storing into avp, but I suspect I'd have the same problem. For reference, this is what I'm doing: $var(basedest) = "sip:" + $var(number) + "#" + $(dbr(destination=>[0,0]))+ ":" + $var(port); seturi($var(basedest)); And what it's outputting when trying to load the config: <core> [cfg.y:3368]: yyerror_at(): parse error in config file //etc/kamailio/kamailio.cfg, line 570, column 9-22: syntax error <core> [cfg.y:3371]: yyerror_at(): parse error in config file //etc/kamailio/kamailio.cfg, line 570, column 23: bad argument, string expected Naturally, when I put $var(basedest) in double quotes, it's literally interpreted as a string. Single quotes behave similarly. Is there something I can do to work around this? When I feed it an explicit hardcoded string, it's happy as a can be and the routing works fine. When I try to do something very simple like the above, it gets upset. If possible, I'd like to avoid updating as I initially grabbed Kamailio from the yum repo. Thanks in advance - this has been bugging me a good while.
Apparently, not a new problem. I ended up finding out what I can do to work around it. For reference, seturi and $ru pseudo variable refer to the same thing. So basically you'd just do: $var(mynewru) = "sip:user#domain:5060"; $ru = $var(mynewru); This would achieve the same thing I was originally attempting to do before based on the TM module's documentation. For serial forking, issuing some number of append_branch calls is fine.
freeimage 3.17 library build failing on Mac OS X: fails with C++11 narrowing error... any ideas?
With not having any understanding of C++ (I'm teaching myself Swift), I'm struggling a bit to get around this one - but ideally would love to be able to expose some of the functionality in the FreeImage library in my project. It appears that only one module is generating any errors: dcraw_common.cpp - and the lines in error are those from the following entry list where there is a value of 0x80 or above. From the investigations I've done, it would appear that these values are too large for a signed char (max 128?), yet the list also includes negative numbers, and so it can't use an unsigned char. Any help would be most gratefully received. Here's an example of the error message generated by the make process: Source/LibRawLite/./internal/dcraw_common.cpp:4543:19: error: constant expression evaluates to 136 which cannot be narrowed to type 'signed char' [-Wc++11-narrowing] +1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40, ^~~~ And here's the code: void CLASS vng_interpolate() { static const signed char *cp, terms[] = { -2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01, -2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01, -2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03, -2,+1,-1,+0,0,0x04, -2,+1,+0,-1,1,0x04, -2,+1,+0,+0,0,0x06, -2,+1,+0,+1,0,0x02, -2,+2,+0,+0,1,0x04, -2,+2,+0,+1,0,0x04, -1,-2,-1,+0,0,0x80, -1,-2,+0,-1,0,0x01, -1,-2,+1,-1,0,0x01, -1,-2,+1,+0,1,0x01, -1,-1,-1,+1,0,0x88, -1,-1,+1,-2,0,0x40, -1,-1,+1,-1,0,0x22, -1,-1,+1,+0,0,0x33, -1,-1,+1,+1,1,0x11, -1,+0,-1,+2,0,0x08, -1,+0,+0,-1,0,0x44, -1,+0,+0,+1,0,0x11, -1,+0,+1,-2,1,0x40, -1,+0,+1,-1,0,0x66, -1,+0,+1,+0,1,0x22, -1,+0,+1,+1,0,0x33, -1,+0,+1,+2,1,0x10, -1,+1,+1,-1,1,0x44, -1,+1,+1,+0,0,0x66, -1,+1,+1,+1,0,0x22, -1,+1,+1,+2,0,0x10, -1,+2,+0,+1,0,0x04, -1,+2,+1,+0,1,0x04, -1,+2,+1,+1,0,0x04, +0,-2,+0,+0,1,0x80, +0,-1,+0,+1,1,0x88, +0,-1,+1,-2,0,0x40, +0,-1,+1,+0,0,0x11, +0,-1,+2,-2,0,0x40, +0,-1,+2,-1,0,0x20, +0,-1,+2,+0,0,0x30, +0,-1,+2,+1,1,0x10, +0,+0,+0,+2,1,0x08, +0,+0,+2,-2,1,0x40, +0,+0,+2,-1,0,0x60, +0,+0,+2,+0,1,0x20, +0,+0,+2,+1,0,0x30, +0,+0,+2,+2,1,0x10, +0,+1,+1,+0,0,0x44, +0,+1,+1,+2,0,0x10, +0,+1,+2,-1,1,0x40, +0,+1,+2,+0,0,0x60, +0,+1,+2,+1,0,0x20, +0,+1,+2,+2,0,0x10, +1,-2,+1,+0,0,0x80, +1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40, +1,+0,+2,+1,0,0x10 }, chood[] = { -1,-1, -1,0, -1,+1, 0,+1, +1,+1, +1,0, +1,-1, 0,-1 }; ...
C++11 prevents 'narrowing conversions' like that. Early versions of C++ would accept them. I think this patch to the source of dcraw_common.cpp should fix it. https://gist.github.com/conchurnavid/ac19c8e882f1835f0310 There's a duplicate question here. Building FreeImage 3.16.0 for Android
The most usable solution I found to this issue was the following GitHub posting: https://github.com/danoli3/FreeImage. Here some kind soul appears to have successfully built the 3.17.0 library and uploaded it. I've found that works just fine. Please bear in mind however that it's been built with a hard-coded path of /opt/local/lib - which may be an issue when you come to implementation, since your app will be looking for it there, not bundled with the app. I did find this LiveCode post aided my understanding in that regard a lot. Hope this helps.
Primitive type as data structure for API Blueprint
I want to use primitive type for describe data structure. Like so: # Data Structures ## Video Delete (enum[number]) + `0` - Successful deletion. + `1` - Error occured. And the output is. { "enum": [ 1, 0 ], "$schema": "http://json-schema.org/draft-04/schema#" } So description is missing. I've tried to put description in different places. I did a lot of things (do not wanna talk about them). Also I've tried to add info to enum values like so: + `0` (number) - Successful deletion. I do not know whether this problem deals with MSON syntax or Aglio generator.
The syntax above is supported by MSON as far as I can tell. The problem is that Aglio doesn't do anything with the description, and when I went to look into adding it I realized that it isn't really supported in JSON Schema. There seem to be two methods people use to get around that fact: Add the enumerated value descriptions to the main description, the Olio theme 1.6.2 has support for this but the C++ parser seems to still have some bugs around this feature: ## Video Delete (enum[number]) - 0 for success, 1 for error Use a weird oneOf syntax where you create sets of single enums with a description. I don't recommend this. Unfortunately the first option requires work on your part and can't easily be done in Aglio. Does anyone else have a better description and some samples of MSON input -> JSON Schema output?
Access translated i18n messages from Scala templates (Play! Internationalization)
In my Play! 2.0 application I would like to define the following languages: # The application languages # ~~~~~ application.langs=en-GB,de-DE,nl-NL I also have created 3 files that ends with the corresponding language codes: Messages.en-GB Messages.de-DE Messages.nl-NL When I start the application without any request for a translated key I get the following error message: conf/application.conf: 12: Key 'de-DE' may not be followed by token: ',' (if you intended ',' to be part of the value for 'de-DE', try enclosing the value in double quotes) Also when trying to access a message from the Scala template I still see the same message. I request the message by the following code: #Messages("login.page") The above changes I have done according to the Play manual: http://www.playframework.org/documentation/2.0/JavaI18N . So I have two questions: How can I set the default langauge and change it like in 1.2.4 (Lang.change("en-GB")) How to access the messages from the Scala templates?
In your scala file use: <h1>#Messages("pack.key")</h1> And in your java file use : String title = Messages.get("pack.key"); Don't forget to add quote around your language list : conf/application.conf application.langs="en-GB,de-DE,nl-NL"
Changing the language is not possible in Play! 2.0, see this discussion: http://groups.google.com/group/play-framework/browse_thread/thread/744d523c169333ac/5bfe28732a6efd89?show_docid=5bfe28732a6efd89 and this ticket: https://play.lighthouseapp.com/projects/82401-play-20/tickets/174-20-i18n-add-ability-to-define-implicit-lang-for-java-api#ticket-174-4 Although, when you register multiple languages you should enclose them in double qoutes, like this: application.langs="en-GB,de-DE,nl-NL" And then you can access them from the scala templates like this: #Messages.get("login.title") So currently the default language is the language that is defined in the file messages (without any prefix!!) Or you can just use #Messages("not.logged.in")
How can I extract/parse from this SOAP envelope using Ruby?
I am using a gem which uses soap/wsdlDriver. When I post I get back a SOAP response and am unable to easily parse it. This is the response I get back: #<SOAP::Mapping::Object:0x159e95faf098 {}id="27b907f8-da51-f611-ab02-4c5f88a8ec8 8" {}error=#<SOAP::Mapping::Object:0x159e95fae33c {}number="0" {}name="No Error" {}description="No Error">> I need to get the entire value in the id="xxxx" This is what on get on heroku (note: it works locally). This comes from testing various variations of response.id (where response.inspect is what created the output above) f" {}error=#> response[id] /disk1/home/slugs/220752_47a08bb_10e7/mnt/app/controllers/sugarcrm_controller.rb :77: warning: Object#id will be deprecated; use Object#object_id nil response.id: /disk1/home/slugs/220752_47a08bb_10e7/mnt/app/controllers/sugarcrm_controller.rb :79: warning: Object#id will be deprecated; use Object#object_id 23891500658740 /disk1/home/slugs/220752_47a08bb_10e7/mnt/app/controllers/sugarcrm_controller.rb :80: warning: Object#id will be deprecated; use Object#object_id this is the contact_id: 23891500658740 events:
Ok, I'm 95% sure that is the output of SOAP::Mapping::Object#inspect and not the actual response. And from that class it looks you use the [] method to pull out attributes. So if I am reading that right, then it looks like you might want: response_id = response_object['id'] Though each attribute being prefaced with {} seems pretty odd. So if that is actually part of the attribute name, you may need: response_id = response_object['{}id'] But that seems pretty strange, and may indicate that the SOAP library you are using is not parsing the response properly. Disclaimer: I've never used this lib before, and posted this from just perusing the docs... This may or may not be very accurate in the ways using this class is described.
I don't know how to do this with ruby, but may be like this code in javascript. var t = "<SOAP message........>"; var id = t.replace(/.*id=\"(.*?)\".*/, "$1"); Regex details: .*id=\"(.*?)\".* .* = anything, 0 or N times. (.*?) = anything, 0 or N times, stopping at first match. $1 = first group, the content inside (). So, everthing will be replaced by id content.