示例#1
0
    void DataSerializer::Serialize<Variant>(const Variant& var)
    {
      uint8_t encodingMask = static_cast<uint8_t>(var.Type);
      if (!var.IsNul())
      {
        if (var.IsArray())
        {
          encodingMask |= HAS_ARRAY_MASK;
        }
        if (!var.Dimensions.empty())
        {
          encodingMask |= HAS_DIMENSIONS_MASK;
        }
      }

      Serialize(encodingMask);
      if (var.IsNul())
      {
        return;
      }
      if (var.IsArray() )
      {
        ApplyToVariantValue(var.Type, var.Value, SerializeValueArray, *this);
      }
      else
      {
        ApplyToVariantValue(var.Type, var.Value, SerializeValue, *this);
      }
      if (!var.Dimensions.empty())
      {
        SerializeContainer(*this, var.Dimensions);
      }
    }
示例#2
0
文件: sdp.cpp 项目: 9aa5/crtmpserver
bool SDP::ParseSDP(SDP &sdp, string &raw) {
	//FINEST("%s", STR(raw));
	//1. Reset
	sdp.Reset();

	//2. Prepare the sections
	sdp[SDP_SESSION].IsArray(false);
	sdp[SDP_MEDIATRACKS].IsArray(true);

	//3. Split the raw content into lines
	replace(raw, "\r\n", "\n");
	vector<string> lines;
	split(raw, "\n", lines);

	//4. Detect the media tracks indexes
	vector<uint32_t> trackIndexes;
	for (uint32_t i = 0; i < lines.size(); i++) {
		trim(lines[i]);
		if (lines[i].find("m=") == 0) {
			ADD_VECTOR_END(trackIndexes, i);
		}
	}
	if (trackIndexes.size() == 0) {
		FATAL("No tracks found");
		return false;
	}

	//5. Parse the header
	if (!ParseSection(sdp[SDP_SESSION], lines, 0, trackIndexes[0])) {
		FATAL("Unable to parse header");
		return false;
	}

	//6. Parse the media sections
	Variant media;
	for (uint32_t i = 0; i < trackIndexes.size() - 1; i++) {
		media.Reset();
		media.IsArray(false);
		if (!ParseSection(media, lines, trackIndexes[i], trackIndexes[i + 1] - trackIndexes[i])) {
			FATAL("Unable to parse header");
			return false;
		}
		sdp[SDP_MEDIATRACKS].PushToArray(media);
	}

	//7. Parse the last media section
	media.Reset();
	media.IsArray(false);
	if (!ParseSection(media, lines,
			trackIndexes[(uint32_t) trackIndexes.size() - 1],
			(uint32_t) trackIndexes.size() - trackIndexes[(uint32_t) trackIndexes.size() - 1])) {
		FATAL("Unable to parse header");
		return false;
	}
	sdp[SDP_MEDIATRACKS].PushToArray(media);


	return true;
}
TEST_F(OpcUaBinaryDeserialization, Variant_QUALIFIED_NAME_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::QUALIFIED_NAME) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  1,0,  4,0,0,0,  'n','a','m','e',
  1,0,  4,0,0,0,  'n','a','m','e'
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::QUALIFIED_NAME);
  std::vector<QualifiedName> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<QualifiedName>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], QualifiedName(1, "name"));
  ASSERT_EQ(vals[1], QualifiedName(1, "name"));
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_LOCALIZED_TEXT_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::LOCALIZED_TEXT) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2, 4,0,0,0,'t','e','x','t',
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::LOCALIZED_TEXT);
  ASSERT_EQ(var.As<LocalizedText>(), LocalizedText("text"));
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_DATE_TIME_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::DATE_TIME) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  8, 7, 6, 5, 4, 3, 2, 1,
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::DATE_TIME);
  ASSERT_EQ(var.As<DateTime>(), 0x0102030405060708);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_LOCALIZED_TEXT_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::LOCALIZED_TEXT) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  2, 4,0,0,0,'t','e','x','t',
  2, 4,0,0,0,'t','e','x','t'
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::LOCALIZED_TEXT);
  std::vector<LocalizedText> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<LocalizedText>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], LocalizedText("text"));
  ASSERT_EQ(vals[1], LocalizedText("text"));
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_BYTE_STRING_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::BYTE_STRING) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0, 1,2,
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  OpcUa::Guid guid = CreateTestGuid();

  ASSERT_EQ(var.Type(), VariantType::BYTE_STRING);
  ASSERT_EQ(var.As<ByteString>(), ByteString(std::vector<uint8_t>{1,2}));
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_DATE_TIME_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::DATE_TIME) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  8, 7, 6, 5, 4, 3, 2, 1,
  8, 7, 6, 5, 4, 3, 2, 1
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::DATE_TIME);
  std::vector<DateTime> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<DateTime>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], 0x0102030405060708);
  ASSERT_EQ(vals[1], 0x0102030405060708);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_STRING_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::STRING) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  4,0,0,0, 'R','o','o','t',
  4,0,0,0, 'R','o','o','t'
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  OpcUa::Guid guid = CreateTestGuid();

  ASSERT_EQ(var.Type(), VariantType::STRING);
  std::vector<std::string> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<std::string>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], std::string("Root"));
  ASSERT_EQ(vals[1], std::string("Root"));
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_BYTE_STRING_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::BYTE_STRING) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  2,0,0,0, 1,2,
  2,0,0,0, 1,2
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::BYTE_STRING);
  std::vector<ByteString> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<ByteString>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], ByteString(std::vector<uint8_t>{1,2}));
  ASSERT_EQ(vals[1], ByteString(std::vector<uint8_t>{1,2}));
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_GUId_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::GUId) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  4,3,2,1, 6,5, 8,7, 1,2,3,4,5,6,7,8,
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  OpcUa::Guid guid = CreateTestGuid();

  ASSERT_EQ(var.Type(), VariantType::GUId);
  ASSERT_EQ(var.As<Guid>(), guid);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_GUId_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::GUId) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  4,3,2,1, 6,5, 8,7, 1,2,3,4,5,6,7,8,
  4,3,2,1, 6,5, 8,7, 1,2,3,4,5,6,7,8
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  OpcUa::Guid guid = CreateTestGuid();

  ASSERT_EQ(var.Type(), VariantType::GUId);
  std::vector<Guid> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<Guid>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], guid);
  ASSERT_EQ(vals[1], guid);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_DOUBLE_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::DOUBLE) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41, // 1200000
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::DOUBLE);
  ASSERT_EQ(var.As<double>(), 1200000);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
