mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 23:49:57 +00:00
TUN-528: Move cloudflared into a separate repo
This commit is contained in:
24
vendor/zombiezen.com/go/capnproto2/internal/aircraftlib/BUILD.bazel
generated
vendored
Normal file
24
vendor/zombiezen.com/go/capnproto2/internal/aircraftlib/BUILD.bazel
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"aircraft.capnp.go",
|
||||
"generate.go",
|
||||
],
|
||||
importpath = "zombiezen.com/go/capnproto2/internal/aircraftlib",
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//:go_default_library",
|
||||
"//encoding/text:go_default_library",
|
||||
"//schemas:go_default_library",
|
||||
"//server:go_default_library",
|
||||
"@org_golang_x_net//context:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "schema",
|
||||
srcs = ["aircraft.capnp"],
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
353
vendor/zombiezen.com/go/capnproto2/internal/aircraftlib/aircraft.capnp
generated
vendored
Normal file
353
vendor/zombiezen.com/go/capnproto2/internal/aircraftlib/aircraft.capnp
generated
vendored
Normal file
@@ -0,0 +1,353 @@
|
||||
using Go = import "/go.capnp";
|
||||
|
||||
$Go.package("aircraftlib");
|
||||
$Go.import("zombiezen.com/go/capnproto2/internal/aircraftlib");
|
||||
|
||||
@0x832bcc6686a26d56;
|
||||
|
||||
const constDate :Zdate = (year = 2015, month = 8, day = 27);
|
||||
const constList :List(Zdate) = [(year = 2015, month = 8, day = 27), (year = 2015, month = 8, day = 28)];
|
||||
const constEnum :Airport = jfk;
|
||||
|
||||
struct Zdate {
|
||||
year @0 :Int16;
|
||||
month @1 :UInt8;
|
||||
day @2 :UInt8;
|
||||
}
|
||||
|
||||
struct Zdata {
|
||||
data @0 :Data;
|
||||
}
|
||||
|
||||
|
||||
enum Airport {
|
||||
none @0;
|
||||
jfk @1;
|
||||
lax @2;
|
||||
sfo @3;
|
||||
luv @4;
|
||||
dfw @5;
|
||||
test @6;
|
||||
# test must be last because we use it to count
|
||||
# the number of elements in the Airport enum.
|
||||
}
|
||||
|
||||
struct PlaneBase {
|
||||
name @0: Text;
|
||||
homes @1: List(Airport);
|
||||
rating @2: Int64;
|
||||
canFly @3: Bool;
|
||||
capacity @4: Int64;
|
||||
maxSpeed @5: Float64;
|
||||
}
|
||||
|
||||
struct B737 {
|
||||
base @0: PlaneBase;
|
||||
}
|
||||
|
||||
struct A320 {
|
||||
base @0: PlaneBase;
|
||||
}
|
||||
|
||||
struct F16 {
|
||||
base @0: PlaneBase;
|
||||
}
|
||||
|
||||
|
||||
# need a struct with at least two pointers to catch certain bugs
|
||||
struct Regression {
|
||||
base @0: PlaneBase;
|
||||
b0 @1: Float64; # intercept
|
||||
beta @2: List(Float64);
|
||||
planes @3: List(Aircraft);
|
||||
ymu @4: Float64; # y-mean in original space
|
||||
ysd @5: Float64; # y-standard deviation in original space
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct Aircraft {
|
||||
# so we can restrict
|
||||
# and specify a Plane is required in
|
||||
# certain places.
|
||||
|
||||
union {
|
||||
void @0: Void; # @0 will be the default, so always make @0 a Void.
|
||||
b737 @1: B737;
|
||||
a320 @2: A320;
|
||||
f16 @3: F16;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct Z {
|
||||
# Z must contain all types, as this is our
|
||||
# runtime type identification. It is a thin shim.
|
||||
|
||||
union {
|
||||
void @0: Void; # always first in any union.
|
||||
zz @1: Z; # any. fyi, this can't be 'z' alone.
|
||||
|
||||
f64 @2: Float64;
|
||||
f32 @3: Float32;
|
||||
|
||||
i64 @4: Int64;
|
||||
i32 @5: Int32;
|
||||
i16 @6: Int16;
|
||||
i8 @7: Int8;
|
||||
|
||||
u64 @8: UInt64;
|
||||
u32 @9: UInt32;
|
||||
u16 @10: UInt16;
|
||||
u8 @11: UInt8;
|
||||
|
||||
bool @12: Bool;
|
||||
text @13: Text;
|
||||
blob @14: Data;
|
||||
|
||||
f64vec @15: List(Float64);
|
||||
f32vec @16: List(Float32);
|
||||
|
||||
i64vec @17: List(Int64);
|
||||
i32vec @18: List(Int32);
|
||||
i16vec @19: List(Int16);
|
||||
i8vec @20: List(Int8);
|
||||
|
||||
u64vec @21: List(UInt64);
|
||||
u32vec @22: List(UInt32);
|
||||
u16vec @23: List(UInt16);
|
||||
u8vec @24: List(UInt8);
|
||||
|
||||
boolvec @39: List(Bool);
|
||||
datavec @40: List(Data);
|
||||
textvec @41: List(Text);
|
||||
|
||||
zvec @25: List(Z);
|
||||
zvecvec @26: List(List(Z));
|
||||
|
||||
zdate @27: Zdate;
|
||||
zdata @28: Zdata;
|
||||
|
||||
aircraftvec @29: List(Aircraft);
|
||||
aircraft @30: Aircraft;
|
||||
regression @31: Regression;
|
||||
planebase @32: PlaneBase;
|
||||
airport @33: Airport;
|
||||
b737 @34: B737;
|
||||
a320 @35: A320;
|
||||
f16 @36: F16;
|
||||
zdatevec @37: List(Zdate);
|
||||
zdatavec @38: List(Zdata);
|
||||
|
||||
grp :group {
|
||||
first @42 :UInt64;
|
||||
second @43 :UInt64;
|
||||
}
|
||||
|
||||
echo @44 :Echo;
|
||||
echoBases @45 :EchoBases;
|
||||
}
|
||||
}
|
||||
|
||||
# tests for Text/List(Text) recusion handling
|
||||
|
||||
struct Counter {
|
||||
size @0: Int64;
|
||||
words @1: Text;
|
||||
wordlist @2: List(Text);
|
||||
bitlist @3: List(Bool);
|
||||
}
|
||||
|
||||
struct Bag {
|
||||
counter @0: Counter;
|
||||
}
|
||||
|
||||
struct Zserver {
|
||||
waitingjobs @0: List(Zjob);
|
||||
}
|
||||
|
||||
struct Zjob {
|
||||
cmd @0: Text;
|
||||
args @1: List(Text);
|
||||
}
|
||||
|
||||
# versioning test structs
|
||||
|
||||
struct VerEmpty {
|
||||
}
|
||||
|
||||
struct VerOneData {
|
||||
val @0: Int16;
|
||||
}
|
||||
|
||||
struct VerTwoData {
|
||||
val @0: Int16;
|
||||
duo @1: Int64;
|
||||
}
|
||||
|
||||
struct VerOnePtr {
|
||||
ptr @0: VerOneData;
|
||||
}
|
||||
|
||||
struct VerTwoPtr {
|
||||
ptr1 @0: VerOneData;
|
||||
ptr2 @1: VerOneData;
|
||||
}
|
||||
|
||||
struct VerTwoDataTwoPtr {
|
||||
val @0: Int16;
|
||||
duo @1: Int64;
|
||||
ptr1 @2: VerOneData;
|
||||
ptr2 @3: VerOneData;
|
||||
}
|
||||
|
||||
struct HoldsVerEmptyList {
|
||||
mylist @0: List(VerEmpty);
|
||||
}
|
||||
|
||||
struct HoldsVerOneDataList {
|
||||
mylist @0: List(VerOneData);
|
||||
}
|
||||
|
||||
struct HoldsVerTwoDataList {
|
||||
mylist @0: List(VerTwoData);
|
||||
}
|
||||
|
||||
struct HoldsVerOnePtrList {
|
||||
mylist @0: List(VerOnePtr);
|
||||
}
|
||||
|
||||
struct HoldsVerTwoPtrList {
|
||||
mylist @0: List(VerTwoPtr);
|
||||
}
|
||||
|
||||
struct HoldsVerTwoTwoList {
|
||||
mylist @0: List(VerTwoDataTwoPtr);
|
||||
}
|
||||
|
||||
struct HoldsVerTwoTwoPlus {
|
||||
mylist @0: List(VerTwoTwoPlus);
|
||||
}
|
||||
|
||||
struct VerTwoTwoPlus {
|
||||
val @0: Int16;
|
||||
duo @1: Int64;
|
||||
ptr1 @2: VerTwoDataTwoPtr;
|
||||
ptr2 @3: VerTwoDataTwoPtr;
|
||||
tre @4: Int64;
|
||||
lst3 @5: List(Int64);
|
||||
}
|
||||
|
||||
# text handling
|
||||
|
||||
struct HoldsText {
|
||||
txt @0: Text;
|
||||
lst @1: List(Text);
|
||||
lstlst @2: List(List(Text));
|
||||
}
|
||||
|
||||
# test that we avoid unnecessary truncation
|
||||
|
||||
struct WrapEmpty {
|
||||
mightNotBeReallyEmpty @0: VerEmpty;
|
||||
}
|
||||
|
||||
struct Wrap2x2 {
|
||||
mightNotBeReallyEmpty @0: VerTwoDataTwoPtr;
|
||||
}
|
||||
|
||||
struct Wrap2x2plus {
|
||||
mightNotBeReallyEmpty @0: VerTwoTwoPlus;
|
||||
}
|
||||
|
||||
# test voids in a union
|
||||
|
||||
struct VoidUnion {
|
||||
union {
|
||||
a @0 :Void;
|
||||
b @1 :Void;
|
||||
}
|
||||
}
|
||||
|
||||
# test List(List(Struct(List)))
|
||||
|
||||
struct Nester1Capn {
|
||||
strs @0: List(Text);
|
||||
}
|
||||
|
||||
struct RWTestCapn {
|
||||
nestMatrix @0: List(List(Nester1Capn));
|
||||
}
|
||||
|
||||
struct ListStructCapn {
|
||||
vec @0: List(Nester1Capn);
|
||||
}
|
||||
|
||||
# test interfaces
|
||||
|
||||
interface Echo {
|
||||
echo @0 (in :Text) -> (out :Text);
|
||||
}
|
||||
|
||||
struct Hoth {
|
||||
base @0 :EchoBase;
|
||||
}
|
||||
|
||||
struct EchoBase {
|
||||
echo @0 :Echo;
|
||||
}
|
||||
|
||||
# test List(Struct(Interface))
|
||||
|
||||
struct EchoBases {
|
||||
bases @0 :List(EchoBase);
|
||||
}
|
||||
|
||||
# test transforms
|
||||
|
||||
struct StackingRoot {
|
||||
a @1 :StackingA;
|
||||
aWithDefault @0 :StackingA = (num = 42);
|
||||
}
|
||||
|
||||
struct StackingA {
|
||||
num @0 :Int32;
|
||||
b @1 :StackingB;
|
||||
}
|
||||
|
||||
struct StackingB {
|
||||
num @0 :Int32;
|
||||
}
|
||||
|
||||
interface CallSequence {
|
||||
getNumber @0 () -> (n :UInt32);
|
||||
}
|
||||
|
||||
# test defaults
|
||||
|
||||
struct Defaults {
|
||||
text @0 :Text = "foo";
|
||||
data @1 :Data = "bar";
|
||||
float @2 :Float32 = 3.14;
|
||||
int @3 :Int32 = -123;
|
||||
uint @4 :UInt32 = 42;
|
||||
}
|
||||
|
||||
# benchmarks
|
||||
|
||||
struct BenchmarkA {
|
||||
name @0 :Text;
|
||||
birthDay @1 :Int64;
|
||||
phone @2 :Text;
|
||||
siblings @3 :Int32;
|
||||
spouse @4 :Bool;
|
||||
money @5 :Float64;
|
||||
}
|
||||
|
||||
struct AllocBenchmark {
|
||||
fields @0 :List(Field);
|
||||
|
||||
struct Field {
|
||||
stringValue @0 :Text;
|
||||
}
|
||||
}
|
6270
vendor/zombiezen.com/go/capnproto2/internal/aircraftlib/aircraft.capnp.go
generated
vendored
Normal file
6270
vendor/zombiezen.com/go/capnproto2/internal/aircraftlib/aircraft.capnp.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3
vendor/zombiezen.com/go/capnproto2/internal/aircraftlib/generate.go
generated
vendored
Normal file
3
vendor/zombiezen.com/go/capnproto2/internal/aircraftlib/generate.go
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
package aircraftlib
|
||||
|
||||
//go:generate capnp compile -I ../../std -ogo aircraft.capnp
|
8
vendor/zombiezen.com/go/capnproto2/internal/capnptool/BUILD.bazel
generated
vendored
Normal file
8
vendor/zombiezen.com/go/capnproto2/internal/capnptool/BUILD.bazel
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["capnptool.go"],
|
||||
importpath = "zombiezen.com/go/capnproto2/internal/capnptool",
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
76
vendor/zombiezen.com/go/capnproto2/internal/capnptool/capnptool.go
generated
vendored
Normal file
76
vendor/zombiezen.com/go/capnproto2/internal/capnptool/capnptool.go
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
// Package capnptool provides an API for calling the capnp tool in tests.
|
||||
package capnptool
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Tool is the path to the capnp command-line tool.
|
||||
// It can be used from multiple goroutines.
|
||||
type Tool string
|
||||
|
||||
var cache struct {
|
||||
init sync.Once
|
||||
tool Tool
|
||||
err error
|
||||
}
|
||||
|
||||
// Find searches PATH for the capnp tool.
|
||||
func Find() (Tool, error) {
|
||||
cache.init.Do(func() {
|
||||
path, err := exec.LookPath("capnp")
|
||||
if err != nil {
|
||||
cache.err = err
|
||||
return
|
||||
}
|
||||
cache.tool = Tool(path)
|
||||
})
|
||||
return cache.tool, cache.err
|
||||
}
|
||||
|
||||
// Run executes the tool with the given stdin and arguments returns the stdout.
|
||||
func (tool Tool) Run(stdin io.Reader, args ...string) ([]byte, error) {
|
||||
c := exec.Command(string(tool), args...)
|
||||
c.Stdin = stdin
|
||||
stderr := new(bytes.Buffer)
|
||||
c.Stderr = stderr
|
||||
out, err := c.Output()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("run `%s`: %v; stderr:\n%s", strings.Join(c.Args, " "), err, stderr)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Encode encodes Cap'n Proto text into the binary representation.
|
||||
func (tool Tool) Encode(typ Type, text string) ([]byte, error) {
|
||||
return tool.Run(strings.NewReader(text), "encode", typ.SchemaPath, typ.Name)
|
||||
}
|
||||
|
||||
// Decode decodes a Cap'n Proto message into text.
|
||||
func (tool Tool) Decode(typ Type, r io.Reader) (string, error) {
|
||||
out, err := tool.Run(r, "decode", "--short", typ.SchemaPath, typ.Name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(out), nil
|
||||
}
|
||||
|
||||
// DecodePacked decodes a packed Cap'n Proto message into text.
|
||||
func (tool Tool) DecodePacked(typ Type, r io.Reader) (string, error) {
|
||||
out, err := tool.Run(r, "decode", "--short", "--packed", typ.SchemaPath, typ.Name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(out), nil
|
||||
}
|
||||
|
||||
// Type is a reference to a Cap'n Proto type in a schema.
|
||||
type Type struct {
|
||||
SchemaPath string
|
||||
Name string
|
||||
}
|
193
vendor/zombiezen.com/go/capnproto2/internal/cmd/mktemplates/mktemplates.go
generated
vendored
Normal file
193
vendor/zombiezen.com/go/capnproto2/internal/cmd/mktemplates/mktemplates.go
generated
vendored
Normal file
@@ -0,0 +1,193 @@
|
||||
// +build mktemplates
|
||||
// Build tag so that users who run `go get zombiezen.com/go/capnproto2/...` don't install this command.
|
||||
// cd internal/cmd/mktemplates && go build -tags=mktemplates
|
||||
|
||||
// mktemplates is a command to regenerate capnpc-go/templates.go.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template/parse"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 3 {
|
||||
fmt.Fprintln(os.Stderr, "usage: mktemplates OUT DIR")
|
||||
os.Exit(64)
|
||||
}
|
||||
dir := os.Args[2]
|
||||
names, err := listdir(dir)
|
||||
if err != nil {
|
||||
fatalln(err)
|
||||
}
|
||||
ts := make([]template, len(names))
|
||||
for i, name := range names {
|
||||
src, err := ioutil.ReadFile(filepath.Join(dir, name))
|
||||
if err != nil {
|
||||
fatalf("reading template %s: %v", name, err)
|
||||
}
|
||||
compiled, err := compileTemplate(name, string(src))
|
||||
if err != nil {
|
||||
fatalf("compiling template %s: %v", name, err)
|
||||
}
|
||||
ts[i] = template{
|
||||
name: name,
|
||||
content: compiled,
|
||||
}
|
||||
}
|
||||
genbuf := new(bytes.Buffer)
|
||||
err = generateGo(genbuf, os.Args, ts)
|
||||
if err != nil {
|
||||
fatalln("generating code:", err)
|
||||
}
|
||||
code, err := format.Source(genbuf.Bytes())
|
||||
if err != nil {
|
||||
fatalln("formatting code:", err)
|
||||
}
|
||||
outname := os.Args[1]
|
||||
out, err := os.Create(outname)
|
||||
if err != nil {
|
||||
fatalf("opening destination %s: %v", outname, err)
|
||||
}
|
||||
_, err = out.Write(code)
|
||||
cerr := out.Close()
|
||||
if err != nil {
|
||||
fatalf("write to %s: %v", outname, err)
|
||||
}
|
||||
if cerr != nil {
|
||||
fatalln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func compileTemplate(name, src string) (string, error) {
|
||||
tset, err := parse.Parse(name, src, "{{", "}}", funcStubs)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return tset[name].Root.String(), nil
|
||||
}
|
||||
|
||||
func generateGo(w io.Writer, args []string, ts []template) error {
|
||||
src := new(bytes.Buffer)
|
||||
for _, t := range ts {
|
||||
fmt.Fprintf(src, "{{define %q}}", t.name)
|
||||
src.WriteString(t.content)
|
||||
src.WriteString("{{end}}")
|
||||
}
|
||||
|
||||
// TODO(light): collect errors
|
||||
fmt.Fprintln(w, "// Code generated from templates directory. DO NOT EDIT.")
|
||||
fmt.Fprintln(w)
|
||||
fmt.Fprintln(w, "//go:generate", strings.Join(args, " "))
|
||||
fmt.Fprintln(w)
|
||||
fmt.Fprintln(w, "package main")
|
||||
fmt.Fprintln(w, "import (")
|
||||
fmt.Fprintln(w, "\t\"strings\"")
|
||||
fmt.Fprintln(w, "\t\"text/template\"")
|
||||
fmt.Fprintln(w, ")")
|
||||
fmt.Fprintln(w, "var templates = template.Must(template.New(\"\").Funcs(template.FuncMap{")
|
||||
fmt.Fprintln(w, "\t\"title\": strings.Title,")
|
||||
fmt.Fprintf(w, "}).Parse(\n\t%q))\n", src.Bytes())
|
||||
for _, t := range ts {
|
||||
if strings.HasPrefix(t.name, "_") {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(w, "func render%s(r renderer, p %sParams) error {\n\treturn r.Render(%[2]q, p)\n}\n", strings.Title(t.name), t.name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type template struct {
|
||||
name string
|
||||
content string
|
||||
}
|
||||
|
||||
func listdir(name string) ([]string, error) {
|
||||
f, err := os.Open(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
names, err := f.Readdirnames(-1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
n := 0
|
||||
for _, name := range names {
|
||||
if !strings.HasPrefix(name, ".") {
|
||||
names[n] = name
|
||||
n++
|
||||
}
|
||||
}
|
||||
names = names[:n]
|
||||
sort.Strings(names)
|
||||
return names, nil
|
||||
}
|
||||
|
||||
func fatalln(args ...interface{}) {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("mktemplates: ")
|
||||
fmt.Fprintln(&buf, args...)
|
||||
os.Stderr.Write(buf.Bytes())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func fatalf(format string, args ...interface{}) {
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("mktemplates: ")
|
||||
fmt.Fprintf(&buf, format, args...)
|
||||
if !bytes.HasSuffix(buf.Bytes(), []byte{'\n'}) {
|
||||
buf.Write([]byte{'\n'})
|
||||
}
|
||||
os.Stderr.Write(buf.Bytes())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var funcStubs = map[string]interface{}{
|
||||
// Built-ins
|
||||
"and": variadicBoolStub,
|
||||
"call": func(interface{}, ...interface{}) (interface{}, error) { return nil, nil },
|
||||
"eq": func(arg0 interface{}, args ...interface{}) (bool, error) { return false, nil },
|
||||
"ge": cmpStub,
|
||||
"gt": cmpStub,
|
||||
"html": escaperStub,
|
||||
"index": func(interface{}, ...interface{}) (interface{}, error) { return nil, nil },
|
||||
"js": escaperStub,
|
||||
"le": cmpStub,
|
||||
"len": func(interface{}) (int, error) { return 0, nil },
|
||||
"lt": cmpStub,
|
||||
"ne": cmpStub,
|
||||
"not": func(interface{}) bool { return false },
|
||||
"or": variadicBoolStub,
|
||||
"print": fmt.Sprint,
|
||||
"printf": fmt.Sprintf,
|
||||
"println": fmt.Sprintln,
|
||||
"urlquery": escaperStub,
|
||||
|
||||
// App-specific
|
||||
"title": strings.Title,
|
||||
}
|
||||
|
||||
func variadicBoolStub(arg0 interface{}, args ...interface{}) interface{} {
|
||||
return arg0
|
||||
}
|
||||
|
||||
func cmpStub(interface{}, interface{}) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func escaperStub(...interface{}) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func importStub() string {
|
||||
return ""
|
||||
}
|
24
vendor/zombiezen.com/go/capnproto2/internal/demo/BUILD.bazel
generated
vendored
Normal file
24
vendor/zombiezen.com/go/capnproto2/internal/demo/BUILD.bazel
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["doc.go"],
|
||||
importpath = "zombiezen.com/go/capnproto2/internal/demo",
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"book_test.go",
|
||||
"hash_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//:go_default_library",
|
||||
"//internal/demo/books:go_default_library",
|
||||
"//internal/demo/hashes:go_default_library",
|
||||
"//rpc:go_default_library",
|
||||
"@org_golang_x_net//context:go_default_library",
|
||||
],
|
||||
)
|
61
vendor/zombiezen.com/go/capnproto2/internal/demo/book_test.go
generated
vendored
Normal file
61
vendor/zombiezen.com/go/capnproto2/internal/demo/book_test.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
package demo_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"zombiezen.com/go/capnproto2"
|
||||
"zombiezen.com/go/capnproto2/internal/demo/books"
|
||||
)
|
||||
|
||||
func Example_book() {
|
||||
r, w := io.Pipe()
|
||||
go writer(w)
|
||||
reader(r)
|
||||
// Output:
|
||||
// "War and Peace" has 1440 pages
|
||||
}
|
||||
|
||||
func writer(out io.Writer) {
|
||||
// Make a brand new empty message. A Message allocates Cap'n Proto structs.
|
||||
msg, seg, err := capnp.NewMessage(capnp.SingleSegment(nil))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Create a new Book struct. Every message must have a root struct.
|
||||
book, err := books.NewRootBook(seg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
book.SetTitle("War and Peace")
|
||||
book.SetPageCount(1440)
|
||||
|
||||
// Write the message to stdout.
|
||||
err = capnp.NewEncoder(out).Encode(msg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func reader(in io.Reader) {
|
||||
// Read the message from stdin.
|
||||
msg, err := capnp.NewDecoder(in).Decode()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Extract the root struct from the message.
|
||||
book, err := books.ReadRootBook(msg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Access fields from the struct.
|
||||
title, err := book.Title()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pageCount := book.PageCount()
|
||||
fmt.Printf("%q has %d pages\n", title, pageCount)
|
||||
}
|
16
vendor/zombiezen.com/go/capnproto2/internal/demo/books/BUILD.bazel
generated
vendored
Normal file
16
vendor/zombiezen.com/go/capnproto2/internal/demo/books/BUILD.bazel
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"books.capnp.go",
|
||||
"gen.go",
|
||||
],
|
||||
importpath = "zombiezen.com/go/capnproto2/internal/demo/books",
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//:go_default_library",
|
||||
"//encoding/text:go_default_library",
|
||||
"//schemas:go_default_library",
|
||||
],
|
||||
)
|
12
vendor/zombiezen.com/go/capnproto2/internal/demo/books/books.capnp
generated
vendored
Normal file
12
vendor/zombiezen.com/go/capnproto2/internal/demo/books/books.capnp
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
using Go = import "/go.capnp";
|
||||
@0x85d3acc39d94e0f8;
|
||||
$Go.package("books");
|
||||
$Go.import("zombiezen.com/go/capnproto2/internal/demo/books");
|
||||
|
||||
struct Book {
|
||||
title @0 :Text;
|
||||
# Title of the book.
|
||||
|
||||
pageCount @1 :Int32;
|
||||
# Number of pages in the book.
|
||||
}
|
104
vendor/zombiezen.com/go/capnproto2/internal/demo/books/books.capnp.go
generated
vendored
Normal file
104
vendor/zombiezen.com/go/capnproto2/internal/demo/books/books.capnp.go
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
// Code generated by capnpc-go. DO NOT EDIT.
|
||||
|
||||
package books
|
||||
|
||||
import (
|
||||
capnp "zombiezen.com/go/capnproto2"
|
||||
text "zombiezen.com/go/capnproto2/encoding/text"
|
||||
schemas "zombiezen.com/go/capnproto2/schemas"
|
||||
)
|
||||
|
||||
type Book struct{ capnp.Struct }
|
||||
|
||||
// Book_TypeID is the unique identifier for the type Book.
|
||||
const Book_TypeID = 0x8100cc88d7d4d47c
|
||||
|
||||
func NewBook(s *capnp.Segment) (Book, error) {
|
||||
st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 1})
|
||||
return Book{st}, err
|
||||
}
|
||||
|
||||
func NewRootBook(s *capnp.Segment) (Book, error) {
|
||||
st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 1})
|
||||
return Book{st}, err
|
||||
}
|
||||
|
||||
func ReadRootBook(msg *capnp.Message) (Book, error) {
|
||||
root, err := msg.RootPtr()
|
||||
return Book{root.Struct()}, err
|
||||
}
|
||||
|
||||
func (s Book) String() string {
|
||||
str, _ := text.Marshal(0x8100cc88d7d4d47c, s.Struct)
|
||||
return str
|
||||
}
|
||||
|
||||
func (s Book) Title() (string, error) {
|
||||
p, err := s.Struct.Ptr(0)
|
||||
return p.Text(), err
|
||||
}
|
||||
|
||||
func (s Book) HasTitle() bool {
|
||||
p, err := s.Struct.Ptr(0)
|
||||
return p.IsValid() || err != nil
|
||||
}
|
||||
|
||||
func (s Book) TitleBytes() ([]byte, error) {
|
||||
p, err := s.Struct.Ptr(0)
|
||||
return p.TextBytes(), err
|
||||
}
|
||||
|
||||
func (s Book) SetTitle(v string) error {
|
||||
return s.Struct.SetText(0, v)
|
||||
}
|
||||
|
||||
func (s Book) PageCount() int32 {
|
||||
return int32(s.Struct.Uint32(0))
|
||||
}
|
||||
|
||||
func (s Book) SetPageCount(v int32) {
|
||||
s.Struct.SetUint32(0, uint32(v))
|
||||
}
|
||||
|
||||
// Book_List is a list of Book.
|
||||
type Book_List struct{ capnp.List }
|
||||
|
||||
// NewBook creates a new list of Book.
|
||||
func NewBook_List(s *capnp.Segment, sz int32) (Book_List, error) {
|
||||
l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 8, PointerCount: 1}, sz)
|
||||
return Book_List{l}, err
|
||||
}
|
||||
|
||||
func (s Book_List) At(i int) Book { return Book{s.List.Struct(i)} }
|
||||
|
||||
func (s Book_List) Set(i int, v Book) error { return s.List.SetStruct(i, v.Struct) }
|
||||
|
||||
func (s Book_List) String() string {
|
||||
str, _ := text.MarshalList(0x8100cc88d7d4d47c, s.List)
|
||||
return str
|
||||
}
|
||||
|
||||
// Book_Promise is a wrapper for a Book promised by a client call.
|
||||
type Book_Promise struct{ *capnp.Pipeline }
|
||||
|
||||
func (p Book_Promise) Struct() (Book, error) {
|
||||
s, err := p.Pipeline.Struct()
|
||||
return Book{s}, err
|
||||
}
|
||||
|
||||
const schema_85d3acc39d94e0f8 = "x\xda\x12\x88w`2d\xdd\xcf\xc8\xc0\x10(\xc2\xca" +
|
||||
"\xb6\xbf\xe6\xca\x95\xeb\x1dg\x1a\x03y\x18\x19\xff\xffx" +
|
||||
"0e\xee\xe15\x97[\x19X\x19\xd9\x19\x18\x04\x8fv" +
|
||||
"\x09\x9e\x05\xd1'\xcb\x19t\xff'\xe5\xe7g\x17\xeb%" +
|
||||
"'2\x16\xe4\x15X9\xe5\xe7g30\x0402\x06" +
|
||||
"r0\xb300\xb0020\x08j\x1a10\x04\xaa" +
|
||||
"03\x06\x1a0122\x8a0\x82\xc4t\x83\x18\x18" +
|
||||
"\x02u\x98\x19\x03-\x98\x18\xe5K2KrR\x19y" +
|
||||
"\x18\x98\x18y\x18\x18\xff\x17$\xa6\xa7:\xe7\x97\xe61" +
|
||||
"0\x960\xb2001\xb200\x02\x02\x00\x00\xff\xff" +
|
||||
"F\xa9$\xae"
|
||||
|
||||
func init() {
|
||||
schemas.Register(schema_85d3acc39d94e0f8,
|
||||
0x8100cc88d7d4d47c)
|
||||
}
|
3
vendor/zombiezen.com/go/capnproto2/internal/demo/books/gen.go
generated
vendored
Normal file
3
vendor/zombiezen.com/go/capnproto2/internal/demo/books/gen.go
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
//go:generate capnp compile -I ../../../std -ogo books.capnp
|
||||
|
||||
package books
|
2
vendor/zombiezen.com/go/capnproto2/internal/demo/doc.go
generated
vendored
Normal file
2
vendor/zombiezen.com/go/capnproto2/internal/demo/doc.go
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
// Package demo contains example tests.
|
||||
package demo
|
93
vendor/zombiezen.com/go/capnproto2/internal/demo/hash_test.go
generated
vendored
Normal file
93
vendor/zombiezen.com/go/capnproto2/internal/demo/hash_test.go
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
package demo_test
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"hash"
|
||||
"net"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"zombiezen.com/go/capnproto2/internal/demo/hashes"
|
||||
"zombiezen.com/go/capnproto2/rpc"
|
||||
)
|
||||
|
||||
// hashFactory is a local implementation of HashFactory.
|
||||
type hashFactory struct{}
|
||||
|
||||
func (hf hashFactory) NewSha1(call hashes.HashFactory_newSha1) error {
|
||||
// Create a new locally implemented Hash capability.
|
||||
hs := hashes.Hash_ServerToClient(hashServer{sha1.New()})
|
||||
// Notice that methods can return other interfaces.
|
||||
return call.Results.SetHash(hs)
|
||||
}
|
||||
|
||||
// hashServer is a local implementation of Hash.
|
||||
type hashServer struct {
|
||||
h hash.Hash
|
||||
}
|
||||
|
||||
func (hs hashServer) Write(call hashes.Hash_write) error {
|
||||
data, err := call.Params.Data()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = hs.h.Write(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hs hashServer) Sum(call hashes.Hash_sum) error {
|
||||
s := hs.h.Sum(nil)
|
||||
return call.Results.SetHash(s)
|
||||
}
|
||||
|
||||
func server(c net.Conn) error {
|
||||
// Create a new locally implemented HashFactory.
|
||||
main := hashes.HashFactory_ServerToClient(hashFactory{})
|
||||
// Listen for calls, using the HashFactory as the bootstrap interface.
|
||||
conn := rpc.NewConn(rpc.StreamTransport(c), rpc.MainInterface(main.Client))
|
||||
// Wait for connection to abort.
|
||||
err := conn.Wait()
|
||||
return err
|
||||
}
|
||||
|
||||
func client(ctx context.Context, c net.Conn) error {
|
||||
// Create a connection that we can use to get the HashFactory.
|
||||
conn := rpc.NewConn(rpc.StreamTransport(c))
|
||||
defer conn.Close()
|
||||
// Get the "bootstrap" interface. This is the capability set with
|
||||
// rpc.MainInterface on the remote side.
|
||||
hf := hashes.HashFactory{Client: conn.Bootstrap(ctx)}
|
||||
|
||||
// Now we can call methods on hf, and they will be sent over c.
|
||||
s := hf.NewSha1(ctx, nil).Hash()
|
||||
// s refers to a remote Hash. Method calls are delivered in order.
|
||||
s.Write(ctx, func(p hashes.Hash_write_Params) error {
|
||||
err := p.SetData([]byte("Hello, "))
|
||||
return err
|
||||
})
|
||||
s.Write(ctx, func(p hashes.Hash_write_Params) error {
|
||||
err := p.SetData([]byte("World!"))
|
||||
return err
|
||||
})
|
||||
result, err := s.Sum(ctx, nil).Struct()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sha1Val, err := result.Hash()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("sha1: %x\n", sha1Val)
|
||||
return nil
|
||||
}
|
||||
|
||||
func Example_hash() {
|
||||
c1, c2 := net.Pipe()
|
||||
go server(c1)
|
||||
client(context.Background(), c2)
|
||||
// Output:
|
||||
// sha1: 0a0a9f2a6772942557ab5355d76af442f8f65e01
|
||||
}
|
18
vendor/zombiezen.com/go/capnproto2/internal/demo/hashes/BUILD.bazel
generated
vendored
Normal file
18
vendor/zombiezen.com/go/capnproto2/internal/demo/hashes/BUILD.bazel
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"gen.go",
|
||||
"hash.capnp.go",
|
||||
],
|
||||
importpath = "zombiezen.com/go/capnproto2/internal/demo/hashes",
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//:go_default_library",
|
||||
"//encoding/text:go_default_library",
|
||||
"//schemas:go_default_library",
|
||||
"//server:go_default_library",
|
||||
"@org_golang_x_net//context:go_default_library",
|
||||
],
|
||||
)
|
3
vendor/zombiezen.com/go/capnproto2/internal/demo/hashes/gen.go
generated
vendored
Normal file
3
vendor/zombiezen.com/go/capnproto2/internal/demo/hashes/gen.go
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
//go:generate capnp compile -I ../../../std -ogo hash.capnp
|
||||
|
||||
package hashes
|
13
vendor/zombiezen.com/go/capnproto2/internal/demo/hashes/hash.capnp
generated
vendored
Normal file
13
vendor/zombiezen.com/go/capnproto2/internal/demo/hashes/hash.capnp
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
using Go = import "/go.capnp";
|
||||
@0xdb8274f9144abc7e;
|
||||
$Go.package("hashes");
|
||||
$Go.import("zombiezen.com/go/capnproto2/internal/demo/hashes");
|
||||
|
||||
interface HashFactory {
|
||||
newSha1 @0 () -> (hash :Hash);
|
||||
}
|
||||
|
||||
interface Hash {
|
||||
write @0 (data :Data) -> ();
|
||||
sum @1 () -> (hash :Data);
|
||||
}
|
605
vendor/zombiezen.com/go/capnproto2/internal/demo/hashes/hash.capnp.go
generated
vendored
Normal file
605
vendor/zombiezen.com/go/capnproto2/internal/demo/hashes/hash.capnp.go
generated
vendored
Normal file
@@ -0,0 +1,605 @@
|
||||
// Code generated by capnpc-go. DO NOT EDIT.
|
||||
|
||||
package hashes
|
||||
|
||||
import (
|
||||
context "golang.org/x/net/context"
|
||||
capnp "zombiezen.com/go/capnproto2"
|
||||
text "zombiezen.com/go/capnproto2/encoding/text"
|
||||
schemas "zombiezen.com/go/capnproto2/schemas"
|
||||
server "zombiezen.com/go/capnproto2/server"
|
||||
)
|
||||
|
||||
type HashFactory struct{ Client capnp.Client }
|
||||
|
||||
// HashFactory_TypeID is the unique identifier for the type HashFactory.
|
||||
const HashFactory_TypeID = 0xaead580f97fddabc
|
||||
|
||||
func (c HashFactory) NewSha1(ctx context.Context, params func(HashFactory_newSha1_Params) error, opts ...capnp.CallOption) HashFactory_newSha1_Results_Promise {
|
||||
if c.Client == nil {
|
||||
return HashFactory_newSha1_Results_Promise{Pipeline: capnp.NewPipeline(capnp.ErrorAnswer(capnp.ErrNullClient))}
|
||||
}
|
||||
call := &capnp.Call{
|
||||
Ctx: ctx,
|
||||
Method: capnp.Method{
|
||||
InterfaceID: 0xaead580f97fddabc,
|
||||
MethodID: 0,
|
||||
InterfaceName: "hash.capnp:HashFactory",
|
||||
MethodName: "newSha1",
|
||||
},
|
||||
Options: capnp.NewCallOptions(opts),
|
||||
}
|
||||
if params != nil {
|
||||
call.ParamsSize = capnp.ObjectSize{DataSize: 0, PointerCount: 0}
|
||||
call.ParamsFunc = func(s capnp.Struct) error { return params(HashFactory_newSha1_Params{Struct: s}) }
|
||||
}
|
||||
return HashFactory_newSha1_Results_Promise{Pipeline: capnp.NewPipeline(c.Client.Call(call))}
|
||||
}
|
||||
|
||||
type HashFactory_Server interface {
|
||||
NewSha1(HashFactory_newSha1) error
|
||||
}
|
||||
|
||||
func HashFactory_ServerToClient(s HashFactory_Server) HashFactory {
|
||||
c, _ := s.(server.Closer)
|
||||
return HashFactory{Client: server.New(HashFactory_Methods(nil, s), c)}
|
||||
}
|
||||
|
||||
func HashFactory_Methods(methods []server.Method, s HashFactory_Server) []server.Method {
|
||||
if cap(methods) == 0 {
|
||||
methods = make([]server.Method, 0, 1)
|
||||
}
|
||||
|
||||
methods = append(methods, server.Method{
|
||||
Method: capnp.Method{
|
||||
InterfaceID: 0xaead580f97fddabc,
|
||||
MethodID: 0,
|
||||
InterfaceName: "hash.capnp:HashFactory",
|
||||
MethodName: "newSha1",
|
||||
},
|
||||
Impl: func(c context.Context, opts capnp.CallOptions, p, r capnp.Struct) error {
|
||||
call := HashFactory_newSha1{c, opts, HashFactory_newSha1_Params{Struct: p}, HashFactory_newSha1_Results{Struct: r}}
|
||||
return s.NewSha1(call)
|
||||
},
|
||||
ResultsSize: capnp.ObjectSize{DataSize: 0, PointerCount: 1},
|
||||
})
|
||||
|
||||
return methods
|
||||
}
|
||||
|
||||
// HashFactory_newSha1 holds the arguments for a server call to HashFactory.newSha1.
|
||||
type HashFactory_newSha1 struct {
|
||||
Ctx context.Context
|
||||
Options capnp.CallOptions
|
||||
Params HashFactory_newSha1_Params
|
||||
Results HashFactory_newSha1_Results
|
||||
}
|
||||
|
||||
type HashFactory_newSha1_Params struct{ capnp.Struct }
|
||||
|
||||
// HashFactory_newSha1_Params_TypeID is the unique identifier for the type HashFactory_newSha1_Params.
|
||||
const HashFactory_newSha1_Params_TypeID = 0x92b20ad1a58ca0ca
|
||||
|
||||
func NewHashFactory_newSha1_Params(s *capnp.Segment) (HashFactory_newSha1_Params, error) {
|
||||
st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0})
|
||||
return HashFactory_newSha1_Params{st}, err
|
||||
}
|
||||
|
||||
func NewRootHashFactory_newSha1_Params(s *capnp.Segment) (HashFactory_newSha1_Params, error) {
|
||||
st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0})
|
||||
return HashFactory_newSha1_Params{st}, err
|
||||
}
|
||||
|
||||
func ReadRootHashFactory_newSha1_Params(msg *capnp.Message) (HashFactory_newSha1_Params, error) {
|
||||
root, err := msg.RootPtr()
|
||||
return HashFactory_newSha1_Params{root.Struct()}, err
|
||||
}
|
||||
|
||||
func (s HashFactory_newSha1_Params) String() string {
|
||||
str, _ := text.Marshal(0x92b20ad1a58ca0ca, s.Struct)
|
||||
return str
|
||||
}
|
||||
|
||||
// HashFactory_newSha1_Params_List is a list of HashFactory_newSha1_Params.
|
||||
type HashFactory_newSha1_Params_List struct{ capnp.List }
|
||||
|
||||
// NewHashFactory_newSha1_Params creates a new list of HashFactory_newSha1_Params.
|
||||
func NewHashFactory_newSha1_Params_List(s *capnp.Segment, sz int32) (HashFactory_newSha1_Params_List, error) {
|
||||
l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}, sz)
|
||||
return HashFactory_newSha1_Params_List{l}, err
|
||||
}
|
||||
|
||||
func (s HashFactory_newSha1_Params_List) At(i int) HashFactory_newSha1_Params {
|
||||
return HashFactory_newSha1_Params{s.List.Struct(i)}
|
||||
}
|
||||
|
||||
func (s HashFactory_newSha1_Params_List) Set(i int, v HashFactory_newSha1_Params) error {
|
||||
return s.List.SetStruct(i, v.Struct)
|
||||
}
|
||||
|
||||
func (s HashFactory_newSha1_Params_List) String() string {
|
||||
str, _ := text.MarshalList(0x92b20ad1a58ca0ca, s.List)
|
||||
return str
|
||||
}
|
||||
|
||||
// HashFactory_newSha1_Params_Promise is a wrapper for a HashFactory_newSha1_Params promised by a client call.
|
||||
type HashFactory_newSha1_Params_Promise struct{ *capnp.Pipeline }
|
||||
|
||||
func (p HashFactory_newSha1_Params_Promise) Struct() (HashFactory_newSha1_Params, error) {
|
||||
s, err := p.Pipeline.Struct()
|
||||
return HashFactory_newSha1_Params{s}, err
|
||||
}
|
||||
|
||||
type HashFactory_newSha1_Results struct{ capnp.Struct }
|
||||
|
||||
// HashFactory_newSha1_Results_TypeID is the unique identifier for the type HashFactory_newSha1_Results.
|
||||
const HashFactory_newSha1_Results_TypeID = 0xea3e50f7663f7bdf
|
||||
|
||||
func NewHashFactory_newSha1_Results(s *capnp.Segment) (HashFactory_newSha1_Results, error) {
|
||||
st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1})
|
||||
return HashFactory_newSha1_Results{st}, err
|
||||
}
|
||||
|
||||
func NewRootHashFactory_newSha1_Results(s *capnp.Segment) (HashFactory_newSha1_Results, error) {
|
||||
st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1})
|
||||
return HashFactory_newSha1_Results{st}, err
|
||||
}
|
||||
|
||||
func ReadRootHashFactory_newSha1_Results(msg *capnp.Message) (HashFactory_newSha1_Results, error) {
|
||||
root, err := msg.RootPtr()
|
||||
return HashFactory_newSha1_Results{root.Struct()}, err
|
||||
}
|
||||
|
||||
func (s HashFactory_newSha1_Results) String() string {
|
||||
str, _ := text.Marshal(0xea3e50f7663f7bdf, s.Struct)
|
||||
return str
|
||||
}
|
||||
|
||||
func (s HashFactory_newSha1_Results) Hash() Hash {
|
||||
p, _ := s.Struct.Ptr(0)
|
||||
return Hash{Client: p.Interface().Client()}
|
||||
}
|
||||
|
||||
func (s HashFactory_newSha1_Results) HasHash() bool {
|
||||
p, err := s.Struct.Ptr(0)
|
||||
return p.IsValid() || err != nil
|
||||
}
|
||||
|
||||
func (s HashFactory_newSha1_Results) SetHash(v Hash) error {
|
||||
if v.Client == nil {
|
||||
return s.Struct.SetPtr(0, capnp.Ptr{})
|
||||
}
|
||||
seg := s.Segment()
|
||||
in := capnp.NewInterface(seg, seg.Message().AddCap(v.Client))
|
||||
return s.Struct.SetPtr(0, in.ToPtr())
|
||||
}
|
||||
|
||||
// HashFactory_newSha1_Results_List is a list of HashFactory_newSha1_Results.
|
||||
type HashFactory_newSha1_Results_List struct{ capnp.List }
|
||||
|
||||
// NewHashFactory_newSha1_Results creates a new list of HashFactory_newSha1_Results.
|
||||
func NewHashFactory_newSha1_Results_List(s *capnp.Segment, sz int32) (HashFactory_newSha1_Results_List, error) {
|
||||
l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz)
|
||||
return HashFactory_newSha1_Results_List{l}, err
|
||||
}
|
||||
|
||||
func (s HashFactory_newSha1_Results_List) At(i int) HashFactory_newSha1_Results {
|
||||
return HashFactory_newSha1_Results{s.List.Struct(i)}
|
||||
}
|
||||
|
||||
func (s HashFactory_newSha1_Results_List) Set(i int, v HashFactory_newSha1_Results) error {
|
||||
return s.List.SetStruct(i, v.Struct)
|
||||
}
|
||||
|
||||
func (s HashFactory_newSha1_Results_List) String() string {
|
||||
str, _ := text.MarshalList(0xea3e50f7663f7bdf, s.List)
|
||||
return str
|
||||
}
|
||||
|
||||
// HashFactory_newSha1_Results_Promise is a wrapper for a HashFactory_newSha1_Results promised by a client call.
|
||||
type HashFactory_newSha1_Results_Promise struct{ *capnp.Pipeline }
|
||||
|
||||
func (p HashFactory_newSha1_Results_Promise) Struct() (HashFactory_newSha1_Results, error) {
|
||||
s, err := p.Pipeline.Struct()
|
||||
return HashFactory_newSha1_Results{s}, err
|
||||
}
|
||||
|
||||
func (p HashFactory_newSha1_Results_Promise) Hash() Hash {
|
||||
return Hash{Client: p.Pipeline.GetPipeline(0).Client()}
|
||||
}
|
||||
|
||||
type Hash struct{ Client capnp.Client }
|
||||
|
||||
// Hash_TypeID is the unique identifier for the type Hash.
|
||||
const Hash_TypeID = 0xf29f97dd675a9431
|
||||
|
||||
func (c Hash) Write(ctx context.Context, params func(Hash_write_Params) error, opts ...capnp.CallOption) Hash_write_Results_Promise {
|
||||
if c.Client == nil {
|
||||
return Hash_write_Results_Promise{Pipeline: capnp.NewPipeline(capnp.ErrorAnswer(capnp.ErrNullClient))}
|
||||
}
|
||||
call := &capnp.Call{
|
||||
Ctx: ctx,
|
||||
Method: capnp.Method{
|
||||
InterfaceID: 0xf29f97dd675a9431,
|
||||
MethodID: 0,
|
||||
InterfaceName: "hash.capnp:Hash",
|
||||
MethodName: "write",
|
||||
},
|
||||
Options: capnp.NewCallOptions(opts),
|
||||
}
|
||||
if params != nil {
|
||||
call.ParamsSize = capnp.ObjectSize{DataSize: 0, PointerCount: 1}
|
||||
call.ParamsFunc = func(s capnp.Struct) error { return params(Hash_write_Params{Struct: s}) }
|
||||
}
|
||||
return Hash_write_Results_Promise{Pipeline: capnp.NewPipeline(c.Client.Call(call))}
|
||||
}
|
||||
func (c Hash) Sum(ctx context.Context, params func(Hash_sum_Params) error, opts ...capnp.CallOption) Hash_sum_Results_Promise {
|
||||
if c.Client == nil {
|
||||
return Hash_sum_Results_Promise{Pipeline: capnp.NewPipeline(capnp.ErrorAnswer(capnp.ErrNullClient))}
|
||||
}
|
||||
call := &capnp.Call{
|
||||
Ctx: ctx,
|
||||
Method: capnp.Method{
|
||||
InterfaceID: 0xf29f97dd675a9431,
|
||||
MethodID: 1,
|
||||
InterfaceName: "hash.capnp:Hash",
|
||||
MethodName: "sum",
|
||||
},
|
||||
Options: capnp.NewCallOptions(opts),
|
||||
}
|
||||
if params != nil {
|
||||
call.ParamsSize = capnp.ObjectSize{DataSize: 0, PointerCount: 0}
|
||||
call.ParamsFunc = func(s capnp.Struct) error { return params(Hash_sum_Params{Struct: s}) }
|
||||
}
|
||||
return Hash_sum_Results_Promise{Pipeline: capnp.NewPipeline(c.Client.Call(call))}
|
||||
}
|
||||
|
||||
type Hash_Server interface {
|
||||
Write(Hash_write) error
|
||||
|
||||
Sum(Hash_sum) error
|
||||
}
|
||||
|
||||
func Hash_ServerToClient(s Hash_Server) Hash {
|
||||
c, _ := s.(server.Closer)
|
||||
return Hash{Client: server.New(Hash_Methods(nil, s), c)}
|
||||
}
|
||||
|
||||
func Hash_Methods(methods []server.Method, s Hash_Server) []server.Method {
|
||||
if cap(methods) == 0 {
|
||||
methods = make([]server.Method, 0, 2)
|
||||
}
|
||||
|
||||
methods = append(methods, server.Method{
|
||||
Method: capnp.Method{
|
||||
InterfaceID: 0xf29f97dd675a9431,
|
||||
MethodID: 0,
|
||||
InterfaceName: "hash.capnp:Hash",
|
||||
MethodName: "write",
|
||||
},
|
||||
Impl: func(c context.Context, opts capnp.CallOptions, p, r capnp.Struct) error {
|
||||
call := Hash_write{c, opts, Hash_write_Params{Struct: p}, Hash_write_Results{Struct: r}}
|
||||
return s.Write(call)
|
||||
},
|
||||
ResultsSize: capnp.ObjectSize{DataSize: 0, PointerCount: 0},
|
||||
})
|
||||
|
||||
methods = append(methods, server.Method{
|
||||
Method: capnp.Method{
|
||||
InterfaceID: 0xf29f97dd675a9431,
|
||||
MethodID: 1,
|
||||
InterfaceName: "hash.capnp:Hash",
|
||||
MethodName: "sum",
|
||||
},
|
||||
Impl: func(c context.Context, opts capnp.CallOptions, p, r capnp.Struct) error {
|
||||
call := Hash_sum{c, opts, Hash_sum_Params{Struct: p}, Hash_sum_Results{Struct: r}}
|
||||
return s.Sum(call)
|
||||
},
|
||||
ResultsSize: capnp.ObjectSize{DataSize: 0, PointerCount: 1},
|
||||
})
|
||||
|
||||
return methods
|
||||
}
|
||||
|
||||
// Hash_write holds the arguments for a server call to Hash.write.
|
||||
type Hash_write struct {
|
||||
Ctx context.Context
|
||||
Options capnp.CallOptions
|
||||
Params Hash_write_Params
|
||||
Results Hash_write_Results
|
||||
}
|
||||
|
||||
// Hash_sum holds the arguments for a server call to Hash.sum.
|
||||
type Hash_sum struct {
|
||||
Ctx context.Context
|
||||
Options capnp.CallOptions
|
||||
Params Hash_sum_Params
|
||||
Results Hash_sum_Results
|
||||
}
|
||||
|
||||
type Hash_write_Params struct{ capnp.Struct }
|
||||
|
||||
// Hash_write_Params_TypeID is the unique identifier for the type Hash_write_Params.
|
||||
const Hash_write_Params_TypeID = 0xdffe94ae546cdee3
|
||||
|
||||
func NewHash_write_Params(s *capnp.Segment) (Hash_write_Params, error) {
|
||||
st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1})
|
||||
return Hash_write_Params{st}, err
|
||||
}
|
||||
|
||||
func NewRootHash_write_Params(s *capnp.Segment) (Hash_write_Params, error) {
|
||||
st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1})
|
||||
return Hash_write_Params{st}, err
|
||||
}
|
||||
|
||||
func ReadRootHash_write_Params(msg *capnp.Message) (Hash_write_Params, error) {
|
||||
root, err := msg.RootPtr()
|
||||
return Hash_write_Params{root.Struct()}, err
|
||||
}
|
||||
|
||||
func (s Hash_write_Params) String() string {
|
||||
str, _ := text.Marshal(0xdffe94ae546cdee3, s.Struct)
|
||||
return str
|
||||
}
|
||||
|
||||
func (s Hash_write_Params) Data() ([]byte, error) {
|
||||
p, err := s.Struct.Ptr(0)
|
||||
return []byte(p.Data()), err
|
||||
}
|
||||
|
||||
func (s Hash_write_Params) HasData() bool {
|
||||
p, err := s.Struct.Ptr(0)
|
||||
return p.IsValid() || err != nil
|
||||
}
|
||||
|
||||
func (s Hash_write_Params) SetData(v []byte) error {
|
||||
return s.Struct.SetData(0, v)
|
||||
}
|
||||
|
||||
// Hash_write_Params_List is a list of Hash_write_Params.
|
||||
type Hash_write_Params_List struct{ capnp.List }
|
||||
|
||||
// NewHash_write_Params creates a new list of Hash_write_Params.
|
||||
func NewHash_write_Params_List(s *capnp.Segment, sz int32) (Hash_write_Params_List, error) {
|
||||
l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz)
|
||||
return Hash_write_Params_List{l}, err
|
||||
}
|
||||
|
||||
func (s Hash_write_Params_List) At(i int) Hash_write_Params {
|
||||
return Hash_write_Params{s.List.Struct(i)}
|
||||
}
|
||||
|
||||
func (s Hash_write_Params_List) Set(i int, v Hash_write_Params) error {
|
||||
return s.List.SetStruct(i, v.Struct)
|
||||
}
|
||||
|
||||
func (s Hash_write_Params_List) String() string {
|
||||
str, _ := text.MarshalList(0xdffe94ae546cdee3, s.List)
|
||||
return str
|
||||
}
|
||||
|
||||
// Hash_write_Params_Promise is a wrapper for a Hash_write_Params promised by a client call.
|
||||
type Hash_write_Params_Promise struct{ *capnp.Pipeline }
|
||||
|
||||
func (p Hash_write_Params_Promise) Struct() (Hash_write_Params, error) {
|
||||
s, err := p.Pipeline.Struct()
|
||||
return Hash_write_Params{s}, err
|
||||
}
|
||||
|
||||
type Hash_write_Results struct{ capnp.Struct }
|
||||
|
||||
// Hash_write_Results_TypeID is the unique identifier for the type Hash_write_Results.
|
||||
const Hash_write_Results_TypeID = 0x80ac741ec7fb8f65
|
||||
|
||||
func NewHash_write_Results(s *capnp.Segment) (Hash_write_Results, error) {
|
||||
st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0})
|
||||
return Hash_write_Results{st}, err
|
||||
}
|
||||
|
||||
func NewRootHash_write_Results(s *capnp.Segment) (Hash_write_Results, error) {
|
||||
st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0})
|
||||
return Hash_write_Results{st}, err
|
||||
}
|
||||
|
||||
func ReadRootHash_write_Results(msg *capnp.Message) (Hash_write_Results, error) {
|
||||
root, err := msg.RootPtr()
|
||||
return Hash_write_Results{root.Struct()}, err
|
||||
}
|
||||
|
||||
func (s Hash_write_Results) String() string {
|
||||
str, _ := text.Marshal(0x80ac741ec7fb8f65, s.Struct)
|
||||
return str
|
||||
}
|
||||
|
||||
// Hash_write_Results_List is a list of Hash_write_Results.
|
||||
type Hash_write_Results_List struct{ capnp.List }
|
||||
|
||||
// NewHash_write_Results creates a new list of Hash_write_Results.
|
||||
func NewHash_write_Results_List(s *capnp.Segment, sz int32) (Hash_write_Results_List, error) {
|
||||
l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}, sz)
|
||||
return Hash_write_Results_List{l}, err
|
||||
}
|
||||
|
||||
func (s Hash_write_Results_List) At(i int) Hash_write_Results {
|
||||
return Hash_write_Results{s.List.Struct(i)}
|
||||
}
|
||||
|
||||
func (s Hash_write_Results_List) Set(i int, v Hash_write_Results) error {
|
||||
return s.List.SetStruct(i, v.Struct)
|
||||
}
|
||||
|
||||
func (s Hash_write_Results_List) String() string {
|
||||
str, _ := text.MarshalList(0x80ac741ec7fb8f65, s.List)
|
||||
return str
|
||||
}
|
||||
|
||||
// Hash_write_Results_Promise is a wrapper for a Hash_write_Results promised by a client call.
|
||||
type Hash_write_Results_Promise struct{ *capnp.Pipeline }
|
||||
|
||||
func (p Hash_write_Results_Promise) Struct() (Hash_write_Results, error) {
|
||||
s, err := p.Pipeline.Struct()
|
||||
return Hash_write_Results{s}, err
|
||||
}
|
||||
|
||||
type Hash_sum_Params struct{ capnp.Struct }
|
||||
|
||||
// Hash_sum_Params_TypeID is the unique identifier for the type Hash_sum_Params.
|
||||
const Hash_sum_Params_TypeID = 0xe74bb2d0190cf89c
|
||||
|
||||
func NewHash_sum_Params(s *capnp.Segment) (Hash_sum_Params, error) {
|
||||
st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0})
|
||||
return Hash_sum_Params{st}, err
|
||||
}
|
||||
|
||||
func NewRootHash_sum_Params(s *capnp.Segment) (Hash_sum_Params, error) {
|
||||
st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0})
|
||||
return Hash_sum_Params{st}, err
|
||||
}
|
||||
|
||||
func ReadRootHash_sum_Params(msg *capnp.Message) (Hash_sum_Params, error) {
|
||||
root, err := msg.RootPtr()
|
||||
return Hash_sum_Params{root.Struct()}, err
|
||||
}
|
||||
|
||||
func (s Hash_sum_Params) String() string {
|
||||
str, _ := text.Marshal(0xe74bb2d0190cf89c, s.Struct)
|
||||
return str
|
||||
}
|
||||
|
||||
// Hash_sum_Params_List is a list of Hash_sum_Params.
|
||||
type Hash_sum_Params_List struct{ capnp.List }
|
||||
|
||||
// NewHash_sum_Params creates a new list of Hash_sum_Params.
|
||||
func NewHash_sum_Params_List(s *capnp.Segment, sz int32) (Hash_sum_Params_List, error) {
|
||||
l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 0}, sz)
|
||||
return Hash_sum_Params_List{l}, err
|
||||
}
|
||||
|
||||
func (s Hash_sum_Params_List) At(i int) Hash_sum_Params { return Hash_sum_Params{s.List.Struct(i)} }
|
||||
|
||||
func (s Hash_sum_Params_List) Set(i int, v Hash_sum_Params) error {
|
||||
return s.List.SetStruct(i, v.Struct)
|
||||
}
|
||||
|
||||
func (s Hash_sum_Params_List) String() string {
|
||||
str, _ := text.MarshalList(0xe74bb2d0190cf89c, s.List)
|
||||
return str
|
||||
}
|
||||
|
||||
// Hash_sum_Params_Promise is a wrapper for a Hash_sum_Params promised by a client call.
|
||||
type Hash_sum_Params_Promise struct{ *capnp.Pipeline }
|
||||
|
||||
func (p Hash_sum_Params_Promise) Struct() (Hash_sum_Params, error) {
|
||||
s, err := p.Pipeline.Struct()
|
||||
return Hash_sum_Params{s}, err
|
||||
}
|
||||
|
||||
type Hash_sum_Results struct{ capnp.Struct }
|
||||
|
||||
// Hash_sum_Results_TypeID is the unique identifier for the type Hash_sum_Results.
|
||||
const Hash_sum_Results_TypeID = 0xd093963b95a4e107
|
||||
|
||||
func NewHash_sum_Results(s *capnp.Segment) (Hash_sum_Results, error) {
|
||||
st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1})
|
||||
return Hash_sum_Results{st}, err
|
||||
}
|
||||
|
||||
func NewRootHash_sum_Results(s *capnp.Segment) (Hash_sum_Results, error) {
|
||||
st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1})
|
||||
return Hash_sum_Results{st}, err
|
||||
}
|
||||
|
||||
func ReadRootHash_sum_Results(msg *capnp.Message) (Hash_sum_Results, error) {
|
||||
root, err := msg.RootPtr()
|
||||
return Hash_sum_Results{root.Struct()}, err
|
||||
}
|
||||
|
||||
func (s Hash_sum_Results) String() string {
|
||||
str, _ := text.Marshal(0xd093963b95a4e107, s.Struct)
|
||||
return str
|
||||
}
|
||||
|
||||
func (s Hash_sum_Results) Hash() ([]byte, error) {
|
||||
p, err := s.Struct.Ptr(0)
|
||||
return []byte(p.Data()), err
|
||||
}
|
||||
|
||||
func (s Hash_sum_Results) HasHash() bool {
|
||||
p, err := s.Struct.Ptr(0)
|
||||
return p.IsValid() || err != nil
|
||||
}
|
||||
|
||||
func (s Hash_sum_Results) SetHash(v []byte) error {
|
||||
return s.Struct.SetData(0, v)
|
||||
}
|
||||
|
||||
// Hash_sum_Results_List is a list of Hash_sum_Results.
|
||||
type Hash_sum_Results_List struct{ capnp.List }
|
||||
|
||||
// NewHash_sum_Results creates a new list of Hash_sum_Results.
|
||||
func NewHash_sum_Results_List(s *capnp.Segment, sz int32) (Hash_sum_Results_List, error) {
|
||||
l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz)
|
||||
return Hash_sum_Results_List{l}, err
|
||||
}
|
||||
|
||||
func (s Hash_sum_Results_List) At(i int) Hash_sum_Results { return Hash_sum_Results{s.List.Struct(i)} }
|
||||
|
||||
func (s Hash_sum_Results_List) Set(i int, v Hash_sum_Results) error {
|
||||
return s.List.SetStruct(i, v.Struct)
|
||||
}
|
||||
|
||||
func (s Hash_sum_Results_List) String() string {
|
||||
str, _ := text.MarshalList(0xd093963b95a4e107, s.List)
|
||||
return str
|
||||
}
|
||||
|
||||
// Hash_sum_Results_Promise is a wrapper for a Hash_sum_Results promised by a client call.
|
||||
type Hash_sum_Results_Promise struct{ *capnp.Pipeline }
|
||||
|
||||
func (p Hash_sum_Results_Promise) Struct() (Hash_sum_Results, error) {
|
||||
s, err := p.Pipeline.Struct()
|
||||
return Hash_sum_Results{s}, err
|
||||
}
|
||||
|
||||
const schema_db8274f9144abc7e = "x\xda\x84\x92?h\x13a\x18\xc6\x9f\xe7\xbb;\xaf\xa8" +
|
||||
"G\xfaq\x05\xe9bP\"\x82\xd8\xe2\xb5[\x05\x13\x1c" +
|
||||
"Tt\xb9\x8b\x0e\xe2\xf6QO#$\xb5\xe4.\x14\x11" +
|
||||
"\xff\xd0\xc5E\x10\xb4\xdaE\xd0A7\xed\xd0Q\xba\x8a" +
|
||||
"(\x08u\xb4\x12\x8b:\x08\xdd\xec\xa2\xa5\xd4\x93\xef\x92" +
|
||||
"k\x02!v\xfb\xe0y\xdf\xe7\x9e\xf7w\xcf\xe0fI" +
|
||||
"x\xd6a\x13\x08\x8eY\xbb\x92\xf0\xc1\xe6\xbb\xfd\xf1\xab" +
|
||||
"\xbb\x90\x83\x04L\x1bp7\xb8\x0e3\xf9\xf0\xfc\xfe\xcb" +
|
||||
"O\xbb\x17\x1fB\xeek\x0b\xe3M\x8e\x11f\xb2\xb4\xb2" +
|
||||
"5\x9f\xbb\xf8z\x01r\x8f\x91\xdc^:;\xb4\x11\xcf" +
|
||||
"~\x01\xe8\xbe\xe5\x1b\xf7#\xb5\xc5{\x9ev\x7f\xe9W" +
|
||||
"b\x7f{\xf1\xf8\xf8\x93G\xcb-\x7f+U?\xf3;" +
|
||||
"\xe86Y\x04\x93\x1f_\xab\x17\x16\xe6\xfe\xaev\xeb[" +
|
||||
"\\\x03]\x0a\xad?\xfd\xb3wxy\xf1\xdc\xcf\xae|" +
|
||||
"\x07\xc4\x0a\xccd\xf5f\xf1\xcao\xff\xc4Z+_\xba" +
|
||||
"8n\x89\x09\x82\xae\x93nzs\x97\xae6\xe7\x9f\xad" +
|
||||
"\xf7\xc4\x1c\x11\xb3\xae'\xb4\xd3\x88\xb8\xe7\xde\x126\x8e" +
|
||||
"&\x15\x15UF'\xd5\xb4\x98\x9a\x9e8\xa3\xdf3\xf5" +
|
||||
"kqX(\x87\xf9\xa8Q\x8d\xa3m\xddh\xeb\xa7\xd4" +
|
||||
"d|\xbd~ct*\x9c9_Q^\xc1\xcf\xab\xba" +
|
||||
"\xaau\xe6\x98\xcd\x15[\x83>\x19\x98\x86\x05lse" +
|
||||
"v\x80\x94'!\xa4e\xdfi{\x95\xe8\x93\xbd\x81\xa2" +
|
||||
"F\xadP\x0e\xa3\x86]\x8d\xa3\xc04L\xc0$ \x9d" +
|
||||
"#@0`0\x18\x12\xcc\xe9%:\x10t\xc0~'" +
|
||||
"\xf9*\xa7\x93\xf6\xb3\xb8\xacb\xd5\xdfB\x87\xf0U]" +
|
||||
"\x19\xb5\x9d\x91\x94\x8ba\xca\xee\xbfae\xe77\x81\x94" +
|
||||
"]\xdf\xcc\x08B\xa3\x1bH\xd1e]aVZ\xe9\x8d" +
|
||||
"A\xc8C6;=aV89|\x10B:v>" +
|
||||
"=\xbbD;j\xd4R\xb4\xff\x02\x00\x00\xff\xff<." +
|
||||
"\xe3\xa6"
|
||||
|
||||
func init() {
|
||||
schemas.Register(schema_db8274f9144abc7e,
|
||||
0x80ac741ec7fb8f65,
|
||||
0x92b20ad1a58ca0ca,
|
||||
0xaead580f97fddabc,
|
||||
0xd093963b95a4e107,
|
||||
0xdffe94ae546cdee3,
|
||||
0xe74bb2d0190cf89c,
|
||||
0xea3e50f7663f7bdf,
|
||||
0xf29f97dd675a9431)
|
||||
}
|
19
vendor/zombiezen.com/go/capnproto2/internal/fulfiller/BUILD.bazel
generated
vendored
Normal file
19
vendor/zombiezen.com/go/capnproto2/internal/fulfiller/BUILD.bazel
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["fulfiller.go"],
|
||||
importpath = "zombiezen.com/go/capnproto2/internal/fulfiller",
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//:go_default_library",
|
||||
"//internal/queue:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["fulfiller_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["//:go_default_library"],
|
||||
)
|
329
vendor/zombiezen.com/go/capnproto2/internal/fulfiller/fulfiller.go
generated
vendored
Normal file
329
vendor/zombiezen.com/go/capnproto2/internal/fulfiller/fulfiller.go
generated
vendored
Normal file
@@ -0,0 +1,329 @@
|
||||
// Package fulfiller provides a type that implements capnp.Answer that
|
||||
// resolves by calling setter methods.
|
||||
package fulfiller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"zombiezen.com/go/capnproto2"
|
||||
"zombiezen.com/go/capnproto2/internal/queue"
|
||||
)
|
||||
|
||||
// callQueueSize is the maximum number of pending calls.
|
||||
const callQueueSize = 64
|
||||
|
||||
// Fulfiller is a promise for a Struct. The zero value is an unresolved
|
||||
// answer. A Fulfiller is considered to be resolved once Fulfill or
|
||||
// Reject is called. Calls to the Fulfiller will queue up until it is
|
||||
// resolved. A Fulfiller is safe to use from multiple goroutines.
|
||||
type Fulfiller struct {
|
||||
once sync.Once
|
||||
resolved chan struct{} // initialized by init()
|
||||
|
||||
// Protected by mu
|
||||
mu sync.RWMutex
|
||||
answer capnp.Answer
|
||||
queue []pcall // initialized by init()
|
||||
}
|
||||
|
||||
// init initializes the Fulfiller. It is idempotent.
|
||||
// Should be called for each method on Fulfiller.
|
||||
func (f *Fulfiller) init() {
|
||||
f.once.Do(func() {
|
||||
f.resolved = make(chan struct{})
|
||||
f.queue = make([]pcall, 0, callQueueSize)
|
||||
})
|
||||
}
|
||||
|
||||
// Fulfill sets the fulfiller's answer to s. If there are queued
|
||||
// pipeline calls, the capabilities on the struct will be embargoed
|
||||
// until the queued calls finish. Fulfill will panic if the fulfiller
|
||||
// has already been resolved.
|
||||
func (f *Fulfiller) Fulfill(s capnp.Struct) {
|
||||
f.init()
|
||||
f.mu.Lock()
|
||||
if f.answer != nil {
|
||||
f.mu.Unlock()
|
||||
panic("Fulfiller.Fulfill called more than once")
|
||||
}
|
||||
f.answer = capnp.ImmediateAnswer(s)
|
||||
queues := f.emptyQueue(s)
|
||||
ctab := s.Segment().Message().CapTable
|
||||
for capIdx, q := range queues {
|
||||
ctab[capIdx] = newEmbargoClient(ctab[capIdx], q)
|
||||
}
|
||||
close(f.resolved)
|
||||
f.mu.Unlock()
|
||||
}
|
||||
|
||||
// emptyQueue splits the queue by which capability it targets and
|
||||
// drops any invalid calls. Once this function returns, f.queue will
|
||||
// be nil.
|
||||
func (f *Fulfiller) emptyQueue(s capnp.Struct) map[capnp.CapabilityID][]ecall {
|
||||
qs := make(map[capnp.CapabilityID][]ecall, len(f.queue))
|
||||
for i, pc := range f.queue {
|
||||
c, err := capnp.TransformPtr(s.ToPtr(), pc.transform)
|
||||
if err != nil {
|
||||
pc.f.Reject(err)
|
||||
continue
|
||||
}
|
||||
in := c.Interface()
|
||||
if !in.IsValid() {
|
||||
pc.f.Reject(capnp.ErrNullClient)
|
||||
continue
|
||||
}
|
||||
cn := in.Capability()
|
||||
if qs[cn] == nil {
|
||||
qs[cn] = make([]ecall, 0, len(f.queue)-i)
|
||||
}
|
||||
qs[cn] = append(qs[cn], pc.ecall)
|
||||
}
|
||||
f.queue = nil
|
||||
return qs
|
||||
}
|
||||
|
||||
// Reject sets the fulfiller's answer to err. If there are queued
|
||||
// pipeline calls, they will all return errors. Reject will panic if
|
||||
// the error is nil or the fulfiller has already been resolved.
|
||||
func (f *Fulfiller) Reject(err error) {
|
||||
if err == nil {
|
||||
panic("Fulfiller.Reject called with nil")
|
||||
}
|
||||
f.init()
|
||||
f.mu.Lock()
|
||||
if f.answer != nil {
|
||||
f.mu.Unlock()
|
||||
panic("Fulfiller.Reject called more than once")
|
||||
}
|
||||
f.answer = capnp.ErrorAnswer(err)
|
||||
for i := range f.queue {
|
||||
f.queue[i].f.Reject(err)
|
||||
f.queue[i] = pcall{}
|
||||
}
|
||||
close(f.resolved)
|
||||
f.mu.Unlock()
|
||||
}
|
||||
|
||||
// Done returns a channel that is closed once f is resolved.
|
||||
func (f *Fulfiller) Done() <-chan struct{} {
|
||||
f.init()
|
||||
return f.resolved
|
||||
}
|
||||
|
||||
// Peek returns f's resolved answer or nil if f has not been resolved.
|
||||
// The Struct method of an answer returned from Peek returns immediately.
|
||||
func (f *Fulfiller) Peek() capnp.Answer {
|
||||
f.init()
|
||||
f.mu.RLock()
|
||||
a := f.answer
|
||||
f.mu.RUnlock()
|
||||
return a
|
||||
}
|
||||
|
||||
// Struct waits until f is resolved and returns its struct if fulfilled
|
||||
// or an error if rejected.
|
||||
func (f *Fulfiller) Struct() (capnp.Struct, error) {
|
||||
<-f.Done()
|
||||
return f.Peek().Struct()
|
||||
}
|
||||
|
||||
// PipelineCall calls PipelineCall on the fulfilled answer or queues the
|
||||
// call if f has not been fulfilled.
|
||||
func (f *Fulfiller) PipelineCall(transform []capnp.PipelineOp, call *capnp.Call) capnp.Answer {
|
||||
f.init()
|
||||
|
||||
// Fast path: pass-through after fulfilled.
|
||||
if a := f.Peek(); a != nil {
|
||||
return a.PipelineCall(transform, call)
|
||||
}
|
||||
|
||||
f.mu.Lock()
|
||||
// Make sure that f wasn't fulfilled.
|
||||
if a := f.answer; a != nil {
|
||||
f.mu.Unlock()
|
||||
return a.PipelineCall(transform, call)
|
||||
}
|
||||
if len(f.queue) == cap(f.queue) {
|
||||
f.mu.Unlock()
|
||||
return capnp.ErrorAnswer(errCallQueueFull)
|
||||
}
|
||||
cc, err := call.Copy(nil)
|
||||
if err != nil {
|
||||
f.mu.Unlock()
|
||||
return capnp.ErrorAnswer(err)
|
||||
}
|
||||
g := new(Fulfiller)
|
||||
f.queue = append(f.queue, pcall{
|
||||
transform: transform,
|
||||
ecall: ecall{
|
||||
call: cc,
|
||||
f: g,
|
||||
},
|
||||
})
|
||||
f.mu.Unlock()
|
||||
return g
|
||||
}
|
||||
|
||||
// PipelineClose waits until f is resolved and then calls PipelineClose
|
||||
// on the fulfilled answer.
|
||||
func (f *Fulfiller) PipelineClose(transform []capnp.PipelineOp) error {
|
||||
<-f.Done()
|
||||
return f.Peek().PipelineClose(transform)
|
||||
}
|
||||
|
||||
// pcall is a queued pipeline call.
|
||||
type pcall struct {
|
||||
transform []capnp.PipelineOp
|
||||
ecall
|
||||
}
|
||||
|
||||
// EmbargoClient is a client that flushes a queue of calls.
|
||||
// Fulfiller will create these automatically when pipelined calls are
|
||||
// made on unresolved answers. EmbargoClient is exported so that rpc
|
||||
// can avoid making calls on its own Conn.
|
||||
type EmbargoClient struct {
|
||||
client capnp.Client
|
||||
|
||||
mu sync.RWMutex
|
||||
q queue.Queue
|
||||
calls ecallList
|
||||
}
|
||||
|
||||
func newEmbargoClient(client capnp.Client, queue []ecall) capnp.Client {
|
||||
ec := &EmbargoClient{
|
||||
client: client,
|
||||
calls: make(ecallList, callQueueSize),
|
||||
}
|
||||
ec.q.Init(ec.calls, copy(ec.calls, queue))
|
||||
go ec.flushQueue()
|
||||
return ec
|
||||
}
|
||||
|
||||
func (ec *EmbargoClient) push(cl *capnp.Call) capnp.Answer {
|
||||
f := new(Fulfiller)
|
||||
cl, err := cl.Copy(nil)
|
||||
if err != nil {
|
||||
return capnp.ErrorAnswer(err)
|
||||
}
|
||||
i := ec.q.Push()
|
||||
if i == -1 {
|
||||
return capnp.ErrorAnswer(errCallQueueFull)
|
||||
}
|
||||
ec.calls[i] = ecall{cl, f}
|
||||
return f
|
||||
}
|
||||
|
||||
// flushQueue is run in its own goroutine.
|
||||
func (ec *EmbargoClient) flushQueue() {
|
||||
var c ecall
|
||||
ec.mu.Lock()
|
||||
if i := ec.q.Front(); i != -1 {
|
||||
c = ec.calls[i]
|
||||
}
|
||||
ec.mu.Unlock()
|
||||
for c.call != nil {
|
||||
ans := ec.client.Call(c.call)
|
||||
go func(f *Fulfiller, ans capnp.Answer) {
|
||||
s, err := ans.Struct()
|
||||
if err == nil {
|
||||
f.Fulfill(s)
|
||||
} else {
|
||||
f.Reject(err)
|
||||
}
|
||||
}(c.f, ans)
|
||||
ec.mu.Lock()
|
||||
ec.q.Pop()
|
||||
if i := ec.q.Front(); i != -1 {
|
||||
c = ec.calls[i]
|
||||
} else {
|
||||
c = ecall{}
|
||||
}
|
||||
ec.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns the underlying client if the embargo has been lifted
|
||||
// and nil otherwise.
|
||||
func (ec *EmbargoClient) Client() capnp.Client {
|
||||
ec.mu.RLock()
|
||||
ok := ec.isPassthrough()
|
||||
ec.mu.RUnlock()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return ec.client
|
||||
}
|
||||
|
||||
func (ec *EmbargoClient) isPassthrough() bool {
|
||||
return ec.q.Len() == 0
|
||||
}
|
||||
|
||||
// Call either queues a call to the underlying client or starts a call
|
||||
// if the embargo has been lifted.
|
||||
func (ec *EmbargoClient) Call(cl *capnp.Call) capnp.Answer {
|
||||
// Fast path: queue is flushed.
|
||||
ec.mu.RLock()
|
||||
ok := ec.isPassthrough()
|
||||
ec.mu.RUnlock()
|
||||
if ok {
|
||||
return ec.client.Call(cl)
|
||||
}
|
||||
|
||||
// Add to queue.
|
||||
ec.mu.Lock()
|
||||
// Since we released the lock, check that the queue hasn't been flushed.
|
||||
if ec.isPassthrough() {
|
||||
ec.mu.Unlock()
|
||||
return ec.client.Call(cl)
|
||||
}
|
||||
ans := ec.push(cl)
|
||||
ec.mu.Unlock()
|
||||
return ans
|
||||
}
|
||||
|
||||
// TryQueue will attempt to queue a call or return nil if the embargo
|
||||
// has been lifted.
|
||||
func (ec *EmbargoClient) TryQueue(cl *capnp.Call) capnp.Answer {
|
||||
ec.mu.Lock()
|
||||
if ec.isPassthrough() {
|
||||
ec.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
ans := ec.push(cl)
|
||||
ec.mu.Unlock()
|
||||
return ans
|
||||
}
|
||||
|
||||
// Close closes the underlying client, rejecting any queued calls.
|
||||
func (ec *EmbargoClient) Close() error {
|
||||
ec.mu.Lock()
|
||||
// reject all queued calls
|
||||
for ec.q.Len() > 0 {
|
||||
ec.calls[ec.q.Front()].f.Reject(errQueueCallCancel)
|
||||
ec.q.Pop()
|
||||
}
|
||||
ec.mu.Unlock()
|
||||
return ec.client.Close()
|
||||
}
|
||||
|
||||
// ecall is an queued embargoed call.
|
||||
type ecall struct {
|
||||
call *capnp.Call
|
||||
f *Fulfiller
|
||||
}
|
||||
|
||||
type ecallList []ecall
|
||||
|
||||
func (el ecallList) Len() int {
|
||||
return len(el)
|
||||
}
|
||||
|
||||
func (el ecallList) Clear(i int) {
|
||||
el[i] = ecall{}
|
||||
}
|
||||
|
||||
var (
|
||||
errCallQueueFull = errors.New("capnp: promised answer call queue full")
|
||||
errQueueCallCancel = errors.New("capnp: queued call canceled")
|
||||
)
|
123
vendor/zombiezen.com/go/capnproto2/internal/fulfiller/fulfiller_test.go
generated
vendored
Normal file
123
vendor/zombiezen.com/go/capnproto2/internal/fulfiller/fulfiller_test.go
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
package fulfiller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"zombiezen.com/go/capnproto2"
|
||||
)
|
||||
|
||||
func TestFulfiller_NewShouldBeUnresolved(t *testing.T) {
|
||||
f := new(Fulfiller)
|
||||
|
||||
if a := f.Peek(); a != nil {
|
||||
t.Errorf("f.Peek() = %v; want nil", a)
|
||||
}
|
||||
select {
|
||||
case <-f.Done():
|
||||
t.Error("Done closed early")
|
||||
default:
|
||||
// success
|
||||
}
|
||||
}
|
||||
|
||||
func TestFulfiller_FulfillShouldResolve(t *testing.T) {
|
||||
f := new(Fulfiller)
|
||||
st := newStruct(t, capnp.ObjectSize{})
|
||||
|
||||
f.Fulfill(st)
|
||||
|
||||
select {
|
||||
case <-f.Done():
|
||||
default:
|
||||
t.Error("Done still closed after Fulfill")
|
||||
}
|
||||
ret, err := f.Struct()
|
||||
if err != nil {
|
||||
t.Errorf("f.Struct() error: %v", err)
|
||||
}
|
||||
if ret != st {
|
||||
t.Errorf("f.Struct() = %v; want %v", ret, st)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFulfiller_RejectShouldResolve(t *testing.T) {
|
||||
f := new(Fulfiller)
|
||||
e := errors.New("failure and rejection")
|
||||
|
||||
f.Reject(e)
|
||||
|
||||
select {
|
||||
case <-f.Done():
|
||||
default:
|
||||
t.Error("Done still closed after Reject")
|
||||
}
|
||||
ret, err := f.Struct()
|
||||
if err != e {
|
||||
t.Errorf("f.Struct() error = %v; want %v", err, e)
|
||||
}
|
||||
if capnp.IsValid(ret) {
|
||||
t.Errorf("f.Struct() = %v; want null", ret)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFulfiller_QueuedCallsDeliveredInOrder(t *testing.T) {
|
||||
f := new(Fulfiller)
|
||||
oc := new(orderClient)
|
||||
result := newStruct(t, capnp.ObjectSize{PointerCount: 1})
|
||||
in := result.Segment().Message().AddCap(oc)
|
||||
result.SetPointer(0, capnp.NewInterface(result.Segment(), in))
|
||||
|
||||
ans1 := f.PipelineCall([]capnp.PipelineOp{{Field: 0}}, new(capnp.Call))
|
||||
ans2 := f.PipelineCall([]capnp.PipelineOp{{Field: 0}}, new(capnp.Call))
|
||||
f.Fulfill(result)
|
||||
ans3 := f.PipelineCall([]capnp.PipelineOp{{Field: 0}}, new(capnp.Call))
|
||||
ans3.Struct()
|
||||
ans4 := f.PipelineCall([]capnp.PipelineOp{{Field: 0}}, new(capnp.Call))
|
||||
|
||||
check := func(a capnp.Answer, n uint64) {
|
||||
r, err := a.Struct()
|
||||
if r.Uint64(0) != n {
|
||||
t.Errorf("r%d = %d; want %d", n+1, r.Uint64(0), n)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("err%d = %v", n+1, err)
|
||||
}
|
||||
}
|
||||
check(ans1, 0)
|
||||
check(ans2, 1)
|
||||
check(ans3, 2)
|
||||
check(ans4, 3)
|
||||
}
|
||||
|
||||
func newStruct(t *testing.T, sz capnp.ObjectSize) capnp.Struct {
|
||||
_, s, err := capnp.NewMessage(capnp.SingleSegment(nil))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st, err := capnp.NewStruct(s, sz)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return st
|
||||
}
|
||||
|
||||
type orderClient int
|
||||
|
||||
func (oc *orderClient) Call(cl *capnp.Call) capnp.Answer {
|
||||
_, s, err := capnp.NewMessage(capnp.SingleSegment(nil))
|
||||
if err != nil {
|
||||
return capnp.ErrorAnswer(err)
|
||||
}
|
||||
st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 8})
|
||||
if err != nil {
|
||||
return capnp.ErrorAnswer(err)
|
||||
}
|
||||
st.SetUint64(0, uint64(*oc))
|
||||
*oc++
|
||||
return capnp.ImmediateAnswer(st)
|
||||
}
|
||||
|
||||
func (oc *orderClient) Close() error {
|
||||
return nil
|
||||
}
|
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/blob
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/blob
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/bool
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/bool
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/boolf
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/boolf
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/boolvec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/boolvec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/datavec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/datavec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/f32
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/f32
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/f32vec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/f32vec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/f64
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/f64
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/f64vec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/f64vec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i16
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i16
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i16vec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i16vec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i32
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i32
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i32vec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i32vec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i64
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i64
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i64vec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i64vec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i8
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i8
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i8vec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/i8vec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/text
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/text
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/textvec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/textvec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u16
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u16
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u16vec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u16vec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u32
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u32
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u32vec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u32vec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u64
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u64
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u64vec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u64vec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u8
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u8
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u8vec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/u8vec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/void
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/void
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/zvec
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/zvec
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/zz
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/corpus/zz
generated
vendored
Normal file
Binary file not shown.
186
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/fuzztest.go
generated
vendored
Normal file
186
vendor/zombiezen.com/go/capnproto2/internal/fuzztest/fuzztest.go
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
// +build gofuzz
|
||||
|
||||
// Fuzz test harness. To run:
|
||||
// go-fuzz-build zombiezen.com/go/capnproto2/internal/fuzztest
|
||||
// go-fuzz -bin=fuzztest-fuzz.zip -workdir=internal/fuzztest
|
||||
|
||||
package fuzztest
|
||||
|
||||
import (
|
||||
"zombiezen.com/go/capnproto2"
|
||||
air "zombiezen.com/go/capnproto2/internal/aircraftlib"
|
||||
)
|
||||
|
||||
func Fuzz(data []byte) int {
|
||||
// TODO(someday): find a way to fuzz multiple segments
|
||||
if len(data)%8 != 0 {
|
||||
// Less interested in outcomes of misaligned segments. Zero-pad.
|
||||
data = append([]byte(nil), data...)
|
||||
for len(data)%8 != 0 {
|
||||
data = append(data, 0)
|
||||
}
|
||||
}
|
||||
msg := &capnp.Message{Arena: capnp.SingleSegment(data)}
|
||||
z, err := air.ReadRootZ(msg)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
switch z.Which() {
|
||||
case air.Z_Which_void:
|
||||
case air.Z_Which_zz:
|
||||
if _, err := z.Zz(); err != nil || !z.HasZz() {
|
||||
return 0
|
||||
}
|
||||
case air.Z_Which_f64:
|
||||
z.F64()
|
||||
case air.Z_Which_f32:
|
||||
z.F32()
|
||||
case air.Z_Which_i64:
|
||||
z.I64()
|
||||
case air.Z_Which_i32:
|
||||
z.I32()
|
||||
case air.Z_Which_i16:
|
||||
z.I16()
|
||||
case air.Z_Which_i8:
|
||||
z.I8()
|
||||
case air.Z_Which_u64:
|
||||
z.U64()
|
||||
case air.Z_Which_u32:
|
||||
z.U32()
|
||||
case air.Z_Which_u16:
|
||||
z.U16()
|
||||
case air.Z_Which_u8:
|
||||
z.U8()
|
||||
case air.Z_Which_bool:
|
||||
z.Bool()
|
||||
case air.Z_Which_text:
|
||||
if t, err := z.Text(); err != nil || t == "" {
|
||||
return 0
|
||||
}
|
||||
case air.Z_Which_blob:
|
||||
if b, err := z.Blob(); err != nil || len(b) == 0 {
|
||||
return 0
|
||||
}
|
||||
case air.Z_Which_f64vec:
|
||||
v, err := z.F64vec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_f32vec:
|
||||
v, err := z.F32vec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_i64vec:
|
||||
v, err := z.I64vec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_i32vec:
|
||||
v, err := z.I32vec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_i16vec:
|
||||
v, err := z.I16vec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_i8vec:
|
||||
v, err := z.I8vec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_u64vec:
|
||||
v, err := z.U64vec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_u32vec:
|
||||
v, err := z.U32vec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_u16vec:
|
||||
v, err := z.U16vec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_u8vec:
|
||||
v, err := z.U8vec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_boolvec:
|
||||
v, err := z.Boolvec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_datavec:
|
||||
v, err := z.Datavec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
if _, err := v.At(i); err != nil {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
case air.Z_Which_textvec:
|
||||
v, err := z.Textvec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
if _, err := v.At(i); err != nil {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
case air.Z_Which_zvec:
|
||||
v, err := z.Zvec()
|
||||
if err != nil || v.Len() == 0 {
|
||||
return 0
|
||||
}
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
v.At(i)
|
||||
}
|
||||
case air.Z_Which_airport:
|
||||
z.Airport()
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
}
|
13
vendor/zombiezen.com/go/capnproto2/internal/nodemap/BUILD.bazel
generated
vendored
Normal file
13
vendor/zombiezen.com/go/capnproto2/internal/nodemap/BUILD.bazel
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["nodemap.go"],
|
||||
importpath = "zombiezen.com/go/capnproto2/internal/nodemap",
|
||||
visibility = ["//:__subpackages__"],
|
||||
deps = [
|
||||
"//:go_default_library",
|
||||
"//internal/schema:go_default_library",
|
||||
"//schemas:go_default_library",
|
||||
],
|
||||
)
|
58
vendor/zombiezen.com/go/capnproto2/internal/nodemap/nodemap.go
generated
vendored
Normal file
58
vendor/zombiezen.com/go/capnproto2/internal/nodemap/nodemap.go
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
// Package nodemap provides a schema registry index type.
|
||||
package nodemap
|
||||
|
||||
import (
|
||||
"zombiezen.com/go/capnproto2"
|
||||
"zombiezen.com/go/capnproto2/internal/schema"
|
||||
"zombiezen.com/go/capnproto2/schemas"
|
||||
)
|
||||
|
||||
// Map is a lazy index of a registry.
|
||||
// The zero value is an index of the default registry.
|
||||
type Map struct {
|
||||
reg *schemas.Registry
|
||||
nodes map[uint64]schema.Node
|
||||
}
|
||||
|
||||
func (m *Map) registry() *schemas.Registry {
|
||||
if m.reg != nil {
|
||||
return m.reg
|
||||
}
|
||||
return &schemas.DefaultRegistry
|
||||
}
|
||||
|
||||
func (m *Map) UseRegistry(reg *schemas.Registry) {
|
||||
m.reg = reg
|
||||
m.nodes = make(map[uint64]schema.Node)
|
||||
}
|
||||
|
||||
// Find returns the node for the given ID.
|
||||
func (m *Map) Find(id uint64) (schema.Node, error) {
|
||||
if n := m.nodes[id]; n.IsValid() {
|
||||
return n, nil
|
||||
}
|
||||
data, err := m.registry().Find(id)
|
||||
if err != nil {
|
||||
return schema.Node{}, err
|
||||
}
|
||||
msg, err := capnp.Unmarshal(data)
|
||||
if err != nil {
|
||||
return schema.Node{}, err
|
||||
}
|
||||
req, err := schema.ReadRootCodeGeneratorRequest(msg)
|
||||
if err != nil {
|
||||
return schema.Node{}, err
|
||||
}
|
||||
nodes, err := req.Nodes()
|
||||
if err != nil {
|
||||
return schema.Node{}, err
|
||||
}
|
||||
if m.nodes == nil {
|
||||
m.nodes = make(map[uint64]schema.Node)
|
||||
}
|
||||
for i := 0; i < nodes.Len(); i++ {
|
||||
n := nodes.At(i)
|
||||
m.nodes[n.Id()] = n
|
||||
}
|
||||
return m.nodes[id], nil
|
||||
}
|
19
vendor/zombiezen.com/go/capnproto2/internal/packed/BUILD.bazel
generated
vendored
Normal file
19
vendor/zombiezen.com/go/capnproto2/internal/packed/BUILD.bazel
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"discard.go",
|
||||
"discard_go14.go",
|
||||
"packed.go",
|
||||
],
|
||||
importpath = "zombiezen.com/go/capnproto2/internal/packed",
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["packed_test.go"],
|
||||
data = glob(["testdata/**"]),
|
||||
embed = [":go_default_library"],
|
||||
)
|
11
vendor/zombiezen.com/go/capnproto2/internal/packed/discard.go
generated
vendored
Normal file
11
vendor/zombiezen.com/go/capnproto2/internal/packed/discard.go
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
// +build go1.5
|
||||
|
||||
package packed
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
)
|
||||
|
||||
func discard(r *bufio.Reader, n int) {
|
||||
r.Discard(n)
|
||||
}
|
13
vendor/zombiezen.com/go/capnproto2/internal/packed/discard_go14.go
generated
vendored
Normal file
13
vendor/zombiezen.com/go/capnproto2/internal/packed/discard_go14.go
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
// +build !go1.5
|
||||
|
||||
package packed
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func discard(r *bufio.Reader, n int) {
|
||||
io.CopyN(ioutil.Discard, r, int64(n))
|
||||
}
|
65
vendor/zombiezen.com/go/capnproto2/internal/packed/fuzz.go
generated
vendored
Normal file
65
vendor/zombiezen.com/go/capnproto2/internal/packed/fuzz.go
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
// +build gofuzz
|
||||
|
||||
// Fuzz test harness. To run:
|
||||
// go-fuzz-build zombiezen.com/go/capnproto2/internal/packed
|
||||
// go-fuzz -bin=packed-fuzz.zip -workdir=internal/packed/testdata
|
||||
|
||||
package packed
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func Fuzz(data []byte) int {
|
||||
result := 0
|
||||
|
||||
// Unpacked
|
||||
if unpacked, err := Unpack(nil, data); err == nil {
|
||||
checkRepack(unpacked)
|
||||
result = 1
|
||||
}
|
||||
|
||||
// Read
|
||||
{
|
||||
r := NewReader(bufio.NewReader(bytes.NewReader(data)))
|
||||
if unpacked, err := ioutil.ReadAll(r); err == nil {
|
||||
checkRepack(unpacked)
|
||||
result = 1
|
||||
}
|
||||
}
|
||||
|
||||
// ReadWord
|
||||
{
|
||||
r := NewReader(bufio.NewReader(bytes.NewReader(data)))
|
||||
var unpacked []byte
|
||||
var err error
|
||||
for {
|
||||
n := len(unpacked)
|
||||
unpacked = append(unpacked, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
if err = r.ReadWord(unpacked[n:]); err != nil {
|
||||
unpacked = unpacked[:n]
|
||||
break
|
||||
}
|
||||
}
|
||||
if err == io.EOF {
|
||||
checkRepack(unpacked)
|
||||
result = 1
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func checkRepack(unpacked []byte) {
|
||||
packed := Pack(nil, unpacked)
|
||||
unpacked2, err := Unpack(nil, packed)
|
||||
if err != nil {
|
||||
panic("correctness: unpack, pack, unpack gives error: " + err.Error())
|
||||
}
|
||||
if !bytes.Equal(unpacked, unpacked2) {
|
||||
panic("correctness: unpack, pack, unpack gives different results")
|
||||
}
|
||||
}
|
334
vendor/zombiezen.com/go/capnproto2/internal/packed/packed.go
generated
vendored
Normal file
334
vendor/zombiezen.com/go/capnproto2/internal/packed/packed.go
generated
vendored
Normal file
@@ -0,0 +1,334 @@
|
||||
// Package packed provides functions to read and write the "packed"
|
||||
// compression scheme described at https://capnproto.org/encoding.html#packing.
|
||||
package packed
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
const wordSize = 8
|
||||
|
||||
// Special case tags.
|
||||
const (
|
||||
zeroTag byte = 0x00
|
||||
unpackedTag byte = 0xff
|
||||
)
|
||||
|
||||
// Pack appends the packed version of src to dst and returns the
|
||||
// resulting slice. len(src) must be a multiple of 8 or Pack panics.
|
||||
func Pack(dst, src []byte) []byte {
|
||||
if len(src)%wordSize != 0 {
|
||||
panic("packed.Pack len(src) must be a multiple of 8")
|
||||
}
|
||||
var buf [wordSize]byte
|
||||
for len(src) > 0 {
|
||||
var hdr byte
|
||||
n := 0
|
||||
for i := uint(0); i < wordSize; i++ {
|
||||
if src[i] != 0 {
|
||||
hdr |= 1 << i
|
||||
buf[n] = src[i]
|
||||
n++
|
||||
}
|
||||
}
|
||||
dst = append(dst, hdr)
|
||||
dst = append(dst, buf[:n]...)
|
||||
src = src[wordSize:]
|
||||
|
||||
switch hdr {
|
||||
case zeroTag:
|
||||
z := min(numZeroWords(src), 0xff)
|
||||
dst = append(dst, byte(z))
|
||||
src = src[z*wordSize:]
|
||||
case unpackedTag:
|
||||
i := 0
|
||||
end := min(len(src), 0xff*wordSize)
|
||||
for i < end {
|
||||
zeros := 0
|
||||
for _, b := range src[i : i+wordSize] {
|
||||
if b == 0 {
|
||||
zeros++
|
||||
}
|
||||
}
|
||||
|
||||
if zeros > 1 {
|
||||
break
|
||||
}
|
||||
i += wordSize
|
||||
}
|
||||
|
||||
rawWords := byte(i / wordSize)
|
||||
dst = append(dst, rawWords)
|
||||
dst = append(dst, src[:i]...)
|
||||
src = src[i:]
|
||||
}
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
// numZeroWords returns the number of leading zero words in b.
|
||||
func numZeroWords(b []byte) int {
|
||||
for i, bb := range b {
|
||||
if bb != 0 {
|
||||
return i / wordSize
|
||||
}
|
||||
}
|
||||
return len(b) / wordSize
|
||||
}
|
||||
|
||||
// Unpack appends the unpacked version of src to dst and returns the
|
||||
// resulting slice.
|
||||
func Unpack(dst, src []byte) ([]byte, error) {
|
||||
for len(src) > 0 {
|
||||
tag := src[0]
|
||||
src = src[1:]
|
||||
|
||||
pstart := len(dst)
|
||||
dst = allocWords(dst, 1)
|
||||
p := dst[pstart : pstart+wordSize]
|
||||
if len(src) >= wordSize {
|
||||
i := 0
|
||||
nz := tag & 1
|
||||
p[0] = src[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 1 & 1
|
||||
p[1] = src[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 2 & 1
|
||||
p[2] = src[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 3 & 1
|
||||
p[3] = src[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 4 & 1
|
||||
p[4] = src[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 5 & 1
|
||||
p[5] = src[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 6 & 1
|
||||
p[6] = src[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 7 & 1
|
||||
p[7] = src[i] & -nz
|
||||
i += int(nz)
|
||||
src = src[i:]
|
||||
} else {
|
||||
for i := uint(0); i < wordSize; i++ {
|
||||
if tag&(1<<i) == 0 {
|
||||
continue
|
||||
}
|
||||
if len(src) == 0 {
|
||||
return dst, io.ErrUnexpectedEOF
|
||||
}
|
||||
p[i] = src[0]
|
||||
src = src[1:]
|
||||
}
|
||||
}
|
||||
switch tag {
|
||||
case zeroTag:
|
||||
if len(src) == 0 {
|
||||
return dst, io.ErrUnexpectedEOF
|
||||
}
|
||||
dst = allocWords(dst, int(src[0]))
|
||||
src = src[1:]
|
||||
case unpackedTag:
|
||||
if len(src) == 0 {
|
||||
return dst, io.ErrUnexpectedEOF
|
||||
}
|
||||
start := len(dst)
|
||||
dst = allocWords(dst, int(src[0]))
|
||||
src = src[1:]
|
||||
n := copy(dst[start:], src)
|
||||
src = src[n:]
|
||||
}
|
||||
}
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func allocWords(p []byte, n int) []byte {
|
||||
target := len(p) + n*wordSize
|
||||
if cap(p) >= target {
|
||||
pp := p[len(p):target]
|
||||
for i := range pp {
|
||||
pp[i] = 0
|
||||
}
|
||||
return p[:target]
|
||||
}
|
||||
newcap := cap(p)
|
||||
doublecap := newcap + newcap
|
||||
if target > doublecap {
|
||||
newcap = target
|
||||
} else {
|
||||
if len(p) < 1024 {
|
||||
newcap = doublecap
|
||||
} else {
|
||||
for newcap < target {
|
||||
newcap += newcap / 4
|
||||
}
|
||||
}
|
||||
}
|
||||
pp := make([]byte, target, newcap)
|
||||
copy(pp, p)
|
||||
return pp
|
||||
}
|
||||
|
||||
// A Reader decompresses a packed byte stream.
|
||||
type Reader struct {
|
||||
// ReadWord state
|
||||
rd *bufio.Reader
|
||||
err error
|
||||
zeroes int
|
||||
literal int
|
||||
|
||||
// Read state
|
||||
word [wordSize]byte
|
||||
wordIdx int
|
||||
}
|
||||
|
||||
// NewReader returns a reader that decompresses a packed stream from r.
|
||||
func NewReader(r *bufio.Reader) *Reader {
|
||||
return &Reader{rd: r, wordIdx: wordSize}
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if b < a {
|
||||
return b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
// ReadWord decompresses the next word from the underlying stream.
|
||||
func (r *Reader) ReadWord(p []byte) error {
|
||||
if len(p) < wordSize {
|
||||
return errors.New("packed: read word buffer too small")
|
||||
}
|
||||
r.wordIdx = wordSize // if the caller tries to call ReadWord and Read, don't give them partial words.
|
||||
if r.err != nil {
|
||||
err := r.err
|
||||
r.err = nil
|
||||
return err
|
||||
}
|
||||
p = p[:wordSize]
|
||||
switch {
|
||||
case r.zeroes > 0:
|
||||
r.zeroes--
|
||||
for i := range p {
|
||||
p[i] = 0
|
||||
}
|
||||
return nil
|
||||
case r.literal > 0:
|
||||
r.literal--
|
||||
_, err := io.ReadFull(r.rd, p)
|
||||
return err
|
||||
}
|
||||
|
||||
var tag byte
|
||||
if r.rd.Buffered() < wordSize+1 {
|
||||
var err error
|
||||
tag, err = r.rd.ReadByte()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := range p {
|
||||
p[i] = 0
|
||||
}
|
||||
for i := uint(0); i < wordSize; i++ {
|
||||
if tag&(1<<i) != 0 {
|
||||
p[i], err = r.rd.ReadByte()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
}
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
p[i] = 0
|
||||
}
|
||||
}
|
||||
} else {
|
||||
b, _ := r.rd.Peek(wordSize + 1)
|
||||
tag = b[0]
|
||||
i := 1
|
||||
nz := tag & 1
|
||||
p[0] = b[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 1 & 1
|
||||
p[1] = b[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 2 & 1
|
||||
p[2] = b[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 3 & 1
|
||||
p[3] = b[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 4 & 1
|
||||
p[4] = b[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 5 & 1
|
||||
p[5] = b[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 6 & 1
|
||||
p[6] = b[i] & -nz
|
||||
i += int(nz)
|
||||
nz = tag >> 7 & 1
|
||||
p[7] = b[i] & -nz
|
||||
i += int(nz)
|
||||
discard(r.rd, i)
|
||||
}
|
||||
switch tag {
|
||||
case zeroTag:
|
||||
z, err := r.rd.ReadByte()
|
||||
if err == io.EOF {
|
||||
r.err = io.ErrUnexpectedEOF
|
||||
return nil
|
||||
} else if err != nil {
|
||||
r.err = err
|
||||
return nil
|
||||
}
|
||||
r.zeroes = int(z)
|
||||
case unpackedTag:
|
||||
l, err := r.rd.ReadByte()
|
||||
if err == io.EOF {
|
||||
r.err = io.ErrUnexpectedEOF
|
||||
return nil
|
||||
} else if err != nil {
|
||||
r.err = err
|
||||
return nil
|
||||
}
|
||||
r.literal = int(l)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Read reads up to len(p) bytes into p. This will decompress whole
|
||||
// words at a time, so mixing calls to Read and ReadWord may lead to
|
||||
// bytes missing.
|
||||
func (r *Reader) Read(p []byte) (n int, err error) {
|
||||
if r.wordIdx < wordSize {
|
||||
n = copy(p, r.word[r.wordIdx:])
|
||||
r.wordIdx += n
|
||||
}
|
||||
for n < len(p) {
|
||||
if r.rd.Buffered() < wordSize+1 && n > 0 {
|
||||
return n, nil
|
||||
}
|
||||
if len(p)-n >= wordSize {
|
||||
err := r.ReadWord(p[n:])
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
n += wordSize
|
||||
} else {
|
||||
err := r.ReadWord(r.word[:])
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
r.wordIdx = copy(p[n:], r.word[:])
|
||||
n += r.wordIdx
|
||||
}
|
||||
}
|
||||
return n, nil
|
||||
}
|
503
vendor/zombiezen.com/go/capnproto2/internal/packed/packed_test.go
generated
vendored
Normal file
503
vendor/zombiezen.com/go/capnproto2/internal/packed/packed_test.go
generated
vendored
Normal file
@@ -0,0 +1,503 @@
|
||||
package packed
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"strings"
|
||||
"testing"
|
||||
"testing/iotest"
|
||||
)
|
||||
|
||||
type testCase struct {
|
||||
name string
|
||||
original []byte
|
||||
compressed []byte
|
||||
}
|
||||
|
||||
var compressionTests = []testCase{
|
||||
{
|
||||
"empty",
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
},
|
||||
{
|
||||
"one zero word",
|
||||
[]byte{0, 0, 0, 0, 0, 0, 0, 0},
|
||||
[]byte{0, 0},
|
||||
},
|
||||
{
|
||||
"one word with mixed zero bytes",
|
||||
[]byte{0, 0, 12, 0, 0, 34, 0, 0},
|
||||
[]byte{0x24, 12, 34},
|
||||
},
|
||||
{
|
||||
"two words with mixed zero bytes",
|
||||
[]byte{
|
||||
0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00,
|
||||
0x19, 0x00, 0x00, 0x00, 0xaa, 0x01, 0x00, 0x00,
|
||||
},
|
||||
[]byte{0x51, 0x08, 0x03, 0x02, 0x31, 0x19, 0xaa, 0x01},
|
||||
},
|
||||
{
|
||||
"two words with mixed zero bytes",
|
||||
[]byte{0x8, 0, 0, 0, 0x3, 0, 0x2, 0, 0x19, 0, 0, 0, 0xaa, 0x1, 0, 0},
|
||||
[]byte{0x51, 0x08, 0x03, 0x02, 0x31, 0x19, 0xaa, 0x01},
|
||||
},
|
||||
{
|
||||
"four zero words",
|
||||
[]byte{
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
},
|
||||
[]byte{0x00, 0x03},
|
||||
},
|
||||
{
|
||||
"four words without zero bytes",
|
||||
[]byte{
|
||||
0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
|
||||
0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
|
||||
0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
|
||||
0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
|
||||
},
|
||||
[]byte{
|
||||
0xff,
|
||||
0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
|
||||
0x03,
|
||||
0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
|
||||
0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
|
||||
0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a, 0x8a,
|
||||
},
|
||||
},
|
||||
{
|
||||
"one word without zero bytes",
|
||||
[]byte{1, 3, 2, 4, 5, 7, 6, 8},
|
||||
[]byte{0xff, 1, 3, 2, 4, 5, 7, 6, 8, 0},
|
||||
},
|
||||
{
|
||||
"one zero word followed by one word without zero bytes",
|
||||
[]byte{0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 4, 5, 7, 6, 8},
|
||||
[]byte{0, 0, 0xff, 1, 3, 2, 4, 5, 7, 6, 8, 0},
|
||||
},
|
||||
{
|
||||
"one word with mixed zero bytes followed by one word without zero bytes",
|
||||
[]byte{0, 0, 12, 0, 0, 34, 0, 0, 1, 3, 2, 4, 5, 7, 6, 8},
|
||||
[]byte{0x24, 12, 34, 0xff, 1, 3, 2, 4, 5, 7, 6, 8, 0},
|
||||
},
|
||||
{
|
||||
"two words with no zero bytes",
|
||||
[]byte{1, 3, 2, 4, 5, 7, 6, 8, 8, 6, 7, 4, 5, 2, 3, 1},
|
||||
[]byte{0xff, 1, 3, 2, 4, 5, 7, 6, 8, 1, 8, 6, 7, 4, 5, 2, 3, 1},
|
||||
},
|
||||
{
|
||||
"five words, with only the last containing zero bytes",
|
||||
[]byte{
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
0, 2, 4, 0, 9, 0, 5, 1,
|
||||
},
|
||||
[]byte{
|
||||
0xff, 1, 2, 3, 4, 5, 6, 7, 8,
|
||||
3,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
0xd6, 2, 4, 9, 5, 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
"five words, with the middle and last words containing zero bytes",
|
||||
[]byte{
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
6, 2, 4, 3, 9, 0, 5, 1,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
0, 2, 4, 0, 9, 0, 5, 1,
|
||||
},
|
||||
[]byte{
|
||||
0xff, 1, 2, 3, 4, 5, 6, 7, 8,
|
||||
3,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
6, 2, 4, 3, 9, 0, 5, 1,
|
||||
1, 2, 3, 4, 5, 6, 7, 8,
|
||||
0xd6, 2, 4, 9, 5, 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
"words with mixed zeroes sandwiching zero words",
|
||||
[]byte{
|
||||
8, 0, 100, 6, 0, 1, 1, 2,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 0, 2, 0, 3, 1,
|
||||
},
|
||||
[]byte{
|
||||
0xed, 8, 100, 6, 1, 1, 2,
|
||||
0, 2,
|
||||
0xd4, 1, 2, 3, 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
"real-world Cap'n Proto data",
|
||||
[]byte{
|
||||
0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x1, 0x0,
|
||||
0x25, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
||||
0x1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0,
|
||||
0xd4, 0x7, 0xc, 0x7, 0x0, 0x0, 0x0, 0x0,
|
||||
},
|
||||
[]byte{
|
||||
0x10, 0x5,
|
||||
0x50, 0x2, 0x1,
|
||||
0x1, 0x25,
|
||||
0x0, 0x0,
|
||||
0x11, 0x1, 0xc,
|
||||
0xf, 0xd4, 0x7, 0xc, 0x7,
|
||||
},
|
||||
},
|
||||
{
|
||||
"shortened benchmark data",
|
||||
[]byte{
|
||||
8, 100, 6, 0, 1, 1, 0, 2,
|
||||
8, 100, 6, 0, 1, 1, 0, 2,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 2, 0, 3, 0, 0,
|
||||
'H', 'e', 'l', 'l', 'o', ',', ' ', 'W',
|
||||
'o', 'r', 'l', 'd', '!', ' ', ' ', 'P',
|
||||
'a', 'd', ' ', 't', 'e', 'x', 't', '.',
|
||||
},
|
||||
[]byte{
|
||||
0xb7, 8, 100, 6, 1, 1, 2,
|
||||
0xb7, 8, 100, 6, 1, 1, 2,
|
||||
0x00, 3,
|
||||
0x2a, 1, 2, 3,
|
||||
0xff, 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W',
|
||||
2,
|
||||
'o', 'r', 'l', 'd', '!', ' ', ' ', 'P',
|
||||
'a', 'd', ' ', 't', 'e', 'x', 't', '.',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var decompressionTests = []testCase{
|
||||
{
|
||||
"fuzz hang #1",
|
||||
mustGunzip("\x1f\x8b\b\x00\x00\tn\x88\x00\xff\xec\xce!\x11\x000\f\x04\xc1G\xd5Q\xff\x02\x8b" +
|
||||
"\xab!(\xc9\xcc.>p\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xf5^" +
|
||||
"\xf7\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x000\xc8\xc9" +
|
||||
"-\xf5?\x00\x00\xff\xff6\xe2l*\x90\xcc\x00\x00"),
|
||||
[]byte("\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff@\xf6\x00\xff\x00\xf6" +
|
||||
"\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6" +
|
||||
"\x00\xff\x00\xf6\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x05\x06 \x00\x04"),
|
||||
},
|
||||
{
|
||||
"fuzz hang #2",
|
||||
mustGunzip("\x1f\x8b\b\x00\x00\tn\x88\x00\xff\xec\xceA\r\x00\x00\b\x04\xa0\xeb\x1fد\xc6p:H@" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00ު\xa4\xb7\x0f\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
|
||||
"\\5\x01\x00\x00\xff\xff\r\xfb\xbac\xe0\xe8\x00\x00"),
|
||||
[]byte("\x00\xf6\x00\xff\x00\u007f\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6" +
|
||||
"\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\x005\x00\xf6\x00\xff\x00" +
|
||||
"\xf6\x00\xff\x00\xf6\x00\xff\x00 \x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00" +
|
||||
"\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6"),
|
||||
},
|
||||
}
|
||||
|
||||
var badDecompressionTests = []struct {
|
||||
name string
|
||||
input []byte
|
||||
}{
|
||||
{
|
||||
"wrong tag",
|
||||
[]byte{
|
||||
0xa7, 8, 100, 6, 1, 1, 2,
|
||||
0xa7, 8, 100, 6, 1, 1, 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
"badly written decompression benchmark",
|
||||
bytes.Repeat([]byte{
|
||||
0xa7, 8, 100, 6, 1, 1, 2,
|
||||
0xa7, 8, 100, 6, 1, 1, 2,
|
||||
0x00, 3,
|
||||
0x2a,
|
||||
0xff, 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W',
|
||||
2,
|
||||
'o', 'r', 'l', 'd', '!', ' ', ' ', 'P',
|
||||
'a', 'd', ' ', 't', 'e', 'x', 't', '.',
|
||||
}, 128),
|
||||
},
|
||||
}
|
||||
|
||||
func TestPack(t *testing.T) {
|
||||
for _, test := range compressionTests {
|
||||
orig := make([]byte, len(test.original))
|
||||
copy(orig, test.original)
|
||||
compressed := Pack(nil, orig)
|
||||
if !bytes.Equal(compressed, test.compressed) {
|
||||
t.Errorf("%s: Pack(nil,\n%s\n) =\n%s\n; want\n%s", test.name, hex.Dump(test.original), hex.Dump(compressed), hex.Dump(test.compressed))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnpack(t *testing.T) {
|
||||
tests := make([]testCase, 0, len(compressionTests)+len(decompressionTests))
|
||||
tests = append(tests, compressionTests...)
|
||||
tests = append(tests, decompressionTests...)
|
||||
for _, test := range tests {
|
||||
compressed := make([]byte, len(test.compressed))
|
||||
copy(compressed, test.compressed)
|
||||
orig, err := Unpack(nil, compressed)
|
||||
if err != nil {
|
||||
t.Errorf("%s: Unpack(nil,\n%s\n) error: %v", test.name, hex.Dump(test.compressed), err)
|
||||
} else if !bytes.Equal(orig, test.original) {
|
||||
t.Errorf("%s: Unpack(nil,\n%s\n) =\n%s\n; want\n%s", test.name, hex.Dump(test.compressed), hex.Dump(orig), hex.Dump(test.original))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnpack_Fail(t *testing.T) {
|
||||
for _, test := range badDecompressionTests {
|
||||
compressed := make([]byte, len(test.input))
|
||||
copy(compressed, test.input)
|
||||
_, err := Unpack(nil, compressed)
|
||||
if err == nil {
|
||||
t.Errorf("%s: did not return error", test.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReader(t *testing.T) {
|
||||
tests := make([]testCase, 0, len(compressionTests)+len(decompressionTests))
|
||||
tests = append(tests, compressionTests...)
|
||||
tests = append(tests, decompressionTests...)
|
||||
testing:
|
||||
for _, test := range tests {
|
||||
for readSize := 1; readSize <= 8+2*len(test.original); readSize = nextPrime(readSize) {
|
||||
r := bytes.NewReader(test.compressed)
|
||||
d := NewReader(bufio.NewReader(r))
|
||||
buf := make([]byte, readSize)
|
||||
var actual []byte
|
||||
for {
|
||||
n, err := d.Read(buf)
|
||||
actual = append(actual, buf[:n]...)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
t.Errorf("%s: Read: %v", test.name, err)
|
||||
continue testing
|
||||
}
|
||||
}
|
||||
|
||||
if len(test.original) != len(actual) {
|
||||
t.Errorf("%s: readSize=%d: expected %d bytes, got %d", test.name, readSize, len(test.original), len(actual))
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(test.original, actual) {
|
||||
t.Errorf("%s: readSize=%d: bytes = %v; want %v", test.name, readSize, actual, test.original)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReader_DataErr(t *testing.T) {
|
||||
const readSize = 3
|
||||
tests := make([]testCase, 0, len(compressionTests)+len(decompressionTests))
|
||||
tests = append(tests, compressionTests...)
|
||||
tests = append(tests, decompressionTests...)
|
||||
testing:
|
||||
for _, test := range tests {
|
||||
r := iotest.DataErrReader(bytes.NewReader(test.compressed))
|
||||
d := NewReader(bufio.NewReader(r))
|
||||
buf := make([]byte, readSize)
|
||||
var actual []byte
|
||||
for {
|
||||
n, err := d.Read(buf)
|
||||
actual = append(actual, buf[:n]...)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
t.Errorf("%s: Read: %v", test.name, err)
|
||||
continue testing
|
||||
}
|
||||
}
|
||||
|
||||
if len(test.original) != len(actual) {
|
||||
t.Errorf("%s: expected %d bytes, got %d", test.name, len(test.original), len(actual))
|
||||
continue
|
||||
}
|
||||
|
||||
if !bytes.Equal(test.original, actual) {
|
||||
t.Errorf("%s: bytes not equal", test.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReader_Fail(t *testing.T) {
|
||||
for _, test := range badDecompressionTests {
|
||||
d := NewReader(bufio.NewReader(bytes.NewReader(test.input)))
|
||||
_, err := ioutil.ReadAll(d)
|
||||
if err == nil {
|
||||
t.Errorf("%s: did not return error", test.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var result []byte
|
||||
|
||||
func BenchmarkPack(b *testing.B) {
|
||||
src := bytes.Repeat([]byte{
|
||||
8, 0, 100, 6, 0, 1, 1, 2,
|
||||
8, 0, 100, 6, 0, 1, 1, 2,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 2, 0, 3, 0, 0,
|
||||
'H', 'e', 'l', 'l', 'o', ',', ' ', 'W',
|
||||
'o', 'r', 'l', 'd', '!', ' ', ' ', 'P',
|
||||
'a', 'd', ' ', 't', 'e', 'x', 't', '.',
|
||||
}, 128)
|
||||
dst := make([]byte, 0, len(src))
|
||||
b.SetBytes(int64(len(src)))
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dst = Pack(dst[:0], src)
|
||||
}
|
||||
result = dst
|
||||
}
|
||||
|
||||
func benchUnpack(b *testing.B, src []byte) {
|
||||
var unpackedSize int
|
||||
{
|
||||
tmp, err := Unpack(nil, src)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
unpackedSize = len(tmp)
|
||||
}
|
||||
b.SetBytes(int64(unpackedSize))
|
||||
dst := make([]byte, 0, unpackedSize)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
var err error
|
||||
dst, err = Unpack(dst[:0], src)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
result = dst
|
||||
}
|
||||
|
||||
func BenchmarkUnpack(b *testing.B) {
|
||||
benchUnpack(b, bytes.Repeat([]byte{
|
||||
0xb7, 8, 100, 6, 1, 1, 2,
|
||||
0xb7, 8, 100, 6, 1, 1, 2,
|
||||
0x00, 3,
|
||||
0x2a, 1, 2, 3,
|
||||
0xff, 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W',
|
||||
2,
|
||||
'o', 'r', 'l', 'd', '!', ' ', ' ', 'P',
|
||||
'a', 'd', ' ', 't', 'e', 'x', 't', '.',
|
||||
}, 128))
|
||||
}
|
||||
|
||||
func BenchmarkUnpack_Large(b *testing.B) {
|
||||
benchUnpack(b, []byte("\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff@\xf6\x00\xff\x00\xf6"+
|
||||
"\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6"+
|
||||
"\x00\xff\x00\xf6\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x05\x06 \x00\x04"))
|
||||
}
|
||||
|
||||
func benchReader(b *testing.B, src []byte) {
|
||||
var unpackedSize int
|
||||
{
|
||||
tmp, err := Unpack(nil, src)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
unpackedSize = len(tmp)
|
||||
}
|
||||
b.SetBytes(int64(unpackedSize))
|
||||
r := bytes.NewReader(src)
|
||||
br := bufio.NewReader(r)
|
||||
|
||||
dst := bytes.NewBuffer(make([]byte, 0, unpackedSize))
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
dst.Reset()
|
||||
r.Seek(0, 0)
|
||||
br.Reset(r)
|
||||
pr := NewReader(br)
|
||||
_, err := dst.ReadFrom(pr)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
result = dst.Bytes()
|
||||
}
|
||||
|
||||
func BenchmarkReader(b *testing.B) {
|
||||
benchReader(b, bytes.Repeat([]byte{
|
||||
0xb7, 8, 100, 6, 1, 1, 2,
|
||||
0xb7, 8, 100, 6, 1, 1, 2,
|
||||
0x00, 3,
|
||||
0x2a, 1, 2, 3,
|
||||
0xff, 'H', 'e', 'l', 'l', 'o', ',', ' ', 'W',
|
||||
2,
|
||||
'o', 'r', 'l', 'd', '!', ' ', ' ', 'P',
|
||||
'a', 'd', ' ', 't', 'e', 'x', 't', '.',
|
||||
}, 128))
|
||||
}
|
||||
|
||||
func BenchmarkReader_Large(b *testing.B) {
|
||||
benchReader(b, []byte("\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff@\xf6\x00\xff\x00\xf6"+
|
||||
"\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6"+
|
||||
"\x00\xff\x00\xf6\x00\xf6\x00\xff\x00\xf6\x00\xff\x00\xf6\x05\x06 \x00\x04"))
|
||||
}
|
||||
|
||||
func nextPrime(n int) int {
|
||||
inc:
|
||||
for {
|
||||
n++
|
||||
root := int(math.Sqrt(float64(n)))
|
||||
for f := 2; f <= root; f++ {
|
||||
if n%f == 0 {
|
||||
continue inc
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
}
|
||||
|
||||
func mustGunzip(s string) []byte {
|
||||
r, err := gzip.NewReader(strings.NewReader(s))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return data
|
||||
}
|
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/03bf57ea7bdec71698adeae87a862cec7164d40b-3
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/03bf57ea7bdec71698adeae87a862cec7164d40b-3
generated
vendored
Normal file
Binary file not shown.
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/0d25a482d77c50ce11c4e19513273663cb7f2760-3
generated
vendored
Normal file
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/0d25a482d77c50ce11c4e19513273663cb7f2760-3
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1#8188940354856483008125<08>
|
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/0ea83e2670b5efd4c1488e7d3b8d47444edcc0de-2
generated
vendored
Normal file
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/0ea83e2670b5efd4c1488e7d3b8d47444edcc0de-2
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<EFBFBD>M22008446049250313080847263336181640625049250d
|
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/0ebc873dc501946f782b80d9ac30e458e3f4c3bb-1
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/0ebc873dc501946f782b80d9ac30e458e3f4c3bb-1
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/11e6f1cf4e924b97fa749270ef3776ca2f622e4a-1
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/11e6f1cf4e924b97fa749270ef3776ca2f622e4a-1
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/1a03558a19149e8a602fa447a75203e565c5bd24-6
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/1a03558a19149e8a602fa447a75203e565c5bd24-6
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/1cbdf332ea41a8607123a73db6848cb1e08a88e8-7
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/1cbdf332ea41a8607123a73db6848cb1e08a88e8-7
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/1f0255d132314eceb4cb53f8b7edba2b5acca411-5
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/1f0255d132314eceb4cb53f8b7edba2b5acca411-5
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/25e8b15e130bd6fbac4db86667c6585220e649fd-6
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/25e8b15e130bd6fbac4db86667c6585220e649fd-6
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/27602d7c8f418c1648200cbbb80652dfa1d32ec3-5
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/27602d7c8f418c1648200cbbb80652dfa1d32ec3-5
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/309aa6808b3440a343e40d2539c4a8f32a7d22c6-7
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/309aa6808b3440a343e40d2539c4a8f32a7d22c6-7
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/32126b1f830c3950f99f7d6c9d4fd501c50fc95a-3
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/32126b1f830c3950f99f7d6c9d4fd501c50fc95a-3
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/36c4bfda59a7f22e1d84c2559edf589e1591ab4e-5
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/36c4bfda59a7f22e1d84c2559edf589e1591ab4e-5
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/386c071e2d382223ad16da6458ac74ab61995d22-1
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/386c071e2d382223ad16da6458ac74ab61995d22-1
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/397ed0b402b6615879ec32c874ad2ce1189a5566
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/397ed0b402b6615879ec32c874ad2ce1189a5566
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/3dedffca29bf233d7aab140d1ebe4f7a393aaf25-1
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/3dedffca29bf233d7aab140d1ebe4f7a393aaf25-1
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/43275097819916f57c004e3d2d7292cd4c494103-2
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/43275097819916f57c004e3d2d7292cd4c494103-2
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/46758529a6f8bdab34817ecc3b60bdeb8fc7d1df-2
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/46758529a6f8bdab34817ecc3b60bdeb8fc7d1df-2
generated
vendored
Normal file
Binary file not shown.
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/46d2e26b94a1e361bbb9561f6bf82f709952079a-1
generated
vendored
Normal file
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/46d2e26b94a1e361bbb9561f6bf82f709952079a-1
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<EFBFBD><08>
|
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/4fbde0ace86d682a07e20940ff917f4c6243c848-1
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/4fbde0ace86d682a07e20940ff917f4c6243c848-1
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/53ff759b338edc76af39e47cba96506942f8fcf4-1
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/53ff759b338edc76af39e47cba96506942f8fcf4-1
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/5b7a93398637f041f5b2aa27f5506e070c4ab93a-10
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/5b7a93398637f041f5b2aa27f5506e070c4ab93a-10
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/62b362cbeb20f5993b35fa4104af45169e729567-5
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/62b362cbeb20f5993b35fa4104af45169e729567-5
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/6545fc074cb9ff87f00d92da2bb0e43fb655a1a0-8
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/6545fc074cb9ff87f00d92da2bb0e43fb655a1a0-8
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/6648f3613b1f7b827c1f8e57dfd6d98297afc120-3
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/6648f3613b1f7b827c1f8e57dfd6d98297afc120-3
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/672e3be57da3f6260bd1224ab122c43db7531c68-1
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/672e3be57da3f6260bd1224ab122c43db7531c68-1
generated
vendored
Normal file
Binary file not shown.
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/685749732874f297765f6aa9cb2149ae8a760a30-2
generated
vendored
Normal file
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/685749732874f297765f6aa9cb2149ae8a760a30-2
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<EFBFBD>1#818989403545856475830078125<08>
|
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/6b71d6625925391d3e5d5df85ed6520b3bdff697-5
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/6b71d6625925391d3e5d5df85ed6520b3bdff697-5
generated
vendored
Normal file
Binary file not shown.
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/6d7d243c36e5b97f088139d68d659a76d8f1a85e-3
generated
vendored
Normal file
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/6d7d243c36e5b97f088139d68d659a76d8f1a85e-3
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<EFBFBD>1#818989403545856475830078125
|
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/733795216f2196269dfb2230101048a8d1a900ef-4
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/733795216f2196269dfb2230101048a8d1a900ef-4
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/79e96c2c0556cf294cb5ccc84fbe6f688b722a4b-5
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/79e96c2c0556cf294cb5ccc84fbe6f688b722a4b-5
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/82449e84f12b12e2e78cd1837063af01f771a8c3-4
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/82449e84f12b12e2e78cd1837063af01f771a8c3-4
generated
vendored
Normal file
Binary file not shown.
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/85c90a0758e25bc682dc2f169cc60394b1aef429-1
generated
vendored
Normal file
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/85c90a0758e25bc682dc2f169cc60394b1aef429-1
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<EFBFBD><03><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/86bb19d6ebfdcb2986e2f5f19e8b1d064bb143b6
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/86bb19d6ebfdcb2986e2f5f19e8b1d064bb143b6
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/8f842db7cc972786baa4aef0bb39cedd92313ff0-6
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/8f842db7cc972786baa4aef0bb39cedd92313ff0-6
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/928cde18fcd017b7d9f617e6efb1ad3d335106d9-9
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/928cde18fcd017b7d9f617e6efb1ad3d335106d9-9
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/950b28b26d2efaa8ca8b77551c9cc4fb9bfa73c7-1
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/950b28b26d2efaa8ca8b77551c9cc4fb9bfa73c7-1
generated
vendored
Normal file
Binary file not shown.
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/95fb90dbbc7bd9d57a1c3c43fa2d9c0370f26f36-6
generated
vendored
Normal file
BIN
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/95fb90dbbc7bd9d57a1c3c43fa2d9c0370f26f36-6
generated
vendored
Normal file
Binary file not shown.
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/96e65fffcc37d53d86825858d055dac113e71283-1
generated
vendored
Normal file
1
vendor/zombiezen.com/go/capnproto2/internal/packed/testdata/corpus/96e65fffcc37d53d86825858d055dac113e71283-1
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<EFBFBD>2220446049250313080847263336181640625d
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user