Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08f982c

Browse files
authored
Support for embedded TypedParams (digitalocean#77)
* Support for embedded TypedParamsAdd support for decoding TypedParams embedded in structures within alibvirt routine's return values. Previously this was handled via a hackin the generated code; this change makes the TypedParam decoderavailable to the xdr library no matter where the TypedParam is found.This moves the xdr decoder into the go-libvirt project so that we canfork it and add support for decoding custom types not part of the xdrspec.Also move travis builds to go 1.11.Fixes issuedigitalocean#71
1 parent83daaa0 commit08f982c

30 files changed

+6103
-994
lines changed

‎.travis.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cache:
88
-$HOME/.ccache
99

1010
go:
11-
-"1.10"
11+
-"1.11"
1212

1313
env:
1414
global:

‎const.gen.go‎

Lines changed: 504 additions & 428 deletions
Large diffs are not rendered by default.

‎internal/constants/constants.gen.go‎

Lines changed: 54 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎internal/constants/constants.go‎

Lines changed: 0 additions & 48 deletions
This file was deleted.

‎internal/go-xdr/LICENSE‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2012-2014 Dave Collins <dave@davec.name>
2+
3+
Permission to use, copy, modify, and distribute this software for any
4+
purpose with or without fee is hereby granted, provided that the above
5+
copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

‎internal/go-xdr/README.md‎

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
go-xdr
2+
======
3+
4+
[![Build Status](https://travis-ci.org/davecgh/go-xdr.png?branch=master)]
5+
(https://travis-ci.org/davecgh/go-xdr)[![Coverage Status]
6+
(https://coveralls.io/repos/davecgh/go-xdr/badge.png?branch=master)]
7+
(https://coveralls.io/r/davecgh/go-xdr?branch=master)
8+
9+
Go-xdr implements the data representation portion of the External Data
10+
Representation (XDR) standard protocol as specified in RFC 4506 (obsoletes RFC
11+
1832 and RFC 1014) in Pure Go (Golang). A comprehensive suite of tests are
12+
provided to ensure proper functionality. It is licensed under the liberal ISC
13+
license, so it may be used in open source or commercial projects.
14+
15+
NOTE: Version 1 of this package is still available via the
16+
github.com/davecgh/go-xdr/xdr import path to avoid breaking existing clients. However, it is highly recommended that all old clients upgrade to version 2
17+
and all new clients use version 2. In addition to some speed optimizations,
18+
version 2 has been been updated to work with standard the io.Reader and
19+
io.Writer interfaces instead of raw byte slices. This allows it to be much more
20+
flexible and work directly with files, network connections, etc.
21+
22+
##Documentation
23+
24+
[![GoDoc](https://godoc.org/github.com/davecgh/go-xdr/xdr2?status.png)]
25+
(http://godoc.org/github.com/davecgh/go-xdr/xdr2)
26+
27+
Full`go doc` style documentation for the project can be viewed online without
28+
installing this package by using the excellent GoDoc site here:
29+
http://godoc.org/github.com/davecgh/go-xdr/xdr2
30+
31+
You can also view the documentation locally once the package is installed with
32+
the`godoc` tool by running`godoc -http=":6060"` and pointing your browser to
33+
http://localhost:6060/pkg/github.com/davecgh/go-xdr/xdr2/
34+
35+
##Installation
36+
37+
```bash
38+
$ go get github.com/davecgh/go-xdr/xdr2
39+
```
40+
41+
##Sample Decode Program
42+
43+
```Go
44+
package main
45+
46+
import (
47+
"bytes"
48+
"fmt"
49+
50+
"github.com/davecgh/go-xdr/xdr2"
51+
)
52+
53+
funcmain() {
54+
// Hypothetical image header format.
55+
type ImageHeaderstruct {
56+
Signature [3]byte
57+
Versionuint32
58+
IsGrayscalebool
59+
NumSectionsuint32
60+
}
61+
62+
// XDR encoded data described by the above structure. Typically this would
63+
// be read from a file or across the network, but use a manual byte array
64+
// here as an example.
65+
encodedData:= []byte{
66+
0xAB,0xCD,0xEF,0x00,// Signature
67+
0x00,0x00,0x00,0x02,// Version
68+
0x00,0x00,0x00,0x01,// IsGrayscale
69+
0x00,0x00,0x00,0x0A,// NumSections
70+
}
71+
72+
// Declare a variable to provide Unmarshal with a concrete type and instance
73+
// to decode into.
74+
varh ImageHeader
75+
bytesRead,err:= xdr.Unmarshal(bytes.NewReader(encodedData), &h)
76+
if err !=nil {
77+
fmt.Println(err)
78+
return
79+
}
80+
81+
fmt.Println("bytes read:", bytesRead)
82+
fmt.Printf("h:%+v", h)
83+
}
84+
```
85+
86+
The struct instance,`h`, will then contain the following values:
87+
88+
```Go
89+
h.Signature = [3]byte{0xAB,0xCD,0xEF}
90+
h.Version =2
91+
h.IsGrayscale =true
92+
h.NumSections =10
93+
```
94+
95+
##Sample Encode Program
96+
97+
```Go
98+
package main
99+
100+
import (
101+
"bytes"
102+
"fmt"
103+
104+
"github.com/davecgh/go-xdr/xdr2"
105+
)
106+
107+
funcmain() {
108+
// Hypothetical image header format.
109+
type ImageHeaderstruct {
110+
Signature [3]byte
111+
Versionuint32
112+
IsGrayscalebool
113+
NumSectionsuint32
114+
}
115+
116+
// Sample image header data.
117+
h:= ImageHeader{[3]byte{0xAB,0xCD,0xEF},2,true,10}
118+
119+
// Use marshal to automatically determine the appropriate underlying XDR
120+
// types and encode.
121+
varw bytes.Buffer
122+
bytesWritten,err:= xdr.Marshal(&w, &h)
123+
if err !=nil {
124+
fmt.Println(err)
125+
return
126+
}
127+
128+
encodedData:= w.Bytes()
129+
fmt.Println("bytes written:", bytesWritten)
130+
fmt.Println("encoded data:", encodedData)
131+
}
132+
```
133+
134+
The result,`encodedData`, will then contain the following XDR encoded byte
135+
sequence:
136+
137+
```
138+
0xAB, 0xCD, 0xEF, 0x00,
139+
0x00, 0x00, 0x00, 0x02,
140+
0x00, 0x00, 0x00, 0x01,
141+
0x00, 0x00, 0x00, 0x0A,
142+
```
143+
144+
##License
145+
146+
Go-xdr is licensed under the liberal ISC License.

‎internal/go-xdr/goclean.sh‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
# The script does automatic checking on a Go package and its sub-packages, including:
3+
# 1. gofmt (http://golang.org/cmd/gofmt/)
4+
# 2. goimports (https://github.com/bradfitz/goimports)
5+
# 3. golint (https://github.com/golang/lint)
6+
# 4. go vet (http://golang.org/cmd/vet)
7+
# 5. test coverage (http://blog.golang.org/cover)
8+
9+
set -e
10+
11+
# Automatic checks
12+
cd xdr2
13+
test -z"$(gofmt -l -w.| tee /dev/stderr)"
14+
test -z"$(goimports -l -w.| tee /dev/stderr)"
15+
test -z"$(golint.| tee /dev/stderr)"
16+
go vet ./...
17+
env GORACE="halt_on_error=1" gotest -v -race ./...
18+
19+
# Run test coverage on each subdirectories and merge the coverage profile.
20+
21+
echo"mode: count"> profile.cov
22+
23+
# Standard go tooling behavior is to ignore dirs with leading underscores.
24+
fordirin$(find. -maxdepth 10 -not -path'./.git*' -not -path'*/_*' -type d);
25+
do
26+
if ls$dir/*.go&> /dev/null;then
27+
gotest -covermode=count -coverprofile=$dir/profile.tmp$dir
28+
if [-f$dir/profile.tmp ];then
29+
cat$dir/profile.tmp| tail -n +2>> profile.cov
30+
rm$dir/profile.tmp
31+
fi
32+
fi
33+
done
34+
35+
go tool cover -func profile.cov
36+
37+
# To submit the test coverage result to coveralls.io,
38+
# use goveralls (https://github.com/mattn/goveralls)
39+
# goveralls -coverprofile=profile.cov -service=travis-ci

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp