How to convert string to Uuid in dart - dart

Is there any thing in dart that has similar functionally to java or C# to convert a string to a Uuid for example something like:
Uuid test = Uuid.parse('797ff043-11eb-11e1-80d6-510998755d10');
or
Uuid test = Uuid.FromString('79700043-11eb-1101-80d6-510900000d10');
Thanks.

The uuid package returns a List object:
List<int> bytes = Uuid.parse('79700043-11eb-1101-80d6-510900000d10');
It doesn't use Uuid as an obtainable object but an "Universally Unique IDentifier" (UUID) as a string or as a byte array.

Related

Json String to Map<> or List

I have a json stored as string like below
String json="[{"name":"a","id",1},{"name":"b","id",2},{"name":"c","id",3}]";
My Question how to encode this to a map or a list to get access to the keys and use the values?
You need to JSON-decode the value first
import 'dart:convert';
final decoded = jsonDecode(json);
print(decoded[0]['name']); // just one example

Siddhi stream schemaless data

I have a source data from ActiveMQ, the problem that I have is that these data do not have a fixed structure, therefore, when I define the stream it throws an incompatible datatype error, is there any way to condition the source stream by some condition?
Thanks in advance.
/*
* Origin of data.
*/
#source(type='jms',
#map(type='csv', delimiter=',', fail.on.unknown.attribute='false'),
factory.initial='org.apache.activemq.jndi.ActiveMQInitialContextFactory',
provider.url='tcp://127.0.0.1:61616',
destination='simulatedData',
connection.factory.type='queue',
connection.factory.jndi.name='QueueConnectionFactory',
transport.jms.SubscriptionDurable='true',
transport.jms.DurableSubscriberClientID='wso2SPclient1')
define stream FileSourceProductionStream(type string, time long, studentId string, fileId string, totalAccesses float); /* totalAccesses : float Incompatible DataType*/
define stream TaskSourceProductionStream(type string, time long, studentId string, taskId string, deadline long); /*deadline: long Incompatible DataType*/
In siddhi, the source stream should have the schema of the input data. Therefore, we cannot have received schemaless data to a defined stream.
One possible solution for your scenario is defining a stream with all the possible input attributes and pre-format the input to a JSON[1], XML[2] or TEXT[3] formats which are supported by the siddhi-map extensions, with attribute names and values. For missing attributes, there won't be a key or a tag in the json/xml/text input payload.
Then use #map(fail.on.missing.attributes='false) configuration in the source config.
Then for all the missing attributes in the input payload, NULL will be assigned to the corresponding attribute of the input stream.
[1] https://wso2-extensions.github.io/siddhi-map-json/api/4.0.20/
[2] https://wso2-extensions.github.io/siddhi-map-xml/api/4.0.12/
[3] https://wso2-extensions.github.io/siddhi-map-text/api/1.0.16/

Extract case-insensitive query parameter from URL

I am trying to extract the case-insensitive query parameter /staging/ec/23463/front-view-72768.jpg?angle=90&or=0x0&wd=400&ht=200 from the URL. When I try to convert the whole URL in lowercase it throws the following exception :
cannot use r.URL (type *url.URL) as type string in argument to strings.ToLower
I printed the value of URL which says underlying it stores all the query strings as map i.e. map[angle:[90] or:[0x0] wd:[400] ht:[200]]. Hence I will get the correct value using this r.URL.Query().Get("or") But if query string comes out Or. It will fail.
*URL.Query() returns a value of type url.Values, which is just a map[string][]string with a few extra methods.
Since URL values are by definition case-sensitive, you will have to access the map directly.
var query url.Values
for k, vs := range query {
if strings.ToLower(k) == "ok" {
// do something with vs
}
}
Try it on the playground: https://play.golang.org/p/7YVuxI3GO6X
cannot use r.URL (type *url.URL) as type string in argument to strings.ToLower
This is because you are passing ur.URL instead of string. Get the string from url through String() function.
url.String()

decode msgpack in redis lua

public class MsgPackInRedis {
private String ip;
private int port;
private String session;
private String protocol;
}
MsgPackInRedis msgPackStringInRedis = new MsgPackInRedis();
I encode a java object msgPackStringInRedis of class MsgPackInRedis with msgpack, then store in redis.
And I want to decode that in lua, which runs in redis, how can I get "session" ?
Can I do like this below, get session by index 3?
local msgPackObject = cmsgpack.unpack(msgPackStringInRedis)
local session = msgPackObject[3]
MessagePack is an encoding - think non-easily-readable JSON. In fact, this website does a back and forth translation between the two: http://kawanet.github.io/msgpack-lite/
Feeding your (0x94 0xc0 0x00 0xa4 0x41 0x42 0x43 0x44 0xc0) to the above website, you can see the JSON representation which looks like:
[
null,
0,
"ABCD",
null
]
You can test that in Redis' Lua as well, e.g. (note that Lua 5.1 accepts decimal byte representation, hence the different representation of the same payload in the example):
$ redis-cli EVAL "return(cmsgpack.unpack('\148\192\00\164\65\66\67\68\192')[3])" 0
"ABCD"
So frankly, I see no issue with your code. What is the problem that you are experiencing exactly?
Assuming that your MessagePack-ed data is stored in the String key called foo, this would do your bidding:
EVAL "return cmsgpack.unpack(redis.call('GET', KEYS[1]))" 1 foo
Note : the above assumes that the data is serialized as arrays. Returning an object will not work as Redis' protocol doesn't support that.

getting error updating the sqlite

I am doing the project and I am structed in database path. I am using the sqlite database for storing. In this my problems is when I updating the table it showing the error. For database part I am using prewritten classes. I am calling that class method whenever I need. See below you can understand.
This below code is working fine
[DataCachingHelper updateTable:#"sendertable" data:dic3 where:#"MESSAGE_ID='1234'"];
but when I am sending the object to the "where", It showing some error.
[DataCachingHelper updateTable:#"sendertable" data:dic3 where:#"MESSAGE_ID=%#",#"hai"];
i am getting the error:
"too many arguments to methods call expected 3,have 4".
here MESSAGE_ID is VARCHAR TYPE
The issue is clear here. You can not pass string format because compiler compiles parameter before converting into string format. From your method declaration allowed parameters must be 3.
So compiler detect 4 parameter as you pass string with format.
Also in sqlite database for VARCHAR type field use double quotes for field values.
So your string should be like this:
NSString *whereClauseString = [NSString stringWithFormat:#"MESSAGE_ID = \"%#\"",#"hai"];
Or if value is pre known simply create string like this:
NSString *whereClauseString = #"MESSAGE_ID = \"hai\"";
And then use this string as third parameter for updateTable method:
[DataCachingHelper updateTable:#"sendertable" data:dic3 where:whereClauseString];
make this in two step.
NSString *strWhere=[NSString stringWithFormat:#"MESSAGE_ID='%#'",#"hai"];
[DataCachingHelper updateTable:#"sendertable" data:dic3 where:strWhere];

Resources