Skip to content

Commit

Permalink
Add support for imported IDLs, split out common parts of Memcache.idl
Browse files Browse the repository at this point in the history
Summary: Add support for imported idls (in possibly different namespaces).

Reviewed By: andreazevedo

Differential Revision: D3793098

fbshipit-source-id: 3aabdd25c0784aa9e90e7e8d5ae14ee3041682ab
  • Loading branch information
jmswen authored and Facebook Github Bot 3 committed Sep 2, 2016
1 parent 524baab commit f29f49e
Showing 20 changed files with 1,516 additions and 1,161 deletions.
2 changes: 1 addition & 1 deletion mcrouter/lib/carbon/CarbonProtocolWriter.h
Original file line number Diff line number Diff line change
@@ -328,7 +328,7 @@ class CarbonProtocolWriter {
writeListSizeAndInnerType(
static_cast<uint32_t>(v.size()), FieldType::Struct);
for (const auto& e : v) {
e.serialize();
e.serialize(*this);
}
}

4 changes: 2 additions & 2 deletions mcrouter/lib/carbon/test/CarbonStructuresTest.cpp
Original file line number Diff line number Diff line change
@@ -22,10 +22,10 @@

using namespace carbon::test::util;

using carbon::test::SimpleEnum;
using carbon::test::SimpleStruct;
using carbon::test::TestRequest;
using carbon::test::TestReply;
using carbon::test::TestRequest;
using carbon::test2::util::SimpleEnum;
using facebook::memcache::coalesceAndGetRange;

