TUN-813: Clean up cloudflared dependencies

This commit is contained in:
Areg Harutyunyan
2018-07-24 18:04:33 -05:00
parent d06fc520c7
commit 0468866626
3310 changed files with 993 additions and 1223303 deletions

View File

@@ -1,24 +0,0 @@
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__"],
)

View File

@@ -1,353 +0,0 @@
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;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +0,0 @@
package aircraftlib
//go:generate capnp compile -I ../../std -ogo aircraft.capnp

View File

@@ -1,8 +0,0 @@
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__"],
)

View File

@@ -1,76 +0,0 @@
// 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
}

View File

@@ -1,193 +0,0 @@
// +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 ""
}

View File

@@ -1,24 +0,0 @@
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",
],
)

View File

@@ -1,61 +0,0 @@
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)
}

View File

@@ -1,16 +0,0 @@
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",
],
)

View File

@@ -1,12 +0,0 @@
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.
}

View File

@@ -1,104 +0,0 @@
// 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)
}

View File

@@ -1,3 +0,0 @@
//go:generate capnp compile -I ../../../std -ogo books.capnp
package books

View File

@@ -1,2 +0,0 @@
// Package demo contains example tests.
package demo

View File

@@ -1,93 +0,0 @@
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
}

View File

@@ -1,18 +0,0 @@
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",
],
)

View File

@@ -1,3 +0,0 @@
//go:generate capnp compile -I ../../../std -ogo hash.capnp
package hashes

View File

@@ -1,13 +0,0 @@
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);
}

View File

@@ -1,605 +0,0 @@
// 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)
}

View File

@@ -1,123 +0,0 @@
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
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,186 +0,0 @@
// +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
}

View File

@@ -1,503 +0,0 @@
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
}

View File

@@ -1 +0,0 @@
1#8188940354856483008125<08>

View File

@@ -1 +0,0 @@
<EFBFBD> M22008446049250313080847263336181640625049250d

View File

@@ -1 +0,0 @@
<EFBFBD><08>

View File

@@ -1 +0,0 @@
<EFBFBD>1#818989403545856475830078125<08>

View File

@@ -1 +0,0 @@
<EFBFBD>1#818989403545856475830078125

View File

@@ -1 +0,0 @@
<EFBFBD><03><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>

View File

@@ -1 +0,0 @@
<EFBFBD>2220446049250313080847263336181640625d

View File

@@ -1 +0,0 @@
<EFBFBD><08>

View File

@@ -1 +0,0 @@
<EFBFBD>1#81898940354585<38><35><EFBFBD>c<EFBFBD><63><EFBFBD>1<EFBFBD><31>ソソ<EFBDBF>'647<34><37>#<23>De5830078125

Some files were not shown because too many files have changed in this diff Show More