vendor: Mega update all dependencies
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4080
This commit is contained in:
10
vendor/github.com/calmh/xdr/README.md
generated
vendored
10
vendor/github.com/calmh/xdr/README.md
generated
vendored
@@ -1,10 +0,0 @@
|
||||
xdr
|
||||
===
|
||||
|
||||
[](https://circleci.com/gh/calmh/xdr)
|
||||
[](https://coveralls.io/r/calmh/xdr?branch=master)
|
||||
[](http://godoc.org/github.com/calmh/xdr)
|
||||
[](http://opensource.org/licenses/MIT)
|
||||
|
||||
This is an XDR marshalling/unmarshalling library. It uses code generation and
|
||||
not reflection.
|
||||
52
vendor/github.com/calmh/xdr/bench_test.go
generated
vendored
52
vendor/github.com/calmh/xdr/bench_test.go
generated
vendored
@@ -1,52 +0,0 @@
|
||||
// Copyright (C) 2014 Jakob Borg. All rights reserved. Use of this source code
|
||||
// is governed by an MIT-style license that can be found in the LICENSE file.
|
||||
|
||||
package xdr_test
|
||||
|
||||
import "testing"
|
||||
|
||||
type XDRBenchStruct struct {
|
||||
I1 uint64
|
||||
I2 uint32
|
||||
I3 uint16
|
||||
I4 uint8
|
||||
Bs0 []byte // max:128
|
||||
Bs1 []byte
|
||||
Is0 []int32
|
||||
S0 string // max:128
|
||||
S1 string
|
||||
}
|
||||
|
||||
var res []byte // not to be optimized away
|
||||
var s = XDRBenchStruct{
|
||||
I1: 42,
|
||||
I2: 43,
|
||||
I3: 44,
|
||||
I4: 45,
|
||||
Bs0: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18},
|
||||
Bs1: []byte{11, 12, 13, 14, 15, 16, 17, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
||||
Is0: []int32{23, 43},
|
||||
S0: "Hello World! String one.",
|
||||
S1: "Hello World! String two.",
|
||||
}
|
||||
|
||||
func BenchmarkThisMarshal(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
res, _ = s.MarshalXDR()
|
||||
}
|
||||
|
||||
b.ReportAllocs()
|
||||
}
|
||||
|
||||
func BenchmarkThisUnmarshal(b *testing.B) {
|
||||
bs := s.MustMarshalXDR()
|
||||
var t XDRBenchStruct
|
||||
for i := 0; i < b.N; i++ {
|
||||
err := t.UnmarshalXDR(bs)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
b.ReportAllocs()
|
||||
}
|
||||
140
vendor/github.com/calmh/xdr/bench_xdr_test.go
generated
vendored
140
vendor/github.com/calmh/xdr/bench_xdr_test.go
generated
vendored
@@ -1,140 +0,0 @@
|
||||
// ************************************************************
|
||||
// This file is automatically generated by genxdr. Do not edit.
|
||||
// ************************************************************
|
||||
|
||||
package xdr_test
|
||||
|
||||
import (
|
||||
"github.com/calmh/xdr"
|
||||
)
|
||||
|
||||
/*
|
||||
|
||||
XDRBenchStruct Structure:
|
||||
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| |
|
||||
+ I1 (64 bits) +
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| I2 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| 16 zero bits | I3 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| 24 zero bits | I4 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ Bs0 (length + padded data) \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ Bs1 (length + padded data) \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Number of Is0 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
| Is0 (n items) |
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ S0 (length + padded data) \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ S1 (length + padded data) \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
|
||||
struct XDRBenchStruct {
|
||||
unsigned hyper I1;
|
||||
unsigned int I2;
|
||||
unsigned int I3;
|
||||
unsigned int I4;
|
||||
opaque Bs0<128>;
|
||||
opaque Bs1<>;
|
||||
int Is0<>;
|
||||
string S0<128>;
|
||||
string S1<>;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
func (o XDRBenchStruct) XDRSize() int {
|
||||
return 8 + 4 + 4 + 4 +
|
||||
4 + len(o.Bs0) + xdr.Padding(len(o.Bs0)) +
|
||||
4 + len(o.Bs1) + xdr.Padding(len(o.Bs1)) +
|
||||
4 + len(o.Is0)*4 +
|
||||
4 + len(o.S0) + xdr.Padding(len(o.S0)) +
|
||||
4 + len(o.S1) + xdr.Padding(len(o.S1))
|
||||
}
|
||||
|
||||
func (o XDRBenchStruct) MarshalXDR() ([]byte, error) {
|
||||
buf := make([]byte, o.XDRSize())
|
||||
m := &xdr.Marshaller{Data: buf}
|
||||
return buf, o.MarshalXDRInto(m)
|
||||
}
|
||||
|
||||
func (o XDRBenchStruct) MustMarshalXDR() []byte {
|
||||
bs, err := o.MarshalXDR()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return bs
|
||||
}
|
||||
|
||||
func (o XDRBenchStruct) MarshalXDRInto(m *xdr.Marshaller) error {
|
||||
m.MarshalUint64(o.I1)
|
||||
m.MarshalUint32(o.I2)
|
||||
m.MarshalUint16(o.I3)
|
||||
m.MarshalUint8(o.I4)
|
||||
if l := len(o.Bs0); l > 128 {
|
||||
return xdr.ElementSizeExceeded("Bs0", l, 128)
|
||||
}
|
||||
m.MarshalBytes(o.Bs0)
|
||||
m.MarshalBytes(o.Bs1)
|
||||
m.MarshalUint32(uint32(len(o.Is0)))
|
||||
for i := range o.Is0 {
|
||||
m.MarshalUint32(uint32(o.Is0[i]))
|
||||
}
|
||||
if l := len(o.S0); l > 128 {
|
||||
return xdr.ElementSizeExceeded("S0", l, 128)
|
||||
}
|
||||
m.MarshalString(o.S0)
|
||||
m.MarshalString(o.S1)
|
||||
return m.Error
|
||||
}
|
||||
|
||||
func (o *XDRBenchStruct) UnmarshalXDR(bs []byte) error {
|
||||
u := &xdr.Unmarshaller{Data: bs}
|
||||
return o.UnmarshalXDRFrom(u)
|
||||
}
|
||||
func (o *XDRBenchStruct) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
|
||||
o.I1 = u.UnmarshalUint64()
|
||||
o.I2 = u.UnmarshalUint32()
|
||||
o.I3 = u.UnmarshalUint16()
|
||||
o.I4 = u.UnmarshalUint8()
|
||||
o.Bs0 = u.UnmarshalBytesMax(128)
|
||||
o.Bs1 = u.UnmarshalBytes()
|
||||
_Is0Size := int(u.UnmarshalUint32())
|
||||
if _Is0Size < 0 {
|
||||
return xdr.ElementSizeExceeded("Is0", _Is0Size, 0)
|
||||
} else if _Is0Size == 0 {
|
||||
o.Is0 = nil
|
||||
} else {
|
||||
if _Is0Size <= len(o.Is0) {
|
||||
o.Is0 = o.Is0[:_Is0Size]
|
||||
} else {
|
||||
o.Is0 = make([]int32, _Is0Size)
|
||||
}
|
||||
for i := range o.Is0 {
|
||||
o.Is0[i] = int32(u.UnmarshalUint32())
|
||||
}
|
||||
}
|
||||
o.S0 = u.UnmarshalStringMax(128)
|
||||
o.S1 = u.UnmarshalString()
|
||||
return u.Error
|
||||
}
|
||||
3
vendor/github.com/calmh/xdr/circle.yml
generated
vendored
3
vendor/github.com/calmh/xdr/circle.yml
generated
vendored
@@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
post:
|
||||
- ./generate.sh
|
||||
241
vendor/github.com/calmh/xdr/encdec_test.go
generated
vendored
241
vendor/github.com/calmh/xdr/encdec_test.go
generated
vendored
@@ -1,241 +0,0 @@
|
||||
// Copyright (C) 2014 Jakob Borg. All rights reserved. Use of this source code
|
||||
// is governed by an MIT-style license that can be found in the LICENSE file.
|
||||
|
||||
package xdr_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
"testing/quick"
|
||||
|
||||
"github.com/calmh/xdr"
|
||||
)
|
||||
|
||||
// Contains all supported types
|
||||
type TestStruct struct {
|
||||
B bool
|
||||
I int
|
||||
I8 int8
|
||||
UI8 uint8
|
||||
I16 int16
|
||||
UI16 uint16
|
||||
I32 int32
|
||||
UI32 uint32
|
||||
I64 int64
|
||||
UI64 uint64
|
||||
BS []byte // max:1024
|
||||
S string // max:1024
|
||||
C Opaque
|
||||
SS []string // max:1024
|
||||
ES EmptyStruct
|
||||
OS OtherStruct
|
||||
OSs []OtherStruct
|
||||
}
|
||||
|
||||
func (s1 TestStruct) TestEquals(s2 TestStruct) bool {
|
||||
if s1.B != s2.B {
|
||||
log.Printf("B differ; %v != %v", s1.B, s2.B)
|
||||
return false
|
||||
}
|
||||
if s1.I != s2.I {
|
||||
log.Printf("I differ; %d != %d", s1.I, s2.I)
|
||||
return false
|
||||
}
|
||||
if s1.I8 != s2.I8 {
|
||||
log.Printf("I8 differ; %d != %d", s1.I8, s2.I8)
|
||||
return false
|
||||
}
|
||||
if s1.UI8 != s2.UI8 {
|
||||
log.Printf("UI8 differ; %d != %d", s1.UI8, s2.UI8)
|
||||
return false
|
||||
}
|
||||
if s1.I16 != s2.I16 {
|
||||
log.Printf("I16 differ; %d != %d", s1.I16, s2.I16)
|
||||
return false
|
||||
}
|
||||
if s1.UI16 != s2.UI16 {
|
||||
log.Printf("UI16 differ; %d != %d", s1.UI16, s2.UI16)
|
||||
return false
|
||||
}
|
||||
if s1.I32 != s2.I32 {
|
||||
log.Printf("I32 differ; %d != %d", s1.I32, s2.I32)
|
||||
return false
|
||||
}
|
||||
if s1.UI32 != s2.UI32 {
|
||||
log.Printf("UI32 differ; %d != %d", s1.UI32, s2.UI32)
|
||||
return false
|
||||
}
|
||||
if s1.I64 != s2.I64 {
|
||||
log.Printf("I64 differ; %d != %d", s1.I64, s2.I64)
|
||||
return false
|
||||
}
|
||||
if s1.UI64 != s2.UI64 {
|
||||
log.Printf("UI64 differ; %d != %d", s1.UI64, s2.UI64)
|
||||
return false
|
||||
}
|
||||
if !bytes.Equal(s1.BS, s2.BS) {
|
||||
log.Println("BS differ")
|
||||
return false
|
||||
}
|
||||
if s1.S != s2.S {
|
||||
log.Printf("S differ; %q != %q", s1.S, s2.S)
|
||||
return false
|
||||
}
|
||||
if s1.C != s2.C {
|
||||
log.Printf("C differ; %q != %q", s1.C, s2.C)
|
||||
return false
|
||||
}
|
||||
if len(s1.SS) != len(s2.SS) {
|
||||
log.Printf("len(SS) differ; %q != %q", len(s1.SS), len(s2.SS))
|
||||
return false
|
||||
}
|
||||
for i := range s1.SS {
|
||||
if s1.SS[i] != s2.SS[i] {
|
||||
log.Printf("SS[%d] differ; %q != %q", i, s1.SS[i], s2.SS[i])
|
||||
return false
|
||||
}
|
||||
}
|
||||
if s1.OS != s2.OS {
|
||||
log.Printf("OS differ; %q != %q", s1.OS, s2.OS)
|
||||
return false
|
||||
}
|
||||
if len(s1.OSs) != len(s2.OSs) {
|
||||
log.Printf("len(OSs) differ; %q != %q", len(s1.OSs), len(s2.OSs))
|
||||
return false
|
||||
}
|
||||
for i := range s1.OSs {
|
||||
if s1.OSs[i] != s2.OSs[i] {
|
||||
log.Printf("OSs[%d] differ; %q != %q", i, s1.OSs[i], s2.OSs[i])
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
type EmptyStruct struct {
|
||||
}
|
||||
|
||||
type OtherStruct struct {
|
||||
F1 uint32
|
||||
F2 string
|
||||
}
|
||||
|
||||
type Opaque [32]byte
|
||||
|
||||
func (u *Opaque) XDRSize() int {
|
||||
return 32
|
||||
}
|
||||
|
||||
func (u *Opaque) MarshalXDRInto(m *xdr.Marshaller) error {
|
||||
m.MarshalRaw(u[:])
|
||||
return m.Error
|
||||
}
|
||||
|
||||
func (o *Opaque) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
|
||||
copy((*o)[:], u.UnmarshalRaw(32))
|
||||
return u.Error
|
||||
}
|
||||
|
||||
func (Opaque) Generate(rand *rand.Rand, size int) reflect.Value {
|
||||
var u Opaque
|
||||
for i := range u[:] {
|
||||
u[i] = byte(rand.Int())
|
||||
}
|
||||
return reflect.ValueOf(u)
|
||||
}
|
||||
|
||||
func TestEncDec(t *testing.T) {
|
||||
fn := func(t0 TestStruct) bool {
|
||||
bs, err := t0.MarshalXDR()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var t1 TestStruct
|
||||
err = t1.UnmarshalXDR(bs)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return t0.TestEquals(t1)
|
||||
}
|
||||
if err := quick.Check(fn, nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalShortBuffer(t *testing.T) {
|
||||
var s TestStruct
|
||||
buf := make([]byte, s.XDRSize())
|
||||
if err := s.MarshalXDRInto(&xdr.Marshaller{Data: buf}); err != nil {
|
||||
t.Fatal("Unexpected error", err)
|
||||
}
|
||||
|
||||
if err := s.MarshalXDRInto(&xdr.Marshaller{Data: buf[1:]}); err != io.ErrShortBuffer {
|
||||
t.Fatal("Expected io.ErrShortBuffer, got", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalUnexpectedEOF(t *testing.T) {
|
||||
var s TestStruct
|
||||
buf := make([]byte, s.XDRSize())
|
||||
if err := s.MarshalXDRInto(&xdr.Marshaller{Data: buf}); err != nil {
|
||||
t.Fatal("Unexpected error", err)
|
||||
}
|
||||
|
||||
if err := s.UnmarshalXDR(buf[:len(buf)-1]); err != io.ErrUnexpectedEOF {
|
||||
t.Fatal("Expected io.ErrUnexpectedEOF, got", err)
|
||||
}
|
||||
|
||||
u := &xdr.Unmarshaller{Data: buf[:3]}
|
||||
u.UnmarshalRaw(4)
|
||||
if err := u.Error; err != io.ErrUnexpectedEOF {
|
||||
t.Fatal("Expected io.ErrUnexpectedEOF, got", err)
|
||||
}
|
||||
|
||||
u = &xdr.Unmarshaller{Data: buf[:3]}
|
||||
u.UnmarshalString()
|
||||
if err := u.Error; err != io.ErrUnexpectedEOF {
|
||||
t.Fatal("Expected io.ErrUnexpectedEOF, got", err)
|
||||
}
|
||||
|
||||
u = &xdr.Unmarshaller{Data: buf[:3]}
|
||||
u.UnmarshalBytes()
|
||||
if err := u.Error; err != io.ErrUnexpectedEOF {
|
||||
t.Fatal("Expected io.ErrUnexpectedEOF, got", err)
|
||||
}
|
||||
|
||||
u = &xdr.Unmarshaller{Data: buf[:3]}
|
||||
u.UnmarshalBool()
|
||||
if err := u.Error; err != io.ErrUnexpectedEOF {
|
||||
t.Fatal("Expected io.ErrUnexpectedEOF, got", err)
|
||||
}
|
||||
|
||||
u = &xdr.Unmarshaller{Data: buf[:3]}
|
||||
u.UnmarshalUint8()
|
||||
if err := u.Error; err != io.ErrUnexpectedEOF {
|
||||
t.Fatal("Expected io.ErrUnexpectedEOF, got", err)
|
||||
}
|
||||
|
||||
u = &xdr.Unmarshaller{Data: buf[:3]}
|
||||
u.UnmarshalUint16()
|
||||
if err := u.Error; err != io.ErrUnexpectedEOF {
|
||||
t.Fatal("Expected io.ErrUnexpectedEOF, got", err)
|
||||
}
|
||||
|
||||
u = &xdr.Unmarshaller{Data: buf[:3]}
|
||||
u.UnmarshalUint32()
|
||||
if err := u.Error; err != io.ErrUnexpectedEOF {
|
||||
t.Fatal("Expected io.ErrUnexpectedEOF, got", err)
|
||||
}
|
||||
|
||||
u = &xdr.Unmarshaller{Data: buf[:7]}
|
||||
u.UnmarshalUint64()
|
||||
if err := u.Error; err != io.ErrUnexpectedEOF {
|
||||
t.Fatal("Expected io.ErrUnexpectedEOF, got", err)
|
||||
}
|
||||
}
|
||||
319
vendor/github.com/calmh/xdr/encdec_xdr_test.go
generated
vendored
319
vendor/github.com/calmh/xdr/encdec_xdr_test.go
generated
vendored
@@ -1,319 +0,0 @@
|
||||
// ************************************************************
|
||||
// This file is automatically generated by genxdr. Do not edit.
|
||||
// ************************************************************
|
||||
|
||||
package xdr_test
|
||||
|
||||
import (
|
||||
"github.com/calmh/xdr"
|
||||
)
|
||||
|
||||
/*
|
||||
|
||||
TestStruct Structure:
|
||||
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| B (V=0 or 1) |V|
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ int Structure \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| 24 zero bits | I8 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| 24 zero bits | UI8 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| 16 zero bits | I16 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| 16 zero bits | UI16 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| I32 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| UI32 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| |
|
||||
+ I64 (64 bits) +
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| |
|
||||
+ UI64 (64 bits) +
|
||||
| |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ BS (length + padded data) \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ S (length + padded data) \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ Opaque Structure \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Number of SS |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
/ /
|
||||
\ SS (length + padded data) \
|
||||
/ /
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ EmptyStruct Structure \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ OtherStruct Structure \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Number of OSs |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ Zero or more OtherStruct Structures \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
|
||||
struct TestStruct {
|
||||
bool B;
|
||||
int I;
|
||||
int I8;
|
||||
unsigned int UI8;
|
||||
int I16;
|
||||
unsigned int UI16;
|
||||
int I32;
|
||||
unsigned int UI32;
|
||||
hyper I64;
|
||||
unsigned hyper UI64;
|
||||
opaque BS<1024>;
|
||||
string S<1024>;
|
||||
Opaque C;
|
||||
string SS<1024>;
|
||||
EmptyStruct ES;
|
||||
OtherStruct OS;
|
||||
OtherStruct OSs<>;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
func (o TestStruct) XDRSize() int {
|
||||
return 4 + 8 + 4 + 4 + 4 + 4 + 4 + 4 + 8 + 8 +
|
||||
4 + len(o.BS) + xdr.Padding(len(o.BS)) +
|
||||
4 + len(o.S) + xdr.Padding(len(o.S)) +
|
||||
o.C.XDRSize() +
|
||||
4 + xdr.SizeOfSlice(o.SS) +
|
||||
o.ES.XDRSize() +
|
||||
o.OS.XDRSize() +
|
||||
4 + xdr.SizeOfSlice(o.OSs)
|
||||
}
|
||||
|
||||
func (o TestStruct) MarshalXDR() ([]byte, error) {
|
||||
buf := make([]byte, o.XDRSize())
|
||||
m := &xdr.Marshaller{Data: buf}
|
||||
return buf, o.MarshalXDRInto(m)
|
||||
}
|
||||
|
||||
func (o TestStruct) MustMarshalXDR() []byte {
|
||||
bs, err := o.MarshalXDR()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return bs
|
||||
}
|
||||
|
||||
func (o TestStruct) MarshalXDRInto(m *xdr.Marshaller) error {
|
||||
m.MarshalBool(o.B)
|
||||
m.MarshalUint64(uint64(o.I))
|
||||
m.MarshalUint8(uint8(o.I8))
|
||||
m.MarshalUint8(o.UI8)
|
||||
m.MarshalUint16(uint16(o.I16))
|
||||
m.MarshalUint16(o.UI16)
|
||||
m.MarshalUint32(uint32(o.I32))
|
||||
m.MarshalUint32(o.UI32)
|
||||
m.MarshalUint64(uint64(o.I64))
|
||||
m.MarshalUint64(o.UI64)
|
||||
if l := len(o.BS); l > 1024 {
|
||||
return xdr.ElementSizeExceeded("BS", l, 1024)
|
||||
}
|
||||
m.MarshalBytes(o.BS)
|
||||
if l := len(o.S); l > 1024 {
|
||||
return xdr.ElementSizeExceeded("S", l, 1024)
|
||||
}
|
||||
m.MarshalString(o.S)
|
||||
if err := o.C.MarshalXDRInto(m); err != nil {
|
||||
return err
|
||||
}
|
||||
if l := len(o.SS); l > 1024 {
|
||||
return xdr.ElementSizeExceeded("SS", l, 1024)
|
||||
}
|
||||
m.MarshalUint32(uint32(len(o.SS)))
|
||||
for i := range o.SS {
|
||||
m.MarshalString(o.SS[i])
|
||||
}
|
||||
if err := o.ES.MarshalXDRInto(m); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := o.OS.MarshalXDRInto(m); err != nil {
|
||||
return err
|
||||
}
|
||||
m.MarshalUint32(uint32(len(o.OSs)))
|
||||
for i := range o.OSs {
|
||||
if err := o.OSs[i].MarshalXDRInto(m); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return m.Error
|
||||
}
|
||||
|
||||
func (o *TestStruct) UnmarshalXDR(bs []byte) error {
|
||||
u := &xdr.Unmarshaller{Data: bs}
|
||||
return o.UnmarshalXDRFrom(u)
|
||||
}
|
||||
func (o *TestStruct) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
|
||||
o.B = u.UnmarshalBool()
|
||||
o.I = int(u.UnmarshalUint64())
|
||||
o.I8 = int8(u.UnmarshalUint8())
|
||||
o.UI8 = u.UnmarshalUint8()
|
||||
o.I16 = int16(u.UnmarshalUint16())
|
||||
o.UI16 = u.UnmarshalUint16()
|
||||
o.I32 = int32(u.UnmarshalUint32())
|
||||
o.UI32 = u.UnmarshalUint32()
|
||||
o.I64 = int64(u.UnmarshalUint64())
|
||||
o.UI64 = u.UnmarshalUint64()
|
||||
o.BS = u.UnmarshalBytesMax(1024)
|
||||
o.S = u.UnmarshalStringMax(1024)
|
||||
(&o.C).UnmarshalXDRFrom(u)
|
||||
_SSSize := int(u.UnmarshalUint32())
|
||||
if _SSSize < 0 {
|
||||
return xdr.ElementSizeExceeded("SS", _SSSize, 1024)
|
||||
} else if _SSSize == 0 {
|
||||
o.SS = nil
|
||||
} else {
|
||||
if _SSSize > 1024 {
|
||||
return xdr.ElementSizeExceeded("SS", _SSSize, 1024)
|
||||
}
|
||||
if _SSSize <= len(o.SS) {
|
||||
for i := _SSSize; i < len(o.SS); i++ {
|
||||
o.SS[i] = ""
|
||||
}
|
||||
o.SS = o.SS[:_SSSize]
|
||||
} else {
|
||||
o.SS = make([]string, _SSSize)
|
||||
}
|
||||
for i := range o.SS {
|
||||
o.SS[i] = u.UnmarshalString()
|
||||
}
|
||||
}
|
||||
(&o.ES).UnmarshalXDRFrom(u)
|
||||
(&o.OS).UnmarshalXDRFrom(u)
|
||||
_OSsSize := int(u.UnmarshalUint32())
|
||||
if _OSsSize < 0 {
|
||||
return xdr.ElementSizeExceeded("OSs", _OSsSize, 0)
|
||||
} else if _OSsSize == 0 {
|
||||
o.OSs = nil
|
||||
} else {
|
||||
if _OSsSize <= len(o.OSs) {
|
||||
o.OSs = o.OSs[:_OSsSize]
|
||||
} else {
|
||||
o.OSs = make([]OtherStruct, _OSsSize)
|
||||
}
|
||||
for i := range o.OSs {
|
||||
(&o.OSs[i]).UnmarshalXDRFrom(u)
|
||||
}
|
||||
}
|
||||
return u.Error
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
EmptyStruct Structure:
|
||||
(contains no fields)
|
||||
|
||||
|
||||
struct EmptyStruct {
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
func (o EmptyStruct) XDRSize() int {
|
||||
return 0
|
||||
}
|
||||
func (o EmptyStruct) MarshalXDR() ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (o EmptyStruct) MustMarshalXDR() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o EmptyStruct) MarshalXDRInto(m *xdr.Marshaller) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *EmptyStruct) UnmarshalXDR(bs []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *EmptyStruct) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
OtherStruct Structure:
|
||||
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| F1 |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ F2 (length + padded data) \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
|
||||
struct OtherStruct {
|
||||
unsigned int F1;
|
||||
string F2<>;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
func (o OtherStruct) XDRSize() int {
|
||||
return 4 +
|
||||
4 + len(o.F2) + xdr.Padding(len(o.F2))
|
||||
}
|
||||
|
||||
func (o OtherStruct) MarshalXDR() ([]byte, error) {
|
||||
buf := make([]byte, o.XDRSize())
|
||||
m := &xdr.Marshaller{Data: buf}
|
||||
return buf, o.MarshalXDRInto(m)
|
||||
}
|
||||
|
||||
func (o OtherStruct) MustMarshalXDR() []byte {
|
||||
bs, err := o.MarshalXDR()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return bs
|
||||
}
|
||||
|
||||
func (o OtherStruct) MarshalXDRInto(m *xdr.Marshaller) error {
|
||||
m.MarshalUint32(o.F1)
|
||||
m.MarshalString(o.F2)
|
||||
return m.Error
|
||||
}
|
||||
|
||||
func (o *OtherStruct) UnmarshalXDR(bs []byte) error {
|
||||
u := &xdr.Unmarshaller{Data: bs}
|
||||
return o.UnmarshalXDRFrom(u)
|
||||
}
|
||||
func (o *OtherStruct) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
|
||||
o.F1 = u.UnmarshalUint32()
|
||||
o.F2 = u.UnmarshalString()
|
||||
return u.Error
|
||||
}
|
||||
4
vendor/github.com/calmh/xdr/generate.sh
generated
vendored
4
vendor/github.com/calmh/xdr/generate.sh
generated
vendored
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
go run cmd/genxdr/main.go -- bench_test.go > bench_xdr_test.go
|
||||
go run cmd/genxdr/main.go -- encdec_test.go > encdec_xdr_test.go
|
||||
Reference in New Issue
Block a user