///-----------------------------------------------------------------------------
TEST_F(OpcUaBinaryDeserialization, Variant_FLOAT)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<char>(VariantType::FLOAT);

  const std::vector<char> expectedData =
  {
    encodingMask,
    //(char)0xC0, (char)0xD0, 0, 0 // -6.5
    0, 0, (char)0xD0, (char)0xC0 // -6.5
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::FLOAT);
  ASSERT_EQ(var.As<float>(), -6.5);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_QUALIFIED_NAME_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::QUALIFIED_NAME) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  1,0,  4,0,0,0,  'n','a','m','e',
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::QUALIFIED_NAME);
  ASSERT_EQ(var.As<QualifiedName>(), QualifiedName(1, "name"));
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_BOOLEAN_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::BOOLEAN) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData =
  {
    encodingMask,
    1,
    1, 0, 0, 0,
    1, 0, 0, 0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::BOOLEAN);
  ASSERT_TRUE(var.As<bool>());
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
}
示例#17
0
    std::size_t RawSize<Variant>(const Variant& var)
    {
      const uint8_t encodingMask = 0;
      std::size_t size = RawSize(encodingMask);
      if (var.IsNul())
      {
        return size;
      }

      std::size_t valueSize = 0;
      if (var.IsArray())
      {
        ApplyToVariantValue(var.Type, var.Value, RawValueSizeArray, valueSize);
      }
      else
      {
        ApplyToVariantValue(var.Type, var.Value, RawValueSize, valueSize);
      }
      size += valueSize;
      if (!var.Dimensions.empty())
      {
        size += RawSizeContainer(var.Dimensions);
      }

      return size;
    }
TEST_F(OpcUaBinaryDeserialization, Variant_DOUBLE_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::DOUBLE) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41, // 1200000
  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41  // 1200000
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::DOUBLE);
  std::vector<double> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<double>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], 1200000);
  ASSERT_EQ(vals[1], 1200000);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
示例#19
0
 Variant::Variant(const Variant& var)
 {
   Type = var.Type;
   Dimensions = var.Dimensions;
   _array = var.IsArray();
   CopyValue(Type, var.Value, this->Value);
 }
