Skip to content

Commit

Permalink
fbcode/thrift/lib/
Browse files Browse the repository at this point in the history
Reviewed By: thedavekwon

Differential Revision: D50832937

fbshipit-source-id: fa7bbaac388d55c8623102ee7275f0a41defb3e5
  • Loading branch information
iahs authored and facebook-github-bot committed Nov 15, 2023
1 parent b3c48a6 commit 7ba2d20
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 108 deletions.
3 changes: 2 additions & 1 deletion thrift/lib/java/test-if/field_wrapper.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ struct TerseWrappedTestStruct {
17: doubleAdaptedIntList wrappedDoubleAdaptedIntList_field;
}

@java.Mutable
@thrift.Experimental
@thrift.TerseWrite
struct MutableTerseWrappedTestStruct {
Expand Down Expand Up @@ -280,7 +281,7 @@ struct MutableTerseWrappedTestStruct {
typeClassName = "com.facebook.thrift.wrapper.test.PoliciedField<com.facebook.thrift.adapter.test.Wrapped<List<String>>>",
}
17: doubleAdaptedIntList wrappedDoubleAdaptedIntList_field;
} (java.swift.mutable = "true")
}

safe permanent client exception WrappedTestException {
1001: i32 context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,4 @@ typedef map<i32, FMap> (
typedef map<i64, string> (
java.swift.type = "it.unimi.dsi.fastutil.longs.Long2ObjectArrayMap<String>",
) map_i64_string_6611

53 changes: 25 additions & 28 deletions thrift/lib/thrift/RpcMetadata.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ namespace py3 thrift.lib.thrift
namespace go thrift.lib.thrift.rpcmetadata

include "thrift/annotation/thrift.thrift"
include "thrift/annotation/cpp.thrift"

cpp_include "thrift/lib/cpp2/util/ManagedStringView.h"
cpp_include "thrift/lib/thrift/RpcMetadata_extra.h"
cpp_include "folly/container/F14Map.h"

typedef binary (cpp2.type = "std::unique_ptr<folly::IOBuf>") IOBufPtr
@cpp.Type{name = "std::unique_ptr<folly::IOBuf>"}
typedef binary IOBufPtr

enum ProtocolId {
// The values must match those in thrift/lib/cpp/protocol/TProtocolTypes.h
Expand Down Expand Up @@ -112,14 +114,14 @@ struct CompressionConfig {
struct NegotiationParameters {
// nth (zero-based) least significant bit set if CompressionAlgorithm = n + 1
// is accepted. For example, 0b10 means ZSTD is accepted.
1: optional i64 (cpp.type = "std::uint64_t") compressionAlgos;
@cpp.Type{name = "std::uint64_t"}
1: optional i64 compressionAlgos;
2: optional bool useStopTLS;
}

// String type optimized for generated code
typedef string (
cpp.type = "::apache::thrift::ManagedStringViewWithConversions",
) ManagedStringViewField
@cpp.Type{name = "::apache::thrift::ManagedStringViewWithConversions"}
typedef string ManagedStringViewField

struct InteractionCreate {
// Client chosen interaction id. Interaction id MAY be reused after the
Expand Down Expand Up @@ -169,14 +171,14 @@ struct RequestRpcMetadata {
7: optional RpcPriority priority;
// Arbitrary metadata that MAY be used by application or Thrift extensions.
// MAY be set.
8: optional map<string, string> (
cpp.template = "folly::F14NodeMap",
) otherMetadata;
@cpp.Type{template = "folly::F14NodeMap"}
8: optional map<string, string> otherMetadata;
// 9: Deprecated
// 10: Deprecated
// The CRC32C of the uncompressed request payload. MAY be set. SHOULD be
// validated if set.
11: optional i32 (cpp.type = "std::uint32_t") crc32c;
@cpp.Type{name = "std::uint32_t"}
11: optional i32 crc32c;
// 12: Deprecated
// The name of the load metric that should be queried as part of this
// request. MAY be set. If set, load field SHOULD be set in response
Expand Down Expand Up @@ -283,14 +285,14 @@ struct ResponseRpcMetadata {
// 2: Deprecated
// Arbitrary metadata that MAY be used by application or Thrift extensions.
// MAY be set.
3: optional map<string, string> (
cpp.template = "folly::F14NodeMap",
) otherMetadata;
@cpp.Type{template = "folly::F14NodeMap"}
3: optional map<string, string> otherMetadata;
// Server load. SHOULD be set iff loadMetric was set in RequestRpcMetadata
4: optional i64 load;
// The CRC32C of the uncompressed response payload. MAY be set. SHOULD be
// validated if set.
5: optional i32 (cpp.type = "std::uint32_t") crc32c;
@cpp.Type{name = "std::uint32_t"}
5: optional i32 crc32c;
// The compression algorithm that was used to compress response payload. MUST
// be set iff response payload is compressed. SHOULD match the algorithm set
// in compressionConfig in RequestRpcMetadata
Expand Down Expand Up @@ -403,9 +405,8 @@ struct StreamPayloadMetadata {
1: optional CompressionAlgorithm compression;
// Arbitrary metadata that MAY be used by application or Thrift extensions.
// MAY be set.
2: optional map<string, string_4852> (
cpp.template = "folly::F14NodeMap",
) otherMetadata;
@cpp.Type{template = "folly::F14NodeMap"}
2: optional map<string, string_4852> otherMetadata;
// Metadata describing the type of stream payload. MUST be set for protocol
// version 8+.
3: optional PayloadMetadata payloadMetadata;
Expand All @@ -430,15 +431,13 @@ const i64 kRocketProtocolKey = 0xf09f9a80;
struct ClientMetadata {
1: optional string agent;
2: optional string hostname;
3: optional map<string, string> (
cpp.template = "folly::F14NodeMap",
) otherMetadata;
@cpp.Type{template = "folly::F14NodeMap"}
3: optional map<string, string> otherMetadata;
}

struct RequestSetupMetadata {
1: optional map<string, binary> (
cpp.template = "apache::thrift::MetadataOpaqueMap",
) opaque;
@cpp.Type{template = "apache::thrift::MetadataOpaqueMap"}
1: optional map<string, binary> opaque;
// Indicates interface kind that MUST be used by this connection. If not set
// or if server doesn't support requested interface kind, USER interface kind
// SHOULD be used. MAY be set.
Expand Down Expand Up @@ -487,9 +486,8 @@ struct TransportMetadataPush {
// client has received the response from the server for the setup frame. Thus
// dynamic information such as the result of the TLS handshake can also be
// added to this metadata map.
1: optional map<string, string> (
cpp.template = "folly::F14NodeMap",
) transportMetadata;
@cpp.Type{template = "folly::F14NodeMap"}
1: optional map<string, string> transportMetadata;
}

enum DrainCompleteCode {
Expand Down Expand Up @@ -523,9 +521,8 @@ union ClientPushMetadata {
struct HeadersPayloadContent {
// Arbitrary metadata that MAY be used by application or Thrift extensions.
// MAY be set.
1: optional map<string, string_4852> (
cpp.template = "folly::F14NodeMap",
) otherMetadata;
@cpp.Type{template = "folly::F14NodeMap"}
1: optional map<string, string_4852> otherMetadata;
}

struct HeadersPayloadMetadata {
Expand Down
13 changes: 9 additions & 4 deletions thrift/lib/thrift/any_rep.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
include "thrift/annotation/thrift.thrift"
include "thrift/lib/thrift/type.thrift"
include "thrift/lib/thrift/standard.thrift"
include "thrift/annotation/python.thrift"

/**
* The **underlying representations** for Thrift: Any.
Expand Down Expand Up @@ -45,14 +46,16 @@ struct AnyStruct {
*
* Must not be empty.
*/
1: type.Type type (py3.hidden);
@python.Py3Hidden
1: type.Type type;

/**
* The protocol used to encode `data`.
*
* Must not be empty.
*/
2: type.Protocol protocol (py3.hidden);
@python.Py3Hidden
2: type.Protocol protocol;

/** The encoded data. */
3: standard.ByteBuffer data;
Expand All @@ -65,10 +68,12 @@ struct AnyStruct {
*/
struct SemiAnyStruct {
/** The type stored in `data`, if known. */
1: type.Type type (py3.hidden);
@python.Py3Hidden
1: type.Type type;

/** The protocol used to encode `data`, if known. */
2: type.Protocol protocol (py3.hidden);
@python.Py3Hidden
2: type.Protocol protocol;

/** The encoded data. */
3: standard.ByteBuffer data;
Expand Down
5 changes: 4 additions & 1 deletion thrift/lib/thrift/dynamic.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace go thrift.lib.thrift.dynamic

cpp_include "thrift/lib/thrift/SerializableDynamic.h"

include "thrift/annotation/cpp.thrift"

union Dynamic {
1: bool boolean (java.swift.name = "_boolean");
2: i64 integer;
Expand All @@ -34,4 +36,5 @@ union Dynamic {
6: map<string, Dynamic> object;
}

typedef Dynamic (cpp.type = "::apache::thrift::SerializableDynamic") DynamicType
@cpp.Type{name = "::apache::thrift::SerializableDynamic"}
typedef Dynamic DynamicType
8 changes: 6 additions & 2 deletions thrift/lib/thrift/frozen.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ cpp_include "folly/sorted_vector_types.h"

namespace cpp2 apache.thrift.frozen.schema

include "thrift/annotation/cpp.thrift"

struct Field {
// layout id, indexes into layouts
1: i16 layoutId;
Expand All @@ -30,7 +32,8 @@ struct Field {
struct Layout {
1: i32 size = 0;
2: i16 bits = 0;
3: map<i16, Field> (cpp.template = "folly::sorted_vector_map") fields;
@cpp.Type{template = "folly::sorted_vector_map"}
3: map<i16, Field> fields;
4: string typeName;
}

Expand All @@ -42,6 +45,7 @@ struct Schema {
4: i32 fileVersion = 0;
// Field type names may not change unless relaxTypeChecks is set.
1: bool relaxTypeChecks = 0;
2: map<i16, Layout> (cpp.template = "folly::sorted_vector_map") layouts;
@cpp.Type{template = "folly::sorted_vector_map"}
2: map<i16, Layout> layouts;
3: i16 rootLayout = 0;
}
37 changes: 13 additions & 24 deletions thrift/lib/thrift/metadata.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace go thrift.lib.thrift.metadata
/*
* Keep synced with : thrift/compiler/generate/t_hack_generator.cc
*/
include "thrift/annotation/cpp.thrift"

enum ThriftPrimitiveType {
THRIFT_BOOL_TYPE = 1,
THRIFT_BYTE_TYPE = 2,
Expand Down Expand Up @@ -60,33 +62,26 @@ struct ThriftConstStruct {
}

struct ThriftListType {
@cpp.Ref{type = cpp.RefType.Unique}
1: optional ThriftType valueType (
cpp.ref = "true",
cpp2.ref = "true",
rust.box,
swift.recursive_reference = "true",
);
}

struct ThriftSetType {
@cpp.Ref{type = cpp.RefType.Unique}
1: optional ThriftType valueType (
cpp.ref = "true",
cpp2.ref = "true",
rust.box,
swift.recursive_reference = "true",
);
}

struct ThriftMapType {
1: optional ThriftType keyType (
cpp.ref = "true",
cpp2.ref = "true",
rust.box,
swift.recursive_reference = "true",
);
@cpp.Ref{type = cpp.RefType.Unique}
1: optional ThriftType keyType (rust.box, swift.recursive_reference = "true");
@cpp.Ref{type = cpp.RefType.Unique}
2: optional ThriftType valueType (
cpp.ref = "true",
cpp2.ref = "true",
rust.box,
swift.recursive_reference = "true",
);
Expand All @@ -106,46 +101,40 @@ struct ThriftUnionType {

struct ThriftTypedefType {
1: string name;
@cpp.Ref{type = cpp.RefType.Unique}
2: optional ThriftType underlyingType (
cpp.ref = "true",
cpp2.ref = "true",
rust.box,
swift.recursive_reference = "true",
);
3: list<ThriftConstStruct> structured_annotations;
}

struct ThriftStreamType {
@cpp.Ref{type = cpp.RefType.Unique}
1: optional ThriftType elemType (
cpp.ref = "true",
cpp2.ref = "true",
rust.box,
swift.recursive_reference = "true",
);
@cpp.Ref{type = cpp.RefType.Unique}
2: optional ThriftType initialResponseType (
cpp.ref = "true",
cpp2.ref = "true",
rust.box,
swift.recursive_reference = "true",
);
}

struct ThriftSinkType {
@cpp.Ref{type = cpp.RefType.Unique}
1: optional ThriftType elemType (
cpp.ref = "true",
cpp2.ref = "true",
rust.box,
swift.recursive_reference = "true",
);
@cpp.Ref{type = cpp.RefType.Unique}
2: optional ThriftType finalResponseType (
cpp.ref = "true",
cpp2.ref = "true",
rust.box,
swift.recursive_reference = "true",
);
@cpp.Ref{type = cpp.RefType.Unique}
3: optional ThriftType initialResponseType (
cpp.ref = "true",
cpp2.ref = "true",
rust.box,
swift.recursive_reference = "true",
);
Expand Down
10 changes: 7 additions & 3 deletions thrift/lib/thrift/protocol.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ include "thrift/lib/thrift/id.thrift"
include "thrift/lib/thrift/protocol_detail.thrift"
include "thrift/lib/thrift/type.thrift"
include "thrift/lib/thrift/standard.thrift"
include "thrift/annotation/python.thrift"

cpp_include "folly/container/F14Map.h"
cpp_include "thrift/lib/thrift/detail/id.h"
Expand All @@ -39,6 +40,7 @@ typedef protocol_detail.Object Object (thrift.uri = "")
typedef protocol_detail.Value Value (thrift.uri = "")

// Represents serialized data of unmasked fields.
@python.Py3Hidden
union MaskedData {
1: id.ValueId full;
// TODO(dokwon): Migrate to @thrift.Box after resolving incomplete type.
Expand All @@ -48,18 +50,20 @@ union MaskedData {
@cpp.Ref{type = cpp.RefType.Unique}
@cpp.Type{template = "folly::F14VectorMap"}
3: map<id.ValueId, MaskedData> values;
} (py3.hidden)
}

@python.Py3Hidden
struct EncodedValue {
1: type.BaseType wireType;
2: standard.ByteBuffer data;
} (py3.hidden)
}

// MaskedData uses ValueId to get encodedValues and map keys from the lists.
@python.Py3Hidden
@cpp.UseOpEncode
struct MaskedProtocolData {
1: type.Protocol protocol;
2: MaskedData data;
3: list<EncodedValue> values;
4: list<Value> keys;
} (py3.hidden)
}
Loading

0 comments on commit 7ba2d20

Please sign in to comment.