What is the initial value of Ethereum contract variables? - ethereum

I make some contracts code with mapping data. When I first access data value, ethereum returns 0.
Is it specification of ethereum? In other word, Can I write a contract on the assumption that variable's initial value is 0?

Yes, this is the default behavior. Each types have a "zero-state" default value.
For example boolean have a default value of false, integer a default value of 0 and strings a default value of ""
You can read more here http://solidity.readthedocs.io/en/develop/control-structures.html#default-value

Related

How to print null fields as `"myField": null` in JSON from protobuf messages?

Due to complications of legacy API dependencies, I need to print json objects with explicit "myField": null, and not omitting it. I have not found a proper way to generate such a result with JsonFormat.
The language guide mentioned Wrappers use the same representation in JSON as the wrapped primitive type, except that null is allowed and preserved during data conversion and transfer. I played a bit with the StringValue and friends, which seemed to be compiled differently than other regular proto messages (I'm using java). But still I found no way to set null as the value, either as the value of the wrapper class, or as the value of the field with the wrapper type in the parent class. Without setting field myField, the JsonFormat.printer().includingDefaultValueFields().print(message); seems to skip the field completely from the output.
What does null is allowed and preserved mean?
I am aware of google.protobuf.Value, which indeed can print "myField": null correctly, with setting the NullValue as the oneof field. However, if I get it right, this Value essentially erases the type info in proto files -- you can choose to assign almost any data to it. The checks happens in code, not in the definition. This is not something I'd prefer, unless there are no other options.
And I also tried to create my own nullable types, by removing unwanted types from google.protobuf.Value, e.g.
message NullableString {
oneof kind {
google.protobuf.NullValue null_value = 1;
string value = 2;
}
}
And the output would be like this:
"stringValue": {
"nullValue": null
}
So this does not have the blessing of google.protobuf.Value which would print "stringValue": null directly.
Are there any way to print null values in json that preserves type info in proto?

Get "Value" from simple JSON using "Key" as variable Azure Logic Apps

I have defined a simple JSON
{
"12345": "Numbers",
"AAAAA": "AllAs",
"ABCXYZ": "AtoZ"
}
All I want to extract the value of "Key" when passed as a variable. I have tried body('Parse_JSON')['name'] but its failing.
I just want to get the value of what ever Key I am looking for as variable.
For those also just starting with logic apps - if its not immediately apparent;
At "Initialize Variable 2" you need to use the "Expression" tab to input the line
body('parse_JSON')?[variables('name')]
As per your comment as you are initializing ABCXYZ value and that you have already declared in inputs you can just type ABCXYZ in value rather than calling Name variable
Figured it !
body('parse_JSON')?[variables('name')]
The above does the following:
1- body('parse_JSON') gets the body of Parsed JSON
2- ?[variables('name')]gets the value of name which is equal to ABCXYZ
3- Returns AtoZ
I just want to add something here as I was looking for a way to use a dynamics value passed in to then use that to look up in a json body to translate that value to a different.
Mapping value eg. {"male":"M", "female":"F", "Non-Specific":"O"}
So I receive the value "Male" but I need that to return as M
to achieve this in a logic app the above partially gets you there.
body('Parse_JSON_gender_mapping')?[string(variables('received_gender'))]
I had to wrap my use of the variable for the value we received in string() function, even though the value was a string.

What is the JSON Standard for an empty string or null variable?

I'm building an application that parses a JSON template and then replaces the values of the objects with new data. My question is what is the standard way to represent empty data in JSON?
This is how I'm handling this right now:
an empty string is represented as " "
an empty int/float/double/bool/etc. is represented as NULL
Is this correct?
It should be pretty straight forward.
{
"Value1": null,
"Value2": null,
}
Null represents a null-able datatype so your business layer needs then to know if that is an int, double, string ...
It is entirely up to you.
The falsy values in JavaScript are:
false
null
undefined
0
NaN
'' or ""
You can use any of these to represent an empty value. However, keep in mind that when you try to access an object's property which doesn't exist, you will get undefined. So undefined can be considered the standard null value, in a way.
Having said that, one convention is to use null so that you can distinguish a property that has been intentionally set to null from a property that is actually undefined.

discrepancy in CRX property data types in AEM

While configuring mail service com.day.cq.mailer.DefaultMailService, I came to know that SMTP port should be an integer (smtp.port=I"465").
But if I try configuring using sling:OsgiConfig node, as the CRX is not providing Integer for data type (only Decimal, Double and Long), I am not able to achieve this.
Is there any alternative?
Use String type in sling:OsgiConfig node to give the smtp:port in CRX/DE. This is internally processed by DefaultMailService.
If we see the DefaultMailService implementation smtp.port is String, is processed by annotations
#Property(intValue={25})
private static final String SMTP_PORT = "smtp.port";
Sandeep is wrong, the internal representation is not String. The SMTP_PORT variable is of type String, because it holds a label and not the field value.
The actual value is of type int.
But you can set the value to Long in crx.de, because the value will be internally cast to int then.
String might also work, but I did not test that.

is it possible to have a input argument as output in JNI?

is it possible to have a input argument as output argument in JNI ?
Suppose I have :
void average(jint n1,jint n2,jint av);
av as output and why not input.
Not in that fashion, no.
In order for the callee to modify an argument, it must have a reference (i.e. pointer) to that argument. jint and other primitives are passed by value, which means that the value of the argument is passed from one location (memory or register) to another. Any changes made by the callee to that argument are made to the last element in the chain, which obviously has no effect on the places it was copied from.
In order to have an argument "modified", you have to pass a reference (pointer) to it instead. The most straightforward way of doing this in Java is to pass a single-element primitive array, and have the callee replace the first element with the "returned" value.
It's usually just easier to return the value, or an aggregate object which contains multiple return values.