TEST_F(OpcUaBinaryDeserialization, Variant_FLOAT_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::FLOAT) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  0, 0, (char)0xD0, (char)0xC0, // -6.5
  0, 0, (char)0xD0, (char)0xC0 // -6.5
  //(char)0xC0, (char)0xD0, 0, 0, // -6.5
  //(char)0xC0, (char)0xD0, 0, 0 // -6.5
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::FLOAT);
  std::vector<float> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<float>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], -6.5);
  ASSERT_EQ(vals[1], -6.5);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_FLOAT_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::FLOAT) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  0, 0, (char)0xD0, (char)0xC0, // -6.5
  //(char)0xC0, (char)0xD0, 0, 0, // -6.5
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::FLOAT);
  ASSERT_EQ(var.As<float>(), -6.5);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_UINT64_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::UINT64) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  0x00,0x20,0,0, 0,0,0,0, // 0x2000
  0x00,0x20,0,0, 0,0,0,0 // 0x2000
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::UINT64);
  std::vector<uint64_t> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<uint64_t>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], 8192);
  ASSERT_EQ(vals[1], 8192);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_UINT64_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::UINT64) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  0x00,0x20,0,0, 0,0,0,0, // 0x2000
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::UINT64);
  ASSERT_EQ(var.As<uint64_t>(), 8192);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_BYTE_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::BYTE) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  (char)200,
  2,0,0,0,
  2,0,0,0,
  3,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::BYTE);
  ASSERT_EQ(var.As<uint8_t>(), 200);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 2);
  ASSERT_EQ(var.Dimensions[0], 2);
  ASSERT_EQ(var.Dimensions[1], 3);
}
TEST_F(OpcUaBinaryDeserialization, Variant_NODE_Id_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::NODE_Id) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  1, 0, (char)0xC1, 0x1,
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::NODE_Id);
  ASSERT_EQ(var.As<NodeId>(), OpcUa::FourByteNodeId(449));
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_NODE_Id_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::NODE_Id) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  1, 0, (char)0xC1, 0x1,
  1, 0, (char)0xC1, 0x1
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::NODE_Id);
  std::vector<NodeId> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<NodeId>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], OpcUa::FourByteNodeId(449));
  ASSERT_EQ(vals[1], OpcUa::FourByteNodeId(449));
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_BOOLEAN_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::BOOLEAN) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  1,
  1
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::BOOLEAN);
  std::vector<bool> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<bool>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], true);
  ASSERT_EQ(vals[1], true);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
}
示例#28
0
Variant AtomDATA::GetVariant() {
	switch (_type) {
		case 1:
		{
			//Single string
			return _dataString;
		}
		case 0:
		{
			//many uint16_t
			Variant result;

			FOR_VECTOR(_dataUI16, i) {
				result[i] = _dataUI16[i];
			}
			result.IsArray(true);
			return result;
		}
		case 21:
		{
			//many uint8_t
			Variant result;

			FOR_VECTOR(_dataUI8, i) {
				result[i] = _dataUI8[i];
			}
			result.IsArray(true);
			return result;
		}
		case 14:
		case 15:
		{
			//jpg/png image data
			Variant result = _dataImg;
			result.IsByteArray(true);
			return result;
			//TODO: for now, return null
		}
		default:
		{
			FATAL("Type %u not yet implemented", _type);
			return false;
		}
	}
}
示例#29
0
Variant AtomDATA::GetVariant() {
	switch (_type) {
		case 1:
		{
			//Single string
			return _dataString;
		}
		case 0:
		{
			//many uint16_t
			Variant result;

			FOR_VECTOR(_dataUI16, i) {
				result[i] = _dataUI16[i];
			}
			result.IsArray(true);
			return result;
		}
		case 21:
		{
			//many uint8_t
			Variant result;

			FOR_VECTOR(_dataUI8, i) {
				result[i] = _dataUI8[i];
			}
			result.IsArray(true);
			return result;
		}
		case 13: //JPEG
		case 14: //PNG
		case 15: //? (looks like this is an image as well... Don't know the type)
		case 27: //BMP
		{
			Variant result = _dataImg;
			result.IsByteArray(true);
			return result;
		}
		default:
		{
			FATAL("Type %" PRIu32 " not yet implemented", _type);
			return false;
		}
	}
}
示例#30
0
bool PopStack(lua_State *pLuaState, Variant &variant) {
	variant.Reset();
	variant.IsArray(true);
	while (lua_gettop(pLuaState) > 0) {
		Variant temp;
		if (!PopVariant(pLuaState, temp)) {
			FATAL("Unable to pop variant");
			return false;
		}
		variant.PushToArray(temp);
	}
	return true;
}