generated from cloudwego/.github
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
698 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# base | ||
|
||
`base` contains optimised generated code for kitex generic. | ||
`base` is used widely in internal systems, so we expect to have a unified place for `base`. | ||
It deprecates `Base` and `BaseResp` structs in `kitex` and `dynamicgo` | ||
|
||
Users should not use this package, it's only for cloudwego internals. | ||
|
||
The code under this package is generated by `fastgo` version of `thriftgo` which we haven't released yet and is only used in a few repos. You can find the code [here](https://github.com/cloudwego/thriftgo/tree/feat-fastcodec). | ||
|
||
Use `thriftgo` `fastgo` at your own risks. it's NOT fully tested and that's why we manually add test code in this package. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#! /bin/bash | ||
|
||
set -e | ||
|
||
thriftgo -g fastgo:no_default_serdes=true -o=.. ./base.thrift | ||
|
||
mv base.go base_tmp.go # fix sed base.go > base.go | ||
# rm unused funcs and vars, keep the file smaller: | ||
# func GetXXX | ||
# func IsSet | ||
# multiline DEFAULT vars | ||
# singleline DEFAULT vars | ||
sed '/func.* Get.* {/,/^}/d' base_tmp.go |\ | ||
sed '/func.* IsSet.* {/,/^}/d' |\ | ||
sed '/DEFAULT.*{/,/^}/d' |\ | ||
sed '/DEFAULT/d' > base.go | ||
|
||
gofmt -w base.go | ||
rm base_tmp.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace py base | ||
namespace go base | ||
namespace java com.bytedance.thrift.base | ||
|
||
struct TrafficEnv { | ||
1: bool Open = false, | ||
2: string Env = "", | ||
} | ||
|
||
struct Base { | ||
1: string LogID = "", | ||
2: string Caller = "", | ||
3: string Addr = "", | ||
4: string Client = "", | ||
5: optional TrafficEnv TrafficEnv, | ||
6: optional map<string, string> Extra, | ||
} | ||
|
||
struct BaseResp { | ||
1: string StatusMessage = "", | ||
2: i32 StatusCode = 0, | ||
3: optional map<string, string> Extra, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2024 CloudWeGo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package base | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBase(t *testing.T) { | ||
var err error | ||
|
||
p := NewBase() | ||
p.InitDefault() // for code coverage ... | ||
p.LogID = "1" | ||
p.Caller = "2" | ||
p.Addr = "3" | ||
p.Client = "4" | ||
t.Log(p.String()) | ||
|
||
sz := p.BLength() | ||
b := make([]byte, sz) | ||
n := p.FastWrite(b) | ||
require.Equal(t, sz, n) | ||
|
||
p2 := NewBase() | ||
n, err = p2.FastRead(b) | ||
require.Equal(t, len(b), n) | ||
require.NoError(t, err) | ||
require.Equal(t, p, p2) | ||
|
||
// optional fields | ||
|
||
p.TrafficEnv = NewTrafficEnv() | ||
p.TrafficEnv.InitDefault() // for code coverage ... | ||
p.Extra = map[string]string{"5": "6"} | ||
t.Log(p.String()) | ||
|
||
sz = p.BLength() | ||
b = make([]byte, sz) | ||
n = p.FastWrite(b) | ||
require.Equal(t, sz, n) | ||
|
||
p2 = NewBase() | ||
n, err = p2.FastRead(b) | ||
require.Equal(t, len(b), n) | ||
require.NoError(t, err) | ||
require.Equal(t, p, p2) | ||
} | ||
|
||
func TestBaseResp(t *testing.T) { | ||
var err error | ||
|
||
p := NewBaseResp() | ||
p.InitDefault() // for code coverage ... | ||
p.StatusMessage = "msg" | ||
p.StatusCode = 200 | ||
p.Extra = map[string]string{"k": "v"} | ||
t.Log(p.String()) | ||
|
||
sz := p.BLength() | ||
b := make([]byte, sz) | ||
n := p.FastWrite(b) | ||
require.Equal(t, sz, n) | ||
|
||
p2 := NewBaseResp() | ||
n, err = p2.FastRead(b) | ||
require.Equal(t, len(b), n) | ||
require.NoError(t, err) | ||
require.Equal(t, p, p2) | ||
} |
Oops, something went wrong.