Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for 2D string arrays similar to 2D double arrays. #407

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ add_library(labview_grpc_server SHARED
src/message_element_metadata_owner.cc
src/message_metadata.cc
src/unpacked_fields.cc
src/well_known_types.cc
src/well_known_messages.cc
)
target_link_libraries(labview_grpc_server
${_REFLECTION}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
<Item Name="NI_LVConfig.lvlib" Type="Library" URL="/&lt;vilib&gt;/Utility/config.llb/NI_LVConfig.lvlib"/>
<Item Name="8.6CompatibleGlobalVar.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/config.llb/8.6CompatibleGlobalVar.vi"/>
<Item Name="Is Path and Not Empty.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/file.llb/Is Path and Not Empty.vi"/>
<Item Name="Remove Duplicates From 1D Array.vim" Type="VI" URL="/&lt;vilib&gt;/Array/Remove Duplicates From 1D Array.vim"/>
</Item>
<Item Name="Arrange VIWin - Window Margins.ctl" Type="VI" URL="/&lt;resource&gt;/dialog/QuickDrop/plugins/_Arrange VIWin SubVIs/Arrange VIWin - Window Margins.ctl"/>
<Item Name="Arrange VIWin - Min Window Dimensions.ctl" Type="VI" URL="/&lt;resource&gt;/dialog/QuickDrop/plugins/_Arrange VIWin SubVIs/Arrange VIWin - Min Window Dimensions.ctl"/>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified labview source/gRPC lv Support/Shared/To Message Name.vi
Binary file not shown.
Binary file modified labview source/gRPC lv Support/Shared/To Well Known Type.vi
Binary file not shown.
Binary file modified labview source/gRPC lv Support/Shared/Well Known Types.ctl
Binary file not shown.
8 changes: 8 additions & 0 deletions labview source/gRPC lv Support/grpc-labview.lvproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version='1.0' encoding='UTF-8'?>
<Project Type="Project" LVVersion="19008000">
<Property Name="NI.LV.All.SaveVersion" Type="Str">19.0</Property>
<Property Name="NI.LV.All.SourceOnly" Type="Bool">true</Property>
<Property Name="NI.Project.Description" Type="Str"></Property>
<Item Name="My Computer" Type="My Computer">
<Property Name="server.app.propertiesEnabled" Type="Bool">true</Property>
<Property Name="server.control.propertiesEnabled" Type="Bool">true</Property>
Expand Down Expand Up @@ -28,8 +31,10 @@
<Item Name="Dependencies" Type="Dependencies">
<Item Name="vi.lib" Type="Folder">
<Item Name="1D String Array to Delimited String.vi" Type="VI" URL="/&lt;vilib&gt;/AdvancedString/1D String Array to Delimited String.vi"/>
<Item Name="8.6CompatibleGlobalVar.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/config.llb/8.6CompatibleGlobalVar.vi"/>
<Item Name="Application Directory.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/file.llb/Application Directory.vi"/>
<Item Name="BuildHelpPath.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/BuildHelpPath.vi"/>
<Item Name="Check if File or Folder Exists.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/libraryn.llb/Check if File or Folder Exists.vi"/>
<Item Name="Check Special Tags.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Check Special Tags.vi"/>
<Item Name="Clear Errors.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Clear Errors.vi"/>
<Item Name="Convert property node font to graphics font.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Convert property node font to graphics font.vi"/>
Expand All @@ -54,15 +59,18 @@
<Item Name="LVRectTypeDef.ctl" Type="VI" URL="/&lt;vilib&gt;/Utility/miscctls.llb/LVRectTypeDef.ctl"/>
<Item Name="NI_Data Type.lvlib" Type="Library" URL="/&lt;vilib&gt;/Utility/Data Type/NI_Data Type.lvlib"/>
<Item Name="NI_FileType.lvlib" Type="Library" URL="/&lt;vilib&gt;/Utility/lvfile.llb/NI_FileType.lvlib"/>
<Item Name="NI_LVConfig.lvlib" Type="Library" URL="/&lt;vilib&gt;/Utility/config.llb/NI_LVConfig.lvlib"/>
<Item Name="NI_PackedLibraryUtility.lvlib" Type="Library" URL="/&lt;vilib&gt;/Utility/LVLibp/NI_PackedLibraryUtility.lvlib"/>
<Item Name="Not Found Dialog.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Not Found Dialog.vi"/>
<Item Name="Search and Replace Pattern.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Search and Replace Pattern.vi"/>
<Item Name="Set Bold Text.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Set Bold Text.vi"/>
<Item Name="Set String Value.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Set String Value.vi"/>
<Item Name="Simple Error Handler.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Simple Error Handler.vi"/>
<Item Name="Space Constant.vi" Type="VI" URL="/&lt;vilib&gt;/dlg_ctls.llb/Space Constant.vi"/>
<Item Name="TagReturnType.ctl" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/TagReturnType.ctl"/>
<Item Name="Three Button Dialog CORE.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Three Button Dialog CORE.vi"/>
<Item Name="Three Button Dialog.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Three Button Dialog.vi"/>
<Item Name="Trim Whitespace One-Sided.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Trim Whitespace One-Sided.vi"/>
<Item Name="Trim Whitespace.vi" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/Trim Whitespace.vi"/>
<Item Name="whitespace.ctl" Type="VI" URL="/&lt;vilib&gt;/Utility/error.llb/whitespace.ctl"/>
</Item>
Expand Down
5 changes: 3 additions & 2 deletions labview source/gRPC lv Support/grpc-lvsupport.lvlib
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Library LVVersion="19008000">
<Property Name="NI.Lib.Icon" Type="Bin">'1#!!!!!!!)!"1!&amp;!!!-!%!!!@````]!!!!"!!%!!!+F!!!*Q(C=\:3`&lt;B."%)&gt;`2EB/3L]"MH!&amp;6/05.+\471J62$-3%D1U,EG"B(G%+5+6.#9H2&lt;37Y!8G&amp;6T15#%,GJ1=X^WN4#Q"13)3&amp;.HVX*`@\-R]HFW&gt;V)Y&gt;[&lt;;K0R\(B$SI4OYWV_L.R96[D\&lt;^O^8:`N\*`?K5[_DAI$INDL.^^5?DVRN`&gt;4TG_6,A4H83_,P]&lt;@TR_,*`8,XNYJ_03`XN_+P]OVX_X3:Z5\`C@@SD!HTXNPCK\P^J\R,CTK]&lt;1]H_Y?(6$@TZU'`(D@`'`X@_KY`@5@W0B^34GHN&gt;*R;99[&lt;'63&gt;[IC&gt;[IC&gt;[IA&gt;[I!&gt;[I!&gt;[I$O[ITO[ITO[IRO[I2O[I2O[I&lt;=48?B#&amp;TJ&gt;39IHB:+E39*E-3B+,AF0QJ0Q*$S]+O&amp;*?"+?B#@B99E3HI1HY5FY%B\#F0!E0!F0QJ0QE+IFS8;CQZ0QE&amp;Y"4]!4]!1]!1]F&amp;@!%!%'R)('1"!Q&amp;TO!BY!FY!BY?&amp;@!%0!&amp;0Q"0QY&amp;&lt;!%`!%0!&amp;0Q%.)WZ6I;:K*$A^JZ0!Y0![0Q_0QE&amp;I/D]0D]$A]$A`FZ0!Y0![%5^"*$I+=)'?"]_,Q/$T=Z0!Y0![0Q_0QY'JXS.P/.$4.2)@(Y$&amp;Y$"[$R_!BB1Q?A]@A-8A-(N,+Y$&amp;Y$"[$R_#BF!Q?A]@A-5#-IJ38E=Q)."9:AM($LTUNVOZ3N#474KE=8J6$K8,96![2SO&amp;1W836T64:**8GKT26J6EK46$Z=SL1+D!K263#GY6;=VVB3WS"T&lt;%:.M5GW"!&lt;.+(8P(#^8GOV7GGZ8'KR7'A_HWMWGWE[H7ISG7AY('IQ''S_6H?9X?BNPEM@8`8LT_]?@HF[8F]]0K]`08H:W&lt;0X;"`[XV\5^&gt;@S(4EC\LKM_S\^$^^'X6*XX`4I/_NZFS%!!!!!</Property>
<Property Name="NI.Lib.SourceVersion" Type="Int">419463168</Property>
<Property Name="NI.Lib.Version" Type="Str">1.0.0.0</Property>
<Property Name="NI.LV.All.SourceOnly" Type="Bool">true</Property>
<Property Name="NI.SortType" Type="Int">3</Property>
Expand Down Expand Up @@ -73,7 +72,9 @@
<Item Name="Element to Enum Metadata.vi" Type="VI" URL="../Server API/Cluster to gRPC message/Element to Enum Metadata.vi">
<Property Name="NI.LibItem.Scope" Type="Int">2</Property>
</Item>
<Item Name="Element to Message Element Metadata.vi" Type="VI" URL="../Server API/Cluster to gRPC message/Element to Message Element Metadata.vi"/>
<Item Name="Element to Message Element Metadata.vi" Type="VI" URL="../Server API/Cluster to gRPC message/Element to Message Element Metadata.vi">
<Property Name="NI.LibItem.Scope" Type="Int">2</Property>
</Item>
</Item>
<Item Name="Message Requests" Type="Folder">
<Item Name="Complete Call.vi" Type="VI" URL="../Server API/Message Requests/Complete Call.vi"/>
Expand Down
24 changes: 16 additions & 8 deletions src/cluster_copier.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//---------------------------------------------------------------------
//---------------------------------------------------------------------
#include <cluster_copier.h>
#include <well_known_types.h>
#include <well_known_messages.h>
#include <lv_message.h>

namespace grpc_labview {
Expand Down Expand Up @@ -258,12 +258,12 @@ namespace grpc_labview {
auto repeatedString = static_cast<const LVRepeatedMessageValue<std::string>&>(*value);
if (repeatedString._value.size() != 0)
{
NumericArrayResize(GetTypeCodeForSize(sizeof(char*)), 1, start, repeatedString._value.size());
NumericArrayResize(GetTypeCodeForSize(sizeof(LStrHandle)), 1, start, repeatedString._value.size());
auto array = *(LV1DArrayHandle*)start;
(*array)->cnt = repeatedString._value.size();
int x = 0;
auto lvString = (*array)->bytes<LStrHandle>();
for (auto str : repeatedString._value)
for (auto& str : repeatedString._value)
{
*lvString = nullptr;
SetLVString(lvString, str);
Expand Down Expand Up @@ -297,7 +297,10 @@ namespace grpc_labview {
switch (metadata->wellKnownType)
{
case wellknown::Types::Double2DArray:
wellknown::Double2DArray::CopyToCluster(*(metadata.get()), start, value);
wellknown::Double2DArray::GetInstance().CopyFromMessageToCluster(*(metadata.get()), value, start);
return;
case wellknown::Types::String2DArray:
wellknown::String2DArray::GetInstance().CopyFromMessageToCluster(*(metadata.get()), value, start);
return;
}

Expand Down Expand Up @@ -664,15 +667,17 @@ namespace grpc_labview {
if (metadata->isRepeated)
{
auto array = *(LV1DArrayHandle*)start;
if (array && *array && ((*array)->cnt != 0))
auto arraySize = (*array)->cnt;
if (array && *array && (arraySize != 0))
{
auto repeatedStringValue = std::make_shared<LVRepeatedMessageValue<std::string>>(metadata->protobufIndex);
message._values.emplace(metadata->protobufIndex, repeatedStringValue);
auto lvStr = (*array)->bytes<LStrHandle>();
for (int x = 0; x < (*array)->cnt; ++x)
repeatedStringValue->_value.Reserve(arraySize);
for (int x = 0; x < arraySize; ++x)
{
auto str = GetLVString(*lvStr);
repeatedStringValue->_value.Add(str);
repeatedStringValue->_value.AddAlreadyReserved(std::move(str));
lvStr += 1;
}
}
Expand Down Expand Up @@ -915,7 +920,10 @@ namespace grpc_labview {
switch (metadata->wellKnownType)
{
case wellknown::Types::Double2DArray:
wellknown::Double2DArray::CopyFromCluster(metadata, start, message);
wellknown::Double2DArray::GetInstance().CopyFromClusterToMessage(metadata, start, message);
return;
case wellknown::Types::String2DArray:
wellknown::String2DArray::GetInstance().CopyFromClusterToMessage(metadata, start, message);
return;
}

Expand Down
24 changes: 20 additions & 4 deletions src/lv_message_efficient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//---------------------------------------------------------------------
#include <grpc_server.h>
#include <lv_message_efficient.h>
#include <well_known_types.h>
#include <well_known_messages.h>
#include <sstream>

//---------------------------------------------------------------------
Expand Down Expand Up @@ -153,7 +153,9 @@ namespace grpc_labview
switch (fieldInfo.wellKnownType)
{
case wellknown::Types::Double2DArray:
return ParseDouble2DArrayMessage(tag, fieldInfo, index, protobuf_ptr, ctx);
return ParseDouble2DArrayMessage(fieldInfo, index, protobuf_ptr, ctx);
case wellknown::Types::String2DArray:
return ParseString2DArrayMessage(fieldInfo, index, protobuf_ptr, ctx);
}

auto metadata = fieldInfo._owner->FindMetadata(fieldInfo.embeddedMessageName);
Expand Down Expand Up @@ -223,17 +225,31 @@ namespace grpc_labview

//---------------------------------------------------------------------
//---------------------------------------------------------------------
const char* LVMessageEfficient::ParseDouble2DArrayMessage(google::protobuf::uint32 tag, const MessageElementMetadata& fieldInfo, uint32_t index, const char* protobuf_ptr, ParseContext* ctx)
const char* LVMessageEfficient::Parse2DArrayMessage(const MessageElementMetadata& fieldInfo, uint32_t index, const char* protobuf_ptr, ParseContext* ctx, wellknown::I2DArray& array)
{
auto metadata = fieldInfo._owner->FindMetadata(fieldInfo.embeddedMessageName);
auto nestedMessage = std::make_shared<LVMessage>(metadata);
protobuf_ptr = ctx->ParseMessage(nestedMessage.get(), protobuf_ptr);
auto nestedClusterPtr = _LVClusterHandle + fieldInfo.clusterOffset;
auto nestedMessageValue = std::make_shared<LVNestedMessageMessageValue>(index, nestedMessage);
wellknown::Double2DArray::CopyToCluster(fieldInfo, nestedClusterPtr, nestedMessageValue);
array.CopyFromMessageToCluster(fieldInfo, nestedMessageValue, nestedClusterPtr);
return protobuf_ptr;
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
const char* LVMessageEfficient::ParseDouble2DArrayMessage(const MessageElementMetadata& fieldInfo, uint32_t index, const char* protobuf_ptr, ParseContext* ctx)
{
return Parse2DArrayMessage(fieldInfo, index, protobuf_ptr, ctx, wellknown::Double2DArray::GetInstance());
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
const char* LVMessageEfficient::ParseString2DArrayMessage(const MessageElementMetadata& fieldInfo, uint32_t index, const char* protobuf_ptr, ParseContext* ctx)
{
return Parse2DArrayMessage(fieldInfo, index, protobuf_ptr, ctx, wellknown::String2DArray::GetInstance());
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
void LVMessageEfficient::PostInteralParseAction()
Expand Down
9 changes: 7 additions & 2 deletions src/lv_message_efficient.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include <message_value.h>
#include <message_metadata.h>
#include <google/protobuf/message.h>
#include "lv_message.h"
#include <lv_message.h>
#include <well_known_messages.h>

using namespace google::protobuf::internal;

Expand Down Expand Up @@ -67,7 +68,11 @@ namespace grpc_labview
const char* ParseString(unsigned int tag, const MessageElementMetadata& fieldInfo, uint32_t index, const char* ptr, google::protobuf::internal::ParseContext* ctx) override;
const char* ParseBytes(unsigned int tag, const MessageElementMetadata& fieldInfo, uint32_t index, const char* ptr, google::protobuf::internal::ParseContext* ctx) override;
const char* ParseNestedMessage(google::protobuf::uint32 tag, const MessageElementMetadata& fieldInfo, uint32_t index, const char* ptr, google::protobuf::internal::ParseContext* ctx) override;
const char* ParseDouble2DArrayMessage(google::protobuf::uint32 tag, const MessageElementMetadata& fieldInfo, uint32_t index, const char* ptr, google::protobuf::internal::ParseContext* ctx);
const char* ParseDouble2DArrayMessage(const MessageElementMetadata& fieldInfo, uint32_t index, const char* ptr, google::protobuf::internal::ParseContext* ctx);
const char* ParseString2DArrayMessage(const MessageElementMetadata& fieldInfo, uint32_t index, const char* ptr, google::protobuf::internal::ParseContext* ctx);

private:
const char* Parse2DArrayMessage(const MessageElementMetadata& fieldInfo, uint32_t index, const char* protobuf_ptr, ParseContext* ctx, wellknown::I2DArray& array);
};

template <typename MessageType, const char* (*ReadFunc)(const char*, MessageType*), const char* (*PackedFunc)(void*, const char*, google::protobuf::internal::ParseContext*)>
Expand Down
3 changes: 3 additions & 0 deletions src/message_element_metadata_owner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <fstream>
#include <iostream>
#include <future>
#include <well_known_messages.h>

//---------------------------------------------------------------------
//---------------------------------------------------------------------
Expand Down Expand Up @@ -62,6 +63,7 @@ namespace grpc_labview {
switch (type)
{
case wellknown::Types::Double2DArray:
case wellknown::Types::String2DArray:
return sizeof(void*);
}
return 0;
Expand All @@ -78,6 +80,7 @@ namespace grpc_labview {
switch (type)
{
case wellknown::Types::Double2DArray:
case wellknown::Types::String2DArray:
return sizeof(void*);
}
return 0;
Expand Down
19 changes: 15 additions & 4 deletions src/message_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,38 @@
//---------------------------------------------------------------------
#include "message_metadata.h"
#include "lv_interop.h"
#include "well_known_types.h"
#include "well_known_messages.h"

namespace grpc_labview
{
//---------------------------------------------------------------------
// Functions for calculating whether an element is considered a well known type.
//---------------------------------------------------------------------
static wellknown::Types CalculateDouble2DArrayWellKnownTypeEnum(const MessageElementMetadata& metadata)
static wellknown::Types Calculate2DArrayWellKnownTypeEnum(const MessageElementMetadata& metadata, wellknown::Types type)
{
if (!metadata.isRepeated)
{
return wellknown::Types::Double2DArray;
return type;
}
return wellknown::Types::None;
}

static wellknown::Types CalculateDouble2DArrayWellKnownTypeEnum(const MessageElementMetadata& metadata)
{
return Calculate2DArrayWellKnownTypeEnum(metadata, wellknown::Types::Double2DArray);
}

static wellknown::Types CalculateString2DArrayWellKnownTypeEnum(const MessageElementMetadata& metadata)
{
return Calculate2DArrayWellKnownTypeEnum(metadata, wellknown::Types::String2DArray);
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
std::map<const std::string, wellknown::Types(*)(const MessageElementMetadata&)> MessageElementMetadata::_wellKnownTypeFunctionMap =
{
{ wellknown::Double2DArray::GetMessageName(), CalculateDouble2DArrayWellKnownTypeEnum}
{ wellknown::Double2DArray::GetInstance().GetMessageName(), CalculateDouble2DArrayWellKnownTypeEnum},
{ wellknown::String2DArray::GetInstance().GetMessageName(), CalculateString2DArrayWellKnownTypeEnum}
};

//---------------------------------------------------------------------
Expand Down
Loading
Loading