how we can parse proto file if it having "." and "-" sign - protocol-buffers

I create one proto file using java and another using python when I put "." and "-" sign in proto file message field name it shows error that is "missing field number". I m not able to parse that file. and if proto file not accept this character please can share list of character which proto file not accept.

Please find the protobuf documentation on proper syntax for defining messages in protos.
. is used for selecting an attribute of an object in python, so obviously one shouldn't use it in message fields of proto. Instead You can use _ as character for separating words in a single field name.
A small Sample for you :
syntax = "proto3";
message SearchRequest {
string query = 1;
int32 page_number = 2;
int32 result_per_page = 3;
}

Related

regex as protobuf message field name?

can we define regular expression in protobuf field name? I send the request as list of dictinary in client.py file
"cur_cur_bin" : [{"cur_cur_bin1_bin3_bin1" : 4,"cur_cur_bin3_bin5_bin8" : 6} ]
I defined .proto file like,
int32 cur_cur_bin1_bin3_bin1 = 1;
}
message Message{
repeated cur_cur_BIN cur_cur_bin = 1;
}```
any one can explain how to define this type of field in .proto file dynamically. because
(bin1) having some range like (1 - [1-8]) same for (bin3) like (3 -[8-11]) like this.
No, as far as I know there is no mechanism to generate field names automatically or dynamically in protoc.
You can create messages dynamically through the python-protobuf reflection API, but that probably doesn't make sense for your usecase.
Instead define a reasonable .proto format, and then write some custom Python code to convert your JSON data to that.

can .proto file fields be without values?

I received "missing field number" error. Is it possible to declare fields without value? since i do not have a default value to the fields.
syntax = "proto3";
package tutorial;
message Person {
required string name;
required string email;
}
The field number is not refer to a default value but each field in the message definition has a unique number. These numbers are used to identify your fields in the message binary format, and should not be changed once your message type is in use.
More info here in the doc

Escaping underscore in SSIS

I have an SSIS expression.as per below:
I am sending the results of this package as an sms,however the sms does not show the underscores,I have therefore opted to using dashes for now.
The sms is showing at as OLEGALINITTEST
I there a way i can escape the underscore so that it shows on the sms?
REPLACE(#[System::PackageName], "_", "-") = O-LEGAL-INIT-TEST
Desired output is O_LEGAL_INIT_TEST
I am replacing the underscore's in the string with "-" dashes .I am sending the variable to an Oracle package that send the actual sms.
#[System::PackageName] is generally the same as the file name without the file extension so given a package named This-Is-Fun.dtsx we would expect to see the PackageName property as This-Is-Fun.
But, there are cases where this not the case. If we named our package A=B.C_D.dtsx, the resulting object name for our package is A B C_D. Each offending character is replaced with spaces.
If you attempt to name an SSIS object with "something weird" it will throw an error on the operation like
The name cannot contain any of the following characters: / \ : [ ] . =
The restrictions are similar, but different, for the package name itself as Windows/Visual Studio will balk with
contain any of the following characters: / ? : & \ * " < > | # %
contain Unicode control characters contain invalid surrogate
characters be system reserved names, including 'CON', 'AUX', 'PRN', 'COM1'
or 'LPT2' be '.' or '..'
As always with expressions in SSIS, check what you're building. Create an SSIS Variable where you specify an expression.
Assuming you create an SSIS variable called SMS_CONTENT data type of string and then I'm going to replace spaces with underscores. The expression is
REPLACE(#[System::PackageName], " ", "_")
Given a starting package name of
a=b.SO_61618859_This_Is_Fun.dtsx
System::PackageName becomes a b SO_61618859_This_Is_Fun
SMS_CONTENT becomes a_b_SO_61618859_This_Is_Fun
If it works fine during development but goes awry in production, log the value via a script task's information event so you can review logs after the run. https://billfellows.blogspot.com/2016/04/biml-script-task-test-for-echo.html You don't need to Biml it, just mark the variable as part of the Read only variable collection and the following script will record the values in the log. In your case, I'd add System::PackageName and then my SSIS variable, User::SMS_CONTENT
bool fireAgain = false;
string message = "{0}::{1} : {2}";
foreach (var item in Dts.Variables)
{
Dts.Events.FireInformation(0, "SCR Echo Back", string.Format(message, item.Namespace, item.Name, item.Value), string.Empty, 0, ref fireAgain);
}

How do I make protobuf case-insensitive?

I have a protobuf contract like this,
message Car{
string carId = 1;
}
I generate java classes from this contract and use it to parse JSON request.
Now if my JSON has "CarID" or "carid" then protobuf generated java classes don't recognize that field. How do I make it case-insensitive?
The protobuff descriptor (.proto) are case insensitive. If you try to compile:
message Car{
string carId = 1;
string carid =2;
}
You will have the compilation error:
CARID_FIELD_NUMBER is already defined in ...
Also you have to know that for proto3, the JSON parser are dealing with lowerCamelCase. As stated on reference guide:
https://developers.google.com/protocol-buffers/docs/proto3#json
Use proto field name instead of lowerCamelCase name: By default proto3
JSON printer should convert the field name to lowerCamelCase and use
that as the JSON name. An implementation may provide an option to use
proto field name as the JSON name instead. Proto3 JSON parsers are
required to accept both the converted lowerCamelCase name and the
proto field name.
From your parser point of view "carID" and "CarID" are the same, because it will automatically convert "CarID" to "carID". But "carId" and "carid" will always be different.

Could protobuf read text file which has no schema but just data?

For example, the proto file is like this.
message {
required int key = 1;
repeated int value = 2;
}
The text file is like this where the first column indicates key while the others indicates the repeated value.
3391 [ 4847 3948 4849 ]
9483 [ 4938 48497 71 ]
...
Could protobuf read and parse this text file?
No, protobuf has no support for custom text formats.
You'll have to write custom parser code for it, which can then convert to protobuf or whatever other representation you might want.

Resources