Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Aniket21mathur/messagefield
Add support for Message fields
- Loading branch information
Showing
15 changed files
with
350 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2020 Hewlett Packard Enterprise Development LP | ||
* Copyright 2004-2019 Cray Inc. | ||
* Other additional copyright holders may be indicated within. | ||
* | ||
* The entirety of this work is licensed under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <message_field.h> | ||
|
||
namespace chapel { | ||
|
||
MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor) | ||
: FieldGeneratorBase(descriptor) { | ||
} | ||
|
||
MessageFieldGenerator::~MessageFieldGenerator() { | ||
} | ||
|
||
void MessageFieldGenerator::GenerateMembers(Printer* printer) { | ||
printer->Print( | ||
variables_, | ||
"var $name$: $type_name$;\n" | ||
); | ||
} | ||
|
||
} // namespace chapel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2020 Hewlett Packard Enterprise Development LP | ||
* Copyright 2004-2019 Cray Inc. | ||
* Other additional copyright holders may be indicated within. | ||
* | ||
* The entirety of this work is licensed under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef PB_MESSAGE_FIELD_HH | ||
#define PB_MESSAGE_FIELD_HH | ||
|
||
#include <google/protobuf/io/printer.h> | ||
#include <google/protobuf/descriptor.h> | ||
|
||
#include <field_base.h> | ||
|
||
namespace chapel { | ||
|
||
using namespace google::protobuf; | ||
using namespace google::protobuf::io; | ||
|
||
class MessageFieldGenerator : public FieldGeneratorBase { | ||
public: | ||
MessageFieldGenerator(const FieldDescriptor* descriptor); | ||
~MessageFieldGenerator(); | ||
|
||
void GenerateMembers(Printer* printer); | ||
}; | ||
|
||
} // namespace chapel | ||
|
||
#endif /* PB_MESSAGE_FIELD_HH */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2020 Hewlett Packard Enterprise Development LP | ||
* Copyright 2004-2019 Cray Inc. | ||
* Other additional copyright holders may be indicated within. | ||
* | ||
* The entirety of this work is licensed under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <repeated_message_field.h> | ||
|
||
namespace chapel { | ||
|
||
RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator( | ||
const FieldDescriptor* descriptor) | ||
: FieldGeneratorBase(descriptor) { | ||
} | ||
|
||
RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() { | ||
|
||
} | ||
|
||
void RepeatedMessageFieldGenerator::GenerateMembers(Printer* printer) { | ||
printer->Print(variables_, "var $name$: list($type_name$);\n"); | ||
} | ||
|
||
} // namespace chapel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2020 Hewlett Packard Enterprise Development LP | ||
* Copyright 2004-2019 Cray Inc. | ||
* Other additional copyright holders may be indicated within. | ||
* | ||
* The entirety of this work is licensed under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef PB_REPEATED_MESSAGE_FIELD_HH | ||
#define PB_REPEATED_MESSAGE_FIELD_HH | ||
|
||
#include <google/protobuf/io/printer.h> | ||
#include <google/protobuf/descriptor.h> | ||
|
||
#include <field_base.h> | ||
|
||
namespace chapel { | ||
|
||
using namespace google::protobuf; | ||
using namespace google::protobuf::io; | ||
|
||
class RepeatedMessageFieldGenerator : public FieldGeneratorBase { | ||
public: | ||
RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor); | ||
~RepeatedMessageFieldGenerator(); | ||
|
||
void GenerateMembers(Printer* printer); | ||
}; | ||
|
||
} // namespace chapel | ||
|
||
#endif /* PB_REPEATED_MESSAGE_FIELD_HH */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
syntax = "proto3"; | ||
|
||
message messageA { | ||
messageB a = 1; | ||
repeated messageC f = 2; | ||
} | ||
|
||
message messageB { | ||
int64 b = 1; | ||
string c = 2; | ||
} | ||
|
||
message messageC { | ||
int32 d = 1; | ||
bool e = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use messagefield; | ||
use IO; | ||
use List; | ||
|
||
var messageObj = new messageA(); | ||
var file = open("out", iomode.r); | ||
var readingChannel = file.reader(); | ||
|
||
messageObj.parseFromInputFile(readingChannel); | ||
|
||
writeln(messageObj.a.b == 150); | ||
writeln(messageObj.a.c == "String with spaces"); | ||
writeln(messageObj.f[0].d == 26); | ||
writeln(messageObj.f[0].e == true); | ||
writeln(messageObj.f[1].d == 36); | ||
writeln(messageObj.f[1].e == false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import messagefield_pb2 | ||
|
||
messageObj = messagefield_pb2.messageA() | ||
|
||
file = open("out", "rb") | ||
messageObj.ParseFromString(file.read()) | ||
file.close() | ||
|
||
if messageObj.a.b != 150 or messageObj.a.c != "String with spaces": | ||
print("false") | ||
else: | ||
print("true") | ||
|
||
if messageObj.f[0].d != 26 or messageObj.f[0].e != True: | ||
print("false") | ||
else: | ||
print("true") | ||
|
||
if messageObj.f[1].d != 36 or messageObj.f[1].e != False: | ||
print("false") | ||
else: | ||
print("true") |
Oops, something went wrong.