You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/04/06 02:27:50 UTC
[45/54] [partial] incubator-mynewt-newtmgr git commit: revendor
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/spf13/pflag/string_slice.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/spf13/pflag/string_slice.go b/newtmgr/vendor/github.com/spf13/pflag/string_slice.go
deleted file mode 100644
index 05eee75..0000000
--- a/newtmgr/vendor/github.com/spf13/pflag/string_slice.go
+++ /dev/null
@@ -1,129 +0,0 @@
-package pflag
-
-import (
- "bytes"
- "encoding/csv"
- "strings"
-)
-
-// -- stringSlice Value
-type stringSliceValue struct {
- value *[]string
- changed bool
-}
-
-func newStringSliceValue(val []string, p *[]string) *stringSliceValue {
- ssv := new(stringSliceValue)
- ssv.value = p
- *ssv.value = val
- return ssv
-}
-
-func readAsCSV(val string) ([]string, error) {
- if val == "" {
- return []string{}, nil
- }
- stringReader := strings.NewReader(val)
- csvReader := csv.NewReader(stringReader)
- return csvReader.Read()
-}
-
-func writeAsCSV(vals []string) (string, error) {
- b := &bytes.Buffer{}
- w := csv.NewWriter(b)
- err := w.Write(vals)
- if err != nil {
- return "", err
- }
- w.Flush()
- return strings.TrimSuffix(b.String(), "\n"), nil
-}
-
-func (s *stringSliceValue) Set(val string) error {
- v, err := readAsCSV(val)
- if err != nil {
- return err
- }
- if !s.changed {
- *s.value = v
- } else {
- *s.value = append(*s.value, v...)
- }
- s.changed = true
- return nil
-}
-
-func (s *stringSliceValue) Type() string {
- return "stringSlice"
-}
-
-func (s *stringSliceValue) String() string {
- str, _ := writeAsCSV(*s.value)
- return "[" + str + "]"
-}
-
-func stringSliceConv(sval string) (interface{}, error) {
- sval = sval[1 : len(sval)-1]
- // An empty string would cause a slice with one (empty) string
- if len(sval) == 0 {
- return []string{}, nil
- }
- return readAsCSV(sval)
-}
-
-// GetStringSlice return the []string value of a flag with the given name
-func (f *FlagSet) GetStringSlice(name string) ([]string, error) {
- val, err := f.getFlagType(name, "stringSlice", stringSliceConv)
- if err != nil {
- return []string{}, err
- }
- return val.([]string), nil
-}
-
-// StringSliceVar defines a string flag with specified name, default value, and usage string.
-// The argument p points to a []string variable in which to store the value of the flag.
-func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string) {
- f.VarP(newStringSliceValue(value, p), name, "", usage)
-}
-
-// StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) {
- f.VarP(newStringSliceValue(value, p), name, shorthand, usage)
-}
-
-// StringSliceVar defines a string flag with specified name, default value, and usage string.
-// The argument p points to a []string variable in which to store the value of the flag.
-func StringSliceVar(p *[]string, name string, value []string, usage string) {
- CommandLine.VarP(newStringSliceValue(value, p), name, "", usage)
-}
-
-// StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.
-func StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) {
- CommandLine.VarP(newStringSliceValue(value, p), name, shorthand, usage)
-}
-
-// StringSlice defines a string flag with specified name, default value, and usage string.
-// The return value is the address of a []string variable that stores the value of the flag.
-func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string {
- p := []string{}
- f.StringSliceVarP(&p, name, "", value, usage)
- return &p
-}
-
-// StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) StringSliceP(name, shorthand string, value []string, usage string) *[]string {
- p := []string{}
- f.StringSliceVarP(&p, name, shorthand, value, usage)
- return &p
-}
-
-// StringSlice defines a string flag with specified name, default value, and usage string.
-// The return value is the address of a []string variable that stores the value of the flag.
-func StringSlice(name string, value []string, usage string) *[]string {
- return CommandLine.StringSliceP(name, "", value, usage)
-}
-
-// StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.
-func StringSliceP(name, shorthand string, value []string, usage string) *[]string {
- return CommandLine.StringSliceP(name, shorthand, value, usage)
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/spf13/pflag/uint.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/spf13/pflag/uint.go b/newtmgr/vendor/github.com/spf13/pflag/uint.go
deleted file mode 100644
index dcbc2b7..0000000
--- a/newtmgr/vendor/github.com/spf13/pflag/uint.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package pflag
-
-import "strconv"
-
-// -- uint Value
-type uintValue uint
-
-func newUintValue(val uint, p *uint) *uintValue {
- *p = val
- return (*uintValue)(p)
-}
-
-func (i *uintValue) Set(s string) error {
- v, err := strconv.ParseUint(s, 0, 64)
- *i = uintValue(v)
- return err
-}
-
-func (i *uintValue) Type() string {
- return "uint"
-}
-
-func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) }
-
-func uintConv(sval string) (interface{}, error) {
- v, err := strconv.ParseUint(sval, 0, 0)
- if err != nil {
- return 0, err
- }
- return uint(v), nil
-}
-
-// GetUint return the uint value of a flag with the given name
-func (f *FlagSet) GetUint(name string) (uint, error) {
- val, err := f.getFlagType(name, "uint", uintConv)
- if err != nil {
- return 0, err
- }
- return val.(uint), nil
-}
-
-// UintVar defines a uint flag with specified name, default value, and usage string.
-// The argument p points to a uint variable in which to store the value of the flag.
-func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) {
- f.VarP(newUintValue(value, p), name, "", usage)
-}
-
-// UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) {
- f.VarP(newUintValue(value, p), name, shorthand, usage)
-}
-
-// UintVar defines a uint flag with specified name, default value, and usage string.
-// The argument p points to a uint variable in which to store the value of the flag.
-func UintVar(p *uint, name string, value uint, usage string) {
- CommandLine.VarP(newUintValue(value, p), name, "", usage)
-}
-
-// UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.
-func UintVarP(p *uint, name, shorthand string, value uint, usage string) {
- CommandLine.VarP(newUintValue(value, p), name, shorthand, usage)
-}
-
-// Uint defines a uint flag with specified name, default value, and usage string.
-// The return value is the address of a uint variable that stores the value of the flag.
-func (f *FlagSet) Uint(name string, value uint, usage string) *uint {
- p := new(uint)
- f.UintVarP(p, name, "", value, usage)
- return p
-}
-
-// UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint {
- p := new(uint)
- f.UintVarP(p, name, shorthand, value, usage)
- return p
-}
-
-// Uint defines a uint flag with specified name, default value, and usage string.
-// The return value is the address of a uint variable that stores the value of the flag.
-func Uint(name string, value uint, usage string) *uint {
- return CommandLine.UintP(name, "", value, usage)
-}
-
-// UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.
-func UintP(name, shorthand string, value uint, usage string) *uint {
- return CommandLine.UintP(name, shorthand, value, usage)
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/spf13/pflag/uint16.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/spf13/pflag/uint16.go b/newtmgr/vendor/github.com/spf13/pflag/uint16.go
deleted file mode 100644
index 7e9914e..0000000
--- a/newtmgr/vendor/github.com/spf13/pflag/uint16.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package pflag
-
-import "strconv"
-
-// -- uint16 value
-type uint16Value uint16
-
-func newUint16Value(val uint16, p *uint16) *uint16Value {
- *p = val
- return (*uint16Value)(p)
-}
-
-func (i *uint16Value) Set(s string) error {
- v, err := strconv.ParseUint(s, 0, 16)
- *i = uint16Value(v)
- return err
-}
-
-func (i *uint16Value) Type() string {
- return "uint16"
-}
-
-func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
-
-func uint16Conv(sval string) (interface{}, error) {
- v, err := strconv.ParseUint(sval, 0, 16)
- if err != nil {
- return 0, err
- }
- return uint16(v), nil
-}
-
-// GetUint16 return the uint16 value of a flag with the given name
-func (f *FlagSet) GetUint16(name string) (uint16, error) {
- val, err := f.getFlagType(name, "uint16", uint16Conv)
- if err != nil {
- return 0, err
- }
- return val.(uint16), nil
-}
-
-// Uint16Var defines a uint flag with specified name, default value, and usage string.
-// The argument p points to a uint variable in which to store the value of the flag.
-func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) {
- f.VarP(newUint16Value(value, p), name, "", usage)
-}
-
-// Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
- f.VarP(newUint16Value(value, p), name, shorthand, usage)
-}
-
-// Uint16Var defines a uint flag with specified name, default value, and usage string.
-// The argument p points to a uint variable in which to store the value of the flag.
-func Uint16Var(p *uint16, name string, value uint16, usage string) {
- CommandLine.VarP(newUint16Value(value, p), name, "", usage)
-}
-
-// Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash.
-func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) {
- CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage)
-}
-
-// Uint16 defines a uint flag with specified name, default value, and usage string.
-// The return value is the address of a uint variable that stores the value of the flag.
-func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 {
- p := new(uint16)
- f.Uint16VarP(p, name, "", value, usage)
- return p
-}
-
-// Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
- p := new(uint16)
- f.Uint16VarP(p, name, shorthand, value, usage)
- return p
-}
-
-// Uint16 defines a uint flag with specified name, default value, and usage string.
-// The return value is the address of a uint variable that stores the value of the flag.
-func Uint16(name string, value uint16, usage string) *uint16 {
- return CommandLine.Uint16P(name, "", value, usage)
-}
-
-// Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash.
-func Uint16P(name, shorthand string, value uint16, usage string) *uint16 {
- return CommandLine.Uint16P(name, shorthand, value, usage)
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/spf13/pflag/uint32.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/spf13/pflag/uint32.go b/newtmgr/vendor/github.com/spf13/pflag/uint32.go
deleted file mode 100644
index d802453..0000000
--- a/newtmgr/vendor/github.com/spf13/pflag/uint32.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package pflag
-
-import "strconv"
-
-// -- uint32 value
-type uint32Value uint32
-
-func newUint32Value(val uint32, p *uint32) *uint32Value {
- *p = val
- return (*uint32Value)(p)
-}
-
-func (i *uint32Value) Set(s string) error {
- v, err := strconv.ParseUint(s, 0, 32)
- *i = uint32Value(v)
- return err
-}
-
-func (i *uint32Value) Type() string {
- return "uint32"
-}
-
-func (i *uint32Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
-
-func uint32Conv(sval string) (interface{}, error) {
- v, err := strconv.ParseUint(sval, 0, 32)
- if err != nil {
- return 0, err
- }
- return uint32(v), nil
-}
-
-// GetUint32 return the uint32 value of a flag with the given name
-func (f *FlagSet) GetUint32(name string) (uint32, error) {
- val, err := f.getFlagType(name, "uint32", uint32Conv)
- if err != nil {
- return 0, err
- }
- return val.(uint32), nil
-}
-
-// Uint32Var defines a uint32 flag with specified name, default value, and usage string.
-// The argument p points to a uint32 variable in which to store the value of the flag.
-func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) {
- f.VarP(newUint32Value(value, p), name, "", usage)
-}
-
-// Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
- f.VarP(newUint32Value(value, p), name, shorthand, usage)
-}
-
-// Uint32Var defines a uint32 flag with specified name, default value, and usage string.
-// The argument p points to a uint32 variable in which to store the value of the flag.
-func Uint32Var(p *uint32, name string, value uint32, usage string) {
- CommandLine.VarP(newUint32Value(value, p), name, "", usage)
-}
-
-// Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash.
-func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) {
- CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage)
-}
-
-// Uint32 defines a uint32 flag with specified name, default value, and usage string.
-// The return value is the address of a uint32 variable that stores the value of the flag.
-func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 {
- p := new(uint32)
- f.Uint32VarP(p, name, "", value, usage)
- return p
-}
-
-// Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
- p := new(uint32)
- f.Uint32VarP(p, name, shorthand, value, usage)
- return p
-}
-
-// Uint32 defines a uint32 flag with specified name, default value, and usage string.
-// The return value is the address of a uint32 variable that stores the value of the flag.
-func Uint32(name string, value uint32, usage string) *uint32 {
- return CommandLine.Uint32P(name, "", value, usage)
-}
-
-// Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash.
-func Uint32P(name, shorthand string, value uint32, usage string) *uint32 {
- return CommandLine.Uint32P(name, shorthand, value, usage)
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/spf13/pflag/uint64.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/spf13/pflag/uint64.go b/newtmgr/vendor/github.com/spf13/pflag/uint64.go
deleted file mode 100644
index f62240f..0000000
--- a/newtmgr/vendor/github.com/spf13/pflag/uint64.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package pflag
-
-import "strconv"
-
-// -- uint64 Value
-type uint64Value uint64
-
-func newUint64Value(val uint64, p *uint64) *uint64Value {
- *p = val
- return (*uint64Value)(p)
-}
-
-func (i *uint64Value) Set(s string) error {
- v, err := strconv.ParseUint(s, 0, 64)
- *i = uint64Value(v)
- return err
-}
-
-func (i *uint64Value) Type() string {
- return "uint64"
-}
-
-func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
-
-func uint64Conv(sval string) (interface{}, error) {
- v, err := strconv.ParseUint(sval, 0, 64)
- if err != nil {
- return 0, err
- }
- return uint64(v), nil
-}
-
-// GetUint64 return the uint64 value of a flag with the given name
-func (f *FlagSet) GetUint64(name string) (uint64, error) {
- val, err := f.getFlagType(name, "uint64", uint64Conv)
- if err != nil {
- return 0, err
- }
- return val.(uint64), nil
-}
-
-// Uint64Var defines a uint64 flag with specified name, default value, and usage string.
-// The argument p points to a uint64 variable in which to store the value of the flag.
-func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) {
- f.VarP(newUint64Value(value, p), name, "", usage)
-}
-
-// Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) {
- f.VarP(newUint64Value(value, p), name, shorthand, usage)
-}
-
-// Uint64Var defines a uint64 flag with specified name, default value, and usage string.
-// The argument p points to a uint64 variable in which to store the value of the flag.
-func Uint64Var(p *uint64, name string, value uint64, usage string) {
- CommandLine.VarP(newUint64Value(value, p), name, "", usage)
-}
-
-// Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.
-func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) {
- CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage)
-}
-
-// Uint64 defines a uint64 flag with specified name, default value, and usage string.
-// The return value is the address of a uint64 variable that stores the value of the flag.
-func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 {
- p := new(uint64)
- f.Uint64VarP(p, name, "", value, usage)
- return p
-}
-
-// Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 {
- p := new(uint64)
- f.Uint64VarP(p, name, shorthand, value, usage)
- return p
-}
-
-// Uint64 defines a uint64 flag with specified name, default value, and usage string.
-// The return value is the address of a uint64 variable that stores the value of the flag.
-func Uint64(name string, value uint64, usage string) *uint64 {
- return CommandLine.Uint64P(name, "", value, usage)
-}
-
-// Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.
-func Uint64P(name, shorthand string, value uint64, usage string) *uint64 {
- return CommandLine.Uint64P(name, shorthand, value, usage)
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/spf13/pflag/uint8.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/spf13/pflag/uint8.go b/newtmgr/vendor/github.com/spf13/pflag/uint8.go
deleted file mode 100644
index bb0e83c..0000000
--- a/newtmgr/vendor/github.com/spf13/pflag/uint8.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package pflag
-
-import "strconv"
-
-// -- uint8 Value
-type uint8Value uint8
-
-func newUint8Value(val uint8, p *uint8) *uint8Value {
- *p = val
- return (*uint8Value)(p)
-}
-
-func (i *uint8Value) Set(s string) error {
- v, err := strconv.ParseUint(s, 0, 8)
- *i = uint8Value(v)
- return err
-}
-
-func (i *uint8Value) Type() string {
- return "uint8"
-}
-
-func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
-
-func uint8Conv(sval string) (interface{}, error) {
- v, err := strconv.ParseUint(sval, 0, 8)
- if err != nil {
- return 0, err
- }
- return uint8(v), nil
-}
-
-// GetUint8 return the uint8 value of a flag with the given name
-func (f *FlagSet) GetUint8(name string) (uint8, error) {
- val, err := f.getFlagType(name, "uint8", uint8Conv)
- if err != nil {
- return 0, err
- }
- return val.(uint8), nil
-}
-
-// Uint8Var defines a uint8 flag with specified name, default value, and usage string.
-// The argument p points to a uint8 variable in which to store the value of the flag.
-func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) {
- f.VarP(newUint8Value(value, p), name, "", usage)
-}
-
-// Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {
- f.VarP(newUint8Value(value, p), name, shorthand, usage)
-}
-
-// Uint8Var defines a uint8 flag with specified name, default value, and usage string.
-// The argument p points to a uint8 variable in which to store the value of the flag.
-func Uint8Var(p *uint8, name string, value uint8, usage string) {
- CommandLine.VarP(newUint8Value(value, p), name, "", usage)
-}
-
-// Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash.
-func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) {
- CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage)
-}
-
-// Uint8 defines a uint8 flag with specified name, default value, and usage string.
-// The return value is the address of a uint8 variable that stores the value of the flag.
-func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 {
- p := new(uint8)
- f.Uint8VarP(p, name, "", value, usage)
- return p
-}
-
-// Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 {
- p := new(uint8)
- f.Uint8VarP(p, name, shorthand, value, usage)
- return p
-}
-
-// Uint8 defines a uint8 flag with specified name, default value, and usage string.
-// The return value is the address of a uint8 variable that stores the value of the flag.
-func Uint8(name string, value uint8, usage string) *uint8 {
- return CommandLine.Uint8P(name, "", value, usage)
-}
-
-// Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash.
-func Uint8P(name, shorthand string, value uint8, usage string) *uint8 {
- return CommandLine.Uint8P(name, shorthand, value, usage)
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/spf13/pflag/uint_slice.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/spf13/pflag/uint_slice.go b/newtmgr/vendor/github.com/spf13/pflag/uint_slice.go
deleted file mode 100644
index edd94c6..0000000
--- a/newtmgr/vendor/github.com/spf13/pflag/uint_slice.go
+++ /dev/null
@@ -1,126 +0,0 @@
-package pflag
-
-import (
- "fmt"
- "strconv"
- "strings"
-)
-
-// -- uintSlice Value
-type uintSliceValue struct {
- value *[]uint
- changed bool
-}
-
-func newUintSliceValue(val []uint, p *[]uint) *uintSliceValue {
- uisv := new(uintSliceValue)
- uisv.value = p
- *uisv.value = val
- return uisv
-}
-
-func (s *uintSliceValue) Set(val string) error {
- ss := strings.Split(val, ",")
- out := make([]uint, len(ss))
- for i, d := range ss {
- u, err := strconv.ParseUint(d, 10, 0)
- if err != nil {
- return err
- }
- out[i] = uint(u)
- }
- if !s.changed {
- *s.value = out
- } else {
- *s.value = append(*s.value, out...)
- }
- s.changed = true
- return nil
-}
-
-func (s *uintSliceValue) Type() string {
- return "uintSlice"
-}
-
-func (s *uintSliceValue) String() string {
- out := make([]string, len(*s.value))
- for i, d := range *s.value {
- out[i] = fmt.Sprintf("%d", d)
- }
- return "[" + strings.Join(out, ",") + "]"
-}
-
-func uintSliceConv(val string) (interface{}, error) {
- val = strings.Trim(val, "[]")
- // Empty string would cause a slice with one (empty) entry
- if len(val) == 0 {
- return []uint{}, nil
- }
- ss := strings.Split(val, ",")
- out := make([]uint, len(ss))
- for i, d := range ss {
- u, err := strconv.ParseUint(d, 10, 0)
- if err != nil {
- return nil, err
- }
- out[i] = uint(u)
- }
- return out, nil
-}
-
-// GetUintSlice returns the []uint value of a flag with the given name.
-func (f *FlagSet) GetUintSlice(name string) ([]uint, error) {
- val, err := f.getFlagType(name, "uintSlice", uintSliceConv)
- if err != nil {
- return []uint{}, err
- }
- return val.([]uint), nil
-}
-
-// UintSliceVar defines a uintSlice flag with specified name, default value, and usage string.
-// The argument p points to a []uint variable in which to store the value of the flag.
-func (f *FlagSet) UintSliceVar(p *[]uint, name string, value []uint, usage string) {
- f.VarP(newUintSliceValue(value, p), name, "", usage)
-}
-
-// UintSliceVarP is like UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string) {
- f.VarP(newUintSliceValue(value, p), name, shorthand, usage)
-}
-
-// UintSliceVar defines a uint[] flag with specified name, default value, and usage string.
-// The argument p points to a uint[] variable in which to store the value of the flag.
-func UintSliceVar(p *[]uint, name string, value []uint, usage string) {
- CommandLine.VarP(newUintSliceValue(value, p), name, "", usage)
-}
-
-// UintSliceVarP is like the UintSliceVar, but accepts a shorthand letter that can be used after a single dash.
-func UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string) {
- CommandLine.VarP(newUintSliceValue(value, p), name, shorthand, usage)
-}
-
-// UintSlice defines a []uint flag with specified name, default value, and usage string.
-// The return value is the address of a []uint variable that stores the value of the flag.
-func (f *FlagSet) UintSlice(name string, value []uint, usage string) *[]uint {
- p := []uint{}
- f.UintSliceVarP(&p, name, "", value, usage)
- return &p
-}
-
-// UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
-func (f *FlagSet) UintSliceP(name, shorthand string, value []uint, usage string) *[]uint {
- p := []uint{}
- f.UintSliceVarP(&p, name, shorthand, value, usage)
- return &p
-}
-
-// UintSlice defines a []uint flag with specified name, default value, and usage string.
-// The return value is the address of a []uint variable that stores the value of the flag.
-func UintSlice(name string, value []uint, usage string) *[]uint {
- return CommandLine.UintSliceP(name, "", value, usage)
-}
-
-// UintSliceP is like UintSlice, but accepts a shorthand letter that can be used after a single dash.
-func UintSliceP(name, shorthand string, value []uint, usage string) *[]uint {
- return CommandLine.UintSliceP(name, shorthand, value, usage)
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/tarm/serial/.travis.yml
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/tarm/serial/.travis.yml b/newtmgr/vendor/github.com/tarm/serial/.travis.yml
deleted file mode 100644
index 01dad03..0000000
--- a/newtmgr/vendor/github.com/tarm/serial/.travis.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-language: go
-go:
- - 1.4
- - 1.6
- - tip
-env:
- - GOOS=linux CGO=1
- - GOOS=linux CGO=0
- - GOOS=windows GOARCH=386
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/tarm/serial/LICENSE
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/tarm/serial/LICENSE b/newtmgr/vendor/github.com/tarm/serial/LICENSE
deleted file mode 100644
index 6a66aea..0000000
--- a/newtmgr/vendor/github.com/tarm/serial/LICENSE
+++ /dev/null
@@ -1,27 +0,0 @@
-Copyright (c) 2009 The Go Authors. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/tarm/serial/README.md
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/tarm/serial/README.md b/newtmgr/vendor/github.com/tarm/serial/README.md
deleted file mode 100644
index d2fa899..0000000
--- a/newtmgr/vendor/github.com/tarm/serial/README.md
+++ /dev/null
@@ -1,82 +0,0 @@
-[![GoDoc](https://godoc.org/github.com/tarm/serial?status.svg)](http://godoc.org/github.com/tarm/serial)
-[![Build Status](https://travis-ci.org/tarm/serial.svg?branch=master)](https://travis-ci.org/tarm/serial)
-
-Serial
-========
-A Go package to allow you to read and write from the
-serial port as a stream of bytes.
-
-Details
--------
-It aims to have the same API on all platforms, including windows. As
-an added bonus, the windows package does not use cgo, so you can cross
-compile for windows from another platform.
-
-You can cross compile with
- GOOS=windows GOARCH=386 go install github.com/tarm/serial
-
-Currently there is very little in the way of configurability. You can
-set the baud rate. Then you can Read(), Write(), or Close() the
-connection. By default Read() will block until at least one byte is
-returned. Write is the same.
-
-Currently all ports are opened with 8 data bits, 1 stop bit, no
-parity, no hardware flow control, and no software flow control. This
-works fine for many real devices and many faux serial devices
-including usb-to-serial converters and bluetooth serial ports.
-
-You may Read() and Write() simulantiously on the same connection (from
-different goroutines).
-
-Usage
------
-```go
-package main
-
-import (
- "log"
-
- "github.com/tarm/serial"
-)
-
-func main() {
- c := &serial.Config{Name: "COM45", Baud: 115200}
- s, err := serial.OpenPort(c)
- if err != nil {
- log.Fatal(err)
- }
-
- n, err := s.Write([]byte("test"))
- if err != nil {
- log.Fatal(err)
- }
-
- buf := make([]byte, 128)
- n, err = s.Read(buf)
- if err != nil {
- log.Fatal(err)
- }
- log.Printf("%q", buf[:n])
-}
-```
-
-NonBlocking Mode
-----------------
-By default the returned Port reads in blocking mode. Which means
-`Read()` will block until at least one byte is returned. If that's not
-what you want, specify a positive ReadTimeout and the Read() will
-timeout returning 0 bytes if no bytes are read. Please note that this
-is the total timeout the read operation will wait and not the interval
-timeout between two bytes.
-
-```go
- c := &serial.Config{Name: "COM45", Baud: 115200, ReadTimeout: time.Second * 5}
-
- // In this mode, you will want to suppress error for read
- // as 0 bytes return EOF error on Linux / POSIX
- n, _ = s.Read(buf)
-```
-
-Possible Future Work
---------------------
-- better tests (loopback etc)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/tarm/serial/serial.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/tarm/serial/serial.go b/newtmgr/vendor/github.com/tarm/serial/serial.go
deleted file mode 100644
index f61ea28..0000000
--- a/newtmgr/vendor/github.com/tarm/serial/serial.go
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
-Goserial is a simple go package to allow you to read and write from
-the serial port as a stream of bytes.
-
-It aims to have the same API on all platforms, including windows. As
-an added bonus, the windows package does not use cgo, so you can cross
-compile for windows from another platform. Unfortunately goinstall
-does not currently let you cross compile so you will have to do it
-manually:
-
- GOOS=windows make clean install
-
-Currently there is very little in the way of configurability. You can
-set the baud rate. Then you can Read(), Write(), or Close() the
-connection. Read() will block until at least one byte is returned.
-Write is the same. There is currently no exposed way to set the
-timeouts, though patches are welcome.
-
-Currently all ports are opened with 8 data bits, 1 stop bit, no
-parity, no hardware flow control, and no software flow control. This
-works fine for many real devices and many faux serial devices
-including usb-to-serial converters and bluetooth serial ports.
-
-You may Read() and Write() simulantiously on the same connection (from
-different goroutines).
-
-Example usage:
-
- package main
-
- import (
- "github.com/tarm/serial"
- "log"
- )
-
- func main() {
- c := &serial.Config{Name: "COM5", Baud: 115200}
- s, err := serial.OpenPort(c)
- if err != nil {
- log.Fatal(err)
- }
-
- n, err := s.Write([]byte("test"))
- if err != nil {
- log.Fatal(err)
- }
-
- buf := make([]byte, 128)
- n, err = s.Read(buf)
- if err != nil {
- log.Fatal(err)
- }
- log.Print("%q", buf[:n])
- }
-*/
-package serial
-
-import (
- "errors"
- "time"
-)
-
-const DefaultSize = 8 // Default value for Config.Size
-
-type StopBits byte
-type Parity byte
-
-const (
- Stop1 StopBits = 1
- Stop1Half StopBits = 15
- Stop2 StopBits = 2
-)
-
-const (
- ParityNone Parity = 'N'
- ParityOdd Parity = 'O'
- ParityEven Parity = 'E'
- ParityMark Parity = 'M' // parity bit is always 1
- ParitySpace Parity = 'S' // parity bit is always 0
-)
-
-// Config contains the information needed to open a serial port.
-//
-// Currently few options are implemented, but more may be added in the
-// future (patches welcome), so it is recommended that you create a
-// new config addressing the fields by name rather than by order.
-//
-// For example:
-//
-// c0 := &serial.Config{Name: "COM45", Baud: 115200, ReadTimeout: time.Millisecond * 500}
-// or
-// c1 := new(serial.Config)
-// c1.Name = "/dev/tty.usbserial"
-// c1.Baud = 115200
-// c1.ReadTimeout = time.Millisecond * 500
-//
-type Config struct {
- Name string
- Baud int
- ReadTimeout time.Duration // Total timeout
-
- // Size is the number of data bits. If 0, DefaultSize is used.
- Size byte
-
- // Parity is the bit to use and defaults to ParityNone (no parity bit).
- Parity Parity
-
- // Number of stop bits to use. Default is 1 (1 stop bit).
- StopBits StopBits
-
- // RTSFlowControl bool
- // DTRFlowControl bool
- // XONFlowControl bool
-
- // CRLFTranslate bool
-}
-
-// ErrBadSize is returned if Size is not supported.
-var ErrBadSize error = errors.New("unsupported serial data size")
-
-// ErrBadStopBits is returned if the specified StopBits setting not supported.
-var ErrBadStopBits error = errors.New("unsupported stop bit setting")
-
-// ErrBadParity is returned if the parity is not supported.
-var ErrBadParity error = errors.New("unsupported parity setting")
-
-// OpenPort opens a serial port with the specified configuration
-func OpenPort(c *Config) (*Port, error) {
- size, par, stop := c.Size, c.Parity, c.StopBits
- if size == 0 {
- size = DefaultSize
- }
- if par == 0 {
- par = ParityNone
- }
- if stop == 0 {
- stop = Stop1
- }
- return openPort(c.Name, c.Baud, size, par, stop, c.ReadTimeout)
-}
-
-// Converts the timeout values for Linux / POSIX systems
-func posixTimeoutValues(readTimeout time.Duration) (vmin uint8, vtime uint8) {
- const MAXUINT8 = 1<<8 - 1 // 255
- // set blocking / non-blocking read
- var minBytesToRead uint8 = 1
- var readTimeoutInDeci int64
- if readTimeout > 0 {
- // EOF on zero read
- minBytesToRead = 0
- // convert timeout to deciseconds as expected by VTIME
- readTimeoutInDeci = (readTimeout.Nanoseconds() / 1e6 / 100)
- // capping the timeout
- if readTimeoutInDeci < 1 {
- // min possible timeout 1 Deciseconds (0.1s)
- readTimeoutInDeci = 1
- } else if readTimeoutInDeci > MAXUINT8 {
- // max possible timeout is 255 deciseconds (25.5s)
- readTimeoutInDeci = MAXUINT8
- }
- }
- return minBytesToRead, uint8(readTimeoutInDeci)
-}
-
-// func SendBreak()
-
-// func RegisterBreakHandler(func())
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/tarm/serial/serial_linux.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/tarm/serial/serial_linux.go b/newtmgr/vendor/github.com/tarm/serial/serial_linux.go
deleted file mode 100644
index adf18c6..0000000
--- a/newtmgr/vendor/github.com/tarm/serial/serial_linux.go
+++ /dev/null
@@ -1,157 +0,0 @@
-// +build linux,!cgo
-
-package serial
-
-import (
- "os"
- "syscall"
- "time"
- "unsafe"
-)
-
-func openPort(name string, baud int, databits byte, parity Parity, stopbits StopBits, readTimeout time.Duration) (p *Port, err error) {
- var bauds = map[int]uint32{
- 50: syscall.B50,
- 75: syscall.B75,
- 110: syscall.B110,
- 134: syscall.B134,
- 150: syscall.B150,
- 200: syscall.B200,
- 300: syscall.B300,
- 600: syscall.B600,
- 1200: syscall.B1200,
- 1800: syscall.B1800,
- 2400: syscall.B2400,
- 4800: syscall.B4800,
- 9600: syscall.B9600,
- 19200: syscall.B19200,
- 38400: syscall.B38400,
- 57600: syscall.B57600,
- 115200: syscall.B115200,
- 230400: syscall.B230400,
- 460800: syscall.B460800,
- 500000: syscall.B500000,
- 576000: syscall.B576000,
- 921600: syscall.B921600,
- 1000000: syscall.B1000000,
- 1152000: syscall.B1152000,
- 1500000: syscall.B1500000,
- 2000000: syscall.B2000000,
- 2500000: syscall.B2500000,
- 3000000: syscall.B3000000,
- 3500000: syscall.B3500000,
- 4000000: syscall.B4000000,
- }
-
- rate := bauds[baud]
-
- if rate == 0 {
- return
- }
-
- f, err := os.OpenFile(name, syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_NONBLOCK, 0666)
- if err != nil {
- return nil, err
- }
-
- defer func() {
- if err != nil && f != nil {
- f.Close()
- }
- }()
-
- // Base settings
- cflagToUse := syscall.CREAD | syscall.CLOCAL | rate
- switch databits {
- case 5:
- cflagToUse |= syscall.CS5
- case 6:
- cflagToUse |= syscall.CS6
- case 7:
- cflagToUse |= syscall.CS7
- case 8:
- cflagToUse |= syscall.CS8
- default:
- return nil, ErrBadSize
- }
- // Stop bits settings
- switch stopbits {
- case Stop1:
- // default is 1 stop bit
- case Stop2:
- cflagToUse |= syscall.CSTOPB
- default:
- // Don't know how to set 1.5
- return nil, ErrBadStopBits
- }
- // Parity settings
- switch parity {
- case ParityNone:
- // default is no parity
- case ParityOdd:
- cflagToUse |= syscall.PARENB
- cflagToUse |= syscall.PARODD
- case ParityEven:
- cflagToUse |= syscall.PARENB
- default:
- return nil, ErrBadParity
- }
- fd := f.Fd()
- vmin, vtime := posixTimeoutValues(readTimeout)
- t := syscall.Termios{
- Iflag: syscall.IGNPAR,
- Cflag: cflagToUse,
- Cc: [32]uint8{syscall.VMIN: vmin, syscall.VTIME: vtime},
- Ispeed: rate,
- Ospeed: rate,
- }
-
- if _, _, errno := syscall.Syscall6(
- syscall.SYS_IOCTL,
- uintptr(fd),
- uintptr(syscall.TCSETS),
- uintptr(unsafe.Pointer(&t)),
- 0,
- 0,
- 0,
- ); errno != 0 {
- return nil, errno
- }
-
- if err = syscall.SetNonblock(int(fd), false); err != nil {
- return
- }
-
- return &Port{f: f}, nil
-}
-
-type Port struct {
- // We intentionly do not use an "embedded" struct so that we
- // don't export File
- f *os.File
-}
-
-func (p *Port) Read(b []byte) (n int, err error) {
- return p.f.Read(b)
-}
-
-func (p *Port) Write(b []byte) (n int, err error) {
- return p.f.Write(b)
-}
-
-// Discards data written to the port but not transmitted,
-// or data received but not read
-func (p *Port) Flush() error {
- const TCFLSH = 0x540B
- _, _, err := syscall.Syscall(
- syscall.SYS_IOCTL,
- uintptr(p.f.Fd()),
- uintptr(TCFLSH),
- uintptr(syscall.TCIOFLUSH),
- )
- return err
-}
-
-func (p *Port) Close() (err error) {
- return p.f.Close()
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/tarm/serial/serial_posix.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/tarm/serial/serial_posix.go b/newtmgr/vendor/github.com/tarm/serial/serial_posix.go
deleted file mode 100644
index 3e8bc7c..0000000
--- a/newtmgr/vendor/github.com/tarm/serial/serial_posix.go
+++ /dev/null
@@ -1,196 +0,0 @@
-// +build !windows,cgo
-
-package serial
-
-// #include <termios.h>
-// #include <unistd.h>
-import "C"
-
-// TODO: Maybe change to using syscall package + ioctl instead of cgo
-
-import (
- "errors"
- "fmt"
- "os"
- "syscall"
- "time"
- //"unsafe"
-)
-
-func openPort(name string, baud int, databits byte, parity Parity, stopbits StopBits, readTimeout time.Duration) (p *Port, err error) {
- f, err := os.OpenFile(name, syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_NONBLOCK, 0666)
- if err != nil {
- return
- }
-
- fd := C.int(f.Fd())
- if C.isatty(fd) != 1 {
- f.Close()
- return nil, errors.New("File is not a tty")
- }
-
- var st C.struct_termios
- _, err = C.tcgetattr(fd, &st)
- if err != nil {
- f.Close()
- return nil, err
- }
- var speed C.speed_t
- switch baud {
- case 115200:
- speed = C.B115200
- case 57600:
- speed = C.B57600
- case 38400:
- speed = C.B38400
- case 19200:
- speed = C.B19200
- case 9600:
- speed = C.B9600
- case 4800:
- speed = C.B4800
- case 2400:
- speed = C.B2400
- case 1200:
- speed = C.B1200
- case 600:
- speed = C.B600
- case 300:
- speed = C.B300
- case 200:
- speed = C.B200
- case 150:
- speed = C.B150
- case 134:
- speed = C.B134
- case 110:
- speed = C.B110
- case 75:
- speed = C.B75
- case 50:
- speed = C.B50
- default:
- f.Close()
- return nil, fmt.Errorf("Unknown baud rate %v", baud)
- }
-
- _, err = C.cfsetispeed(&st, speed)
- if err != nil {
- f.Close()
- return nil, err
- }
- _, err = C.cfsetospeed(&st, speed)
- if err != nil {
- f.Close()
- return nil, err
- }
-
- // Turn off break interrupts, CR->NL, Parity checks, strip, and IXON
- st.c_iflag &= ^C.tcflag_t(C.BRKINT | C.ICRNL | C.INPCK | C.ISTRIP | C.IXOFF | C.IXON | C.PARMRK)
-
- // Select local mode, turn off parity, set to 8 bits
- st.c_cflag &= ^C.tcflag_t(C.CSIZE | C.PARENB)
- st.c_cflag |= (C.CLOCAL | C.CREAD)
- // databits
- switch databits {
- case 5:
- st.c_cflag |= C.CS5
- case 6:
- st.c_cflag |= C.CS6
- case 7:
- st.c_cflag |= C.CS7
- case 8:
- st.c_cflag |= C.CS8
- default:
- return nil, ErrBadSize
- }
- // Parity settings
- switch parity {
- case ParityNone:
- // default is no parity
- case ParityOdd:
- st.c_cflag |= C.PARENB
- st.c_cflag |= C.PARODD
- case ParityEven:
- st.c_cflag |= C.PARENB
- default:
- return nil, ErrBadParity
- }
- // Stop bits settings
- switch stopbits {
- case Stop1:
- // as is, default is 1 bit
- case Stop2:
- st.c_cflag |= C.CSTOPB
- default:
- return nil, ErrBadStopBits
- }
- // Select raw mode
- st.c_lflag &= ^C.tcflag_t(C.ICANON | C.ECHO | C.ECHOE | C.ISIG)
- st.c_oflag &= ^C.tcflag_t(C.OPOST)
-
- // set blocking / non-blocking read
- /*
- * http://man7.org/linux/man-pages/man3/termios.3.html
- * - Supports blocking read and read with timeout operations
- */
- vmin, vtime := posixTimeoutValues(readTimeout)
- st.c_cc[C.VMIN] = C.cc_t(vmin)
- st.c_cc[C.VTIME] = C.cc_t(vtime)
-
- _, err = C.tcsetattr(fd, C.TCSANOW, &st)
- if err != nil {
- f.Close()
- return nil, err
- }
-
- //fmt.Println("Tweaking", name)
- r1, _, e := syscall.Syscall(syscall.SYS_FCNTL,
- uintptr(f.Fd()),
- uintptr(syscall.F_SETFL),
- uintptr(0))
- if e != 0 || r1 != 0 {
- s := fmt.Sprint("Clearing NONBLOCK syscall error:", e, r1)
- f.Close()
- return nil, errors.New(s)
- }
-
- /*
- r1, _, e = syscall.Syscall(syscall.SYS_IOCTL,
- uintptr(f.Fd()),
- uintptr(0x80045402), // IOSSIOSPEED
- uintptr(unsafe.Pointer(&baud)));
- if e != 0 || r1 != 0 {
- s := fmt.Sprint("Baudrate syscall error:", e, r1)
- f.Close()
- return nil, os.NewError(s)
- }
- */
-
- return &Port{f: f}, nil
-}
-
-type Port struct {
- // We intentionly do not use an "embedded" struct so that we
- // don't export File
- f *os.File
-}
-
-func (p *Port) Read(b []byte) (n int, err error) {
- return p.f.Read(b)
-}
-
-func (p *Port) Write(b []byte) (n int, err error) {
- return p.f.Write(b)
-}
-
-// Discards data written to the port but not transmitted,
-// or data received but not read
-func (p *Port) Flush() error {
- _, err := C.tcflush(C.int(p.f.Fd()), C.TCIOFLUSH)
- return err
-}
-
-func (p *Port) Close() (err error) {
- return p.f.Close()
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/tarm/serial/serial_windows.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/tarm/serial/serial_windows.go b/newtmgr/vendor/github.com/tarm/serial/serial_windows.go
deleted file mode 100644
index a41bf4f..0000000
--- a/newtmgr/vendor/github.com/tarm/serial/serial_windows.go
+++ /dev/null
@@ -1,327 +0,0 @@
-// +build windows
-
-package serial
-
-import (
- "fmt"
- "os"
- "sync"
- "syscall"
- "time"
- "unsafe"
-)
-
-type Port struct {
- f *os.File
- fd syscall.Handle
- rl sync.Mutex
- wl sync.Mutex
- ro *syscall.Overlapped
- wo *syscall.Overlapped
-}
-
-type structDCB struct {
- DCBlength, BaudRate uint32
- flags [4]byte
- wReserved, XonLim, XoffLim uint16
- ByteSize, Parity, StopBits byte
- XonChar, XoffChar, ErrorChar, EofChar, EvtChar byte
- wReserved1 uint16
-}
-
-type structTimeouts struct {
- ReadIntervalTimeout uint32
- ReadTotalTimeoutMultiplier uint32
- ReadTotalTimeoutConstant uint32
- WriteTotalTimeoutMultiplier uint32
- WriteTotalTimeoutConstant uint32
-}
-
-func openPort(name string, baud int, databits byte, parity Parity, stopbits StopBits, readTimeout time.Duration) (p *Port, err error) {
- if len(name) > 0 && name[0] != '\\' {
- name = "\\\\.\\" + name
- }
-
- h, err := syscall.CreateFile(syscall.StringToUTF16Ptr(name),
- syscall.GENERIC_READ|syscall.GENERIC_WRITE,
- 0,
- nil,
- syscall.OPEN_EXISTING,
- syscall.FILE_ATTRIBUTE_NORMAL|syscall.FILE_FLAG_OVERLAPPED,
- 0)
- if err != nil {
- return nil, err
- }
- f := os.NewFile(uintptr(h), name)
- defer func() {
- if err != nil {
- f.Close()
- }
- }()
-
- if err = setCommState(h, baud, databits, parity, stopbits); err != nil {
- return nil, err
- }
- if err = setupComm(h, 64, 64); err != nil {
- return nil, err
- }
- if err = setCommTimeouts(h, readTimeout); err != nil {
- return nil, err
- }
- if err = setCommMask(h); err != nil {
- return nil, err
- }
-
- ro, err := newOverlapped()
- if err != nil {
- return nil, err
- }
- wo, err := newOverlapped()
- if err != nil {
- return nil, err
- }
- port := new(Port)
- port.f = f
- port.fd = h
- port.ro = ro
- port.wo = wo
-
- return port, nil
-}
-
-func (p *Port) Close() error {
- return p.f.Close()
-}
-
-func (p *Port) Write(buf []byte) (int, error) {
- p.wl.Lock()
- defer p.wl.Unlock()
-
- if err := resetEvent(p.wo.HEvent); err != nil {
- return 0, err
- }
- var n uint32
- err := syscall.WriteFile(p.fd, buf, &n, p.wo)
- if err != nil && err != syscall.ERROR_IO_PENDING {
- return int(n), err
- }
- return getOverlappedResult(p.fd, p.wo)
-}
-
-func (p *Port) Read(buf []byte) (int, error) {
- if p == nil || p.f == nil {
- return 0, fmt.Errorf("Invalid port on read %v %v", p, p.f)
- }
-
- p.rl.Lock()
- defer p.rl.Unlock()
-
- if err := resetEvent(p.ro.HEvent); err != nil {
- return 0, err
- }
- var done uint32
- err := syscall.ReadFile(p.fd, buf, &done, p.ro)
- if err != nil && err != syscall.ERROR_IO_PENDING {
- return int(done), err
- }
- return getOverlappedResult(p.fd, p.ro)
-}
-
-// Discards data written to the port but not transmitted,
-// or data received but not read
-func (p *Port) Flush() error {
- return purgeComm(p.fd)
-}
-
-var (
- nSetCommState,
- nSetCommTimeouts,
- nSetCommMask,
- nSetupComm,
- nGetOverlappedResult,
- nCreateEvent,
- nResetEvent,
- nPurgeComm,
- nFlushFileBuffers uintptr
-)
-
-func init() {
- k32, err := syscall.LoadLibrary("kernel32.dll")
- if err != nil {
- panic("LoadLibrary " + err.Error())
- }
- defer syscall.FreeLibrary(k32)
-
- nSetCommState = getProcAddr(k32, "SetCommState")
- nSetCommTimeouts = getProcAddr(k32, "SetCommTimeouts")
- nSetCommMask = getProcAddr(k32, "SetCommMask")
- nSetupComm = getProcAddr(k32, "SetupComm")
- nGetOverlappedResult = getProcAddr(k32, "GetOverlappedResult")
- nCreateEvent = getProcAddr(k32, "CreateEventW")
- nResetEvent = getProcAddr(k32, "ResetEvent")
- nPurgeComm = getProcAddr(k32, "PurgeComm")
- nFlushFileBuffers = getProcAddr(k32, "FlushFileBuffers")
-}
-
-func getProcAddr(lib syscall.Handle, name string) uintptr {
- addr, err := syscall.GetProcAddress(lib, name)
- if err != nil {
- panic(name + " " + err.Error())
- }
- return addr
-}
-
-func setCommState(h syscall.Handle, baud int, databits byte, parity Parity, stopbits StopBits) error {
- var params structDCB
- params.DCBlength = uint32(unsafe.Sizeof(params))
-
- params.flags[0] = 0x01 // fBinary
- params.flags[0] |= 0x10 // Assert DSR
-
- params.BaudRate = uint32(baud)
-
- params.ByteSize = databits
-
- switch parity {
- case ParityNone:
- params.Parity = 0
- case ParityOdd:
- params.Parity = 1
- case ParityEven:
- params.Parity = 2
- case ParityMark:
- params.Parity = 3
- case ParitySpace:
- params.Parity = 4
- default:
- return ErrBadParity
- }
-
- switch stopbits {
- case Stop1:
- params.StopBits = 0
- case Stop1Half:
- params.StopBits = 1
- case Stop2:
- params.StopBits = 2
- default:
- return ErrBadStopBits
- }
-
- r, _, err := syscall.Syscall(nSetCommState, 2, uintptr(h), uintptr(unsafe.Pointer(¶ms)), 0)
- if r == 0 {
- return err
- }
- return nil
-}
-
-func setCommTimeouts(h syscall.Handle, readTimeout time.Duration) error {
- var timeouts structTimeouts
- const MAXDWORD = 1<<32 - 1
-
- // blocking read by default
- var timeoutMs int64 = MAXDWORD - 1
-
- if readTimeout > 0 {
- // non-blocking read
- timeoutMs = readTimeout.Nanoseconds() / 1e6
- if timeoutMs < 1 {
- timeoutMs = 1
- } else if timeoutMs > MAXDWORD-1 {
- timeoutMs = MAXDWORD - 1
- }
- }
-
- /* From http://msdn.microsoft.com/en-us/library/aa363190(v=VS.85).aspx
-
- For blocking I/O see below:
-
- Remarks:
-
- If an application sets ReadIntervalTimeout and
- ReadTotalTimeoutMultiplier to MAXDWORD and sets
- ReadTotalTimeoutConstant to a value greater than zero and
- less than MAXDWORD, one of the following occurs when the
- ReadFile function is called:
-
- If there are any bytes in the input buffer, ReadFile returns
- immediately with the bytes in the buffer.
-
- If there are no bytes in the input buffer, ReadFile waits
- until a byte arrives and then returns immediately.
-
- If no bytes arrive within the time specified by
- ReadTotalTimeoutConstant, ReadFile times out.
- */
-
- timeouts.ReadIntervalTimeout = MAXDWORD
- timeouts.ReadTotalTimeoutMultiplier = MAXDWORD
- timeouts.ReadTotalTimeoutConstant = uint32(timeoutMs)
-
- r, _, err := syscall.Syscall(nSetCommTimeouts, 2, uintptr(h), uintptr(unsafe.Pointer(&timeouts)), 0)
- if r == 0 {
- return err
- }
- return nil
-}
-
-func setupComm(h syscall.Handle, in, out int) error {
- r, _, err := syscall.Syscall(nSetupComm, 3, uintptr(h), uintptr(in), uintptr(out))
- if r == 0 {
- return err
- }
- return nil
-}
-
-func setCommMask(h syscall.Handle) error {
- const EV_RXCHAR = 0x0001
- r, _, err := syscall.Syscall(nSetCommMask, 2, uintptr(h), EV_RXCHAR, 0)
- if r == 0 {
- return err
- }
- return nil
-}
-
-func resetEvent(h syscall.Handle) error {
- r, _, err := syscall.Syscall(nResetEvent, 1, uintptr(h), 0, 0)
- if r == 0 {
- return err
- }
- return nil
-}
-
-func purgeComm(h syscall.Handle) error {
- const PURGE_TXABORT = 0x0001
- const PURGE_RXABORT = 0x0002
- const PURGE_TXCLEAR = 0x0004
- const PURGE_RXCLEAR = 0x0008
- r, _, err := syscall.Syscall(nPurgeComm, 2, uintptr(h),
- PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR, 0)
- if r == 0 {
- return err
- }
- return nil
-}
-
-func newOverlapped() (*syscall.Overlapped, error) {
- var overlapped syscall.Overlapped
- r, _, err := syscall.Syscall6(nCreateEvent, 4, 0, 1, 0, 0, 0, 0)
- if r == 0 {
- return nil, err
- }
- overlapped.HEvent = syscall.Handle(r)
- return &overlapped, nil
-}
-
-func getOverlappedResult(h syscall.Handle, overlapped *syscall.Overlapped) (int, error) {
- var n int
- r, _, err := syscall.Syscall6(nGetOverlappedResult, 4,
- uintptr(h),
- uintptr(unsafe.Pointer(overlapped)),
- uintptr(unsafe.Pointer(&n)), 1, 0, 0)
- if r == 0 {
- return n, err
- }
-
- return n, nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/ugorji/go/LICENSE
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/ugorji/go/LICENSE b/newtmgr/vendor/github.com/ugorji/go/LICENSE
deleted file mode 100644
index 95a0f05..0000000
--- a/newtmgr/vendor/github.com/ugorji/go/LICENSE
+++ /dev/null
@@ -1,22 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2012-2015 Ugorji Nwoke.
-All rights reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/ugorji/go/codec/0doc.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/ugorji/go/codec/0doc.go b/newtmgr/vendor/github.com/ugorji/go/codec/0doc.go
deleted file mode 100644
index 209f9eb..0000000
--- a/newtmgr/vendor/github.com/ugorji/go/codec/0doc.go
+++ /dev/null
@@ -1,199 +0,0 @@
-// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
-// Use of this source code is governed by a MIT license found in the LICENSE file.
-
-/*
-High Performance, Feature-Rich Idiomatic Go codec/encoding library for
-binc, msgpack, cbor, json.
-
-Supported Serialization formats are:
-
- - msgpack: https://github.com/msgpack/msgpack
- - binc: http://github.com/ugorji/binc
- - cbor: http://cbor.io http://tools.ietf.org/html/rfc7049
- - json: http://json.org http://tools.ietf.org/html/rfc7159
- - simple:
-
-To install:
-
- go get github.com/ugorji/go/codec
-
-This package understands the 'unsafe' tag, to allow using unsafe semantics:
-
- - When decoding into a struct, you need to read the field name as a string
- so you can find the struct field it is mapped to.
- Using `unsafe` will bypass the allocation and copying overhead of []byte->string conversion.
-
-To install using unsafe, pass the 'unsafe' tag:
-
- go get -tags=unsafe github.com/ugorji/go/codec
-
-For detailed usage information, read the primer at http://ugorji.net/blog/go-codec-primer .
-
-The idiomatic Go support is as seen in other encoding packages in
-the standard library (ie json, xml, gob, etc).
-
-Rich Feature Set includes:
-
- - Simple but extremely powerful and feature-rich API
- - Very High Performance.
- Our extensive benchmarks show us outperforming Gob, Json, Bson, etc by 2-4X.
- - Multiple conversions:
- Package coerces types where appropriate
- e.g. decode an int in the stream into a float, etc.
- - Corner Cases:
- Overflows, nil maps/slices, nil values in streams are handled correctly
- - Standard field renaming via tags
- - Support for omitting empty fields during an encoding
- - Encoding from any value and decoding into pointer to any value
- (struct, slice, map, primitives, pointers, interface{}, etc)
- - Extensions to support efficient encoding/decoding of any named types
- - Support encoding.(Binary|Text)(M|Unm)arshaler interfaces
- - Decoding without a schema (into a interface{}).
- Includes Options to configure what specific map or slice type to use
- when decoding an encoded list or map into a nil interface{}
- - Encode a struct as an array, and decode struct from an array in the data stream
- - Comprehensive support for anonymous fields
- - Fast (no-reflection) encoding/decoding of common maps and slices
- - Code-generation for faster performance.
- - Support binary (e.g. messagepack, cbor) and text (e.g. json) formats
- - Support indefinite-length formats to enable true streaming
- (for formats which support it e.g. json, cbor)
- - Support canonical encoding, where a value is ALWAYS encoded as same sequence of bytes.
- This mostly applies to maps, where iteration order is non-deterministic.
- - NIL in data stream decoded as zero value
- - Never silently skip data when decoding.
- User decides whether to return an error or silently skip data when keys or indexes
- in the data stream do not map to fields in the struct.
- - Detect and error when encoding a cyclic reference (instead of stack overflow shutdown)
- - Encode/Decode from/to chan types (for iterative streaming support)
- - Drop-in replacement for encoding/json. `json:` key in struct tag supported.
- - Provides a RPC Server and Client Codec for net/rpc communication protocol.
- - Handle unique idiosyncrasies of codecs e.g.
- - For messagepack, configure how ambiguities in handling raw bytes are resolved
- - For messagepack, provide rpc server/client codec to support
- msgpack-rpc protocol defined at:
- https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md
-
-Extension Support
-
-Users can register a function to handle the encoding or decoding of
-their custom types.
-
-There are no restrictions on what the custom type can be. Some examples:
-
- type BisSet []int
- type BitSet64 uint64
- type UUID string
- type MyStructWithUnexportedFields struct { a int; b bool; c []int; }
- type GifImage struct { ... }
-
-As an illustration, MyStructWithUnexportedFields would normally be
-encoded as an empty map because it has no exported fields, while UUID
-would be encoded as a string. However, with extension support, you can
-encode any of these however you like.
-
-RPC
-
-RPC Client and Server Codecs are implemented, so the codecs can be used
-with the standard net/rpc package.
-
-Usage
-
-The Handle is SAFE for concurrent READ, but NOT SAFE for concurrent modification.
-
-The Encoder and Decoder are NOT safe for concurrent use.
-
-Consequently, the usage model is basically:
-
- - Create and initialize the Handle before any use.
- Once created, DO NOT modify it.
- - Multiple Encoders or Decoders can now use the Handle concurrently.
- They only read information off the Handle (never write).
- - However, each Encoder or Decoder MUST not be used concurrently
- - To re-use an Encoder/Decoder, call Reset(...) on it first.
- This allows you use state maintained on the Encoder/Decoder.
-
-Sample usage model:
-
- // create and configure Handle
- var (
- bh codec.BincHandle
- mh codec.MsgpackHandle
- ch codec.CborHandle
- )
-
- mh.MapType = reflect.TypeOf(map[string]interface{}(nil))
-
- // configure extensions
- // e.g. for msgpack, define functions and enable Time support for tag 1
- // mh.SetExt(reflect.TypeOf(time.Time{}), 1, myExt)
-
- // create and use decoder/encoder
- var (
- r io.Reader
- w io.Writer
- b []byte
- h = &bh // or mh to use msgpack
- )
-
- dec = codec.NewDecoder(r, h)
- dec = codec.NewDecoderBytes(b, h)
- err = dec.Decode(&v)
-
- enc = codec.NewEncoder(w, h)
- enc = codec.NewEncoderBytes(&b, h)
- err = enc.Encode(v)
-
- //RPC Server
- go func() {
- for {
- conn, err := listener.Accept()
- rpcCodec := codec.GoRpc.ServerCodec(conn, h)
- //OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h)
- rpc.ServeCodec(rpcCodec)
- }
- }()
-
- //RPC Communication (client side)
- conn, err = net.Dial("tcp", "localhost:5555")
- rpcCodec := codec.GoRpc.ClientCodec(conn, h)
- //OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h)
- client := rpc.NewClientWithCodec(rpcCodec)
-
-*/
-package codec
-
-// Benefits of go-codec:
-//
-// - encoding/json always reads whole file into memory first.
-// This makes it unsuitable for parsing very large files.
-// - encoding/xml cannot parse into a map[string]interface{}
-// I found this out on reading https://github.com/clbanning/mxj
-
-// TODO:
-//
-// - optimization for codecgen:
-// if len of entity is <= 3 words, then support a value receiver for encode.
-// - (En|De)coder should store an error when it occurs.
-// Until reset, subsequent calls return that error that was stored.
-// This means that free panics must go away.
-// All errors must be raised through errorf method.
-// - Decoding using a chan is good, but incurs concurrency costs.
-// This is because there's no fast way to use a channel without it
-// having to switch goroutines constantly.
-// Callback pattern is still the best. Maybe consider supporting something like:
-// type X struct {
-// Name string
-// Ys []Y
-// Ys chan <- Y
-// Ys func(Y) -> call this function for each entry
-// }
-// - Consider adding a isZeroer interface { isZero() bool }
-// It is used within isEmpty, for omitEmpty support.
-// - Consider making Handle used AS-IS within the encoding/decoding session.
-// This means that we don't cache Handle information within the (En|De)coder,
-// except we really need it at Reset(...)
-// - Consider adding math/big support
-// - Consider reducing the size of the generated functions:
-// Maybe use one loop, and put the conditionals in the loop.
-// for ... { if cLen > 0 { if j == cLen { break } } else if dd.CheckBreak() { break } }
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/ugorji/go/codec/README.md
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/ugorji/go/codec/README.md b/newtmgr/vendor/github.com/ugorji/go/codec/README.md
deleted file mode 100644
index 91cb3a2..0000000
--- a/newtmgr/vendor/github.com/ugorji/go/codec/README.md
+++ /dev/null
@@ -1,148 +0,0 @@
-# Codec
-
-High Performance, Feature-Rich Idiomatic Go codec/encoding library for
-binc, msgpack, cbor, json.
-
-Supported Serialization formats are:
-
- - msgpack: https://github.com/msgpack/msgpack
- - binc: http://github.com/ugorji/binc
- - cbor: http://cbor.io http://tools.ietf.org/html/rfc7049
- - json: http://json.org http://tools.ietf.org/html/rfc7159
- - simple:
-
-To install:
-
- go get github.com/ugorji/go/codec
-
-This package understands the `unsafe` tag, to allow using unsafe semantics:
-
- - When decoding into a struct, you need to read the field name as a string
- so you can find the struct field it is mapped to.
- Using `unsafe` will bypass the allocation and copying overhead of `[]byte->string` conversion.
-
-To use it, you must pass the `unsafe` tag during install:
-
-```
-go install -tags=unsafe github.com/ugorji/go/codec
-```
-
-Online documentation: http://godoc.org/github.com/ugorji/go/codec
-Detailed Usage/How-to Primer: http://ugorji.net/blog/go-codec-primer
-
-The idiomatic Go support is as seen in other encoding packages in
-the standard library (ie json, xml, gob, etc).
-
-Rich Feature Set includes:
-
- - Simple but extremely powerful and feature-rich API
- - Very High Performance.
- Our extensive benchmarks show us outperforming Gob, Json, Bson, etc by 2-4X.
- - Multiple conversions:
- Package coerces types where appropriate
- e.g. decode an int in the stream into a float, etc.
- - Corner Cases:
- Overflows, nil maps/slices, nil values in streams are handled correctly
- - Standard field renaming via tags
- - Support for omitting empty fields during an encoding
- - Encoding from any value and decoding into pointer to any value
- (struct, slice, map, primitives, pointers, interface{}, etc)
- - Extensions to support efficient encoding/decoding of any named types
- - Support encoding.(Binary|Text)(M|Unm)arshaler interfaces
- - Decoding without a schema (into a interface{}).
- Includes Options to configure what specific map or slice type to use
- when decoding an encoded list or map into a nil interface{}
- - Encode a struct as an array, and decode struct from an array in the data stream
- - Comprehensive support for anonymous fields
- - Fast (no-reflection) encoding/decoding of common maps and slices
- - Code-generation for faster performance.
- - Support binary (e.g. messagepack, cbor) and text (e.g. json) formats
- - Support indefinite-length formats to enable true streaming
- (for formats which support it e.g. json, cbor)
- - Support canonical encoding, where a value is ALWAYS encoded as same sequence of bytes.
- This mostly applies to maps, where iteration order is non-deterministic.
- - NIL in data stream decoded as zero value
- - Never silently skip data when decoding.
- User decides whether to return an error or silently skip data when keys or indexes
- in the data stream do not map to fields in the struct.
- - Encode/Decode from/to chan types (for iterative streaming support)
- - Drop-in replacement for encoding/json. `json:` key in struct tag supported.
- - Provides a RPC Server and Client Codec for net/rpc communication protocol.
- - Handle unique idiosyncrasies of codecs e.g.
- - For messagepack, configure how ambiguities in handling raw bytes are resolved
- - For messagepack, provide rpc server/client codec to support
- msgpack-rpc protocol defined at:
- https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md
-
-## Extension Support
-
-Users can register a function to handle the encoding or decoding of
-their custom types.
-
-There are no restrictions on what the custom type can be. Some examples:
-
- type BisSet []int
- type BitSet64 uint64
- type UUID string
- type MyStructWithUnexportedFields struct { a int; b bool; c []int; }
- type GifImage struct { ... }
-
-As an illustration, MyStructWithUnexportedFields would normally be
-encoded as an empty map because it has no exported fields, while UUID
-would be encoded as a string. However, with extension support, you can
-encode any of these however you like.
-
-## RPC
-
-RPC Client and Server Codecs are implemented, so the codecs can be used
-with the standard net/rpc package.
-
-## Usage
-
-Typical usage model:
-
- // create and configure Handle
- var (
- bh codec.BincHandle
- mh codec.MsgpackHandle
- ch codec.CborHandle
- )
-
- mh.MapType = reflect.TypeOf(map[string]interface{}(nil))
-
- // configure extensions
- // e.g. for msgpack, define functions and enable Time support for tag 1
- // mh.SetExt(reflect.TypeOf(time.Time{}), 1, myExt)
-
- // create and use decoder/encoder
- var (
- r io.Reader
- w io.Writer
- b []byte
- h = &bh // or mh to use msgpack
- )
-
- dec = codec.NewDecoder(r, h)
- dec = codec.NewDecoderBytes(b, h)
- err = dec.Decode(&v)
-
- enc = codec.NewEncoder(w, h)
- enc = codec.NewEncoderBytes(&b, h)
- err = enc.Encode(v)
-
- //RPC Server
- go func() {
- for {
- conn, err := listener.Accept()
- rpcCodec := codec.GoRpc.ServerCodec(conn, h)
- //OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h)
- rpc.ServeCodec(rpcCodec)
- }
- }()
-
- //RPC Communication (client side)
- conn, err = net.Dial("tcp", "localhost:5555")
- rpcCodec := codec.GoRpc.ClientCodec(conn, h)
- //OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h)
- client := rpc.NewClientWithCodec(rpcCodec)
-