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:54 UTC
[49/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/kr/text/wrap.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/kr/text/wrap.go b/newtmgr/vendor/github.com/kr/text/wrap.go
deleted file mode 100644
index b09bb03..0000000
--- a/newtmgr/vendor/github.com/kr/text/wrap.go
+++ /dev/null
@@ -1,86 +0,0 @@
-package text
-
-import (
- "bytes"
- "math"
-)
-
-var (
- nl = []byte{'\n'}
- sp = []byte{' '}
-)
-
-const defaultPenalty = 1e5
-
-// Wrap wraps s into a paragraph of lines of length lim, with minimal
-// raggedness.
-func Wrap(s string, lim int) string {
- return string(WrapBytes([]byte(s), lim))
-}
-
-// WrapBytes wraps b into a paragraph of lines of length lim, with minimal
-// raggedness.
-func WrapBytes(b []byte, lim int) []byte {
- words := bytes.Split(bytes.Replace(bytes.TrimSpace(b), nl, sp, -1), sp)
- var lines [][]byte
- for _, line := range WrapWords(words, 1, lim, defaultPenalty) {
- lines = append(lines, bytes.Join(line, sp))
- }
- return bytes.Join(lines, nl)
-}
-
-// WrapWords is the low-level line-breaking algorithm, useful if you need more
-// control over the details of the text wrapping process. For most uses, either
-// Wrap or WrapBytes will be sufficient and more convenient.
-//
-// WrapWords splits a list of words into lines with minimal "raggedness",
-// treating each byte as one unit, accounting for spc units between adjacent
-// words on each line, and attempting to limit lines to lim units. Raggedness
-// is the total error over all lines, where error is the square of the
-// difference of the length of the line and lim. Too-long lines (which only
-// happen when a single word is longer than lim units) have pen penalty units
-// added to the error.
-func WrapWords(words [][]byte, spc, lim, pen int) [][][]byte {
- n := len(words)
-
- length := make([][]int, n)
- for i := 0; i < n; i++ {
- length[i] = make([]int, n)
- length[i][i] = len(words[i])
- for j := i + 1; j < n; j++ {
- length[i][j] = length[i][j-1] + spc + len(words[j])
- }
- }
-
- nbrk := make([]int, n)
- cost := make([]int, n)
- for i := range cost {
- cost[i] = math.MaxInt32
- }
- for i := n - 1; i >= 0; i-- {
- if length[i][n-1] <= lim || i == n-1 {
- cost[i] = 0
- nbrk[i] = n
- } else {
- for j := i + 1; j < n; j++ {
- d := lim - length[i][j-1]
- c := d*d + cost[j]
- if length[i][j-1] > lim {
- c += pen // too-long lines get a worse penalty
- }
- if c < cost[i] {
- cost[i] = c
- nbrk[i] = j
- }
- }
- }
- }
-
- var lines [][][]byte
- i := 0
- for i < n {
- lines = append(lines, words[i:nbrk[i]])
- i = nbrk[i]
- }
- return lines
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/mitchellh/go-homedir/LICENSE
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/mitchellh/go-homedir/LICENSE b/newtmgr/vendor/github.com/mitchellh/go-homedir/LICENSE
deleted file mode 100644
index f9c841a..0000000
--- a/newtmgr/vendor/github.com/mitchellh/go-homedir/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2013 Mitchell Hashimoto
-
-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/mitchellh/go-homedir/README.md
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/mitchellh/go-homedir/README.md b/newtmgr/vendor/github.com/mitchellh/go-homedir/README.md
deleted file mode 100644
index d70706d..0000000
--- a/newtmgr/vendor/github.com/mitchellh/go-homedir/README.md
+++ /dev/null
@@ -1,14 +0,0 @@
-# go-homedir
-
-This is a Go library for detecting the user's home directory without
-the use of cgo, so the library can be used in cross-compilation environments.
-
-Usage is incredibly simple, just call `homedir.Dir()` to get the home directory
-for a user, and `homedir.Expand()` to expand the `~` in a path to the home
-directory.
-
-**Why not just use `os/user`?** The built-in `os/user` package requires
-cgo on Darwin systems. This means that any Go code that uses that package
-cannot cross compile. But 99% of the time the use for `os/user` is just to
-retrieve the home directory, which we can do for the current user without
-cgo. This library does that, enabling cross-compilation.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/mitchellh/go-homedir/homedir.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/mitchellh/go-homedir/homedir.go b/newtmgr/vendor/github.com/mitchellh/go-homedir/homedir.go
deleted file mode 100644
index 47e1f9e..0000000
--- a/newtmgr/vendor/github.com/mitchellh/go-homedir/homedir.go
+++ /dev/null
@@ -1,137 +0,0 @@
-package homedir
-
-import (
- "bytes"
- "errors"
- "os"
- "os/exec"
- "path/filepath"
- "runtime"
- "strconv"
- "strings"
- "sync"
-)
-
-// DisableCache will disable caching of the home directory. Caching is enabled
-// by default.
-var DisableCache bool
-
-var homedirCache string
-var cacheLock sync.RWMutex
-
-// Dir returns the home directory for the executing user.
-//
-// This uses an OS-specific method for discovering the home directory.
-// An error is returned if a home directory cannot be detected.
-func Dir() (string, error) {
- if !DisableCache {
- cacheLock.RLock()
- cached := homedirCache
- cacheLock.RUnlock()
- if cached != "" {
- return cached, nil
- }
- }
-
- cacheLock.Lock()
- defer cacheLock.Unlock()
-
- var result string
- var err error
- if runtime.GOOS == "windows" {
- result, err = dirWindows()
- } else {
- // Unix-like system, so just assume Unix
- result, err = dirUnix()
- }
-
- if err != nil {
- return "", err
- }
- homedirCache = result
- return result, nil
-}
-
-// Expand expands the path to include the home directory if the path
-// is prefixed with `~`. If it isn't prefixed with `~`, the path is
-// returned as-is.
-func Expand(path string) (string, error) {
- if len(path) == 0 {
- return path, nil
- }
-
- if path[0] != '~' {
- return path, nil
- }
-
- if len(path) > 1 && path[1] != '/' && path[1] != '\\' {
- return "", errors.New("cannot expand user-specific home dir")
- }
-
- dir, err := Dir()
- if err != nil {
- return "", err
- }
-
- return filepath.Join(dir, path[1:]), nil
-}
-
-func dirUnix() (string, error) {
- // First prefer the HOME environmental variable
- if home := os.Getenv("HOME"); home != "" {
- return home, nil
- }
-
- // If that fails, try getent
- var stdout bytes.Buffer
- cmd := exec.Command("getent", "passwd", strconv.Itoa(os.Getuid()))
- cmd.Stdout = &stdout
- if err := cmd.Run(); err != nil {
- // If the error is ErrNotFound, we ignore it. Otherwise, return it.
- if err != exec.ErrNotFound {
- return "", err
- }
- } else {
- if passwd := strings.TrimSpace(stdout.String()); passwd != "" {
- // username:password:uid:gid:gecos:home:shell
- passwdParts := strings.SplitN(passwd, ":", 7)
- if len(passwdParts) > 5 {
- return passwdParts[5], nil
- }
- }
- }
-
- // If all else fails, try the shell
- stdout.Reset()
- cmd = exec.Command("sh", "-c", "cd && pwd")
- cmd.Stdout = &stdout
- if err := cmd.Run(); err != nil {
- return "", err
- }
-
- result := strings.TrimSpace(stdout.String())
- if result == "" {
- return "", errors.New("blank output when reading home directory")
- }
-
- return result, nil
-}
-
-func dirWindows() (string, error) {
- // First prefer the HOME environmental variable
- if home := os.Getenv("HOME"); home != "" {
- return home, nil
- }
-
- drive := os.Getenv("HOMEDRIVE")
- path := os.Getenv("HOMEPATH")
- home := drive + path
- if drive == "" || path == "" {
- home = os.Getenv("USERPROFILE")
- }
- if home == "" {
- return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank")
- }
-
- return home, nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/mitchellh/mapstructure/.travis.yml
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/mitchellh/mapstructure/.travis.yml b/newtmgr/vendor/github.com/mitchellh/mapstructure/.travis.yml
deleted file mode 100644
index 7f3fe9a..0000000
--- a/newtmgr/vendor/github.com/mitchellh/mapstructure/.travis.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-language: go
-
-go:
- - 1.4
-
-script:
- - go test
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/mitchellh/mapstructure/LICENSE
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/mitchellh/mapstructure/LICENSE b/newtmgr/vendor/github.com/mitchellh/mapstructure/LICENSE
deleted file mode 100644
index f9c841a..0000000
--- a/newtmgr/vendor/github.com/mitchellh/mapstructure/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2013 Mitchell Hashimoto
-
-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/mitchellh/mapstructure/README.md
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/mitchellh/mapstructure/README.md b/newtmgr/vendor/github.com/mitchellh/mapstructure/README.md
deleted file mode 100644
index 659d688..0000000
--- a/newtmgr/vendor/github.com/mitchellh/mapstructure/README.md
+++ /dev/null
@@ -1,46 +0,0 @@
-# mapstructure
-
-mapstructure is a Go library for decoding generic map values to structures
-and vice versa, while providing helpful error handling.
-
-This library is most useful when decoding values from some data stream (JSON,
-Gob, etc.) where you don't _quite_ know the structure of the underlying data
-until you read a part of it. You can therefore read a `map[string]interface{}`
-and use this library to decode it into the proper underlying native Go
-structure.
-
-## Installation
-
-Standard `go get`:
-
-```
-$ go get github.com/mitchellh/mapstructure
-```
-
-## Usage & Example
-
-For usage and examples see the [Godoc](http://godoc.org/github.com/mitchellh/mapstructure).
-
-The `Decode` function has examples associated with it there.
-
-## But Why?!
-
-Go offers fantastic standard libraries for decoding formats such as JSON.
-The standard method is to have a struct pre-created, and populate that struct
-from the bytes of the encoded format. This is great, but the problem is if
-you have configuration or an encoding that changes slightly depending on
-specific fields. For example, consider this JSON:
-
-```json
-{
- "type": "person",
- "name": "Mitchell"
-}
-```
-
-Perhaps we can't populate a specific structure without first reading
-the "type" field from the JSON. We could always do two passes over the
-decoding of the JSON (reading the "type" first, and the rest later).
-However, it is much simpler to just decode this into a `map[string]interface{}`
-structure, read the "type" key, then use something like this library
-to decode it into the proper structure.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/mitchellh/mapstructure/decode_hooks.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/mitchellh/mapstructure/decode_hooks.go b/newtmgr/vendor/github.com/mitchellh/mapstructure/decode_hooks.go
deleted file mode 100644
index 115ae67..0000000
--- a/newtmgr/vendor/github.com/mitchellh/mapstructure/decode_hooks.go
+++ /dev/null
@@ -1,154 +0,0 @@
-package mapstructure
-
-import (
- "errors"
- "reflect"
- "strconv"
- "strings"
- "time"
-)
-
-// typedDecodeHook takes a raw DecodeHookFunc (an interface{}) and turns
-// it into the proper DecodeHookFunc type, such as DecodeHookFuncType.
-func typedDecodeHook(h DecodeHookFunc) DecodeHookFunc {
- // Create variables here so we can reference them with the reflect pkg
- var f1 DecodeHookFuncType
- var f2 DecodeHookFuncKind
-
- // Fill in the variables into this interface and the rest is done
- // automatically using the reflect package.
- potential := []interface{}{f1, f2}
-
- v := reflect.ValueOf(h)
- vt := v.Type()
- for _, raw := range potential {
- pt := reflect.ValueOf(raw).Type()
- if vt.ConvertibleTo(pt) {
- return v.Convert(pt).Interface()
- }
- }
-
- return nil
-}
-
-// DecodeHookExec executes the given decode hook. This should be used
-// since it'll naturally degrade to the older backwards compatible DecodeHookFunc
-// that took reflect.Kind instead of reflect.Type.
-func DecodeHookExec(
- raw DecodeHookFunc,
- from reflect.Type, to reflect.Type,
- data interface{}) (interface{}, error) {
- // Build our arguments that reflect expects
- argVals := make([]reflect.Value, 3)
- argVals[0] = reflect.ValueOf(from)
- argVals[1] = reflect.ValueOf(to)
- argVals[2] = reflect.ValueOf(data)
-
- switch f := typedDecodeHook(raw).(type) {
- case DecodeHookFuncType:
- return f(from, to, data)
- case DecodeHookFuncKind:
- return f(from.Kind(), to.Kind(), data)
- default:
- return nil, errors.New("invalid decode hook signature")
- }
-}
-
-// ComposeDecodeHookFunc creates a single DecodeHookFunc that
-// automatically composes multiple DecodeHookFuncs.
-//
-// The composed funcs are called in order, with the result of the
-// previous transformation.
-func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc {
- return func(
- f reflect.Type,
- t reflect.Type,
- data interface{}) (interface{}, error) {
- var err error
- for _, f1 := range fs {
- data, err = DecodeHookExec(f1, f, t, data)
- if err != nil {
- return nil, err
- }
-
- // Modify the from kind to be correct with the new data
- f = nil
- if val := reflect.ValueOf(data); val.IsValid() {
- f = val.Type()
- }
- }
-
- return data, nil
- }
-}
-
-// StringToSliceHookFunc returns a DecodeHookFunc that converts
-// string to []string by splitting on the given sep.
-func StringToSliceHookFunc(sep string) DecodeHookFunc {
- return func(
- f reflect.Kind,
- t reflect.Kind,
- data interface{}) (interface{}, error) {
- if f != reflect.String || t != reflect.Slice {
- return data, nil
- }
-
- raw := data.(string)
- if raw == "" {
- return []string{}, nil
- }
-
- return strings.Split(raw, sep), nil
- }
-}
-
-// StringToTimeDurationHookFunc returns a DecodeHookFunc that converts
-// strings to time.Duration.
-func StringToTimeDurationHookFunc() DecodeHookFunc {
- return func(
- f reflect.Type,
- t reflect.Type,
- data interface{}) (interface{}, error) {
- if f.Kind() != reflect.String {
- return data, nil
- }
- if t != reflect.TypeOf(time.Duration(5)) {
- return data, nil
- }
-
- // Convert it by parsing
- return time.ParseDuration(data.(string))
- }
-}
-
-func WeaklyTypedHook(
- f reflect.Kind,
- t reflect.Kind,
- data interface{}) (interface{}, error) {
- dataVal := reflect.ValueOf(data)
- switch t {
- case reflect.String:
- switch f {
- case reflect.Bool:
- if dataVal.Bool() {
- return "1", nil
- } else {
- return "0", nil
- }
- case reflect.Float32:
- return strconv.FormatFloat(dataVal.Float(), 'f', -1, 64), nil
- case reflect.Int:
- return strconv.FormatInt(dataVal.Int(), 10), nil
- case reflect.Slice:
- dataType := dataVal.Type()
- elemKind := dataType.Elem().Kind()
- if elemKind == reflect.Uint8 {
- return string(dataVal.Interface().([]uint8)), nil
- }
- case reflect.Uint:
- return strconv.FormatUint(dataVal.Uint(), 10), nil
- }
- }
-
- return data, nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/mitchellh/mapstructure/error.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/mitchellh/mapstructure/error.go b/newtmgr/vendor/github.com/mitchellh/mapstructure/error.go
deleted file mode 100644
index 47a99e5..0000000
--- a/newtmgr/vendor/github.com/mitchellh/mapstructure/error.go
+++ /dev/null
@@ -1,50 +0,0 @@
-package mapstructure
-
-import (
- "errors"
- "fmt"
- "sort"
- "strings"
-)
-
-// Error implements the error interface and can represents multiple
-// errors that occur in the course of a single decode.
-type Error struct {
- Errors []string
-}
-
-func (e *Error) Error() string {
- points := make([]string, len(e.Errors))
- for i, err := range e.Errors {
- points[i] = fmt.Sprintf("* %s", err)
- }
-
- sort.Strings(points)
- return fmt.Sprintf(
- "%d error(s) decoding:\n\n%s",
- len(e.Errors), strings.Join(points, "\n"))
-}
-
-// WrappedErrors implements the errwrap.Wrapper interface to make this
-// return value more useful with the errwrap and go-multierror libraries.
-func (e *Error) WrappedErrors() []error {
- if e == nil {
- return nil
- }
-
- result := make([]error, len(e.Errors))
- for i, e := range e.Errors {
- result[i] = errors.New(e)
- }
-
- return result
-}
-
-func appendErrors(errors []string, err error) []string {
- switch e := err.(type) {
- case *Error:
- return append(errors, e.Errors...)
- default:
- return append(errors, e.Error())
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/mitchellh/mapstructure/mapstructure.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/mitchellh/mapstructure/mapstructure.go b/newtmgr/vendor/github.com/mitchellh/mapstructure/mapstructure.go
deleted file mode 100644
index 1595982..0000000
--- a/newtmgr/vendor/github.com/mitchellh/mapstructure/mapstructure.go
+++ /dev/null
@@ -1,809 +0,0 @@
-// The mapstructure package exposes functionality to convert an
-// arbitrary map[string]interface{} into a native Go structure.
-//
-// The Go structure can be arbitrarily complex, containing slices,
-// other structs, etc. and the decoder will properly decode nested
-// maps and so on into the proper structures in the native Go struct.
-// See the examples to see what the decoder is capable of.
-package mapstructure
-
-import (
- "encoding/json"
- "errors"
- "fmt"
- "reflect"
- "sort"
- "strconv"
- "strings"
-)
-
-// DecodeHookFunc is the callback function that can be used for
-// data transformations. See "DecodeHook" in the DecoderConfig
-// struct.
-//
-// The type should be DecodeHookFuncType or DecodeHookFuncKind.
-// Either is accepted. Types are a superset of Kinds (Types can return
-// Kinds) and are generally a richer thing to use, but Kinds are simpler
-// if you only need those.
-//
-// The reason DecodeHookFunc is multi-typed is for backwards compatibility:
-// we started with Kinds and then realized Types were the better solution,
-// but have a promise to not break backwards compat so we now support
-// both.
-type DecodeHookFunc interface{}
-
-type DecodeHookFuncType func(reflect.Type, reflect.Type, interface{}) (interface{}, error)
-type DecodeHookFuncKind func(reflect.Kind, reflect.Kind, interface{}) (interface{}, error)
-
-// DecoderConfig is the configuration that is used to create a new decoder
-// and allows customization of various aspects of decoding.
-type DecoderConfig struct {
- // DecodeHook, if set, will be called before any decoding and any
- // type conversion (if WeaklyTypedInput is on). This lets you modify
- // the values before they're set down onto the resulting struct.
- //
- // If an error is returned, the entire decode will fail with that
- // error.
- DecodeHook DecodeHookFunc
-
- // If ErrorUnused is true, then it is an error for there to exist
- // keys in the original map that were unused in the decoding process
- // (extra keys).
- ErrorUnused bool
-
- // ZeroFields, if set to true, will zero fields before writing them.
- // For example, a map will be emptied before decoded values are put in
- // it. If this is false, a map will be merged.
- ZeroFields bool
-
- // If WeaklyTypedInput is true, the decoder will make the following
- // "weak" conversions:
- //
- // - bools to string (true = "1", false = "0")
- // - numbers to string (base 10)
- // - bools to int/uint (true = 1, false = 0)
- // - strings to int/uint (base implied by prefix)
- // - int to bool (true if value != 0)
- // - string to bool (accepts: 1, t, T, TRUE, true, True, 0, f, F,
- // FALSE, false, False. Anything else is an error)
- // - empty array = empty map and vice versa
- // - negative numbers to overflowed uint values (base 10)
- // - slice of maps to a merged map
- //
- WeaklyTypedInput bool
-
- // Metadata is the struct that will contain extra metadata about
- // the decoding. If this is nil, then no metadata will be tracked.
- Metadata *Metadata
-
- // Result is a pointer to the struct that will contain the decoded
- // value.
- Result interface{}
-
- // The tag name that mapstructure reads for field names. This
- // defaults to "mapstructure"
- TagName string
-}
-
-// A Decoder takes a raw interface value and turns it into structured
-// data, keeping track of rich error information along the way in case
-// anything goes wrong. Unlike the basic top-level Decode method, you can
-// more finely control how the Decoder behaves using the DecoderConfig
-// structure. The top-level Decode method is just a convenience that sets
-// up the most basic Decoder.
-type Decoder struct {
- config *DecoderConfig
-}
-
-// Metadata contains information about decoding a structure that
-// is tedious or difficult to get otherwise.
-type Metadata struct {
- // Keys are the keys of the structure which were successfully decoded
- Keys []string
-
- // Unused is a slice of keys that were found in the raw value but
- // weren't decoded since there was no matching field in the result interface
- Unused []string
-}
-
-// Decode takes a map and uses reflection to convert it into the
-// given Go native structure. val must be a pointer to a struct.
-func Decode(m interface{}, rawVal interface{}) error {
- config := &DecoderConfig{
- Metadata: nil,
- Result: rawVal,
- }
-
- decoder, err := NewDecoder(config)
- if err != nil {
- return err
- }
-
- return decoder.Decode(m)
-}
-
-// WeakDecode is the same as Decode but is shorthand to enable
-// WeaklyTypedInput. See DecoderConfig for more info.
-func WeakDecode(input, output interface{}) error {
- config := &DecoderConfig{
- Metadata: nil,
- Result: output,
- WeaklyTypedInput: true,
- }
-
- decoder, err := NewDecoder(config)
- if err != nil {
- return err
- }
-
- return decoder.Decode(input)
-}
-
-// NewDecoder returns a new decoder for the given configuration. Once
-// a decoder has been returned, the same configuration must not be used
-// again.
-func NewDecoder(config *DecoderConfig) (*Decoder, error) {
- val := reflect.ValueOf(config.Result)
- if val.Kind() != reflect.Ptr {
- return nil, errors.New("result must be a pointer")
- }
-
- val = val.Elem()
- if !val.CanAddr() {
- return nil, errors.New("result must be addressable (a pointer)")
- }
-
- if config.Metadata != nil {
- if config.Metadata.Keys == nil {
- config.Metadata.Keys = make([]string, 0)
- }
-
- if config.Metadata.Unused == nil {
- config.Metadata.Unused = make([]string, 0)
- }
- }
-
- if config.TagName == "" {
- config.TagName = "mapstructure"
- }
-
- result := &Decoder{
- config: config,
- }
-
- return result, nil
-}
-
-// Decode decodes the given raw interface to the target pointer specified
-// by the configuration.
-func (d *Decoder) Decode(raw interface{}) error {
- return d.decode("", raw, reflect.ValueOf(d.config.Result).Elem())
-}
-
-// Decodes an unknown data type into a specific reflection value.
-func (d *Decoder) decode(name string, data interface{}, val reflect.Value) error {
- if data == nil {
- // If the data is nil, then we don't set anything.
- return nil
- }
-
- dataVal := reflect.ValueOf(data)
- if !dataVal.IsValid() {
- // If the data value is invalid, then we just set the value
- // to be the zero value.
- val.Set(reflect.Zero(val.Type()))
- return nil
- }
-
- if d.config.DecodeHook != nil {
- // We have a DecodeHook, so let's pre-process the data.
- var err error
- data, err = DecodeHookExec(
- d.config.DecodeHook,
- dataVal.Type(), val.Type(), data)
- if err != nil {
- return fmt.Errorf("error decoding '%s': %s", name, err)
- }
- }
-
- var err error
- dataKind := getKind(val)
- switch dataKind {
- case reflect.Bool:
- err = d.decodeBool(name, data, val)
- case reflect.Interface:
- err = d.decodeBasic(name, data, val)
- case reflect.String:
- err = d.decodeString(name, data, val)
- case reflect.Int:
- err = d.decodeInt(name, data, val)
- case reflect.Uint:
- err = d.decodeUint(name, data, val)
- case reflect.Float32:
- err = d.decodeFloat(name, data, val)
- case reflect.Struct:
- err = d.decodeStruct(name, data, val)
- case reflect.Map:
- err = d.decodeMap(name, data, val)
- case reflect.Ptr:
- err = d.decodePtr(name, data, val)
- case reflect.Slice:
- err = d.decodeSlice(name, data, val)
- case reflect.Func:
- err = d.decodeFunc(name, data, val)
- default:
- // If we reached this point then we weren't able to decode it
- return fmt.Errorf("%s: unsupported type: %s", name, dataKind)
- }
-
- // If we reached here, then we successfully decoded SOMETHING, so
- // mark the key as used if we're tracking metadata.
- if d.config.Metadata != nil && name != "" {
- d.config.Metadata.Keys = append(d.config.Metadata.Keys, name)
- }
-
- return err
-}
-
-// This decodes a basic type (bool, int, string, etc.) and sets the
-// value to "data" of that type.
-func (d *Decoder) decodeBasic(name string, data interface{}, val reflect.Value) error {
- dataVal := reflect.ValueOf(data)
- if !dataVal.IsValid() {
- dataVal = reflect.Zero(val.Type())
- }
-
- dataValType := dataVal.Type()
- if !dataValType.AssignableTo(val.Type()) {
- return fmt.Errorf(
- "'%s' expected type '%s', got '%s'",
- name, val.Type(), dataValType)
- }
-
- val.Set(dataVal)
- return nil
-}
-
-func (d *Decoder) decodeString(name string, data interface{}, val reflect.Value) error {
- dataVal := reflect.ValueOf(data)
- dataKind := getKind(dataVal)
-
- converted := true
- switch {
- case dataKind == reflect.String:
- val.SetString(dataVal.String())
- case dataKind == reflect.Bool && d.config.WeaklyTypedInput:
- if dataVal.Bool() {
- val.SetString("1")
- } else {
- val.SetString("0")
- }
- case dataKind == reflect.Int && d.config.WeaklyTypedInput:
- val.SetString(strconv.FormatInt(dataVal.Int(), 10))
- case dataKind == reflect.Uint && d.config.WeaklyTypedInput:
- val.SetString(strconv.FormatUint(dataVal.Uint(), 10))
- case dataKind == reflect.Float32 && d.config.WeaklyTypedInput:
- val.SetString(strconv.FormatFloat(dataVal.Float(), 'f', -1, 64))
- case dataKind == reflect.Slice && d.config.WeaklyTypedInput:
- dataType := dataVal.Type()
- elemKind := dataType.Elem().Kind()
- switch {
- case elemKind == reflect.Uint8:
- val.SetString(string(dataVal.Interface().([]uint8)))
- default:
- converted = false
- }
- default:
- converted = false
- }
-
- if !converted {
- return fmt.Errorf(
- "'%s' expected type '%s', got unconvertible type '%s'",
- name, val.Type(), dataVal.Type())
- }
-
- return nil
-}
-
-func (d *Decoder) decodeInt(name string, data interface{}, val reflect.Value) error {
- dataVal := reflect.ValueOf(data)
- dataKind := getKind(dataVal)
- dataType := dataVal.Type()
-
- switch {
- case dataKind == reflect.Int:
- val.SetInt(dataVal.Int())
- case dataKind == reflect.Uint:
- val.SetInt(int64(dataVal.Uint()))
- case dataKind == reflect.Float32:
- val.SetInt(int64(dataVal.Float()))
- case dataKind == reflect.Bool && d.config.WeaklyTypedInput:
- if dataVal.Bool() {
- val.SetInt(1)
- } else {
- val.SetInt(0)
- }
- case dataKind == reflect.String && d.config.WeaklyTypedInput:
- i, err := strconv.ParseInt(dataVal.String(), 0, val.Type().Bits())
- if err == nil {
- val.SetInt(i)
- } else {
- return fmt.Errorf("cannot parse '%s' as int: %s", name, err)
- }
- case dataType.PkgPath() == "encoding/json" && dataType.Name() == "Number":
- jn := data.(json.Number)
- i, err := jn.Int64()
- if err != nil {
- return fmt.Errorf(
- "error decoding json.Number into %s: %s", name, err)
- }
- val.SetInt(i)
- default:
- return fmt.Errorf(
- "'%s' expected type '%s', got unconvertible type '%s'",
- name, val.Type(), dataVal.Type())
- }
-
- return nil
-}
-
-func (d *Decoder) decodeUint(name string, data interface{}, val reflect.Value) error {
- dataVal := reflect.ValueOf(data)
- dataKind := getKind(dataVal)
-
- switch {
- case dataKind == reflect.Int:
- i := dataVal.Int()
- if i < 0 && !d.config.WeaklyTypedInput {
- return fmt.Errorf("cannot parse '%s', %d overflows uint",
- name, i)
- }
- val.SetUint(uint64(i))
- case dataKind == reflect.Uint:
- val.SetUint(dataVal.Uint())
- case dataKind == reflect.Float32:
- f := dataVal.Float()
- if f < 0 && !d.config.WeaklyTypedInput {
- return fmt.Errorf("cannot parse '%s', %f overflows uint",
- name, f)
- }
- val.SetUint(uint64(f))
- case dataKind == reflect.Bool && d.config.WeaklyTypedInput:
- if dataVal.Bool() {
- val.SetUint(1)
- } else {
- val.SetUint(0)
- }
- case dataKind == reflect.String && d.config.WeaklyTypedInput:
- i, err := strconv.ParseUint(dataVal.String(), 0, val.Type().Bits())
- if err == nil {
- val.SetUint(i)
- } else {
- return fmt.Errorf("cannot parse '%s' as uint: %s", name, err)
- }
- default:
- return fmt.Errorf(
- "'%s' expected type '%s', got unconvertible type '%s'",
- name, val.Type(), dataVal.Type())
- }
-
- return nil
-}
-
-func (d *Decoder) decodeBool(name string, data interface{}, val reflect.Value) error {
- dataVal := reflect.ValueOf(data)
- dataKind := getKind(dataVal)
-
- switch {
- case dataKind == reflect.Bool:
- val.SetBool(dataVal.Bool())
- case dataKind == reflect.Int && d.config.WeaklyTypedInput:
- val.SetBool(dataVal.Int() != 0)
- case dataKind == reflect.Uint && d.config.WeaklyTypedInput:
- val.SetBool(dataVal.Uint() != 0)
- case dataKind == reflect.Float32 && d.config.WeaklyTypedInput:
- val.SetBool(dataVal.Float() != 0)
- case dataKind == reflect.String && d.config.WeaklyTypedInput:
- b, err := strconv.ParseBool(dataVal.String())
- if err == nil {
- val.SetBool(b)
- } else if dataVal.String() == "" {
- val.SetBool(false)
- } else {
- return fmt.Errorf("cannot parse '%s' as bool: %s", name, err)
- }
- default:
- return fmt.Errorf(
- "'%s' expected type '%s', got unconvertible type '%s'",
- name, val.Type(), dataVal.Type())
- }
-
- return nil
-}
-
-func (d *Decoder) decodeFloat(name string, data interface{}, val reflect.Value) error {
- dataVal := reflect.ValueOf(data)
- dataKind := getKind(dataVal)
- dataType := dataVal.Type()
-
- switch {
- case dataKind == reflect.Int:
- val.SetFloat(float64(dataVal.Int()))
- case dataKind == reflect.Uint:
- val.SetFloat(float64(dataVal.Uint()))
- case dataKind == reflect.Float32:
- val.SetFloat(float64(dataVal.Float()))
- case dataKind == reflect.Bool && d.config.WeaklyTypedInput:
- if dataVal.Bool() {
- val.SetFloat(1)
- } else {
- val.SetFloat(0)
- }
- case dataKind == reflect.String && d.config.WeaklyTypedInput:
- f, err := strconv.ParseFloat(dataVal.String(), val.Type().Bits())
- if err == nil {
- val.SetFloat(f)
- } else {
- return fmt.Errorf("cannot parse '%s' as float: %s", name, err)
- }
- case dataType.PkgPath() == "encoding/json" && dataType.Name() == "Number":
- jn := data.(json.Number)
- i, err := jn.Float64()
- if err != nil {
- return fmt.Errorf(
- "error decoding json.Number into %s: %s", name, err)
- }
- val.SetFloat(i)
- default:
- return fmt.Errorf(
- "'%s' expected type '%s', got unconvertible type '%s'",
- name, val.Type(), dataVal.Type())
- }
-
- return nil
-}
-
-func (d *Decoder) decodeMap(name string, data interface{}, val reflect.Value) error {
- valType := val.Type()
- valKeyType := valType.Key()
- valElemType := valType.Elem()
-
- // By default we overwrite keys in the current map
- valMap := val
-
- // If the map is nil or we're purposely zeroing fields, make a new map
- if valMap.IsNil() || d.config.ZeroFields {
- // Make a new map to hold our result
- mapType := reflect.MapOf(valKeyType, valElemType)
- valMap = reflect.MakeMap(mapType)
- }
-
- // Check input type
- dataVal := reflect.Indirect(reflect.ValueOf(data))
- if dataVal.Kind() != reflect.Map {
- // In weak mode, we accept a slice of maps as an input...
- if d.config.WeaklyTypedInput {
- switch dataVal.Kind() {
- case reflect.Array, reflect.Slice:
- // Special case for BC reasons (covered by tests)
- if dataVal.Len() == 0 {
- val.Set(valMap)
- return nil
- }
-
- for i := 0; i < dataVal.Len(); i++ {
- err := d.decode(
- fmt.Sprintf("%s[%d]", name, i),
- dataVal.Index(i).Interface(), val)
- if err != nil {
- return err
- }
- }
-
- return nil
- }
- }
-
- return fmt.Errorf("'%s' expected a map, got '%s'", name, dataVal.Kind())
- }
-
- // Accumulate errors
- errors := make([]string, 0)
-
- for _, k := range dataVal.MapKeys() {
- fieldName := fmt.Sprintf("%s[%s]", name, k)
-
- // First decode the key into the proper type
- currentKey := reflect.Indirect(reflect.New(valKeyType))
- if err := d.decode(fieldName, k.Interface(), currentKey); err != nil {
- errors = appendErrors(errors, err)
- continue
- }
-
- // Next decode the data into the proper type
- v := dataVal.MapIndex(k).Interface()
- currentVal := reflect.Indirect(reflect.New(valElemType))
- if err := d.decode(fieldName, v, currentVal); err != nil {
- errors = appendErrors(errors, err)
- continue
- }
-
- valMap.SetMapIndex(currentKey, currentVal)
- }
-
- // Set the built up map to the value
- val.Set(valMap)
-
- // If we had errors, return those
- if len(errors) > 0 {
- return &Error{errors}
- }
-
- return nil
-}
-
-func (d *Decoder) decodePtr(name string, data interface{}, val reflect.Value) error {
- // Create an element of the concrete (non pointer) type and decode
- // into that. Then set the value of the pointer to this type.
- valType := val.Type()
- valElemType := valType.Elem()
-
- realVal := val
- if realVal.IsNil() || d.config.ZeroFields {
- realVal = reflect.New(valElemType)
- }
-
- if err := d.decode(name, data, reflect.Indirect(realVal)); err != nil {
- return err
- }
-
- val.Set(realVal)
- return nil
-}
-
-func (d *Decoder) decodeFunc(name string, data interface{}, val reflect.Value) error {
- // Create an element of the concrete (non pointer) type and decode
- // into that. Then set the value of the pointer to this type.
- dataVal := reflect.Indirect(reflect.ValueOf(data))
- if val.Type() != dataVal.Type() {
- return fmt.Errorf(
- "'%s' expected type '%s', got unconvertible type '%s'",
- name, val.Type(), dataVal.Type())
- }
- val.Set(dataVal)
- return nil
-}
-
-func (d *Decoder) decodeSlice(name string, data interface{}, val reflect.Value) error {
- dataVal := reflect.Indirect(reflect.ValueOf(data))
- dataValKind := dataVal.Kind()
- valType := val.Type()
- valElemType := valType.Elem()
- sliceType := reflect.SliceOf(valElemType)
-
- valSlice := val
- if valSlice.IsNil() || d.config.ZeroFields {
-
- // Check input type
- if dataValKind != reflect.Array && dataValKind != reflect.Slice {
- // Accept empty map instead of array/slice in weakly typed mode
- if d.config.WeaklyTypedInput && dataVal.Kind() == reflect.Map && dataVal.Len() == 0 {
- val.Set(reflect.MakeSlice(sliceType, 0, 0))
- return nil
- } else {
- return fmt.Errorf(
- "'%s': source data must be an array or slice, got %s", name, dataValKind)
- }
- }
-
- // Make a new slice to hold our result, same size as the original data.
- valSlice = reflect.MakeSlice(sliceType, dataVal.Len(), dataVal.Len())
- }
-
- // Accumulate any errors
- errors := make([]string, 0)
-
- for i := 0; i < dataVal.Len(); i++ {
- currentData := dataVal.Index(i).Interface()
- for valSlice.Len() <= i {
- valSlice = reflect.Append(valSlice, reflect.Zero(valElemType))
- }
- currentField := valSlice.Index(i)
-
- fieldName := fmt.Sprintf("%s[%d]", name, i)
- if err := d.decode(fieldName, currentData, currentField); err != nil {
- errors = appendErrors(errors, err)
- }
- }
-
- // Finally, set the value to the slice we built up
- val.Set(valSlice)
-
- // If there were errors, we return those
- if len(errors) > 0 {
- return &Error{errors}
- }
-
- return nil
-}
-
-func (d *Decoder) decodeStruct(name string, data interface{}, val reflect.Value) error {
- dataVal := reflect.Indirect(reflect.ValueOf(data))
-
- // If the type of the value to write to and the data match directly,
- // then we just set it directly instead of recursing into the structure.
- if dataVal.Type() == val.Type() {
- val.Set(dataVal)
- return nil
- }
-
- dataValKind := dataVal.Kind()
- if dataValKind != reflect.Map {
- return fmt.Errorf("'%s' expected a map, got '%s'", name, dataValKind)
- }
-
- dataValType := dataVal.Type()
- if kind := dataValType.Key().Kind(); kind != reflect.String && kind != reflect.Interface {
- return fmt.Errorf(
- "'%s' needs a map with string keys, has '%s' keys",
- name, dataValType.Key().Kind())
- }
-
- dataValKeys := make(map[reflect.Value]struct{})
- dataValKeysUnused := make(map[interface{}]struct{})
- for _, dataValKey := range dataVal.MapKeys() {
- dataValKeys[dataValKey] = struct{}{}
- dataValKeysUnused[dataValKey.Interface()] = struct{}{}
- }
-
- errors := make([]string, 0)
-
- // This slice will keep track of all the structs we'll be decoding.
- // There can be more than one struct if there are embedded structs
- // that are squashed.
- structs := make([]reflect.Value, 1, 5)
- structs[0] = val
-
- // Compile the list of all the fields that we're going to be decoding
- // from all the structs.
- fields := make(map[*reflect.StructField]reflect.Value)
- for len(structs) > 0 {
- structVal := structs[0]
- structs = structs[1:]
-
- structType := structVal.Type()
-
- for i := 0; i < structType.NumField(); i++ {
- fieldType := structType.Field(i)
- fieldKind := fieldType.Type.Kind()
-
- // If "squash" is specified in the tag, we squash the field down.
- squash := false
- tagParts := strings.Split(fieldType.Tag.Get(d.config.TagName), ",")
- for _, tag := range tagParts[1:] {
- if tag == "squash" {
- squash = true
- break
- }
- }
-
- if squash {
- if fieldKind != reflect.Struct {
- errors = appendErrors(errors,
- fmt.Errorf("%s: unsupported type for squash: %s", fieldType.Name, fieldKind))
- } else {
- structs = append(structs, val.FieldByName(fieldType.Name))
- }
- continue
- }
-
- // Normal struct field, store it away
- fields[&fieldType] = structVal.Field(i)
- }
- }
-
- for fieldType, field := range fields {
- fieldName := fieldType.Name
-
- tagValue := fieldType.Tag.Get(d.config.TagName)
- tagValue = strings.SplitN(tagValue, ",", 2)[0]
- if tagValue != "" {
- fieldName = tagValue
- }
-
- rawMapKey := reflect.ValueOf(fieldName)
- rawMapVal := dataVal.MapIndex(rawMapKey)
- if !rawMapVal.IsValid() {
- // Do a slower search by iterating over each key and
- // doing case-insensitive search.
- for dataValKey := range dataValKeys {
- mK, ok := dataValKey.Interface().(string)
- if !ok {
- // Not a string key
- continue
- }
-
- if strings.EqualFold(mK, fieldName) {
- rawMapKey = dataValKey
- rawMapVal = dataVal.MapIndex(dataValKey)
- break
- }
- }
-
- if !rawMapVal.IsValid() {
- // There was no matching key in the map for the value in
- // the struct. Just ignore.
- continue
- }
- }
-
- // Delete the key we're using from the unused map so we stop tracking
- delete(dataValKeysUnused, rawMapKey.Interface())
-
- if !field.IsValid() {
- // This should never happen
- panic("field is not valid")
- }
-
- // If we can't set the field, then it is unexported or something,
- // and we just continue onwards.
- if !field.CanSet() {
- continue
- }
-
- // If the name is empty string, then we're at the root, and we
- // don't dot-join the fields.
- if name != "" {
- fieldName = fmt.Sprintf("%s.%s", name, fieldName)
- }
-
- if err := d.decode(fieldName, rawMapVal.Interface(), field); err != nil {
- errors = appendErrors(errors, err)
- }
- }
-
- if d.config.ErrorUnused && len(dataValKeysUnused) > 0 {
- keys := make([]string, 0, len(dataValKeysUnused))
- for rawKey := range dataValKeysUnused {
- keys = append(keys, rawKey.(string))
- }
- sort.Strings(keys)
-
- err := fmt.Errorf("'%s' has invalid keys: %s", name, strings.Join(keys, ", "))
- errors = appendErrors(errors, err)
- }
-
- if len(errors) > 0 {
- return &Error{errors}
- }
-
- // Add the unused keys to the list of unused keys if we're tracking metadata
- if d.config.Metadata != nil {
- for rawKey := range dataValKeysUnused {
- key := rawKey.(string)
- if name != "" {
- key = fmt.Sprintf("%s.%s", name, key)
- }
-
- d.config.Metadata.Unused = append(d.config.Metadata.Unused, key)
- }
- }
-
- return nil
-}
-
-func getKind(val reflect.Value) reflect.Kind {
- kind := val.Kind()
-
- switch {
- case kind >= reflect.Int && kind <= reflect.Int64:
- return reflect.Int
- case kind >= reflect.Uint && kind <= reflect.Uint64:
- return reflect.Uint
- case kind >= reflect.Float32 && kind <= reflect.Float64:
- return reflect.Float32
- default:
- return kind
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/runtimeco/go-coap/.gitignore
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeco/go-coap/.gitignore b/newtmgr/vendor/github.com/runtimeco/go-coap/.gitignore
deleted file mode 100644
index 1256dd2..0000000
--- a/newtmgr/vendor/github.com/runtimeco/go-coap/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-#*
-*~
-/example/server/server
-/example/subserver/subserver
-/example/client/client
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/runtimeco/go-coap/LICENSE
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeco/go-coap/LICENSE b/newtmgr/vendor/github.com/runtimeco/go-coap/LICENSE
deleted file mode 100644
index 1ddd439..0000000
--- a/newtmgr/vendor/github.com/runtimeco/go-coap/LICENSE
+++ /dev/null
@@ -1,20 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2013 Dustin Sallings
-
-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/runtimeco/go-coap/README.markdown
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeco/go-coap/README.markdown b/newtmgr/vendor/github.com/runtimeco/go-coap/README.markdown
deleted file mode 100644
index 748fe6f..0000000
--- a/newtmgr/vendor/github.com/runtimeco/go-coap/README.markdown
+++ /dev/null
@@ -1,8 +0,0 @@
-# Constrained Application Protocol Client and Server for go
-
-You can read more about CoAP in [RFC 7252][coap]. I also did
-some preliminary work on `SUBSCRIBE` support from
-[an early draft][shelby].
-
-[shelby]: http://tools.ietf.org/html/draft-shelby-core-coap-01
-[coap]: http://tools.ietf.org/html/rfc7252
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/runtimeco/go-coap/client.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeco/go-coap/client.go b/newtmgr/vendor/github.com/runtimeco/go-coap/client.go
deleted file mode 100644
index 95cf03f..0000000
--- a/newtmgr/vendor/github.com/runtimeco/go-coap/client.go
+++ /dev/null
@@ -1,66 +0,0 @@
-package coap
-
-import (
- "net"
- "time"
-)
-
-const (
- // ResponseTimeout is the amount of time to wait for a
- // response.
- ResponseTimeout = time.Second * 2
- // ResponseRandomFactor is a multiplier for response backoff.
- ResponseRandomFactor = 1.5
- // MaxRetransmit is the maximum number of times a message will
- // be retransmitted.
- MaxRetransmit = 4
-)
-
-// Conn is a CoAP client connection.
-type Conn struct {
- conn *net.UDPConn
- buf []byte
-}
-
-// Dial connects a CoAP client.
-func Dial(n, addr string) (*Conn, error) {
- uaddr, err := net.ResolveUDPAddr(n, addr)
- if err != nil {
- return nil, err
- }
-
- s, err := net.DialUDP("udp", nil, uaddr)
- if err != nil {
- return nil, err
- }
-
- return &Conn{s, make([]byte, maxPktLen)}, nil
-}
-
-// Send a message. Get a response if there is one.
-func (c *Conn) Send(req Message) (*Message, error) {
- err := Transmit(c.conn, nil, req)
- if err != nil {
- return nil, err
- }
-
- if !req.IsConfirmable() {
- return nil, nil
- }
-
- rv, err := Receive(c.conn, c.buf)
- if err != nil {
- return nil, err
- }
-
- return &rv, nil
-}
-
-// Receive a message.
-func (c *Conn) Receive() (*Message, error) {
- rv, err := Receive(c.conn, c.buf)
- if err != nil {
- return nil, err
- }
- return &rv, nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/runtimeco/go-coap/message.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeco/go-coap/message.go b/newtmgr/vendor/github.com/runtimeco/go-coap/message.go
deleted file mode 100644
index 8142fb6..0000000
--- a/newtmgr/vendor/github.com/runtimeco/go-coap/message.go
+++ /dev/null
@@ -1,667 +0,0 @@
-package coap
-
-import (
- "bytes"
- "encoding/binary"
- "errors"
- "fmt"
- "io"
- "reflect"
- "sort"
- "strings"
-)
-
-// COAPType represents the message type.
-type COAPType uint8
-
-const (
- // Confirmable messages require acknowledgements.
- Confirmable COAPType = 0
- // NonConfirmable messages do not require acknowledgements.
- NonConfirmable COAPType = 1
- // Acknowledgement is a message indicating a response to confirmable message.
- Acknowledgement COAPType = 2
- // Reset indicates a permanent negative acknowledgement.
- Reset COAPType = 3
-)
-
-var typeNames = [256]string{
- Confirmable: "Confirmable",
- NonConfirmable: "NonConfirmable",
- Acknowledgement: "Acknowledgement",
- Reset: "Reset",
-}
-
-func init() {
- for i := range typeNames {
- if typeNames[i] == "" {
- typeNames[i] = fmt.Sprintf("Unknown (0x%x)", i)
- }
- }
-}
-
-func (t COAPType) String() string {
- return typeNames[t]
-}
-
-// COAPCode is the type used for both request and response codes.
-type COAPCode uint8
-
-// Request Codes
-const (
- GET COAPCode = 1
- POST COAPCode = 2
- PUT COAPCode = 3
- DELETE COAPCode = 4
-)
-
-// Response Codes
-const (
- Created COAPCode = 65
- Deleted COAPCode = 66
- Valid COAPCode = 67
- Changed COAPCode = 68
- Content COAPCode = 69
- BadRequest COAPCode = 128
- Unauthorized COAPCode = 129
- BadOption COAPCode = 130
- Forbidden COAPCode = 131
- NotFound COAPCode = 132
- MethodNotAllowed COAPCode = 133
- NotAcceptable COAPCode = 134
- PreconditionFailed COAPCode = 140
- RequestEntityTooLarge COAPCode = 141
- UnsupportedMediaType COAPCode = 143
- InternalServerError COAPCode = 160
- NotImplemented COAPCode = 161
- BadGateway COAPCode = 162
- ServiceUnavailable COAPCode = 163
- GatewayTimeout COAPCode = 164
- ProxyingNotSupported COAPCode = 165
-)
-
-var codeNames = [256]string{
- GET: "GET",
- POST: "POST",
- PUT: "PUT",
- DELETE: "DELETE",
- Created: "Created",
- Deleted: "Deleted",
- Valid: "Valid",
- Changed: "Changed",
- Content: "Content",
- BadRequest: "BadRequest",
- Unauthorized: "Unauthorized",
- BadOption: "BadOption",
- Forbidden: "Forbidden",
- NotFound: "NotFound",
- MethodNotAllowed: "MethodNotAllowed",
- NotAcceptable: "NotAcceptable",
- PreconditionFailed: "PreconditionFailed",
- RequestEntityTooLarge: "RequestEntityTooLarge",
- UnsupportedMediaType: "UnsupportedMediaType",
- InternalServerError: "InternalServerError",
- NotImplemented: "NotImplemented",
- BadGateway: "BadGateway",
- ServiceUnavailable: "ServiceUnavailable",
- GatewayTimeout: "GatewayTimeout",
- ProxyingNotSupported: "ProxyingNotSupported",
-}
-
-func init() {
- for i := range codeNames {
- if codeNames[i] == "" {
- codeNames[i] = fmt.Sprintf("Unknown (0x%x)", i)
- }
- }
-}
-
-func (c COAPCode) String() string {
- return codeNames[c]
-}
-
-// Message encoding errors.
-var (
- ErrInvalidTokenLen = errors.New("invalid token length")
- ErrOptionTooLong = errors.New("option is too long")
- ErrOptionGapTooLarge = errors.New("option gap too large")
-)
-
-// OptionID identifies an option in a message.
-type OptionID uint8
-
-/*
- +-----+----+---+---+---+----------------+--------+--------+---------+
- | No. | C | U | N | R | Name | Format | Length | Default |
- +-----+----+---+---+---+----------------+--------+--------+---------+
- | 1 | x | | | x | If-Match | opaque | 0-8 | (none) |
- | 3 | x | x | - | | Uri-Host | string | 1-255 | (see |
- | | | | | | | | | below) |
- | 4 | | | | x | ETag | opaque | 1-8 | (none) |
- | 5 | x | | | | If-None-Match | empty | 0 | (none) |
- | 7 | x | x | - | | Uri-Port | uint | 0-2 | (see |
- | | | | | | | | | below) |
- | 8 | | | | x | Location-Path | string | 0-255 | (none) |
- | 11 | x | x | - | x | Uri-Path | string | 0-255 | (none) |
- | 12 | | | | | Content-Format | uint | 0-2 | (none) |
- | 14 | | x | - | | Max-Age | uint | 0-4 | 60 |
- | 15 | x | x | - | x | Uri-Query | string | 0-255 | (none) |
- | 17 | x | | | | Accept | uint | 0-2 | (none) |
- | 20 | | | | x | Location-Query | string | 0-255 | (none) |
- | 35 | x | x | - | | Proxy-Uri | string | 1-1034 | (none) |
- | 39 | x | x | - | | Proxy-Scheme | string | 1-255 | (none) |
- | 60 | | | x | | Size1 | uint | 0-4 | (none) |
- +-----+----+---+---+---+----------------+--------+--------+---------+
-*/
-
-// Option IDs.
-const (
- IfMatch OptionID = 1
- URIHost OptionID = 3
- ETag OptionID = 4
- IfNoneMatch OptionID = 5
- Observe OptionID = 6
- URIPort OptionID = 7
- LocationPath OptionID = 8
- URIPath OptionID = 11
- ContentFormat OptionID = 12
- MaxAge OptionID = 14
- URIQuery OptionID = 15
- Accept OptionID = 17
- LocationQuery OptionID = 20
- ProxyURI OptionID = 35
- ProxyScheme OptionID = 39
- Size1 OptionID = 60
-)
-
-// Option value format (RFC7252 section 3.2)
-type valueFormat uint8
-
-const (
- valueUnknown valueFormat = iota
- valueEmpty
- valueOpaque
- valueUint
- valueString
-)
-
-type optionDef struct {
- valueFormat valueFormat
- minLen int
- maxLen int
-}
-
-var optionDefs = [256]optionDef{
- IfMatch: optionDef{valueFormat: valueOpaque, minLen: 0, maxLen: 8},
- URIHost: optionDef{valueFormat: valueString, minLen: 1, maxLen: 255},
- ETag: optionDef{valueFormat: valueOpaque, minLen: 1, maxLen: 8},
- IfNoneMatch: optionDef{valueFormat: valueEmpty, minLen: 0, maxLen: 0},
- Observe: optionDef{valueFormat: valueUint, minLen: 0, maxLen: 3},
- URIPort: optionDef{valueFormat: valueUint, minLen: 0, maxLen: 2},
- LocationPath: optionDef{valueFormat: valueString, minLen: 0, maxLen: 255},
- URIPath: optionDef{valueFormat: valueString, minLen: 0, maxLen: 255},
- ContentFormat: optionDef{valueFormat: valueUint, minLen: 0, maxLen: 2},
- MaxAge: optionDef{valueFormat: valueUint, minLen: 0, maxLen: 4},
- URIQuery: optionDef{valueFormat: valueString, minLen: 0, maxLen: 255},
- Accept: optionDef{valueFormat: valueUint, minLen: 0, maxLen: 2},
- LocationQuery: optionDef{valueFormat: valueString, minLen: 0, maxLen: 255},
- ProxyURI: optionDef{valueFormat: valueString, minLen: 1, maxLen: 1034},
- ProxyScheme: optionDef{valueFormat: valueString, minLen: 1, maxLen: 255},
- Size1: optionDef{valueFormat: valueUint, minLen: 0, maxLen: 4},
-}
-
-// MediaType specifies the content type of a message.
-type MediaType byte
-
-// Content types.
-const (
- TextPlain MediaType = 0 // text/plain;charset=utf-8
- AppLinkFormat MediaType = 40 // application/link-format
- AppXML MediaType = 41 // application/xml
- AppOctets MediaType = 42 // application/octet-stream
- AppExi MediaType = 47 // application/exi
- AppJSON MediaType = 50 // application/json
-)
-
-type option struct {
- ID OptionID
- Value interface{}
-}
-
-func encodeInt(v uint32) []byte {
- switch {
- case v == 0:
- return nil
- case v < 256:
- return []byte{byte(v)}
- case v < 65536:
- rv := []byte{0, 0}
- binary.BigEndian.PutUint16(rv, uint16(v))
- return rv
- case v < 16777216:
- rv := []byte{0, 0, 0, 0}
- binary.BigEndian.PutUint32(rv, uint32(v))
- return rv[1:]
- default:
- rv := []byte{0, 0, 0, 0}
- binary.BigEndian.PutUint32(rv, uint32(v))
- return rv
- }
-}
-
-func decodeInt(b []byte) uint32 {
- tmp := []byte{0, 0, 0, 0}
- copy(tmp[4-len(b):], b)
- return binary.BigEndian.Uint32(tmp)
-}
-
-func (o option) toBytes() []byte {
- var v uint32
-
- switch i := o.Value.(type) {
- case string:
- return []byte(i)
- case []byte:
- return i
- case MediaType:
- v = uint32(i)
- case int:
- v = uint32(i)
- case int32:
- v = uint32(i)
- case uint:
- v = uint32(i)
- case uint32:
- v = i
- default:
- panic(fmt.Errorf("invalid type for option %x: %T (%v)",
- o.ID, o.Value, o.Value))
- }
-
- return encodeInt(v)
-}
-
-func parseOptionValue(optionID OptionID, valueBuf []byte) interface{} {
- def := optionDefs[optionID]
- if def.valueFormat == valueUnknown {
- // Skip unrecognized options (RFC7252 section 5.4.1)
- return nil
- }
- if len(valueBuf) < def.minLen || len(valueBuf) > def.maxLen {
- // Skip options with illegal value length (RFC7252 section 5.4.3)
- return nil
- }
- switch def.valueFormat {
- case valueUint:
- intValue := decodeInt(valueBuf)
- if optionID == ContentFormat || optionID == Accept {
- return MediaType(intValue)
- } else {
- return intValue
- }
- case valueString:
- return string(valueBuf)
- case valueOpaque, valueEmpty:
- return valueBuf
- }
- // Skip unrecognized options (should never be reached)
- return nil
-}
-
-type options []option
-
-func (o options) Len() int {
- return len(o)
-}
-
-func (o options) Less(i, j int) bool {
- if o[i].ID == o[j].ID {
- return i < j
- }
- return o[i].ID < o[j].ID
-}
-
-func (o options) Swap(i, j int) {
- o[i], o[j] = o[j], o[i]
-}
-
-func (o options) Minus(oid OptionID) options {
- rv := options{}
- for _, opt := range o {
- if opt.ID != oid {
- rv = append(rv, opt)
- }
- }
- return rv
-}
-
-// Message is a CoAP message.
-type Message struct {
- Type COAPType
- Code COAPCode
- MessageID uint16
-
- Token, Payload []byte
-
- opts options
-}
-
-// IsConfirmable returns true if this message is confirmable.
-func (m Message) IsConfirmable() bool {
- return m.Type == Confirmable
-}
-
-// Options gets all the values for the given option.
-func (m Message) Options(o OptionID) []interface{} {
- var rv []interface{}
-
- for _, v := range m.opts {
- if o == v.ID {
- rv = append(rv, v.Value)
- }
- }
-
- return rv
-}
-
-// Option gets the first value for the given option ID.
-func (m Message) Option(o OptionID) interface{} {
- for _, v := range m.opts {
- if o == v.ID {
- return v.Value
- }
- }
- return nil
-}
-
-func (m Message) optionStrings(o OptionID) []string {
- var rv []string
- for _, o := range m.Options(o) {
- rv = append(rv, o.(string))
- }
- return rv
-}
-
-// Path gets the Path set on this message if any.
-func (m Message) Path() []string {
- return m.optionStrings(URIPath)
-}
-
-// PathString gets a path as a / separated string.
-func (m Message) PathString() string {
- return strings.Join(m.Path(), "/")
-}
-
-// SetPathString sets a path by a / separated string.
-func (m *Message) SetPathString(s string) {
- for s[0] == '/' {
- s = s[1:]
- }
- m.SetPath(strings.Split(s, "/"))
-}
-
-// SetPath updates or adds a URIPath attribute on this message.
-func (m *Message) SetPath(s []string) {
- m.SetOption(URIPath, s)
-}
-
-// RemoveOption removes all references to an option
-func (m *Message) RemoveOption(opID OptionID) {
- m.opts = m.opts.Minus(opID)
-}
-
-// AddOption adds an option.
-func (m *Message) AddOption(opID OptionID, val interface{}) {
- iv := reflect.ValueOf(val)
- if (iv.Kind() == reflect.Slice || iv.Kind() == reflect.Array) &&
- iv.Type().Elem().Kind() == reflect.String {
- for i := 0; i < iv.Len(); i++ {
- m.opts = append(m.opts, option{opID, iv.Index(i).Interface()})
- }
- return
- }
- m.opts = append(m.opts, option{opID, val})
-}
-
-// SetOption sets an option, discarding any previous value
-func (m *Message) SetOption(opID OptionID, val interface{}) {
- m.RemoveOption(opID)
- m.AddOption(opID, val)
-}
-
-const (
- extoptByteCode = 13
- extoptByteAddend = 13
- extoptWordCode = 14
- extoptWordAddend = 269
- extoptError = 15
-)
-
-func writeOpt(o option, buf io.Writer, delta int) {
- /*
- 0 1 2 3 4 5 6 7
- +---------------+---------------+
- | | |
- | Option Delta | Option Length | 1 byte
- | | |
- +---------------+---------------+
- \ \
- / Option Delta / 0-2 bytes
- \ (extended) \
- +-------------------------------+
- \ \
- / Option Length / 0-2 bytes
- \ (extended) \
- +-------------------------------+
- \ \
- / /
- \ \
- / Option Value / 0 or more bytes
- \ \
- / /
- \ \
- +-------------------------------+
-
- See parseExtOption(), extendOption()
- and writeOptionHeader() below for implementation details
- */
-
- extendOpt := func(opt int) (int, int) {
- ext := 0
- if opt >= extoptByteAddend {
- if opt >= extoptWordAddend {
- ext = opt - extoptWordAddend
- opt = extoptWordCode
- } else {
- ext = opt - extoptByteAddend
- opt = extoptByteCode
- }
- }
- return opt, ext
- }
-
- writeOptHeader := func(delta, length int) {
- d, dx := extendOpt(delta)
- l, lx := extendOpt(length)
-
- buf.Write([]byte{byte(d<<4) | byte(l)})
-
- tmp := []byte{0, 0}
- writeExt := func(opt, ext int) {
- switch opt {
- case extoptByteCode:
- buf.Write([]byte{byte(ext)})
- case extoptWordCode:
- binary.BigEndian.PutUint16(tmp, uint16(ext))
- buf.Write(tmp)
- }
- }
-
- writeExt(d, dx)
- writeExt(l, lx)
- }
-
- b := o.toBytes()
- writeOptHeader(delta, len(b))
- buf.Write(b)
-}
-
-func writeOpts(buf io.Writer, opts options) {
- prev := 0
- for _, o := range opts {
- writeOpt(o, buf, int(o.ID)-prev)
- prev = int(o.ID)
- }
-}
-
-// MarshalBinary produces the binary form of this Message.
-func (m *Message) MarshalBinary() ([]byte, error) {
- tmpbuf := []byte{0, 0}
- binary.BigEndian.PutUint16(tmpbuf, m.MessageID)
-
- /*
- 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
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- |Ver| T | TKL | Code | Message ID |
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Token (if any, TKL bytes) ...
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Options (if any) ...
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- |1 1 1 1 1 1 1 1| Payload (if any) ...
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- */
-
- buf := bytes.Buffer{}
- buf.Write([]byte{
- (1 << 6) | (uint8(m.Type) << 4) | uint8(0xf&len(m.Token)),
- byte(m.Code),
- tmpbuf[0], tmpbuf[1],
- })
- buf.Write(m.Token)
-
- sort.Stable(&m.opts)
- writeOpts(&buf, m.opts)
-
- if len(m.Payload) > 0 {
- buf.Write([]byte{0xff})
- }
-
- buf.Write(m.Payload)
-
- return buf.Bytes(), nil
-}
-
-// ParseMessage extracts the Message from the given input.
-func ParseMessage(data []byte) (Message, error) {
- rv := Message{}
- return rv, rv.UnmarshalBinary(data)
-}
-
-// parseBody extracts the options and payload from a byte slice. The supplied
-// byte slice contains everything following the message header (everything
-// after the token).
-func parseBody(data []byte) (options, []byte, error) {
- prev := 0
-
- parseExtOpt := func(opt int) (int, error) {
- switch opt {
- case extoptByteCode:
- if len(data) < 1 {
- return -1, errors.New("truncated")
- }
- opt = int(data[0]) + extoptByteAddend
- data = data[1:]
- case extoptWordCode:
- if len(data) < 2 {
- return -1, errors.New("truncated")
- }
- opt = int(binary.BigEndian.Uint16(data[:2])) + extoptWordAddend
- data = data[2:]
- }
- return opt, nil
- }
-
- var opts options
-
- for len(data) > 0 {
- if data[0] == 0xff {
- data = data[1:]
- break
- }
-
- delta := int(data[0] >> 4)
- length := int(data[0] & 0x0f)
-
- if delta == extoptError || length == extoptError {
- return nil, nil, errors.New("unexpected extended option marker")
- }
-
- data = data[1:]
-
- delta, err := parseExtOpt(delta)
- if err != nil {
- return nil, nil, err
- }
- length, err = parseExtOpt(length)
- if err != nil {
- return nil, nil, err
- }
-
- if len(data) < length {
- return nil, nil, errors.New("truncated")
- }
-
- oid := OptionID(prev + delta)
- opval := parseOptionValue(oid, data[:length])
- data = data[length:]
- prev = int(oid)
-
- if opval != nil {
- opt := option{ID: oid, Value: opval}
- opts = append(opts, opt)
- }
- }
-
- return opts, data, nil
-}
-
-// UnmarshalBinary parses the given binary slice as a Message.
-func (m *Message) UnmarshalBinary(data []byte) error {
- if len(data) < 4 {
- return errors.New("short packet")
- }
-
- if data[0]>>6 != 1 {
- return errors.New("invalid version")
- }
-
- m.Type = COAPType((data[0] >> 4) & 0x3)
- tokenLen := int(data[0] & 0xf)
- if tokenLen > 8 {
- return ErrInvalidTokenLen
- }
-
- m.Code = COAPCode(data[1])
- m.MessageID = binary.BigEndian.Uint16(data[2:4])
-
- if tokenLen > 0 {
- m.Token = make([]byte, tokenLen)
- }
- if len(data) < 4+tokenLen {
- return errors.New("truncated")
- }
- copy(m.Token, data[4:4+tokenLen])
- b := data[4+tokenLen:]
-
- o, p, err := parseBody(b)
- if err != nil {
- return err
- }
-
- m.Payload = p
- m.opts = o
-
- return nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/runtimeco/go-coap/messagetcp.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeco/go-coap/messagetcp.go b/newtmgr/vendor/github.com/runtimeco/go-coap/messagetcp.go
deleted file mode 100644
index db35472..0000000
--- a/newtmgr/vendor/github.com/runtimeco/go-coap/messagetcp.go
+++ /dev/null
@@ -1,275 +0,0 @@
-package coap
-
-import (
- "bytes"
- "encoding/binary"
- "fmt"
- "io"
- "sort"
-)
-
-const (
- TCP_MESSAGE_LEN13_BASE = 13
- TCP_MESSAGE_LEN14_BASE = 269
- TCP_MESSAGE_LEN15_BASE = 65805
- TCP_MESSAGE_MAX_LEN = 4295033101
-)
-
-// TcpMessage is a CoAP Message that can encode itself for TCP
-// transport.
-type TcpMessage struct {
- Message
-}
-
-func (m *TcpMessage) MarshalBinary() ([]byte, error) {
- /*
- A CoAP TCP message looks like:
-
- 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
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Len | TKL | Extended Length ...
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Code | TKL bytes ...
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- | Options (if any) ...
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- |1 1 1 1 1 1 1 1| Payload (if any) ...
- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
- The size of the Extended Length field is inferred from the value of the
- Len field as follows:
-
- | Len value | Extended Length size | Total length |
- +------------+-----------------------+---------------------------+
- | 0-12 | 0 | Len |
- | 13 | 1 | Extended Length + 13 |
- | 14 | 2 | Extended Length + 269 |
- | 15 | 4 | Extended Length + 65805 |
- */
-
- buf := bytes.Buffer{}
-
- sort.Stable(&m.Message.opts)
- writeOpts(&buf, m.Message.opts)
-
- if len(m.Message.Payload) > 0 {
- buf.Write([]byte{0xff})
- buf.Write(m.Message.Payload)
- }
-
- var lenNib uint8
- var extLenBytes []byte
-
- if buf.Len() < TCP_MESSAGE_LEN14_BASE {
- lenNib = uint8(buf.Len())
- } else if buf.Len() < TCP_MESSAGE_LEN14_BASE {
- lenNib = 13
- extLen := buf.Len() - TCP_MESSAGE_LEN13_BASE
- extLenBytes = []byte{uint8(extLen)}
- } else if buf.Len() < TCP_MESSAGE_LEN15_BASE {
- lenNib = 14
- extLen := buf.Len() - TCP_MESSAGE_LEN14_BASE
- extLenBytes = make([]byte, 2)
- binary.BigEndian.PutUint16(extLenBytes, uint16(extLen))
- } else if buf.Len() < TCP_MESSAGE_MAX_LEN {
- lenNib = 15
- extLen := buf.Len() - TCP_MESSAGE_LEN15_BASE
- extLenBytes = make([]byte, 4)
- binary.BigEndian.PutUint32(extLenBytes, uint32(extLen))
- }
-
- hdr := make([]byte, 1+len(extLenBytes)+len(m.Message.Token)+1)
- hdrOff := 0
-
- // Length and TKL nibbles.
- hdr[hdrOff] = uint8(0xf&len(m.Token)) | (lenNib << 4)
- hdrOff++
-
- // Extended length, if present.
- if len(extLenBytes) > 0 {
- copy(hdr[hdrOff:hdrOff+len(extLenBytes)], extLenBytes)
- hdrOff += len(extLenBytes)
- }
-
- // Code.
- hdr[hdrOff] = byte(m.Message.Code)
- hdrOff++
-
- // Token.
- if len(m.Message.Token) > 0 {
- copy(hdr[hdrOff:hdrOff+len(m.Message.Token)], m.Message.Token)
- hdrOff += len(m.Message.Token)
- }
-
- return append(hdr, buf.Bytes()...), nil
-}
-
-// msgTcpInfo describes a single TCP CoAP message. Used during reassembly.
-type msgTcpInfo struct {
- typ uint8
- token []byte
- code uint8
- hdrLen int
- totLen int
-}
-
-// readTcpMsgInfo infers information about a TCP CoAP message from the first
-// fragment.
-func readTcpMsgInfo(r io.Reader) (msgTcpInfo, error) {
- mti := msgTcpInfo{}
-
- hdrOff := 0
-
- var firstByte byte
- if err := binary.Read(r, binary.BigEndian, &firstByte); err != nil {
- return mti, err
- }
- hdrOff++
-
- lenNib := (firstByte & 0xf0) >> 4
- tkl := firstByte & 0x0f
-
- var opLen int
- if lenNib < TCP_MESSAGE_LEN13_BASE {
- opLen = int(lenNib)
- } else if lenNib == 13 {
- var extLen byte
- if err := binary.Read(r, binary.BigEndian, &extLen); err != nil {
- return mti, err
- }
- hdrOff++
- opLen = TCP_MESSAGE_LEN13_BASE + int(extLen)
- } else if lenNib == 14 {
- var extLen uint16
- if err := binary.Read(r, binary.BigEndian, &extLen); err != nil {
- return mti, err
- }
- hdrOff += 2
- opLen = TCP_MESSAGE_LEN14_BASE + int(extLen)
- } else if lenNib == 15 {
- var extLen uint32
- if err := binary.Read(r, binary.BigEndian, &extLen); err != nil {
- return mti, err
- }
- hdrOff += 4
- opLen = TCP_MESSAGE_LEN15_BASE + int(extLen)
- }
-
- mti.totLen = hdrOff + 1 + int(tkl) + opLen
-
- if err := binary.Read(r, binary.BigEndian, &mti.code); err != nil {
- return mti, err
- }
- hdrOff++
-
- mti.token = make([]byte, tkl)
- if _, err := io.ReadFull(r, mti.token); err != nil {
- return mti, err
- }
- hdrOff += int(tkl)
-
- mti.hdrLen = hdrOff
-
- return mti, nil
-}
-
-func readTcpMsgBody(mti msgTcpInfo, r io.Reader) (options, []byte, error) {
- bodyLen := mti.totLen - mti.hdrLen
- b := make([]byte, bodyLen)
- if _, err := io.ReadFull(r, b); err != nil {
- return nil, nil, err
- }
-
- o, p, err := parseBody(b)
- if err != nil {
- return nil, nil, err
- }
-
- return o, p, nil
-}
-
-func (m *TcpMessage) fill(mti msgTcpInfo, o options, p []byte) {
- m.Type = COAPType(mti.typ)
- m.Code = COAPCode(mti.code)
- m.Token = mti.token
- m.opts = o
- m.Payload = p
-}
-
-func (m *TcpMessage) UnmarshalBinary(data []byte) error {
- r := bytes.NewReader(data)
-
- mti, err := readTcpMsgInfo(r)
- if err != nil {
- return fmt.Errorf("Error reading TCP CoAP header; %s", err.Error())
- }
-
- if len(data) != mti.totLen {
- return fmt.Errorf("CoAP length mismatch (hdr=%d pkt=%d)",
- mti.totLen, len(data))
- }
-
- o, p, err := readTcpMsgBody(mti, r)
- if err != nil {
- return err
- }
-
- m.fill(mti, o, p)
- return nil
-}
-
-// PullTcp extracts a complete TCP CoAP message from the front of a byte queue.
-//
-// Return values:
-// *TcpMessage: On success, points to the extracted message; nil if a complete
-// message could not be extracted.
-// []byte: The unread portion of of the supplied byte buffer. If a message
-// was not extracted, this is the unchanged buffer that was passed in.
-// error: Non-nil if the buffer contains an invalid CoAP message.
-//
-// Note: It is not an error if the supplied buffer does not contain a complete
-// message. In such a case, nil *TclMessage and error values are returned
-// along with the original buffer.
-func PullTcp(data []byte) (*TcpMessage, []byte, error) {
- r := bytes.NewReader(data)
- m, err := Decode(r)
- if err != nil {
- if err == io.EOF {
- // Packet is incomplete.
- return nil, data, nil
- } else {
- // Some other error.
- return nil, data, err
- }
- }
-
- // Determine the number of bytes read. These bytes get trimmed from the
- // front of the returned data slice.
- // XXX: Replace "1" with io.SeekCurrent when go 1.7 becomes mainstream.
- sz, err := r.Seek(0, 1)
- if err != nil {
- // This should never happen.
- return nil, data, err
- }
-
- return m, data[sz:], nil
-}
-
-// Decode reads a single message from its input.
-func Decode(r io.Reader) (*TcpMessage, error) {
- mti, err := readTcpMsgInfo(r)
- if err != nil {
- return nil, err
- }
-
- o, p, err := readTcpMsgBody(mti, r)
- if err != nil {
- return nil, err
- }
-
- m := &TcpMessage{}
- m.fill(mti, o, p)
-
- return m, nil
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/runtimeco/go-coap/server.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeco/go-coap/server.go b/newtmgr/vendor/github.com/runtimeco/go-coap/server.go
deleted file mode 100644
index 343b875..0000000
--- a/newtmgr/vendor/github.com/runtimeco/go-coap/server.go
+++ /dev/null
@@ -1,102 +0,0 @@
-// Package coap provides a CoAP client and server.
-package coap
-
-import (
- "log"
- "net"
- "time"
-)
-
-const maxPktLen = 1500
-
-// Handler is a type that handles CoAP messages.
-type Handler interface {
- // Handle the message and optionally return a response message.
- ServeCOAP(l *net.UDPConn, a *net.UDPAddr, m *Message) *Message
-}
-
-type funcHandler func(l *net.UDPConn, a *net.UDPAddr, m *Message) *Message
-
-func (f funcHandler) ServeCOAP(l *net.UDPConn, a *net.UDPAddr, m *Message) *Message {
- return f(l, a, m)
-}
-
-// FuncHandler builds a handler from a function.
-func FuncHandler(f func(l *net.UDPConn, a *net.UDPAddr, m *Message) *Message) Handler {
- return funcHandler(f)
-}
-
-func handlePacket(l *net.UDPConn, data []byte, u *net.UDPAddr,
- rh Handler) {
-
- msg, err := ParseMessage(data)
- if err != nil {
- log.Printf("Error parsing %v", err)
- return
- }
-
- rv := rh.ServeCOAP(l, u, &msg)
- if rv != nil {
- Transmit(l, u, *rv)
- }
-}
-
-// Transmit a message.
-func Transmit(l *net.UDPConn, a *net.UDPAddr, m Message) error {
- d, err := m.MarshalBinary()
- if err != nil {
- return err
- }
-
- if a == nil {
- _, err = l.Write(d)
- } else {
- _, err = l.WriteTo(d, a)
- }
- return err
-}
-
-// Receive a message.
-func Receive(l *net.UDPConn, buf []byte) (Message, error) {
- l.SetReadDeadline(time.Now().Add(ResponseTimeout))
-
- nr, _, err := l.ReadFromUDP(buf)
- if err != nil {
- return Message{}, err
- }
- return ParseMessage(buf[:nr])
-}
-
-// ListenAndServe binds to the given address and serve requests forever.
-func ListenAndServe(n, addr string, rh Handler) error {
- uaddr, err := net.ResolveUDPAddr(n, addr)
- if err != nil {
- return err
- }
-
- l, err := net.ListenUDP(n, uaddr)
- if err != nil {
- return err
- }
-
- return Serve(l, rh)
-}
-
-// Serve processes incoming UDP packets on the given listener, and processes
-// these requests forever (or until the listener is closed).
-func Serve(listener *net.UDPConn, rh Handler) error {
- buf := make([]byte, maxPktLen)
- for {
- nr, addr, err := listener.ReadFromUDP(buf)
- if err != nil {
- if neterr, ok := err.(net.Error); ok && (neterr.Temporary() || neterr.Timeout()) {
- time.Sleep(5 * time.Millisecond)
- continue
- }
- return err
- }
- tmp := make([]byte, nr)
- copy(tmp, buf)
- go handlePacket(listener, tmp, addr, rh)
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/runtimeco/go-coap/servmux.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/runtimeco/go-coap/servmux.go b/newtmgr/vendor/github.com/runtimeco/go-coap/servmux.go
deleted file mode 100644
index 23132f1..0000000
--- a/newtmgr/vendor/github.com/runtimeco/go-coap/servmux.go
+++ /dev/null
@@ -1,94 +0,0 @@
-package coap
-
-import (
- "net"
-)
-
-// ServeMux provides mappings from a common endpoint to handlers by
-// request path.
-type ServeMux struct {
- m map[string]muxEntry
-}
-
-type muxEntry struct {
- h Handler
- pattern string
-}
-
-// NewServeMux creates a new ServeMux.
-func NewServeMux() *ServeMux { return &ServeMux{m: make(map[string]muxEntry)} }
-
-// Does path match pattern?
-func pathMatch(pattern, path string) bool {
- if len(pattern) == 0 {
- // should not happen
- return false
- }
- n := len(pattern)
- if pattern[n-1] != '/' {
- return pattern == path
- }
- return len(path) >= n && path[0:n] == pattern
-}
-
-// Find a handler on a handler map given a path string
-// Most-specific (longest) pattern wins
-func (mux *ServeMux) match(path string) (h Handler, pattern string) {
- var n = 0
- for k, v := range mux.m {
- if !pathMatch(k, path) {
- continue
- }
- if h == nil || len(k) > n {
- n = len(k)
- h = v.h
- pattern = v.pattern
- }
- }
- return
-}
-
-func notFoundHandler(l *net.UDPConn, a *net.UDPAddr, m *Message) *Message {
- if m.IsConfirmable() {
- return &Message{
- Type: Acknowledgement,
- Code: NotFound,
- }
- }
- return nil
-}
-
-var _ = Handler(&ServeMux{})
-
-// ServeCOAP handles a single COAP message. The message arrives from
-// the given listener having originated from the given UDPAddr.
-func (mux *ServeMux) ServeCOAP(l *net.UDPConn, a *net.UDPAddr, m *Message) *Message {
- h, _ := mux.match(m.PathString())
- if h == nil {
- h, _ = funcHandler(notFoundHandler), ""
- }
- // TODO: Rewrite path?
- return h.ServeCOAP(l, a, m)
-}
-
-// Handle configures a handler for the given path.
-func (mux *ServeMux) Handle(pattern string, handler Handler) {
- for pattern != "" && pattern[0] == '/' {
- pattern = pattern[1:]
- }
-
- if pattern == "" {
- panic("http: invalid pattern " + pattern)
- }
- if handler == nil {
- panic("http: nil handler")
- }
-
- mux.m[pattern] = muxEntry{h: handler, pattern: pattern}
-}
-
-// HandleFunc configures a handler for the given path.
-func (mux *ServeMux) HandleFunc(pattern string,
- f func(l *net.UDPConn, a *net.UDPAddr, m *Message) *Message) {
- mux.Handle(pattern, FuncHandler(f))
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/spf13/cast/.gitignore
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/spf13/cast/.gitignore b/newtmgr/vendor/github.com/spf13/cast/.gitignore
deleted file mode 100644
index 53053a8..0000000
--- a/newtmgr/vendor/github.com/spf13/cast/.gitignore
+++ /dev/null
@@ -1,25 +0,0 @@
-# Compiled Object files, Static and Dynamic libs (Shared Objects)
-*.o
-*.a
-*.so
-
-# Folders
-_obj
-_test
-
-# Architecture specific extensions/prefixes
-*.[568vq]
-[568vq].out
-
-*.cgo1.go
-*.cgo2.c
-_cgo_defun.c
-_cgo_gotypes.go
-_cgo_export.*
-
-_testmain.go
-
-*.exe
-*.test
-
-*.bench
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/spf13/cast/LICENSE
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/spf13/cast/LICENSE b/newtmgr/vendor/github.com/spf13/cast/LICENSE
deleted file mode 100644
index 4527efb..0000000
--- a/newtmgr/vendor/github.com/spf13/cast/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2014 Steve Francia
-
-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.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/spf13/cast/README.md
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/spf13/cast/README.md b/newtmgr/vendor/github.com/spf13/cast/README.md
deleted file mode 100644
index af7a1fd..0000000
--- a/newtmgr/vendor/github.com/spf13/cast/README.md
+++ /dev/null
@@ -1,72 +0,0 @@
-cast
-====
-
-Easy and safe casting from one type to another in Go
-
-Don\u2019t Panic! ... Cast
-
-## What is Cast?
-
-Cast is a library to convert between different go types in a consistent and easy way.
-
-Cast provides simple functions to easily convert a number to a string, an
-interface into a bool, etc. Cast does this intelligently when an obvious
-conversion is possible. It doesn\u2019t make any attempts to guess what you meant,
-for example you can only convert a string to an int when it is a string
-representation of an int such as \u201c8\u201d. Cast was developed for use in
-[Hugo](http://hugo.spf13.com), a website engine which uses YAML, TOML or JSON
-for meta data.
-
-## Why use Cast?
-
-When working with dynamic data in Go you often need to cast or convert the data
-from one type into another. Cast goes beyond just using type assertion (though
-it uses that when possible) to provide a very straightforward and convenient
-library.
-
-If you are working with interfaces to handle things like dynamic content
-you\u2019ll need an easy way to convert an interface into a given type. This
-is the library for you.
-
-If you are taking in data from YAML, TOML or JSON or other formats which lack
-full types, then Cast is the library for you.
-
-## Usage
-
-Cast provides a handful of To_____ methods. These methods will always return
-the desired type. **If input is provided that will not convert to that type, the
-0 or nil value for that type will be returned**.
-
-Cast also provides identical methods To_____E. These return the same result as
-the To_____ methods, plus an additional error which tells you if it successfully
-converted. Using these methods you can tell the difference between when the
-input matched the zero value or when the conversion failed and the zero value
-was returned.
-
-The following examples are merely a sample of what is available. Please review
-the code for a complete set.
-
-### Example \u2018ToString\u2019:
-
- cast.ToString("mayonegg") // "mayonegg"
- cast.ToString(8) // "8"
- cast.ToString(8.31) // "8.31"
- cast.ToString([]byte("one time")) // "one time"
- cast.ToString(nil) // ""
-
- var foo interface{} = "one more time"
- cast.ToString(foo) // "one more time"
-
-
-### Example \u2018ToInt\u2019:
-
- cast.ToInt(8) // 8
- cast.ToInt(8.31) // 8
- cast.ToInt("8") // 8
- cast.ToInt(true) // 1
- cast.ToInt(false) // 0
-
- var eight interface{} = 8
- cast.ToInt(eight) // 8
- cast.ToInt(nil) // 0
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newtmgr/blob/9975ef7a/newtmgr/vendor/github.com/spf13/cast/cast.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/github.com/spf13/cast/cast.go b/newtmgr/vendor/github.com/spf13/cast/cast.go
deleted file mode 100644
index 6ca3e0e..0000000
--- a/newtmgr/vendor/github.com/spf13/cast/cast.go
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright � 2014 Steve Francia <sp...@spf13.com>.
-//
-// Use of this source code is governed by an MIT-style
-// license that can be found in the LICENSE file.
-
-package cast
-
-import "time"
-
-func ToBool(i interface{}) bool {
- v, _ := ToBoolE(i)
- return v
-}
-
-func ToTime(i interface{}) time.Time {
- v, _ := ToTimeE(i)
- return v
-}
-
-func ToDuration(i interface{}) time.Duration {
- v, _ := ToDurationE(i)
- return v
-}
-
-func ToFloat64(i interface{}) float64 {
- v, _ := ToFloat64E(i)
- return v
-}
-
-func ToInt64(i interface{}) int64 {
- v, _ := ToInt64E(i)
- return v
-}
-
-func ToInt(i interface{}) int {
- v, _ := ToIntE(i)
- return v
-}
-
-func ToString(i interface{}) string {
- v, _ := ToStringE(i)
- return v
-}
-
-func ToStringMapString(i interface{}) map[string]string {
- v, _ := ToStringMapStringE(i)
- return v
-}
-
-func ToStringMapStringSlice(i interface{}) map[string][]string {
- v, _ := ToStringMapStringSliceE(i)
- return v
-}
-
-func ToStringMapBool(i interface{}) map[string]bool {
- v, _ := ToStringMapBoolE(i)
- return v
-}
-
-func ToStringMap(i interface{}) map[string]interface{} {
- v, _ := ToStringMapE(i)
- return v
-}
-
-func ToSlice(i interface{}) []interface{} {
- v, _ := ToSliceE(i)
- return v
-}
-
-func ToBoolSlice(i interface{}) []bool {
- v, _ := ToBoolSliceE(i)
- return v
-}
-
-func ToStringSlice(i interface{}) []string {
- v, _ := ToStringSliceE(i)
- return v
-}
-
-func ToIntSlice(i interface{}) []int {
- v, _ := ToIntSliceE(i)
- return v
-}