Protobuf equivalent of JsonHttpClient? - servicestack

is there an equivalent of the new (-ish) JsonHttpClient that uses protobuf-net instead of JSON ? I realize that the old-style ProtobufServiceClient exists, but I'd like to replace it with something that uses HttpClient, instead of the old HttpWebRequest.
If such a client does not exist, how hard would it be to write one ? Should I just copy/paste JsonHttpClient.cs and change a few things, or is there a better way ?

No there isn't another ServiceClient for ProtoBuf other than ProtobufServiceClient. The easiest approach would be to take a copy of JsonHttpClient and modify it to use ProtoBuf, but JsonHttpClient wasn't designed to support multiple Content Types so it's not going to be as straight-forward as implementing a new ServiceClient.

Related

Custom type conversion in Karate

As Karate supports type conversion, I was wondering if it is possible to write a custom type conversion in such a way that I could write something similar to this in my .feature file
customType customTypeResponse = response
which should have the same semantic as
yaml yamlResponse = response
but for customType instead of yaml.
I think I found the code enabling the custom type conversion. But I am not sure about the extensibility.
Thus the shortest way might be to use the Java interop enabling something like this
def customTypeResponse = CustomType.convert(response)
Please let me know of any possibiliy of type conversion.
Yes, I strongly suggest just using Java interop and not complicating it further for now. Maybe in the future we'll have a better way to do contribute custom syntax (hint: look for the Plugin interface and how karate-robot uses it).

Creating libraries that can be imported and used in Groovy

Currently, I am working on a project to transpile from my company's in house scripting language, which is Object Orientated and takes quite a few features from other languages, into Groovy, which has many similar features.
To keep code as close to original as possible, I am trying to leave certain function names and parameters the same. To cater for this, I would like to write a set of libraries that can be imported.
For example, say I have an inbuilt method in the original scripting language,
I would like to be able to write the definition for this method in a groovy file, that can then be imported when needed, and the method may be called.
Tools.groovy
// filename: Tools.groovy
public String foo(String bar) {
return bar;
}
and in another file
Main.groovy
// filename: Main.groovy
import Tools;
String bat = foo("bar")
I know you can can compile class files into jars and put them into the class path, but a lot of the methods I will need to implement will either require meta programming or won't be associated with an object.
Sorry if it's either a bad question or not clear enough. I'm not sure whether its even possible.
Cheers
I believe you should be able to create libraries and reuse them when needed.
All you need to do is create class and add the static methods if you do not have to create instances, non static methods otherwise. Then it looks like you already aware how to proceed later.
For instance, you can create utilities classes for String, List, etc based on your description.
By the way, even if you do not create libraries, it is even possible to write one lines in groovy achieve what you may needed most of the cases.

Using NSJSONSerialization with swift on ubuntu/linux

Is it possible to parse JSON using NSJSONSerialization when running swift on ubuntu? Since foundation is available I am assuming it should be?
If not, Is there any other way of serialising and deserialising JSON in swift on linux?
NSJSONSerialization is partly implemented (serialization is not yet implemented)
do it yourself, in accordance with your needs, and you will see, that it is the best investment and great way to understand Swift and its possibilities. you can also use one of the opensource libraries available around. SwiftyJSON is very popular, for an example
As mentioned by Sebastian OsiƄski, unfortunately it use NSJSONSerialization too.
you can check this very simple, but working example swift json. it is far away to be 'perfect', but as an inspiration it could help you, i hope so.
I am using TidyJSON for this, because it combines much of the ease of SwiftyJSON but does not rely on NSJSONSerialization for parsing. It works wherever Swift works, and I'm using it just fine in my current Swift/Ubuntu projects.
If you're using the server side Swift framework "Perfect", You can do something like this to convert "data" (Binary) type to "JSONConvertable" (Swift Arrays etc) object types.
do{
let jsonObject = try String.init(data: jsonData, encoding: .utf8)?.jsonDecode()
print("\(jsonObject as! [String])")
}catch{
response.completed(status: .badRequest)
return
}

Java Card program using GPJ

So I was tasked to create a java client to communicate with java card.
Right now I can authenticate, write and read data using javax.smartcardio but having a bit of trouble trying to upload cap file and install it.
So after googling around, I found that I can use gpj as a library and use it in my java application to upload and install the cap file.
The problem is I can't find any documentation for gpj and I can't understand the code without one.
Here's one that I have trouble to understand public void installAndMakeSelecatable(AID paramAID1, AID paramAID2, AID paramAID3, byte paramByte, byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
Even when I look on the other part of the code, I can't find out the last parameter since all that use these method will pass null.
So if anyone know where can I find the documentation, I would be really glad. Or better yet, another library that can upload cap file and have some documentation with it.
so far, I've found gpj,jpcsc,jcManager and opal.
Nevermind, it seems that I'm not a clever guy.
For future reference, you can find out what to pass to what method by looking through the main method of the Global Platform Services class. For parameter that you are not sure what to pass, just use null.

Mono.Cecil Modifying the RVA of a method

I would like to modify the RVA of a method using Mono.Cecil. I noticed a similar question asked back in 2007 but is this doable in 0.95?
For eg: methodA.RVA = 0x1234;
I understand Mono.Cecil compute and write RVA during compilation but
are there anyways to go about modifying the RVA?
It can be done using CFF explorer though.
Thank You.
No this is not possible: that's simply not the goal of Mono.Cecil.
Cecil let you read, modify and write the managed code and metadata, but when it comes to the PE file organization, that's considered an implementation detail.

Resources