TEST(CarbonBasic, staticAsserts) {
19 changes: 2 additions & 17 deletions mcrouter/lib/carbon/test/CarbonTest.idl
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
namespace carbon::test;

enum SimpleEnum : int64_t {
Twenty = 20,
Zero = 0,
One = 1,
Negative = -92233
};

struct BaseStruct {
1: int64_t baseInt64Member;
};

struct SimpleStruct with 1: BaseStruct {
1: int32_t int32Member;
2: string stringMember;
3: SimpleEnum enumMember;
};
import "mcrouter/lib/carbon/test/a/A.idl"

request TestRequest with 1: SimpleStruct as Base {
id: 1;
name: "test";
reply: TestReply;

1: Keys<IOBuf> key;
2: SimpleEnum testEnum;
2: test2::util::SimpleEnum testEnum;
3: bool testBool;
4: char testChar;
5: int8_t testInt8;
4 changes: 4 additions & 0 deletions mcrouter/lib/carbon/test/a/A.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace carbon::test;

import "mcrouter/lib/carbon/test/a/b/B.idl"
import "mcrouter/lib/carbon/test/b/B.idl"
12 changes: 12 additions & 0 deletions mcrouter/lib/carbon/test/a/b/B.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace carbon::test2::util;

enum SimpleEnum : int64_t {
Twenty = 20,
Zero = 0,
One = 1,
Negative = -92233
};

struct SimpleStruct {
1: int64_t member1;
};
56 changes: 56 additions & 0 deletions mcrouter/lib/carbon/test/a/b/gen/B-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2016, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

/*
* THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN
* VAIN.
*
*/

namespace carbon {
namespace test2 {
namespace util {

inline void SimpleStruct::serialize(
carbon::CarbonProtocolWriter& writer) const {
writer.writeStructBegin();
writer.writeInt64Field(1 /* field id */, member1());
writer.writeStructEnd();
writer.writeStop();
}

inline void SimpleStruct::deserialize(carbon::CarbonProtocolReader& reader) {
reader.readStructBegin();
while (true) {
const auto pr = reader.readFieldHeader();
const auto fieldType = pr.first;
const auto fieldId = pr.second;

if (fieldType == carbon::FieldType::Stop) {
break;
}

switch (fieldId) {
case 1: {
member1() = reader.readInt64Field();
break;
}
default: {
reader.skip(fieldType);
break;
}
}
}
reader.readStructEnd();
}

} // util
} // test2
} // carbon
82 changes: 82 additions & 0 deletions mcrouter/lib/carbon/test/a/b/gen/B.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2016, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

/*
* THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN
* VAIN.
*
*/
#pragma once

#include <memory>
#include <string>
#include <utility>

#include <folly/Optional.h>
#include <folly/io/IOBuf.h>
#include <mcrouter/lib/carbon/CarbonProtocolReader.h>
#include <mcrouter/lib/carbon/CarbonProtocolWriter.h>
#include <mcrouter/lib/carbon/CommonSerializationTraits.h>
#include <mcrouter/lib/carbon/Keys.h>
#include <mcrouter/lib/carbon/ReplyCommon.h>
#include <mcrouter/lib/carbon/RequestCommon.h>
#include <mcrouter/lib/carbon/RequestReplyUtil.h>
#include <mcrouter/lib/carbon/Result.h>

namespace carbon {
namespace test2 {
namespace util {

enum class SimpleEnum : int64_t {
Twenty = 20,
Zero = 0,
One = 1,
Negative = -92233
};

class SimpleStruct {
public:
static constexpr bool hasExptime = false;
static constexpr bool hasFlags = false;
static constexpr bool hasKey = false;
static constexpr bool hasValue = false;

SimpleStruct() = default;
SimpleStruct(const SimpleStruct&) = default;
SimpleStruct& operator=(const SimpleStruct&) = default;
SimpleStruct(SimpleStruct&&) = default;
SimpleStruct& operator=(SimpleStruct&&) = default;

int64_t member1() const {
return member1_;
}
int64_t& member1() {
return member1_;
}
uint64_t flags() const {
return 0;
}
int32_t exptime() const {
return 0;
}

void serialize(carbon::CarbonProtocolWriter& writer) const;

void deserialize(carbon::CarbonProtocolReader& reader);

private:
int64_t member1_{0};
};

} // util
} // test2
} // carbon

#include "B-inl.h"
19 changes: 19 additions & 0 deletions mcrouter/lib/carbon/test/a/gen/A-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2016, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

/*
* THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN
* VAIN.
*
*/

namespace carbon {
namespace test {} // test
} // carbon
40 changes: 40 additions & 0 deletions mcrouter/lib/carbon/test/a/gen/A.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2016, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

/*
* THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN
* VAIN.
*
*/
#pragma once

#include <memory>
#include <string>
#include <utility>

#include <folly/Optional.h>
#include <folly/io/IOBuf.h>
#include <mcrouter/lib/carbon/CarbonProtocolReader.h>
#include <mcrouter/lib/carbon/CarbonProtocolWriter.h>
#include <mcrouter/lib/carbon/CommonSerializationTraits.h>
#include <mcrouter/lib/carbon/Keys.h>
#include <mcrouter/lib/carbon/ReplyCommon.h>
#include <mcrouter/lib/carbon/RequestCommon.h>
#include <mcrouter/lib/carbon/RequestReplyUtil.h>
#include <mcrouter/lib/carbon/Result.h>

#include "mcrouter/lib/carbon/test/a/b/gen/B.h"
#include "mcrouter/lib/carbon/test/b/gen/B.h"

namespace carbon {
namespace test {} // test
} // carbon

#include "A-inl.h"
14 changes: 14 additions & 0 deletions mcrouter/lib/carbon/test/b/B.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace carbon::test;

import "mcrouter/lib/carbon/test/a/b/B.idl"

struct BaseStruct {
1: int64_t baseInt64Member;
};

struct SimpleStruct with 1: BaseStruct {
1: int32_t int32Member;
2: string stringMember;
3: test2::util::SimpleEnum enumMember;
4: vector<test2::util::SimpleStruct> vectorMember;
};
109 changes: 109 additions & 0 deletions mcrouter/lib/carbon/test/b/gen/B-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2016, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

/*
* THIS FILE IS AUTOGENERATED. DO NOT MODIFY IT; ALL CHANGES WILL BE LOST IN
* VAIN.
*
*/

namespace carbon {
namespace test {

inline void BaseStruct::serialize(carbon::CarbonProtocolWriter& writer) const {
writer.writeStructBegin();
writer.writeInt64Field(1 /* field id */, baseInt64Member());
writer.writeStructEnd();
writer.writeStop();
}

inline void BaseStruct::deserialize(carbon::CarbonProtocolReader& reader) {
reader.readStructBegin();
while (true) {
const auto pr = reader.readFieldHeader();
const auto fieldType = pr.first;
const auto fieldId = pr.second;

if (fieldType == carbon::FieldType::Stop) {
break;
}

switch (fieldId) {
case 1: {
baseInt64Member() = reader.readInt64Field();
break;
}
default: {
reader.skip(fieldType);
break;
}
}
}
reader.readStructEnd();
}

inline void SimpleStruct::serialize(
carbon::CarbonProtocolWriter& writer) const {
writer.writeStructBegin();
writer.writeInt32Field(1 /* field id */, int32Member());
writer.writeBinaryField(2 /* field id */, stringMember());
writer.writeInt64Field(3 /* field id */, static_cast<int64_t>(enumMember()));
writer.writeVectorField<test2::util::SimpleStruct>(
4 /* field id */, vectorMember());
writer.writeFieldHeader(carbon::FieldType::Struct, -1);
_carbon_basestruct_.serialize(writer);
writer.writeStructEnd();
writer.writeStop();
}

inline void SimpleStruct::deserialize(carbon::CarbonProtocolReader& reader) {
reader.readStructBegin();
while (true) {
const auto pr = reader.readFieldHeader();
const auto fieldType = pr.first;
const auto fieldId = pr.second;

if (fieldType == carbon::FieldType::Stop) {
break;
}

switch (fieldId) {
case -1: {
_carbon_basestruct_.deserialize(reader);
break;
}
case 1: {
int32Member() = reader.readInt32Field();
break;
}
case 2: {
stringMember() = reader.readBinaryField<std::string>();
break;
}
case 3: {
enumMember() =
static_cast<test2::util::SimpleEnum>(reader.readInt64Field());
break;
}
case 4: {
vectorMember() = reader.readVectorField<test2::util::SimpleStruct>();
break;
}
default: {
reader.skip(fieldType);
break;
}
}
}
reader.readStructEnd();
}

} // test
} // carbon
Loading

0 comments on commit f29f49e

Please sign in to comment.