www1350 / javaweb

http://www1350.github.io/
31 stars 5 forks source link

Thrift #57

Open www1350 opened 8 years ago

www1350 commented 8 years ago

Apache Thrift - 可伸缩的跨语言服务开发框架

qq 20160928173938

类型(java为例)

  1. 基本类型 bool(boolean): 布尔类型(TRUE or FALSE)

byte(byte): 8位带符号整数

i16(short): 16位带符号整数

i32(int): 32位带符号整数

i64(long): 64位带符号整数

double(double): 64位浮点数

string(String): 采用UTF-8编码的字符串

  1. 特殊类型 binary(ByteBuffer):未经过编码的字节流
  2. Structs(结构)
struct UserProfile {
1: i32 uid,
2: string name,
3: string blurb
}

有默认值

struct UserProfile {
1: i32 uid = 1,
2: string name = "User1",
3: string blurb
}
  1. 容器 list(java.util.ArrayList)

set(java.util.HashSet)

map(java.util.HashMap) 如:

struct Node {
1: i32 id,
2: string name,
3: list<i32> subNodeList,
4: map<i32,string> subNodeMap,
5: set<i32> subNodeSet
}
struct SubNode {
1: i32 uid,
2: string name,
3: i32 pid
}

struct Node {
1: i32 uid,
2: string name,
3: list<subNode> subNodes
}
  1. Services服务
service UserStorage {
void store(1: UserProfile user),
UserProfile retrieve(1: i32 uid)
}

写了一个小demo

www1350 commented 8 years ago

test

www1350 commented 8 years ago

test2