From 314eea7ff0f76910d0265262bacfe6169f77c560 Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Thu, 18 Jun 2015 17:17:18 -0700 Subject: [PATCH 01/19] Adding error and remote_address to audit log lines --- audit/format_json.go | 26 +++++++++++++++++--------- http/help.go | 5 +++-- http/logical.go | 28 +++++++++++++++++----------- http/sys_audit.go | 16 ++++++++++------ http/sys_auth.go | 15 +++++++++------ http/sys_lease.go | 15 +++++++++------ http/sys_mount.go | 20 ++++++++++++-------- http/sys_policy.go | 20 ++++++++++++-------- http/sys_rotate.go | 10 ++++++---- vault/rollback.go | 1 + 10 files changed, 96 insertions(+), 60 deletions(-) diff --git a/audit/format_json.go b/audit/format_json.go index 40bbc305a9..1f423f6123 100644 --- a/audit/format_json.go +++ b/audit/format_json.go @@ -5,6 +5,7 @@ import ( "io" "github.com/hashicorp/vault/logical" + "errors" ) // FormatJSON is a Formatter implementation that structuteres data into @@ -31,9 +32,10 @@ func (f *FormatJSON) FormatRequest( }, Request: JSONRequest{ - Operation: req.Operation, - Path: req.Path, - Data: req.Data, + Operation: req.Operation, + Path: req.Path, + Data: req.Data, + RemoteAddr: req.Connection.RemoteAddr, }, }) } @@ -51,6 +53,9 @@ func (f *FormatJSON) FormatResponse( if resp == nil { resp = new(logical.Response) } + if err == nil { + err = errors.New("") + } var respAuth JSONAuth if resp.Auth != nil { @@ -73,6 +78,7 @@ func (f *FormatJSON) FormatResponse( enc := json.NewEncoder(w) return enc.Encode(&JSONResponseEntry{ Type: "response", + Error: err.Error(), Auth: JSONAuth{ Policies: auth.Policies, @@ -80,9 +86,10 @@ func (f *FormatJSON) FormatResponse( }, Request: JSONRequest{ - Operation: req.Operation, - Path: req.Path, - Data: req.Data, + Operation: req.Operation, + Path: req.Path, + Data: req.Data, + RemoteAddr: req.Connection.RemoteAddr, }, Response: JSONResponse{ @@ -111,9 +118,10 @@ type JSONResponseEntry struct { } type JSONRequest struct { - Operation logical.Operation `json:"operation"` - Path string `json:"path"` - Data map[string]interface{} `json:"data"` + Operation logical.Operation `json:"operation"` + Path string `json:"path"` + Data map[string]interface{} `json:"data"` + RemoteAddr string `json:"remote_address"` } type JSONResponse struct { diff --git a/http/help.go b/http/help.go index b512da5fc5..589012ea90 100644 --- a/http/help.go +++ b/http/help.go @@ -28,8 +28,9 @@ func handleHelp(core *vault.Core, w http.ResponseWriter, req *http.Request) { } resp, err := core.HandleRequest(requestAuth(req, &logical.Request{ - Operation: logical.HelpOperation, - Path: path, + Operation: logical.HelpOperation, + Path: path, + Connection: getConnection(req), })) if err != nil { respondError(w, http.StatusInternalServerError, err) diff --git a/http/logical.go b/http/logical.go index 70d0535ab1..a94edc372c 100644 --- a/http/logical.go +++ b/http/logical.go @@ -54,13 +54,6 @@ func handleLogical(core *vault.Core) http.Handler { } } - // http.Server will set RemoteAddr to an "IP:port" string - var remoteAddr string - remoteAddr, _, err := net.SplitHostPort(r.RemoteAddr) - if err != nil { - remoteAddr = "" - } - // Make the internal request. We attach the connection info // as well in case this is an authentication request that requires // it. Vault core handles stripping this if we need to. @@ -68,10 +61,7 @@ func handleLogical(core *vault.Core) http.Handler { Operation: op, Path: path, Data: req, - Connection: &logical.Connection{ - RemoteAddr: remoteAddr, - ConnState: r.TLS, - }, + Connection: getConnection(r), })) if !ok { return @@ -198,6 +188,22 @@ func respondRaw(w http.ResponseWriter, r *http.Request, path string, resp *logic w.Write(body) } +func getConnection(r *http.Request) (connection *logical.Connection) { + var remoteAddr string + + remoteAddr, _, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + remoteAddr = "" + } + + connection = &logical.Connection{ + RemoteAddr: remoteAddr, + ConnState: r.TLS, + } + + return +} + type LogicalResponse struct { LeaseID string `json:"lease_id"` Renewable bool `json:"renewable"` diff --git a/http/sys_audit.go b/http/sys_audit.go index ad5e1412da..65cb7baa20 100644 --- a/http/sys_audit.go +++ b/http/sys_audit.go @@ -16,8 +16,9 @@ func handleSysListAudit(core *vault.Core) http.Handler { } resp, ok := request(core, w, r, requestAuth(r, &logical.Request{ - Operation: logical.ReadOperation, - Path: "sys/audit", + Operation: logical.ReadOperation, + Path: "sys/audit", + Connection: getConnection(r), })) if !ok { return @@ -57,8 +58,9 @@ func handleSysDisableAudit(core *vault.Core, w http.ResponseWriter, r *http.Requ } _, ok := request(core, w, r, requestAuth(r, &logical.Request{ - Operation: logical.DeleteOperation, - Path: "sys/audit/" + path, + Operation: logical.DeleteOperation, + Path: "sys/audit/" + path, + Connection: getConnection(r), })) if !ok { return @@ -74,6 +76,7 @@ func handleSysEnableAudit(core *vault.Core, w http.ResponseWriter, r *http.Reque respondError(w, http.StatusNotFound, nil) return } + path := r.URL.Path[len(prefix):] if path == "" { respondError(w, http.StatusNotFound, nil) @@ -88,8 +91,9 @@ func handleSysEnableAudit(core *vault.Core, w http.ResponseWriter, r *http.Reque } _, ok := request(core, w, r, requestAuth(r, &logical.Request{ - Operation: logical.WriteOperation, - Path: "sys/audit/" + path, + Operation: logical.WriteOperation, + Path: "sys/audit/" + path, + Connection: getConnection(r), Data: map[string]interface{}{ "type": req.Type, "description": req.Description, diff --git a/http/sys_auth.go b/http/sys_auth.go index 7fd1ebb448..598b3cab6b 100644 --- a/http/sys_auth.go +++ b/http/sys_auth.go @@ -30,8 +30,9 @@ func handleSysListAuth(core *vault.Core) http.Handler { } resp, err := core.HandleRequest(requestAuth(r, &logical.Request{ - Operation: logical.ReadOperation, - Path: "sys/auth", + Operation: logical.ReadOperation, + Path: "sys/auth", + Connection: getConnection(r), })) if err != nil { respondError(w, http.StatusInternalServerError, err) @@ -78,8 +79,9 @@ func handleSysEnableAuth( } _, err := core.HandleRequest(requestAuth(r, &logical.Request{ - Operation: logical.WriteOperation, - Path: "sys/auth/" + path, + Operation: logical.WriteOperation, + Path: "sys/auth/" + path, + Connection: getConnection(r), Data: map[string]interface{}{ "type": req.Type, "description": req.Description, @@ -99,8 +101,9 @@ func handleSysDisableAuth( r *http.Request, path string) { _, err := core.HandleRequest(requestAuth(r, &logical.Request{ - Operation: logical.DeleteOperation, - Path: "sys/auth/" + path, + Operation: logical.DeleteOperation, + Path: "sys/auth/" + path, + Connection: getConnection(r), })) if err != nil { respondError(w, http.StatusInternalServerError, err) diff --git a/http/sys_lease.go b/http/sys_lease.go index 08323d736d..ce36118d3e 100644 --- a/http/sys_lease.go +++ b/http/sys_lease.go @@ -38,8 +38,9 @@ func handleSysRenew(core *vault.Core) http.Handler { } resp, ok := request(core, w, r, requestAuth(r, &logical.Request{ - Operation: logical.WriteOperation, - Path: "sys/renew/" + path, + Operation: logical.WriteOperation, + Path: "sys/renew/" + path, + Connection: getConnection(r), Data: map[string]interface{}{ "increment": req.Increment, }, @@ -72,8 +73,9 @@ func handleSysRevoke(core *vault.Core) http.Handler { } _, err := core.HandleRequest(requestAuth(r, &logical.Request{ - Operation: logical.WriteOperation, - Path: "sys/revoke/" + path, + Operation: logical.WriteOperation, + Path: "sys/revoke/" + path, + Connection: getConnection(r), })) if err != nil { respondError(w, http.StatusBadRequest, err) @@ -104,8 +106,9 @@ func handleSysRevokePrefix(core *vault.Core) http.Handler { } _, err := core.HandleRequest(requestAuth(r, &logical.Request{ - Operation: logical.WriteOperation, - Path: "sys/revoke-prefix/" + path, + Operation: logical.WriteOperation, + Path: "sys/revoke-prefix/" + path, + Connection: getConnection(r), })) if err != nil { respondError(w, http.StatusBadRequest, err) diff --git a/http/sys_mount.go b/http/sys_mount.go index 68eae02e41..61a53f0738 100644 --- a/http/sys_mount.go +++ b/http/sys_mount.go @@ -41,8 +41,9 @@ func handleSysRemount(core *vault.Core) http.Handler { } _, err := core.HandleRequest(requestAuth(r, &logical.Request{ - Operation: logical.WriteOperation, - Path: "sys/remount", + Operation: logical.WriteOperation, + Path: "sys/remount", + Connection: getConnection(r), Data: map[string]interface{}{ "from": req.From, "to": req.To, @@ -65,8 +66,9 @@ func handleSysListMounts(core *vault.Core) http.Handler { } resp, err := core.HandleRequest(requestAuth(r, &logical.Request{ - Operation: logical.ReadOperation, - Path: "sys/mounts", + Operation: logical.ReadOperation, + Path: "sys/mounts", + Connection: getConnection(r), })) if err != nil { respondError(w, http.StatusInternalServerError, err) @@ -121,8 +123,9 @@ func handleSysMount( } _, err := core.HandleRequest(requestAuth(r, &logical.Request{ - Operation: logical.WriteOperation, - Path: "sys/mounts/" + path, + Operation: logical.WriteOperation, + Path: "sys/mounts/" + path, + Connection: getConnection(r), Data: map[string]interface{}{ "type": req.Type, "description": req.Description, @@ -142,8 +145,9 @@ func handleSysUnmount( r *http.Request, path string) { _, err := core.HandleRequest(requestAuth(r, &logical.Request{ - Operation: logical.DeleteOperation, - Path: "sys/mounts/" + path, + Operation: logical.DeleteOperation, + Path: "sys/mounts/" + path, + Connection: getConnection(r), })) if err != nil { respondError(w, http.StatusInternalServerError, err) diff --git a/http/sys_policy.go b/http/sys_policy.go index d17d75be56..49ea7902c6 100644 --- a/http/sys_policy.go +++ b/http/sys_policy.go @@ -16,8 +16,9 @@ func handleSysListPolicies(core *vault.Core) http.Handler { } resp, ok := request(core, w, r, requestAuth(r, &logical.Request{ - Operation: logical.ReadOperation, - Path: "sys/policy", + Operation: logical.ReadOperation, + Path: "sys/policy", + Connection: getConnection(r), })) if !ok { return @@ -65,8 +66,9 @@ func handleSysDeletePolicy(core *vault.Core, w http.ResponseWriter, r *http.Requ } _, ok := request(core, w, r, requestAuth(r, &logical.Request{ - Operation: logical.DeleteOperation, - Path: "sys/policy/" + path, + Operation: logical.DeleteOperation, + Path: "sys/policy/" + path, + Connection: getConnection(r), })) if !ok { return @@ -89,8 +91,9 @@ func handleSysReadPolicy(core *vault.Core, w http.ResponseWriter, r *http.Reques } resp, ok := request(core, w, r, requestAuth(r, &logical.Request{ - Operation: logical.ReadOperation, - Path: "sys/policy/" + path, + Operation: logical.ReadOperation, + Path: "sys/policy/" + path, + Connection: getConnection(r), })) if !ok { return @@ -124,8 +127,9 @@ func handleSysWritePolicy(core *vault.Core, w http.ResponseWriter, r *http.Reque } _, ok := request(core, w, r, requestAuth(r, &logical.Request{ - Operation: logical.WriteOperation, - Path: "sys/policy/" + path, + Operation: logical.WriteOperation, + Path: "sys/policy/" + path, + Connection: getConnection(r), Data: map[string]interface{}{ "rules": req.Rules, }, diff --git a/http/sys_rotate.go b/http/sys_rotate.go index ea8f2920fc..ea968adcd1 100644 --- a/http/sys_rotate.go +++ b/http/sys_rotate.go @@ -15,8 +15,9 @@ func handleSysKeyStatus(core *vault.Core) http.Handler { } resp, err := core.HandleRequest(requestAuth(r, &logical.Request{ - Operation: logical.ReadOperation, - Path: "sys/key-status", + Operation: logical.ReadOperation, + Path: "sys/key-status", + Connection: getConnection(r), })) if err != nil { respondError(w, http.StatusInternalServerError, err) @@ -37,8 +38,9 @@ func handleSysRotate(core *vault.Core) http.Handler { } _, err := core.HandleRequest(requestAuth(r, &logical.Request{ - Operation: logical.WriteOperation, - Path: "sys/rotate", + Operation: logical.WriteOperation, + Path: "sys/rotate", + Connection: getConnection(r), })) if err != nil { respondError(w, http.StatusInternalServerError, err) diff --git a/vault/rollback.go b/vault/rollback.go index 317e7c4aaa..ac6391c27b 100644 --- a/vault/rollback.go +++ b/vault/rollback.go @@ -140,6 +140,7 @@ func (m *RollbackManager) attemptRollback(path string, rs *rollbackState) (err e req := &logical.Request{ Operation: logical.RollbackOperation, Path: path, + Connection: &logical.Connection{}, } _, err = m.router.Route(req) From 71a738ad7d433b5d0fe38bfa31bf767ef10f97c9 Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Thu, 18 Jun 2015 18:30:18 -0700 Subject: [PATCH 02/19] Logging authentication errors and bad token usage --- audit/audit.go | 2 +- audit/format_json.go | 12 ++++++++++-- audit/formatter.go | 2 +- builtin/audit/file/backend.go | 4 ++-- builtin/audit/syslog/backend.go | 4 ++-- vault/audit.go | 4 ++-- vault/core.go | 10 ++++++++-- vault/testing.go | 2 +- vault/token_store.go | 4 ++-- 9 files changed, 29 insertions(+), 15 deletions(-) diff --git a/audit/audit.go b/audit/audit.go index 6043613879..8ffaf8b660 100644 --- a/audit/audit.go +++ b/audit/audit.go @@ -11,7 +11,7 @@ type Backend interface { // request is authorized but before the request is executed. The arguments // MUST not be modified in anyway. They should be deep copied if this is // a possibility. - LogRequest(*logical.Auth, *logical.Request) error + LogRequest(*logical.Auth, *logical.Request, error) error // LogResponse is used to syncronously log a response. This is done after // the request is processed but before the response is sent. The arguments diff --git a/audit/format_json.go b/audit/format_json.go index 1f423f6123..cba7bc10b8 100644 --- a/audit/format_json.go +++ b/audit/format_json.go @@ -8,22 +8,29 @@ import ( "errors" ) -// FormatJSON is a Formatter implementation that structuteres data into +// FormatJSON is a Formatter implementation that structures data into // a JSON format. type FormatJSON struct{} func (f *FormatJSON) FormatRequest( w io.Writer, - auth *logical.Auth, req *logical.Request) error { + auth *logical.Auth, + req *logical.Request, + err error) error { + // If auth is nil, make an empty one if auth == nil { auth = new(logical.Auth) } + if err == nil { + err = errors.New("") + } // Encode! enc := json.NewEncoder(w) return enc.Encode(&JSONRequestEntry{ Type: "request", + Error: err.Error(), Auth: JSONAuth{ DisplayName: auth.DisplayName, @@ -106,6 +113,7 @@ type JSONRequestEntry struct { Type string `json:"type"` Auth JSONAuth `json:"auth"` Request JSONRequest `json:"request"` + Error string `json:"error"` } // JSONResponseEntry is the structure of a response audit log entry in JSON. diff --git a/audit/formatter.go b/audit/formatter.go index 9294d4ed3a..45f665ed4b 100644 --- a/audit/formatter.go +++ b/audit/formatter.go @@ -12,6 +12,6 @@ import ( // // It is recommended that you pass data through Hash prior to formatting it. type Formatter interface { - FormatRequest(io.Writer, *logical.Auth, *logical.Request) error + FormatRequest(io.Writer, *logical.Auth, *logical.Request, error) error FormatResponse(io.Writer, *logical.Auth, *logical.Request, *logical.Response, error) error } diff --git a/builtin/audit/file/backend.go b/builtin/audit/file/backend.go index c917354d9c..d99010daba 100644 --- a/builtin/audit/file/backend.go +++ b/builtin/audit/file/backend.go @@ -48,7 +48,7 @@ type Backend struct { f *os.File } -func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request) error { +func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request, outerErr error) error { if err := b.open(); err != nil { return err } @@ -76,7 +76,7 @@ func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request) error { } var format audit.FormatJSON - return format.FormatRequest(b.f, auth, req) + return format.FormatRequest(b.f, auth, req, outerErr) } func (b *Backend) LogResponse( diff --git a/builtin/audit/syslog/backend.go b/builtin/audit/syslog/backend.go index f0856e8b64..79f6eb740f 100644 --- a/builtin/audit/syslog/backend.go +++ b/builtin/audit/syslog/backend.go @@ -52,7 +52,7 @@ type Backend struct { logRaw bool } -func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request) error { +func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request, outerErr error) error { if !b.logRaw { // Copy the structures cp, err := copystructure.Copy(auth) @@ -79,7 +79,7 @@ func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request) error { // Encode the entry as JSON var buf bytes.Buffer var format audit.FormatJSON - if err := format.FormatRequest(&buf, auth, req); err != nil { + if err := format.FormatRequest(&buf, auth, req, outerErr); err != nil { return err } diff --git a/vault/audit.go b/vault/audit.go index ad1a157558..ac0dc27d62 100644 --- a/vault/audit.go +++ b/vault/audit.go @@ -261,7 +261,7 @@ func (a *AuditBroker) IsRegistered(name string) bool { // LogRequest is used to ensure all the audit backends have an opportunity to // log the given request and that *at least one* succeeds. -func (a *AuditBroker) LogRequest(auth *logical.Auth, req *logical.Request) error { +func (a *AuditBroker) LogRequest(auth *logical.Auth, req *logical.Request, outerErr error) error { defer metrics.MeasureSince([]string{"audit", "log_request"}, time.Now()) a.l.RLock() defer a.l.RUnlock() @@ -270,7 +270,7 @@ func (a *AuditBroker) LogRequest(auth *logical.Auth, req *logical.Request) error anyLogged := false for name, be := range a.backends { start := time.Now() - err := be.backend.LogRequest(auth, req) + err := be.backend.LogRequest(auth, req, outerErr) metrics.MeasureSince([]string{"audit", name, "log_request"}, start) if err != nil { a.logger.Printf("[ERR] audit: backend '%s' failed to log request: %v", name, err) diff --git a/vault/core.go b/vault/core.go index 3c67f63fad..3b0dd3d311 100644 --- a/vault/core.go +++ b/vault/core.go @@ -374,6 +374,7 @@ func (c *Core) HandleRequest(req *logical.Request) (resp *logical.Response, err func (c *Core) handleRequest(req *logical.Request) (*logical.Response, error) { defer metrics.MeasureSince([]string{"core", "handle_request"}, time.Now()) + // Validate the token auth, err := c.checkToken(req.Operation, req.Path, req.ClientToken) if err != nil { @@ -387,6 +388,11 @@ func (c *Core) handleRequest(req *logical.Request) (*logical.Response, error) { errType = logical.ErrInvalidRequest } + if err := c.auditBroker.LogRequest(auth, req, err); err != nil { + c.logger.Printf("[ERR] core: failed to audit request (%#v): %v", + req, err) + } + return logical.ErrorResponse(err.Error()), errType } @@ -394,7 +400,7 @@ func (c *Core) handleRequest(req *logical.Request) (*logical.Response, error) { req.DisplayName = auth.DisplayName // Create an audit trail of the request - if err := c.auditBroker.LogRequest(auth, req); err != nil { + if err := c.auditBroker.LogRequest(auth, req, errors.New("")); err != nil { c.logger.Printf("[ERR] core: failed to audit request (%#v): %v", req, err) return nil, ErrInternalError @@ -473,7 +479,7 @@ func (c *Core) handleLoginRequest(req *logical.Request) (*logical.Response, erro defer metrics.MeasureSince([]string{"core", "handle_login_request"}, time.Now()) // Create an audit trail of the request, auth is not available on login requests - if err := c.auditBroker.LogRequest(nil, req); err != nil { + if err := c.auditBroker.LogRequest(nil, req, errors.New("")); err != nil { c.logger.Printf("[ERR] core: failed to audit request (%#v): %v", req, err) return nil, ErrInternalError diff --git a/vault/testing.go b/vault/testing.go index 5bb4946eab..e1d1c4da7a 100644 --- a/vault/testing.go +++ b/vault/testing.go @@ -86,7 +86,7 @@ func TestKeyCopy(key []byte) []byte { type noopAudit struct{} -func (n *noopAudit) LogRequest(a *logical.Auth, r *logical.Request) error { +func (n *noopAudit) LogRequest(a *logical.Auth, r *logical.Request, e error) error { return nil } diff --git a/vault/token_store.go b/vault/token_store.go index 03f278c83c..af032ca422 100644 --- a/vault/token_store.go +++ b/vault/token_store.go @@ -656,13 +656,13 @@ func (ts *TokenStore) handleLookup( // Lookup the token out, err := ts.Lookup(id) + if err != nil { return logical.ErrorResponse(err.Error()), logical.ErrInvalidRequest } - // Fast-path the not found case if out == nil { - return nil, nil + return logical.ErrorResponse("bad token"), logical.ErrPermissionDenied } // Generate a response. We purposely omit the parent reference otherwise From 55e37392ad3af2f037e5fa41fba20c535bbccc43 Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Thu, 18 Jun 2015 19:48:00 -0700 Subject: [PATCH 03/19] Actually not logging auth in the response if nil --- audit/format_json.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/audit/format_json.go b/audit/format_json.go index cba7bc10b8..afa7e961d5 100644 --- a/audit/format_json.go +++ b/audit/format_json.go @@ -64,9 +64,9 @@ func (f *FormatJSON) FormatResponse( err = errors.New("") } - var respAuth JSONAuth + var respAuth *JSONAuth if resp.Auth != nil { - respAuth = JSONAuth{ + respAuth = &JSONAuth{ ClientToken: resp.Auth.ClientToken, DisplayName: resp.Auth.DisplayName, Policies: resp.Auth.Policies, @@ -74,9 +74,9 @@ func (f *FormatJSON) FormatResponse( } } - var respSecret JSONSecret + var respSecret *JSONSecret if resp.Secret != nil { - respSecret = JSONSecret{ + respSecret = &JSONSecret{ LeaseID: resp.Secret.LeaseID, } } @@ -133,8 +133,8 @@ type JSONRequest struct { } type JSONResponse struct { - Auth JSONAuth `json:"auth,omitempty"` - Secret JSONSecret `json:"secret,emitempty"` + Auth *JSONAuth `json:"auth,omitempty"` + Secret *JSONSecret `json:"secret,emitempty"` Data map[string]interface{} `json:"data"` Redirect string `json:"redirect"` } From fb3ee8838c61359b6a68424f0b113ce58e75a589 Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Thu, 18 Jun 2015 19:48:26 -0700 Subject: [PATCH 04/19] Collapsing audit response logging to a single point --- vault/core.go | 54 ++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/vault/core.go b/vault/core.go index 3b0dd3d311..d7ffe0b940 100644 --- a/vault/core.go +++ b/vault/core.go @@ -354,10 +354,12 @@ func (c *Core) HandleRequest(req *logical.Request) (resp *logical.Response, err return nil, ErrStandby } + var auth *logical.Auth + if c.router.LoginPath(req.Path) { - resp, err = c.handleLoginRequest(req) + resp, auth, err = c.handleLoginRequest(req) } else { - resp, err = c.handleRequest(req) + resp, auth, err = c.handleRequest(req) } // Ensure we don't leak internal data @@ -369,10 +371,18 @@ func (c *Core) HandleRequest(req *logical.Request) (resp *logical.Response, err resp.Auth.InternalData = nil } } + + // Create an audit trail of the response + if err := c.auditBroker.LogResponse(auth, req, resp, err); err != nil { + c.logger.Printf("[ERR] core: failed to audit response (request: %#v, response: %#v): %v", + req, resp, err) + return nil, ErrInternalError + } + return } -func (c *Core) handleRequest(req *logical.Request) (*logical.Response, error) { +func (c *Core) handleRequest(req *logical.Request) (*logical.Response, *logical.Auth, error) { defer metrics.MeasureSince([]string{"core", "handle_request"}, time.Now()) // Validate the token @@ -393,7 +403,7 @@ func (c *Core) handleRequest(req *logical.Request) (*logical.Response, error) { req, err) } - return logical.ErrorResponse(err.Error()), errType + return logical.ErrorResponse(err.Error()), nil, errType } // Attach the display name @@ -403,7 +413,7 @@ func (c *Core) handleRequest(req *logical.Request) (*logical.Response, error) { if err := c.auditBroker.LogRequest(auth, req, errors.New("")); err != nil { c.logger.Printf("[ERR] core: failed to audit request (%#v): %v", req, err) - return nil, ErrInternalError + return nil, auth, ErrInternalError } // Route the request @@ -428,7 +438,7 @@ func (c *Core) handleRequest(req *logical.Request) (*logical.Response, error) { c.logger.Printf( "[ERR] core: failed to register lease "+ "(request: %#v, response: %#v): %v", req, resp, err) - return nil, ErrInternalError + return nil, auth, ErrInternalError } resp.Secret.LeaseID = leaseID } @@ -441,7 +451,7 @@ func (c *Core) handleRequest(req *logical.Request) (*logical.Response, error) { c.logger.Printf( "[ERR] core: unexpected Auth response for non-token backend "+ "(request: %#v, response: %#v)", req, resp) - return nil, ErrInternalError + return nil, auth, ErrInternalError } // Set the default lease if non-provided, root tokens are exempt @@ -458,31 +468,24 @@ func (c *Core) handleRequest(req *logical.Request) (*logical.Response, error) { if err := c.expiration.RegisterAuth(req.Path, resp.Auth); err != nil { c.logger.Printf("[ERR] core: failed to register token lease "+ "(request: %#v, response: %#v): %v", req, resp, err) - return nil, ErrInternalError + return nil, auth, ErrInternalError } } - // Create an audit trail of the response - if err := c.auditBroker.LogResponse(auth, req, resp, err); err != nil { - c.logger.Printf("[ERR] core: failed to audit response (request: %#v, response: %#v): %v", - req, resp, err) - return nil, ErrInternalError - } - // Return the response and error - return resp, err + return resp, auth, err } // handleLoginRequest is used to handle a login request, which is an // unauthenticated request to the backend. -func (c *Core) handleLoginRequest(req *logical.Request) (*logical.Response, error) { +func (c *Core) handleLoginRequest(req *logical.Request) (*logical.Response, *logical.Auth, error) { defer metrics.MeasureSince([]string{"core", "handle_login_request"}, time.Now()) // Create an audit trail of the request, auth is not available on login requests if err := c.auditBroker.LogRequest(nil, req, errors.New("")); err != nil { c.logger.Printf("[ERR] core: failed to audit request (%#v): %v", req, err) - return nil, ErrInternalError + return nil, nil, ErrInternalError } // Route the request @@ -492,7 +495,7 @@ func (c *Core) handleLoginRequest(req *logical.Request) (*logical.Response, erro if resp != nil && resp.Secret != nil { c.logger.Printf("[ERR] core: unexpected Secret response for login path"+ "(request: %#v, response: %#v)", req, resp) - return nil, ErrInternalError + return nil, nil, ErrInternalError } // If the response generated an authentication, then generate the token @@ -517,7 +520,7 @@ func (c *Core) handleLoginRequest(req *logical.Request) (*logical.Response, erro } if err := c.tokenStore.Create(&te); err != nil { c.logger.Printf("[ERR] core: failed to create token: %v", err) - return nil, ErrInternalError + return nil, auth, ErrInternalError } // Populate the client token @@ -537,21 +540,14 @@ func (c *Core) handleLoginRequest(req *logical.Request) (*logical.Response, erro if err := c.expiration.RegisterAuth(req.Path, auth); err != nil { c.logger.Printf("[ERR] core: failed to register token lease "+ "(request: %#v, response: %#v): %v", req, resp, err) - return nil, ErrInternalError + return nil, auth, ErrInternalError } // Attach the display name, might be used by audit backends req.DisplayName = auth.DisplayName } - // Create an audit trail of the response - if err := c.auditBroker.LogResponse(auth, req, resp, err); err != nil { - c.logger.Printf("[ERR] core: failed to audit response (request: %#v, response: %#v): %v", - req, resp, err) - return nil, ErrInternalError - } - - return resp, err + return resp, auth, err } func (c *Core) checkToken( From f5ebc5cc3b3dee571b46e99fb6b7a8467dc8af76 Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Thu, 18 Jun 2015 20:14:20 -0700 Subject: [PATCH 05/19] Fixing tests --- audit/format_json_test.go | 10 ++++++++-- vault/audit_test.go | 15 +++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/audit/format_json_test.go b/audit/format_json_test.go index fdef20806d..88e1df0901 100644 --- a/audit/format_json_test.go +++ b/audit/format_json_test.go @@ -5,12 +5,14 @@ import ( "testing" "github.com/hashicorp/vault/logical" + "errors" ) func TestFormatJSON_formatRequest(t *testing.T) { cases := map[string]struct { Auth *logical.Auth Req *logical.Request + Err error Result string }{ "auth, request": { @@ -18,7 +20,11 @@ func TestFormatJSON_formatRequest(t *testing.T) { &logical.Request{ Operation: logical.WriteOperation, Path: "/foo", + Connection: &logical.Connection{ + RemoteAddr: "127.0.0.1", + }, }, + errors.New("this is an error"), testFormatJSONReqBasicStr, }, } @@ -26,7 +32,7 @@ func TestFormatJSON_formatRequest(t *testing.T) { for name, tc := range cases { var buf bytes.Buffer var format FormatJSON - if err := format.FormatRequest(&buf, tc.Auth, tc.Req); err != nil { + if err := format.FormatRequest(&buf, tc.Auth, tc.Req, tc.Err); err != nil { t.Fatalf("bad: %s\nerr: %s", name, err) } @@ -38,5 +44,5 @@ func TestFormatJSON_formatRequest(t *testing.T) { } } -const testFormatJSONReqBasicStr = `{"type":"request","auth":{"display_name":"","policies":["root"],"metadata":null},"request":{"operation":"write","path":"/foo","data":null}} +const testFormatJSONReqBasicStr = `{"type":"request","auth":{"display_name":"","policies":["root"],"metadata":null},"request":{"operation":"write","path":"/foo","data":null,"remote_address":"127.0.0.1"},"error":"this is an error"} ` diff --git a/vault/audit_test.go b/vault/audit_test.go index 56c71197dd..f4e484806b 100644 --- a/vault/audit_test.go +++ b/vault/audit_test.go @@ -10,12 +10,14 @@ import ( "github.com/hashicorp/vault/audit" "github.com/hashicorp/vault/logical" + "errors" ) type NoopAudit struct { ReqErr error ReqAuth []*logical.Auth Req []*logical.Request + ReqErrs []error RespErr error RespAuth []*logical.Auth @@ -24,9 +26,10 @@ type NoopAudit struct { RespErrs []error } -func (n *NoopAudit) LogRequest(a *logical.Auth, r *logical.Request) error { +func (n *NoopAudit) LogRequest(a *logical.Auth, r *logical.Request, err error) error { n.ReqAuth = append(n.ReqAuth, a) n.Req = append(n.Req, r) + n.ReqErrs = append(n.ReqErrs, err) return n.ReqErr } @@ -203,8 +206,9 @@ func TestAuditBroker_LogRequest(t *testing.T) { Operation: logical.ReadOperation, Path: "sys/mounts", } + reqErrs := errors.New("errs") - err := b.LogRequest(auth, req) + err := b.LogRequest(auth, req, reqErrs) if err != nil { t.Fatalf("err: %v", err) } @@ -216,17 +220,20 @@ func TestAuditBroker_LogRequest(t *testing.T) { if !reflect.DeepEqual(a.Req[0], req) { t.Fatalf("Bad: %#v", a.Req[0]) } + if !reflect.DeepEqual(a.ReqErrs[0], reqErrs) { + t.Fatalf("Bad: %#v", a.ReqErrs[0]) + } } // Should still work with one failing backend a1.ReqErr = fmt.Errorf("failed") - if err := b.LogRequest(auth, req); err != nil { + if err := b.LogRequest(auth, req, nil); err != nil { t.Fatalf("err: %v", err) } // Should FAIL work with both failing backends a2.ReqErr = fmt.Errorf("failed") - if err := b.LogRequest(auth, req); err.Error() != "no audit backend succeeded in logging the request" { + if err := b.LogRequest(auth, req, nil); err.Error() != "no audit backend succeeded in logging the request" { t.Fatalf("err: %v", err) } } From ed0853ce18442c16a9bc192dc963198b74cf9371 Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Fri, 19 Jun 2015 13:56:44 -0700 Subject: [PATCH 06/19] Doing a little better with http response codes --- http/handler.go | 21 ++++++++++++++++++--- vault/router.go | 4 ++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/http/handler.go b/http/handler.go index 56ba8e0aab..efaf3375a2 100644 --- a/http/handler.go +++ b/http/handler.go @@ -80,7 +80,7 @@ func request(core *vault.Core, w http.ResponseWriter, rawReq *http.Request, r *l respondStandby(core, w, rawReq.URL) return resp, false } - if respondCommon(w, resp) { + if respondCommon(w, resp, err) { return resp, false } if err != nil { @@ -168,14 +168,29 @@ func respondError(w http.ResponseWriter, status int, err error) { enc.Encode(resp) } -func respondCommon(w http.ResponseWriter, resp *logical.Response) bool { +func respondCommon(w http.ResponseWriter, resp *logical.Response, err error) bool { if resp == nil { return false } if resp.IsError() { + var statusCode int + + switch err { + case logical.ErrPermissionDenied: + statusCode = http.StatusForbidden + case logical.ErrUnsupportedOperation: + statusCode = http.StatusMethodNotAllowed + case logical.ErrUnsupportedPath: + statusCode = http.StatusNotFound + case logical.ErrInvalidRequest: + statusCode = http.StatusBadRequest + default: + statusCode = http.StatusBadRequest + } + err := fmt.Errorf("%s", resp.Data["error"].(string)) - respondError(w, http.StatusBadRequest, err) + respondError(w, statusCode, err) return true } diff --git a/vault/router.go b/vault/router.go index 653d5aa5dc..c5b3c4667d 100644 --- a/vault/router.go +++ b/vault/router.go @@ -156,7 +156,7 @@ func (r *Router) Route(req *logical.Request) (*logical.Response, error) { } r.l.RUnlock() if !ok { - return nil, fmt.Errorf("no handler for route '%s'", req.Path) + return logical.ErrorResponse(fmt.Sprintf("no handler for route '%s'", req.Path)), logical.ErrUnsupportedPath } defer metrics.MeasureSince([]string{"route", string(req.Operation), strings.Replace(mount, "/", "-", -1)}, time.Now()) @@ -168,7 +168,7 @@ func (r *Router) Route(req *logical.Request) (*logical.Response, error) { switch req.Operation { case logical.RevokeOperation, logical.RollbackOperation: default: - return nil, fmt.Errorf("no handler for route '%s'", req.Path) + return logical.ErrorResponse(fmt.Sprintf("no handler for route '%s'", req.Path)), logical.ErrUnsupportedPath } } From a6b70d04d46fc9004fe74714786d16d3480f10c5 Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Fri, 19 Jun 2015 14:04:32 -0700 Subject: [PATCH 07/19] Fixing tests --- vault/router_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vault/router_test.go b/vault/router_test.go index 8087344cc9..522fe38de2 100644 --- a/vault/router_test.go +++ b/vault/router_test.go @@ -115,7 +115,7 @@ func TestRouter_Unmount(t *testing.T) { Path: "prod/aws/foo", } _, err = r.Route(req) - if !strings.Contains(err.Error(), "no handler for route") { + if !strings.Contains(err.Error(), "unsupported path") { t.Fatalf("err: %v", err) } } @@ -145,7 +145,7 @@ func TestRouter_Remount(t *testing.T) { Path: "prod/aws/foo", } _, err = r.Route(req) - if !strings.Contains(err.Error(), "no handler for route") { + if !strings.Contains(err.Error(), "unsupported path") { t.Fatalf("err: %v", err) } @@ -258,7 +258,7 @@ func TestRouter_Taint(t *testing.T) { Path: "prod/aws/foo", } _, err = r.Route(req) - if err.Error() != "no handler for route 'prod/aws/foo'" { + if err.Error() != "unsupported path" { t.Fatalf("err: %v", err) } From 74013ac751fe83a32d05f88848cd7b26cf234b5b Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Wed, 24 Jun 2015 10:57:05 -0700 Subject: [PATCH 08/19] Fixing key-status if audit logging is on --- vault/logical_system.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vault/logical_system.go b/vault/logical_system.go index 6673226d0a..12d521b4a6 100644 --- a/vault/logical_system.go +++ b/vault/logical_system.go @@ -741,7 +741,7 @@ func (b *SystemBackend) handleKeyStatus( resp := &logical.Response{ Data: map[string]interface{}{ "term": info.Term, - "install_time": info.InstallTime, + "install_time": info.InstallTime.Format(time.RFC3339), }, } return resp, nil From de6ce89c399c5724b0b6d31020bd9870a4220865 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 29 Jun 2015 14:50:55 -0700 Subject: [PATCH 09/19] Fixing merge conflict --- Godeps/Godeps.json | 23 +- .../aws/aws-sdk-go/internal/apierr/error.go | 139 - .../{vanackere => go-ldap}/ldap/.gitignore | 0 .../src/github.com/go-ldap/ldap/.travis.yml | 12 + .../asn1-ber => go-ldap/ldap}/LICENSE | 0 .../src/github.com/go-ldap/ldap/README.md | 48 + .../src/github.com/go-ldap/ldap/bind.go | 135 + .../{vanackere => go-ldap}/ldap/conn.go | 200 +- .../{vanackere => go-ldap}/ldap/control.go | 153 +- .../{vanackere => go-ldap}/ldap/debug.go | 2 +- .../src/github.com/go-ldap/ldap/dn.go | 155 + .../src/github.com/go-ldap/ldap/dn_test.go | 70 + .../examples/beherappolicy/beherappolicy.go | 60 + .../ldap/examples/enterprise.ldif | 0 .../examples/passwdmodify/passwdmodify.go | 125 + .../searchStartTLS/searchStartTLS.go} | 29 +- .../ldap/examples/slapd.conf | 0 .../ldap/examples/vchuppolicy/vchuppolicy.go | 63 + .../{vanackere => go-ldap}/ldap/filter.go | 111 +- .../ldap/filter_test.go | 47 +- .../{vanackere => go-ldap}/ldap/ldap.go | 158 +- .../src/github.com/go-ldap/ldap/ldap_test.go | 226 + .../{vanackere => go-ldap}/ldap/modify.go | 10 +- .../github.com/go-ldap/ldap/passwdmodify.go | 137 + .../{vanackere => go-ldap}/ldap/search.go | 35 +- .../src/github.com/go-ldap/ldap/todo | 19 + .../src/github.com/ugorji/go/codec/0doc.go | 150 + .../src/github.com/ugorji/go/codec/README.md | 148 + .../src/github.com/ugorji/go/codec/binc.go | 901 + .../src/github.com/ugorji/go/codec/cbor.go | 566 + .../github.com/ugorji/go/codec/cbor_test.go | 205 + .../github.com/ugorji/go/codec/codec_test.go | 1117 + .../ugorji/go/codec/codecgen/README.md | 36 + .../ugorji/go/codec/codecgen/gen.go | 271 + .../github.com/ugorji/go/codec/codecgen/z.go | 3 + .../ugorji/go/codec/codecgen_test.go | 22 + .../src/github.com/ugorji/go/codec/decode.go | 1550 + .../src/github.com/ugorji/go/codec/encode.go | 1232 + .../ugorji/go/codec/fast-path.generated.go | 28307 ++++++++++++++++ .../ugorji/go/codec/fast-path.go.tmpl | 442 + .../ugorji/go/codec/gen-dec-array.go.tmpl | 77 + .../ugorji/go/codec/gen-dec-map.go.tmpl | 46 + .../ugorji/go/codec/gen-helper.generated.go | 102 + .../ugorji/go/codec/gen-helper.go.tmpl | 250 + .../ugorji/go/codec/gen.generated.go | 136 + .../src/github.com/ugorji/go/codec/gen.go | 1709 + .../src/github.com/ugorji/go/codec/helper.go | 846 + .../ugorji/go/codec/helper_internal.go | 151 + .../ugorji/go/codec/helper_not_unsafe.go | 20 + .../github.com/ugorji/go/codec/helper_test.go | 155 + .../ugorji/go/codec/helper_unsafe.go | 39 + .../src/github.com/ugorji/go/codec/json.go | 924 + .../src/github.com/ugorji/go/codec/msgpack.go | 843 + .../src/github.com/ugorji/go/codec/noop.go | 164 + .../github.com/ugorji/go/codec/prebuild.go | 3 + .../github.com/ugorji/go/codec/prebuild.sh | 191 + .../src/github.com/ugorji/go/codec/py_test.go | 29 + .../src/github.com/ugorji/go/codec/rpc.go | 169 + .../src/github.com/ugorji/go/codec/simple.go | 505 + .../ugorji/go/codec/test-cbor-goldens.json | 639 + .../src/github.com/ugorji/go/codec/test.py | 119 + .../src/github.com/ugorji/go/codec/time.go | 193 + .../github.com/ugorji/go/codec/values_test.go | 198 + .../src/github.com/vanackere/ldap/.travis.yml | 12 - .../src/github.com/vanackere/ldap/README.md | 37 - .../src/github.com/vanackere/ldap/bind.go | 55 - .../vanackere/ldap/examples/modify.go | 91 - .../vanackere/ldap/examples/search.go | 54 - .../vanackere/ldap/examples/searchSSL.go | 47 - .../github.com/vanackere/ldap/ldap_test.go | 123 - .../asn1-ber.v1}/.travis.yml | 0 .../ldap => gopkg.in/asn1-ber.v1}/LICENSE | 0 .../asn1-ber.v1}/README.md | 2 +- .../asn1-ber => gopkg.in/asn1-ber.v1}/ber.go | 0 .../asn1-ber.v1}/ber_test.go | 0 builtin/credential/ldap/backend.go | 48 +- builtin/credential/ldap/backend_test.go | 17 + builtin/credential/ldap/path_config.go | 6 +- builtin/credential/ldap/path_groups.go | 2 +- builtin/credential/ldap/path_login.go | 2 +- 80 files changed, 44128 insertions(+), 783 deletions(-) delete mode 100644 Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/apierr/error.go rename Godeps/_workspace/src/github.com/{vanackere => go-ldap}/ldap/.gitignore (100%) create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/.travis.yml rename Godeps/_workspace/src/github.com/{vanackere/asn1-ber => go-ldap/ldap}/LICENSE (100%) create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/README.md create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/bind.go rename Godeps/_workspace/src/github.com/{vanackere => go-ldap}/ldap/conn.go (58%) rename Godeps/_workspace/src/github.com/{vanackere => go-ldap}/ldap/control.go (52%) rename Godeps/_workspace/src/github.com/{vanackere => go-ldap}/ldap/debug.go (91%) create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/dn.go create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/dn_test.go create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/examples/beherappolicy/beherappolicy.go rename Godeps/_workspace/src/github.com/{vanackere => go-ldap}/ldap/examples/enterprise.ldif (100%) create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/examples/passwdmodify/passwdmodify.go rename Godeps/_workspace/src/github.com/{vanackere/ldap/examples/searchTLS.go => go-ldap/ldap/examples/searchStartTLS/searchStartTLS.go} (58%) rename Godeps/_workspace/src/github.com/{vanackere => go-ldap}/ldap/examples/slapd.conf (100%) create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/examples/vchuppolicy/vchuppolicy.go rename Godeps/_workspace/src/github.com/{vanackere => go-ldap}/ldap/filter.go (66%) rename Godeps/_workspace/src/github.com/{vanackere => go-ldap}/ldap/filter_test.go (65%) rename Godeps/_workspace/src/github.com/{vanackere => go-ldap}/ldap/ldap.go (71%) create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/ldap_test.go rename Godeps/_workspace/src/github.com/{vanackere => go-ldap}/ldap/modify.go (94%) create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/passwdmodify.go rename Godeps/_workspace/src/github.com/{vanackere => go-ldap}/ldap/search.go (92%) create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/todo create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/0doc.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/README.md create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/binc.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/cbor.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/cbor_test.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/codec_test.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/README.md create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/gen.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/z.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen_test.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/decode.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/encode.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/fast-path.generated.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/fast-path.go.tmpl create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/gen-dec-array.go.tmpl create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/gen-dec-map.go.tmpl create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/gen-helper.generated.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/gen-helper.go.tmpl create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/gen.generated.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/gen.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/helper.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/helper_internal.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/helper_not_unsafe.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/helper_test.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/helper_unsafe.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/json.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/msgpack.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/noop.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/prebuild.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/prebuild.sh create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/py_test.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/rpc.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/simple.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/test-cbor-goldens.json create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/test.py create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/time.go create mode 100644 Godeps/_workspace/src/github.com/ugorji/go/codec/values_test.go delete mode 100644 Godeps/_workspace/src/github.com/vanackere/ldap/.travis.yml delete mode 100644 Godeps/_workspace/src/github.com/vanackere/ldap/README.md delete mode 100644 Godeps/_workspace/src/github.com/vanackere/ldap/bind.go delete mode 100644 Godeps/_workspace/src/github.com/vanackere/ldap/examples/modify.go delete mode 100644 Godeps/_workspace/src/github.com/vanackere/ldap/examples/search.go delete mode 100644 Godeps/_workspace/src/github.com/vanackere/ldap/examples/searchSSL.go delete mode 100644 Godeps/_workspace/src/github.com/vanackere/ldap/ldap_test.go rename Godeps/_workspace/src/{github.com/vanackere/asn1-ber => gopkg.in/asn1-ber.v1}/.travis.yml (100%) rename Godeps/_workspace/src/{github.com/vanackere/ldap => gopkg.in/asn1-ber.v1}/LICENSE (100%) rename Godeps/_workspace/src/{github.com/vanackere/asn1-ber => gopkg.in/asn1-ber.v1}/README.md (61%) rename Godeps/_workspace/src/{github.com/vanackere/asn1-ber => gopkg.in/asn1-ber.v1}/ber.go (100%) rename Godeps/_workspace/src/{github.com/vanackere/asn1-ber => gopkg.in/asn1-ber.v1}/ber_test.go (100%) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index b72705bf9e..16c84ceb67 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -18,11 +18,6 @@ "Comment": "v0.6.0", "Rev": "ea83c25c44525da47e8044bbd21e4045758ea39b" }, - { - "ImportPath": "github.com/aws/aws-sdk-go/internal/apierr", - "Comment": "v0.6.0", - "Rev": "ea83c25c44525da47e8044bbd21e4045758ea39b" - }, { "ImportPath": "github.com/aws/aws-sdk-go/internal/endpoints", "Comment": "v0.6.0", @@ -66,6 +61,11 @@ { "ImportPath": "github.com/fatih/structs", "Rev": "a9f7daa9c2729e97450c2da2feda19130a367d8f" + }, + { + "ImportPath": "github.com/go-ldap/ldap", + "Comment": "v1-8-g4d41e0d", + "Rev": "4d41e0d546efa36b1500653d519d1b39fc007dbd" }, { "ImportPath": "github.com/go-sql-driver/mysql", @@ -168,12 +168,8 @@ "Rev": "d0e0d8e11f318e000a8cc434616d69e329edc374" }, { - "ImportPath": "github.com/vanackere/asn1-ber", - "Rev": "295c7b21db5d9525ad959e3382610f3aff029663" - }, - { - "ImportPath": "github.com/vanackere/ldap", - "Rev": "e29b797d1abde6567ccb4ab56236e033cabf845a" + "ImportPath": "github.com/ugorji/go/codec", + "Rev": "821cda7e48749cacf7cad2c6ed01e96457ca7e9d" }, { "ImportPath": "github.com/vaughan0/go-ini", @@ -190,6 +186,11 @@ { "ImportPath": "golang.org/x/oauth2", "Rev": "ec6d5d770f531108a6464462b2201b74fcd09314" + }, + { + "ImportPath": "gopkg.in/asn1-ber.v1", + "Comment": "v1", + "Rev": "9eae18c3681ae3d3c677ac2b80a8fe57de45fc09" } ] } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/apierr/error.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/apierr/error.go deleted file mode 100644 index c45555a9f0..0000000000 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/apierr/error.go +++ /dev/null @@ -1,139 +0,0 @@ -// Package apierr represents API error types. -package apierr - -import "fmt" - -// A BaseError wraps the code and message which defines an error. It also -// can be used to wrap an original error object. -// -// Should be used as the root for errors satisfying the awserr.Error. Also -// for any error which does not fit into a specific error wrapper type. -type BaseError struct { - // Classification of error - code string - - // Detailed information about error - message string - - // Optional original error this error is based off of. Allows building - // chained errors. - origErr error -} - -// New returns an error object for the code, message, and err. -// -// code is a short no whitespace phrase depicting the classification of -// the error that is being created. -// -// message is the free flow string containing detailed information about the error. -// -// origErr is the error object which will be nested under the new error to be returned. -func New(code, message string, origErr error) *BaseError { - return &BaseError{ - code: code, - message: message, - origErr: origErr, - } -} - -// Error returns the string representation of the error. -// -// See ErrorWithExtra for formatting. -// -// Satisfies the error interface. -func (b *BaseError) Error() string { - return b.ErrorWithExtra("") -} - -// String returns the string representation of the error. -// Alias for Error to satisfy the stringer interface. -func (b *BaseError) String() string { - return b.Error() -} - -// Code returns the short phrase depicting the classification of the error. -func (b *BaseError) Code() string { - return b.code -} - -// Message returns the error details message. -func (b *BaseError) Message() string { - return b.message -} - -// OrigErr returns the original error if one was set. Nil is returned if no error -// was set. -func (b *BaseError) OrigErr() error { - return b.origErr -} - -// ErrorWithExtra is a helper method to add an extra string to the stratified -// error message. The extra message will be added on the next line below the -// error message like the following: -// -// : -// -// -// If there is a original error the error will be included on a new line. -// -// : -// -// caused by: -func (b *BaseError) ErrorWithExtra(extra string) string { - msg := fmt.Sprintf("%s: %s", b.code, b.message) - if extra != "" { - msg = fmt.Sprintf("%s\n\t%s", msg, extra) - } - if b.origErr != nil { - msg = fmt.Sprintf("%s\ncaused by: %s", msg, b.origErr.Error()) - } - return msg -} - -// A RequestError wraps a request or service error. -// -// Composed of BaseError for code, message, and original error. -type RequestError struct { - *BaseError - statusCode int - requestID string -} - -// NewRequestError returns a wrapped error with additional information for request -// status code, and service requestID. -// -// Should be used to wrap all request which involve service requests. Even if -// the request failed without a service response, but had an HTTP status code -// that may be meaningful. -// -// Also wraps original errors via the BaseError. -func NewRequestError(base *BaseError, statusCode int, requestID string) *RequestError { - return &RequestError{ - BaseError: base, - statusCode: statusCode, - requestID: requestID, - } -} - -// Error returns the string representation of the error. -// Satisfies the error interface. -func (r *RequestError) Error() string { - return r.ErrorWithExtra(fmt.Sprintf("status code: %d, request id: [%s]", - r.statusCode, r.requestID)) -} - -// String returns the string representation of the error. -// Alias for Error to satisfy the stringer interface. -func (r *RequestError) String() string { - return r.Error() -} - -// StatusCode returns the wrapped status code for the error -func (r *RequestError) StatusCode() int { - return r.statusCode -} - -// RequestID returns the wrapped requestID -func (r *RequestError) RequestID() string { - return r.requestID -} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/.gitignore b/Godeps/_workspace/src/github.com/go-ldap/ldap/.gitignore similarity index 100% rename from Godeps/_workspace/src/github.com/vanackere/ldap/.gitignore rename to Godeps/_workspace/src/github.com/go-ldap/ldap/.gitignore diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/.travis.yml b/Godeps/_workspace/src/github.com/go-ldap/ldap/.travis.yml new file mode 100644 index 0000000000..f90ee667c0 --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/.travis.yml @@ -0,0 +1,12 @@ +language: go +go: + - 1.2 + - 1.3 + - tip +install: + - go get gopkg.in/asn1-ber.v1 + - go get gopkg.in/ldap.v1 + - go get code.google.com/p/go.tools/cmd/cover || go get golang.org/x/tools/cmd/cover + - go build -v ./... +script: + - go test -v -cover ./... diff --git a/Godeps/_workspace/src/github.com/vanackere/asn1-ber/LICENSE b/Godeps/_workspace/src/github.com/go-ldap/ldap/LICENSE similarity index 100% rename from Godeps/_workspace/src/github.com/vanackere/asn1-ber/LICENSE rename to Godeps/_workspace/src/github.com/go-ldap/ldap/LICENSE diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/README.md b/Godeps/_workspace/src/github.com/go-ldap/ldap/README.md new file mode 100644 index 0000000000..c940520461 --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/README.md @@ -0,0 +1,48 @@ +[![GoDoc](https://godoc.org/gopkg.in/ldap.v1?status.svg)](https://godoc.org/gopkg.in/ldap.v1) [![Build Status](https://travis-ci.org/go-ldap/ldap.svg)](https://travis-ci.org/go-ldap/ldap) + +# Basic LDAP v3 functionality for the GO programming language. + +## Required Librarys: + + - gopkg.in/asn1-ber.v1 + +## Working: + + - Connecting to LDAP server + - Binding to LDAP server + - Searching for entries + - Compiling string filters to LDAP filters + - Paging Search Results + - Modify Requests / Responses + +## Examples: + + - search + - modify + +## Tests Implemented: + + - Filter Compile / Decompile + +## TODO: + + - Add Requests / Responses + - Delete Requests / Responses + - Modify DN Requests / Responses + - Compare Requests / Responses + - Implement Tests / Benchmarks + +--- +This feature is disabled at the moment, because in some cases the "Search Request Done" packet will be handled before the last "Search Request Entry": + + - Mulitple internal goroutines to handle network traffic + Makes library goroutine safe + Can perform multiple search requests at the same time and return + the results to the proper goroutine. All requests are blocking requests, + so the goroutine does not need special handling + +--- + +The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/) +The design is licensed under the Creative Commons 3.0 Attributions license. +Read this article for more details: http://blog.golang.org/gopher diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/bind.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/bind.go new file mode 100644 index 0000000000..4ad4b896c2 --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/bind.go @@ -0,0 +1,135 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ldap + +import ( + "errors" + + "gopkg.in/asn1-ber.v1" +) + +type SimpleBindRequest struct { + Username string + Password string + Controls []Control +} + +type SimpleBindResult struct { + Controls []Control +} + +func NewSimpleBindRequest(username string, password string, controls []Control) *SimpleBindRequest { + return &SimpleBindRequest{ + Username: username, + Password: password, + Controls: controls, + } +} + +func (bindRequest *SimpleBindRequest) encode() *ber.Packet { + request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationBindRequest, nil, "Bind Request") + request.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, 3, "Version")) + request.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, bindRequest.Username, "User Name")) + request.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, 0, bindRequest.Password, "Password")) + + request.AppendChild(encodeControls(bindRequest.Controls)) + + return request +} + +func (l *Conn) SimpleBind(simpleBindRequest *SimpleBindRequest) (*SimpleBindResult, error) { + messageID := l.nextMessageID() + + packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") + packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, messageID, "MessageID")) + encodedBindRequest := simpleBindRequest.encode() + packet.AppendChild(encodedBindRequest) + + if l.Debug { + ber.PrintPacket(packet) + } + + channel, err := l.sendMessage(packet) + if err != nil { + return nil, err + } + if channel == nil { + return nil, NewError(ErrorNetwork, errors.New("ldap: could not send message")) + } + defer l.finishMessage(messageID) + + packet = <-channel + if packet == nil { + return nil, NewError(ErrorNetwork, errors.New("ldap: could not retrieve response")) + } + + if l.Debug { + if err := addLDAPDescriptions(packet); err != nil { + return nil, err + } + ber.PrintPacket(packet) + } + + result := &SimpleBindResult{ + Controls: make([]Control, 0), + } + + if len(packet.Children) == 3 { + for _, child := range packet.Children[2].Children { + result.Controls = append(result.Controls, DecodeControl(child)) + } + } + + resultCode, resultDescription := getLDAPResultCode(packet) + if resultCode != 0 { + return result, NewError(resultCode, errors.New(resultDescription)) + } + + return result, nil +} + +func (l *Conn) Bind(username, password string) error { + messageID := l.nextMessageID() + + packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") + packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, messageID, "MessageID")) + bindRequest := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationBindRequest, nil, "Bind Request") + bindRequest.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, 3, "Version")) + bindRequest.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, username, "User Name")) + bindRequest.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, 0, password, "Password")) + packet.AppendChild(bindRequest) + + if l.Debug { + ber.PrintPacket(packet) + } + + channel, err := l.sendMessage(packet) + if err != nil { + return err + } + if channel == nil { + return NewError(ErrorNetwork, errors.New("ldap: could not send message")) + } + defer l.finishMessage(messageID) + + packet = <-channel + if packet == nil { + return NewError(ErrorNetwork, errors.New("ldap: could not retrieve response")) + } + + if l.Debug { + if err := addLDAPDescriptions(packet); err != nil { + return err + } + ber.PrintPacket(packet) + } + + resultCode, resultDescription := getLDAPResultCode(packet) + if resultCode != 0 { + return NewError(resultCode, errors.New(resultDescription)) + } + + return nil +} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/conn.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go similarity index 58% rename from Godeps/_workspace/src/github.com/vanackere/ldap/conn.go rename to Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go index 0e28a107fe..d4b1027be3 100644 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/conn.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go @@ -7,11 +7,13 @@ package ldap import ( "crypto/tls" "errors" + "flag" + "fmt" + "gopkg.in/asn1-ber.v1" "log" "net" "sync" - - "github.com/vanackere/asn1-ber" + "time" ) const ( @@ -23,71 +25,101 @@ const ( type messagePacket struct { Op int - MessageID uint64 + MessageID int64 Packet *ber.Packet Channel chan *ber.Packet } +type sendMessageFlags uint + +const ( + startTLS sendMessageFlags = 1 << iota +) + // Conn represents an LDAP Connection type Conn struct { - conn net.Conn - isTLS bool - Debug debugging - chanConfirm chan bool - chanResults map[uint64]chan *ber.Packet - chanMessage chan *messagePacket - chanMessageID chan uint64 - wgSender sync.WaitGroup - chanDone chan struct{} - once sync.Once + conn net.Conn + isTLS bool + isClosing bool + isStartingTLS bool + Debug debugging + chanConfirm chan bool + chanResults map[int64]chan *ber.Packet + chanMessage chan *messagePacket + chanMessageID chan int64 + wgSender sync.WaitGroup + wgClose sync.WaitGroup + once sync.Once + outstandingRequests uint + messageMutex sync.Mutex +} + +var ldapTimeout time.Duration + +func init() { + var timeoutVar string + flag.StringVar(&timeoutVar, "ldapConnectionTimeout", "60s", "Default connection timeout for ldap") + flag.Parse() + timeout, err := time.ParseDuration(timeoutVar) + if err != nil { + ldapTimeout = 60 * time.Second + return + } + ldapTimeout = timeout + return } // Dial connects to the given address on the given network using net.Dial // and then returns a new Conn for the connection. func Dial(network, addr string) (*Conn, error) { - c, err := net.Dial(network, addr) + c, err := net.DialTimeout(network, addr, ldapTimeout) if err != nil { return nil, NewError(ErrorNetwork, err) } - conn := NewConn(c) - conn.start() + conn := NewConn(c, false) + conn.Start() return conn, nil } // DialTLS connects to the given address on the given network using tls.Dial // and then returns a new Conn for the connection. func DialTLS(network, addr string, config *tls.Config) (*Conn, error) { - c, err := tls.Dial(network, addr, config) + dc, err := net.DialTimeout(network, addr, ldapTimeout) if err != nil { return nil, NewError(ErrorNetwork, err) } - conn := NewConn(c) - conn.isTLS = true - conn.start() + c := tls.Client(dc, config) + err = c.Handshake() + if err != nil { + return nil, NewError(ErrorNetwork, err) + } + conn := NewConn(c, true) + conn.Start() return conn, nil } // NewConn returns a new Conn using conn for network I/O. -func NewConn(conn net.Conn) *Conn { +func NewConn(conn net.Conn, isTLS bool) *Conn { return &Conn{ conn: conn, chanConfirm: make(chan bool), - chanMessageID: make(chan uint64), + chanMessageID: make(chan int64), chanMessage: make(chan *messagePacket, 10), - chanResults: map[uint64]chan *ber.Packet{}, - chanDone: make(chan struct{}), + chanResults: map[int64]chan *ber.Packet{}, + isTLS: isTLS, } } -func (l *Conn) start() { +func (l *Conn) Start() { go l.reader() go l.processMessages() + l.wgClose.Add(1) } // Close closes the connection. func (l *Conn) Close() { l.once.Do(func() { - close(l.chanDone) + l.isClosing = true l.wgSender.Wait() l.Debug.Printf("Sending quit message and waiting for confirmation") @@ -99,12 +131,14 @@ func (l *Conn) Close() { if err := l.conn.Close(); err != nil { log.Print(err) } + + l.wgClose.Done() }) - <-l.chanDone + l.wgClose.Wait() } // Returns the next available messageID -func (l *Conn) nextMessageID() uint64 { +func (l *Conn) nextMessageID() int64 { if l.chanMessageID != nil { if messageID, ok := <-l.chanMessageID; ok { return messageID @@ -122,24 +156,28 @@ func (l *Conn) StartTLS(config *tls.Config) error { } packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") - packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, int64(messageID), "MessageID")) + packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, messageID, "MessageID")) request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationExtendedRequest, nil, "Start TLS") request.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, 0, "1.3.6.1.4.1.1466.20037", "TLS Extended Command")) packet.AppendChild(request) l.Debug.PrintPacket(packet) - _, err := l.conn.Write(packet.Bytes()) + channel, err := l.sendMessageWithFlags(packet, startTLS) if err != nil { - return NewError(ErrorNetwork, err) + return err + } + if channel == nil { + return NewError(ErrorNetwork, errors.New("ldap: could not send message")) } - packet, err = ber.ReadPacket(l.conn) - if err != nil { - return NewError(ErrorNetwork, err) - } + l.Debug.Printf("%d: waiting for response", messageID) + packet = <-channel + l.Debug.Printf("%d: got response %p", messageID, packet) + l.finishMessage(messageID) if l.Debug { if err := addLDAPDescriptions(packet); err != nil { + l.Close() return err } ber.PrintPacket(packet) @@ -147,30 +185,50 @@ func (l *Conn) StartTLS(config *tls.Config) error { if packet.Children[1].Children[0].Value.(int64) == 0 { conn := tls.Client(l.conn, config) + + if err := conn.Handshake(); err != nil { + l.Close() + return NewError(ErrorNetwork, fmt.Errorf("TLS handshake failed (%v)", err)) + } + l.isTLS = true l.conn = conn } + go l.reader() return nil } -func (l *Conn) closing() bool { - select { - case <-l.chanDone: - return true - default: - return false - } +func (l *Conn) sendMessage(packet *ber.Packet) (chan *ber.Packet, error) { + return l.sendMessageWithFlags(packet, 0) } -func (l *Conn) sendMessage(packet *ber.Packet) (chan *ber.Packet, error) { - if l.closing() { +func (l *Conn) sendMessageWithFlags(packet *ber.Packet, flags sendMessageFlags) (chan *ber.Packet, error) { + if l.isClosing { return nil, NewError(ErrorNetwork, errors.New("ldap: connection closed")) } + l.messageMutex.Lock() + l.Debug.Printf("flags&startTLS = %d", flags&startTLS) + if l.isStartingTLS { + l.messageMutex.Unlock() + return nil, NewError(ErrorNetwork, errors.New("ldap: connection is in startls phase.")) + } + if flags&startTLS != 0 { + if l.outstandingRequests != 0 { + l.messageMutex.Unlock() + return nil, NewError(ErrorNetwork, errors.New("ldap: cannot StartTLS with outstanding requests")) + } else { + l.isStartingTLS = true + } + } + l.outstandingRequests++ + + l.messageMutex.Unlock() + out := make(chan *ber.Packet) message := &messagePacket{ Op: MessageRequest, - MessageID: uint64(packet.Children[0].Value.(int64)), + MessageID: packet.Children[0].Value.(int64), Packet: packet, Channel: out, } @@ -178,10 +236,18 @@ func (l *Conn) sendMessage(packet *ber.Packet) (chan *ber.Packet, error) { return out, nil } -func (l *Conn) finishMessage(messageID uint64) { - if l.closing() { +func (l *Conn) finishMessage(messageID int64) { + if l.isClosing { return } + + l.messageMutex.Lock() + l.outstandingRequests-- + if l.isStartingTLS { + l.isStartingTLS = false + } + l.messageMutex.Unlock() + message := &messagePacket{ Op: MessageFinish, MessageID: messageID, @@ -190,18 +256,20 @@ func (l *Conn) finishMessage(messageID uint64) { } func (l *Conn) sendProcessMessage(message *messagePacket) bool { - l.wgSender.Add(1) - defer l.wgSender.Done() - - if l.closing() { + if l.isClosing { return false } + l.wgSender.Add(1) l.chanMessage <- message + l.wgSender.Done() return true } func (l *Conn) processMessages() { defer func() { + if err := recover(); err != nil { + log.Printf("ldap: recovered panic in processMessages: %v", err) + } for messageID, channel := range l.chanResults { l.Debug.Printf("Closing channel for MessageID %d", messageID) close(channel) @@ -212,7 +280,7 @@ func (l *Conn) processMessages() { close(l.chanConfirm) }() - var messageID uint64 = 1 + var messageID int64 = 1 for { select { case l.chanMessageID <- messageID: @@ -257,20 +325,42 @@ func (l *Conn) processMessages() { } func (l *Conn) reader() { + cleanstop := false defer func() { - l.Close() + if err := recover(); err != nil { + log.Printf("ldap: recovered panic in reader: %v", err) + } + if !cleanstop { + l.Close() + } }() for { + if cleanstop { + l.Debug.Printf("reader clean stopping (without closing the connection)") + return + } packet, err := ber.ReadPacket(l.conn) if err != nil { - l.Debug.Printf("reader: %s", err.Error()) + // A read error is expected here if we are closing the connection... + if !l.isClosing { + l.Debug.Printf("reader error: %s", err.Error()) + } return } addLDAPDescriptions(packet) + if len(packet.Children) == 0 { + l.Debug.Printf("Received bad ldap packet") + continue + } + l.messageMutex.Lock() + if l.isStartingTLS { + cleanstop = true + } + l.messageMutex.Unlock() message := &messagePacket{ Op: MessageResponse, - MessageID: uint64(packet.Children[0].Value.(int64)), + MessageID: packet.Children[0].Value.(int64), Packet: packet, } if !l.sendProcessMessage(message) { diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/control.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/control.go similarity index 52% rename from Godeps/_workspace/src/github.com/vanackere/ldap/control.go rename to Godeps/_workspace/src/github.com/go-ldap/ldap/control.go index 8ba714f3b2..562fbe4309 100644 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/control.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/control.go @@ -6,16 +6,21 @@ package ldap import ( "fmt" + "strconv" - "github.com/vanackere/asn1-ber" + "gopkg.in/asn1-ber.v1" ) const ( - ControlTypePaging = "1.2.840.113556.1.4.319" + ControlTypePaging = "1.2.840.113556.1.4.319" + ControlTypeBeheraPasswordPolicy = "1.3.6.1.4.1.42.2.27.8.5.1" + ControlTypeVChuPasswordMustChange = "2.16.840.1.113730.3.4.4" + ControlTypeVChuPasswordWarning = "2.16.840.1.113730.3.4.5" ) var ControlTypeMap = map[string]string{ - ControlTypePaging: "Paging", + ControlTypePaging: "Paging", + ControlTypeBeheraPasswordPolicy: "Password Policy - Behera Draft", } type Control interface { @@ -40,7 +45,7 @@ func (c *ControlString) Encode() *ber.Packet { if c.Criticality { packet.AppendChild(ber.NewBoolean(ber.ClassUniversal, ber.TypePrimitive, ber.TagBoolean, c.Criticality, "Criticality")) } - packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, c.ControlValue, "Control Value")) + packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, string(c.ControlValue), "Control Value")) return packet } @@ -63,7 +68,7 @@ func (c *ControlPaging) Encode() *ber.Packet { p2 := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Control Value (Paging)") seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Search Control Value") - seq.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, int64(c.PagingSize), "Paging Size")) + seq.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, uint64(c.PagingSize), "Paging Size")) cookie := ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, nil, "Cookie") cookie.Value = c.Cookie cookie.Data.Write(c.Cookie) @@ -88,6 +93,78 @@ func (c *ControlPaging) SetCookie(cookie []byte) { c.Cookie = cookie } +type ControlBeheraPasswordPolicy struct { + Expire int64 + Grace int64 + Error int8 + ErrorString string +} + +func (c *ControlBeheraPasswordPolicy) GetControlType() string { + return ControlTypeBeheraPasswordPolicy +} + +func (c *ControlBeheraPasswordPolicy) Encode() *ber.Packet { + packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Control") + packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, ControlTypeBeheraPasswordPolicy, "Control Type ("+ControlTypeMap[ControlTypeBeheraPasswordPolicy]+")")) + + return packet +} + +func (c *ControlBeheraPasswordPolicy) String() string { + return fmt.Sprintf( + "Control Type: %s (%q) Criticality: %t Expire: %d Grace: %d Error: %d, ErrorString: %s", + ControlTypeMap[ControlTypeBeheraPasswordPolicy], + ControlTypeBeheraPasswordPolicy, + false, + c.Expire, + c.Grace, + c.Error, + c.ErrorString) +} + +type ControlVChuPasswordMustChange struct { + MustChange bool +} + +func (c *ControlVChuPasswordMustChange) GetControlType() string { + return ControlTypeVChuPasswordMustChange +} + +func (c *ControlVChuPasswordMustChange) Encode() *ber.Packet { + return nil +} + +func (c *ControlVChuPasswordMustChange) String() string { + return fmt.Sprintf( + "Control Type: %s (%q) Criticality: %t MustChange: %b", + ControlTypeMap[ControlTypeVChuPasswordMustChange], + ControlTypeVChuPasswordMustChange, + false, + c.MustChange) +} + +type ControlVChuPasswordWarning struct { + Expire int64 +} + +func (c *ControlVChuPasswordWarning) GetControlType() string { + return ControlTypeVChuPasswordWarning +} + +func (c *ControlVChuPasswordWarning) Encode() *ber.Packet { + return nil +} + +func (c *ControlVChuPasswordWarning) String() string { + return fmt.Sprintf( + "Control Type: %s (%q) Criticality: %t Expire: %b", + ControlTypeMap[ControlTypeVChuPasswordWarning], + ControlTypeVChuPasswordWarning, + false, + c.Expire) +} + func FindControl(controls []Control, controlType string) Control { for _, c := range controls { if c.GetControlType() == controlType { @@ -127,6 +204,64 @@ func DecodeControl(packet *ber.Packet) Control { c.PagingSize = uint32(value.Children[0].Value.(int64)) c.Cookie = value.Children[1].Data.Bytes() value.Children[1].Value = c.Cookie + return c + case ControlTypeBeheraPasswordPolicy: + value.Description += " (Password Policy - Behera)" + c := NewControlBeheraPasswordPolicy() + if value.Value != nil { + valueChildren := ber.DecodePacket(value.Data.Bytes()) + value.Data.Truncate(0) + value.Value = nil + value.AppendChild(valueChildren) + } + + sequence := value.Children[0] + + for _, child := range sequence.Children { + if child.Tag == 0 { + //Warning + child := child.Children[0] + packet := ber.DecodePacket(child.Data.Bytes()) + val, ok := packet.Value.(int64) + if ok { + if child.Tag == 0 { + //timeBeforeExpiration + c.Expire = val + child.Value = c.Expire + } else if child.Tag == 1 { + //graceAuthNsRemaining + c.Grace = val + child.Value = c.Grace + } + } + } else if child.Tag == 1 { + // Error + packet := ber.DecodePacket(child.Data.Bytes()) + val, ok := packet.Value.(int8) + if !ok { + // what to do? + val = -1 + } + c.Error = val + child.Value = c.Error + c.ErrorString = BeheraPasswordPolicyErrorMap[c.Error] + } + } + return c + case ControlTypeVChuPasswordMustChange: + c := &ControlVChuPasswordMustChange{MustChange: true} + return c + case ControlTypeVChuPasswordWarning: + c := &ControlVChuPasswordWarning{Expire: -1} + expireStr := ber.DecodeString(value.Data.Bytes()) + + expire, err := strconv.ParseInt(expireStr, 10, 64) + if err != nil { + return nil + } + c.Expire = expire + value.Value = c.Expire + return c } c := new(ControlString) @@ -148,6 +283,14 @@ func NewControlPaging(pagingSize uint32) *ControlPaging { return &ControlPaging{PagingSize: pagingSize} } +func NewControlBeheraPasswordPolicy() *ControlBeheraPasswordPolicy { + return &ControlBeheraPasswordPolicy{ + Expire: -1, + Grace: -1, + Error: -1, + } +} + func encodeControls(controls []Control) *ber.Packet { packet := ber.Encode(ber.ClassContext, ber.TypeConstructed, 0, nil, "Controls") for _, control := range controls { diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/debug.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/debug.go similarity index 91% rename from Godeps/_workspace/src/github.com/vanackere/ldap/debug.go rename to Godeps/_workspace/src/github.com/go-ldap/ldap/debug.go index e6edfd4da5..b8a7ecbff1 100644 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/debug.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/debug.go @@ -3,7 +3,7 @@ package ldap import ( "log" - "github.com/vanackere/asn1-ber" + "gopkg.in/asn1-ber.v1" ) // debbuging type diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/dn.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/dn.go new file mode 100644 index 0000000000..31d52db4b2 --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/dn.go @@ -0,0 +1,155 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// +// File contains DN parsing functionallity +// +// https://tools.ietf.org/html/rfc4514 +// +// distinguishedName = [ relativeDistinguishedName +// *( COMMA relativeDistinguishedName ) ] +// relativeDistinguishedName = attributeTypeAndValue +// *( PLUS attributeTypeAndValue ) +// attributeTypeAndValue = attributeType EQUALS attributeValue +// attributeType = descr / numericoid +// attributeValue = string / hexstring +// +// ; The following characters are to be escaped when they appear +// ; in the value to be encoded: ESC, one of , leading +// ; SHARP or SPACE, trailing SPACE, and NULL. +// string = [ ( leadchar / pair ) [ *( stringchar / pair ) +// ( trailchar / pair ) ] ] +// +// leadchar = LUTF1 / UTFMB +// LUTF1 = %x01-1F / %x21 / %x24-2A / %x2D-3A / +// %x3D / %x3F-5B / %x5D-7F +// +// trailchar = TUTF1 / UTFMB +// TUTF1 = %x01-1F / %x21 / %x23-2A / %x2D-3A / +// %x3D / %x3F-5B / %x5D-7F +// +// stringchar = SUTF1 / UTFMB +// SUTF1 = %x01-21 / %x23-2A / %x2D-3A / +// %x3D / %x3F-5B / %x5D-7F +// +// pair = ESC ( ESC / special / hexpair ) +// special = escaped / SPACE / SHARP / EQUALS +// escaped = DQUOTE / PLUS / COMMA / SEMI / LANGLE / RANGLE +// hexstring = SHARP 1*hexpair +// hexpair = HEX HEX +// +// where the productions , , , , +// , , , , , , , , +// , , and are defined in [RFC4512]. +// + +package ldap + +import ( + "bytes" + "errors" + "fmt" + "strings" + enchex "encoding/hex" + + ber "gopkg.in/asn1-ber.v1" +) + +type AttributeTypeAndValue struct { + Type string + Value string +} + +type RelativeDN struct { + Attributes []*AttributeTypeAndValue +} + +type DN struct { + RDNs []*RelativeDN +} + +func ParseDN(str string) (*DN, error) { + dn := new(DN) + dn.RDNs = make([]*RelativeDN, 0) + rdn := new (RelativeDN) + rdn.Attributes = make([]*AttributeTypeAndValue, 0) + buffer := bytes.Buffer{} + attribute := new(AttributeTypeAndValue) + escaping := false + + for i := 0; i < len(str); i++ { + char := str[i] + if escaping { + escaping = false + switch char { + case ' ', '"', '#', '+', ',', ';', '<', '=', '>', '\\': + buffer.WriteByte(char) + continue + } + // Not a special character, assume hex encoded octet + if len(str) == i+1 { + return nil, errors.New("Got corrupted escaped character") + } + + dst := []byte{0} + n, err := enchex.Decode([]byte(dst), []byte(str[i:i+2])) + if err != nil { + return nil, errors.New( + fmt.Sprintf("Failed to decode escaped character: %s", err)) + } else if n != 1 { + return nil, errors.New( + fmt.Sprintf("Expected 1 byte when un-escaping, got %d", n)) + } + buffer.WriteByte(dst[0]) + i++ + } else if char == '\\' { + escaping = true + } else if char == '=' { + attribute.Type = buffer.String() + buffer.Reset() + // Special case: If the first character in the value is # the + // following data is BER encoded so we can just fast forward + // and decode. + if len(str) > i+1 && str[i+1] == '#' { + i += 2 + index := strings.IndexAny(str[i:], ",+") + data := str + if index > 0 { + data = str[i:i+index] + } else { + data = str[i:] + } + raw_ber, err := enchex.DecodeString(data) + if err != nil { + return nil, errors.New( + fmt.Sprintf("Failed to decode BER encoding: %s", err)) + } + packet := ber.DecodePacket(raw_ber) + buffer.WriteString(packet.Data.String()) + i += len(data)-1 + } + } else if char == ',' || char == '+' { + // We're done with this RDN or value, push it + attribute.Value = buffer.String() + rdn.Attributes = append(rdn.Attributes, attribute) + attribute = new(AttributeTypeAndValue) + if char == ',' { + dn.RDNs = append(dn.RDNs, rdn) + rdn = new(RelativeDN) + rdn.Attributes = make([]*AttributeTypeAndValue, 0) + } + buffer.Reset() + } else { + buffer.WriteByte(char) + } + } + if buffer.Len() > 0 { + if len(attribute.Type) == 0 { + return nil, errors.New("DN ended with incomplete type, value pair") + } + attribute.Value = buffer.String() + rdn.Attributes = append(rdn.Attributes, attribute) + dn.RDNs = append(dn.RDNs, rdn) + } + return dn, nil +} diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/dn_test.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/dn_test.go new file mode 100644 index 0000000000..6740e1819c --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/dn_test.go @@ -0,0 +1,70 @@ +package ldap + +import ( + "reflect" + "testing" +) + +func TestSuccessfulDNParsing(t *testing.T) { + testcases := map[string]DN { + "": DN{[]*RelativeDN{}}, + "cn=Jim\\2C \\22Hasse Hö\\22 Hansson!,dc=dummy,dc=com": DN{[]*RelativeDN{ + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"cn", "Jim, \"Hasse Hö\" Hansson!"},}}, + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"dc", "dummy"},}}, + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"dc", "com"}, }},}}, + "UID=jsmith,DC=example,DC=net": DN{[]*RelativeDN{ + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"UID", "jsmith"},}}, + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"DC", "example"},}}, + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"DC", "net"}, }},}}, + "OU=Sales+CN=J. Smith,DC=example,DC=net": DN{[]*RelativeDN{ + &RelativeDN{[]*AttributeTypeAndValue{ + &AttributeTypeAndValue{"OU", "Sales"}, + &AttributeTypeAndValue{"CN", "J. Smith"},}}, + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"DC", "example"},}}, + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"DC", "net"}, }},}}, + "1.3.6.1.4.1.1466.0=#04024869": DN{[]*RelativeDN{ + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"1.3.6.1.4.1.1466.0", "Hi"},}},}}, + "1.3.6.1.4.1.1466.0=#04024869,DC=net": DN{[]*RelativeDN{ + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"1.3.6.1.4.1.1466.0", "Hi"},}}, + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"DC", "net"}, }},}}, + "CN=Lu\\C4\\8Di\\C4\\87": DN{[]*RelativeDN{ + &RelativeDN{[]*AttributeTypeAndValue{&AttributeTypeAndValue{"CN", "Lučić"},}},}}, + } + + for test, answer := range testcases { + dn, err := ParseDN(test) + if err != nil { + t.Errorf(err.Error()) + continue + } + if !reflect.DeepEqual(dn, &answer) { + t.Errorf("Parsed DN %s is not equal to the expected structure", test) + for _, rdn := range dn.RDNs { + for _, attribs := range rdn.Attributes { + t.Logf("#%v\n", attribs) + } + } + } + } +} + +func TestErrorDNParsing(t *testing.T) { + testcases := map[string]string { + "*": "DN ended with incomplete type, value pair", + "cn=Jim\\0Test": "Failed to decode escaped character: encoding/hex: invalid byte: U+0054 'T'", + "cn=Jim\\0": "Got corrupted escaped character", + "DC=example,=net": "DN ended with incomplete type, value pair", + "1=#0402486": "Failed to decode BER encoding: encoding/hex: odd length hex string", + } + + for test, answer := range testcases { + _, err := ParseDN(test) + if err == nil { + t.Errorf("Expected %s to fail parsing but succeeded\n", test) + } else if err.Error() != answer { + t.Errorf("Unexpected error on %s:\n%s\nvs.\n%s\n", test, answer, err.Error()) + } + } +} + + diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/beherappolicy/beherappolicy.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/beherappolicy/beherappolicy.go new file mode 100644 index 0000000000..33e9e193d5 --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/beherappolicy/beherappolicy.go @@ -0,0 +1,60 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "log" + + "github.com/go-ldap/ldap" +) + +var ( + ldapServer string = "localhost" + ldapPort uint16 = 389 + baseDN string = "dc=enterprise,dc=org" + user string = "cn=kirkj,ou=crew,dc=enterprise,dc=org" + passwd string = "*" +) + +func main() { + l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) + if err != nil { + log.Fatalf("ERROR: %s\n", err.Error()) + } + defer l.Close() + l.Debug = true + + controls := []ldap.Control{} + controls = append(controls, ldap.NewControlBeheraPasswordPolicy()) + bindRequest := ldap.NewSimpleBindRequest(user, passwd, controls) + + r, err := l.SimpleBind(bindRequest) + ppolicyControl := ldap.FindControl(r.Controls, ldap.ControlTypeBeheraPasswordPolicy) + + var ppolicy *ldap.ControlBeheraPasswordPolicy + if ppolicyControl != nil { + ppolicy = ppolicyControl.(*ldap.ControlBeheraPasswordPolicy) + } else { + log.Printf("ppolicyControl response not avaliable.\n") + } + if err != nil { + errStr := "ERROR: Cannot bind: " + err.Error() + if ppolicy != nil && ppolicy.Error >= 0 { + errStr += ":" + ppolicy.ErrorString + } + log.Print(errStr) + } else { + logStr := "Login Ok" + if ppolicy != nil { + if ppolicy.Expire >= 0 { + logStr += fmt.Sprintf(". Password expires in %d seconds\n", ppolicy.Expire) + } else if ppolicy.Grace >= 0 { + logStr += fmt.Sprintf(". Password expired, %d grace logins remain\n", ppolicy.Grace) + } + } + log.Print(logStr) + } +} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/examples/enterprise.ldif b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/enterprise.ldif similarity index 100% rename from Godeps/_workspace/src/github.com/vanackere/ldap/examples/enterprise.ldif rename to Godeps/_workspace/src/github.com/go-ldap/ldap/examples/enterprise.ldif diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/passwdmodify/passwdmodify.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/passwdmodify/passwdmodify.go new file mode 100644 index 0000000000..2ce199ee69 --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/passwdmodify/passwdmodify.go @@ -0,0 +1,125 @@ +package main + +import ( + "fmt" + "log" + + "github.com/go-ldap/ldap" +) + +// Example password policy. For this test pwdMinAge is 0 or subsequent password +// changes will fail. +// +// dn: cn=default,ou=policies,dc=enterprise,dc=org +// objectClass: pwdPolicy +// objectClass: person +// objectClass: top +// cn: default +// pwdAllowUserChange: TRUE +// pwdAttribute: userPassword +// pwdCheckQuality: 2 +// pwdExpireWarning: 300 +// pwdFailureCountInterval: 30 +// pwdGraceAuthNLimit: 5 +// pwdInHistory: 0 +// pwdLockout: TRUE +// pwdLockoutDuration: 0 +// pwdMaxAge: 300 +// pwdMaxFailure: 0 +// pwdMinAge: 0 +// pwdMinLength: 5 +// pwdMustChange: TRUE +// pwdSafeModify: TRUE +// sn: dummy value + +var ( + ldapServer string = "localhost" + ldapPort uint16 = 389 + baseDN string = "dc=enterprise,dc=org" + adminUser string = "cn=admin,dc=enterprise,dc=org" + adminPassword string = "*" + user string = "cn=kirkj,ou=crew,dc=enterprise,dc=org" + oldPassword string = "*" + password1 string = "password123" + password2 string = "password1234" +) + +const ( + debug = false +) + +func login(user string, password string) (*ldap.Conn, error) { + + l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) + if err != nil { + return nil, err + } + l.Debug = debug + + bindRequest := ldap.NewSimpleBindRequest(user, password, nil) + _, err = l.SimpleBind(bindRequest) + if err != nil { + return nil, err + } + return l, nil +} + +func main() { + + // Login as the admin and change the password of an user (without providing the old password) + log.Printf("Logging in as the admin and changing the password of user (without providing the old password") + l, err := login(adminUser, adminPassword) + if err != nil { + log.Fatalf("ERROR: %s\n", err.Error()) + } + + passwordModifyRequest := ldap.NewPasswordModifyRequest(user, "", password1) + _, err = l.PasswordModify(passwordModifyRequest) + + if err != nil { + l.Close() + log.Fatalf("ERROR: Cannot change password: %s\n", err) + } + + log.Printf("Done") + l.Close() + + // Login as the user and change the password without providing a new password. + log.Printf("Logging in as the user and changing the password without providing a new one") + l, err = login(user, password1) + if err != nil { + log.Fatalf("ERROR: %s\n", err.Error()) + } + + passwordModifyRequest = ldap.NewPasswordModifyRequest("", password1, "") + passwordModifyResponse, err := l.PasswordModify(passwordModifyRequest) + + if err != nil { + l.Close() + log.Fatalf("ERROR: Cannot change password: %s\n", err) + } + + generatedPassword := passwordModifyResponse.GeneratedPassword + log.Printf("Done. Generated password: %s\n", generatedPassword) + + l.Close() + + // Login as the user with the generated password and change it to another one + log.Printf("Logging in as the user and changing the password") + l, err = login(user, generatedPassword) + if err != nil { + log.Fatalf("ERROR: %s\n", err.Error()) + } + + passwordModifyRequest = ldap.NewPasswordModifyRequest("", generatedPassword, password2) + _, err = l.PasswordModify(passwordModifyRequest) + + if err != nil { + l.Close() + log.Fatalf("ERROR: Cannot change password: %s\n", err) + } + + log.Printf("Done") + l.Close() + +} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/examples/searchTLS.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/searchStartTLS/searchStartTLS.go similarity index 58% rename from Godeps/_workspace/src/github.com/vanackere/ldap/examples/searchTLS.go rename to Godeps/_workspace/src/github.com/go-ldap/ldap/examples/searchStartTLS/searchStartTLS.go index b4dce8a95e..580499df3e 100644 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/examples/searchTLS.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/searchStartTLS/searchStartTLS.go @@ -1,5 +1,3 @@ -// +build ignore - // Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -7,10 +5,11 @@ package main import ( + "crypto/tls" "fmt" "log" - "github.com/vanackere/ldap" + "gopkg.in/ldap.v1" ) var ( @@ -22,12 +21,12 @@ var ( ) func main() { - l, err := ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", LdapServer, LdapPort), nil) + l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", LdapServer, LdapPort)) if err != nil { - log.Fatalf("ERROR: %s\n", err.Error()) + log.Fatalf("ERROR: %s\n", err) } defer l.Close() - // l.Debug = true + l.Debug = true search := ldap.NewSearchRequest( BaseDN, @@ -36,10 +35,24 @@ func main() { Attributes, nil) + // First search without tls. sr, err := l.Search(search) if err != nil { - log.Fatalf("ERROR: %s\n", err.Error()) - return + log.Printf("ERROR: %s\n", err) + } + + log.Printf("Search: %s -> num of entries = %d\n", search.Filter, len(sr.Entries)) + sr.PrettyPrint(0) + + // Then startTLS + err = l.StartTLS(&tls.Config{InsecureSkipVerify: true}) + if err != nil { + log.Fatalf("ERROR: %s\n", err) + } + + sr, err = l.Search(search) + if err != nil { + log.Printf("ERROR: %s\n", err) } log.Printf("Search: %s -> num of entries = %d\n", search.Filter, len(sr.Entries)) diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/examples/slapd.conf b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/slapd.conf similarity index 100% rename from Godeps/_workspace/src/github.com/vanackere/ldap/examples/slapd.conf rename to Godeps/_workspace/src/github.com/go-ldap/ldap/examples/slapd.conf diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/vchuppolicy/vchuppolicy.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/vchuppolicy/vchuppolicy.go new file mode 100644 index 0000000000..4730484460 --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/vchuppolicy/vchuppolicy.go @@ -0,0 +1,63 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "log" + + "gopkg.in/ldap.v1" +) + +var ( + ldapServer string = "localhost" + ldapPort uint16 = 389 + baseDN string = "dc=enterprise,dc=org" + user string = "uid=kirkj,ou=crew,dc=enterprise,dc=org" + passwd string = "*" +) + +func main() { + l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) + if err != nil { + log.Fatalf("ERROR: %s\n", err.Error()) + } + defer l.Close() + l.Debug = true + + bindRequest := ldap.NewSimpleBindRequest(user, passwd, nil) + + r, err := l.SimpleBind(bindRequest) + + passwordMustChangeControl := ldap.FindControl(r.Controls, ldap.ControlTypeVChuPasswordMustChange) + var passwordMustChange *ldap.ControlVChuPasswordMustChange + if passwordMustChangeControl != nil { + passwordMustChange = passwordMustChangeControl.(*ldap.ControlVChuPasswordMustChange) + } + + if passwordMustChange != nil && passwordMustChange.MustChange { + log.Printf("Password Must be changed.\n") + } + + passwordWarningControl := ldap.FindControl(r.Controls, ldap.ControlTypeVChuPasswordWarning) + + var passwordWarning *ldap.ControlVChuPasswordWarning + if passwordWarningControl != nil { + passwordWarning = passwordWarningControl.(*ldap.ControlVChuPasswordWarning) + } else { + log.Printf("ppolicyControl response not available.\n") + } + if err != nil { + log.Print("ERROR: Cannot bind: " + err.Error()) + } else { + logStr := "Login Ok" + if passwordWarning != nil { + if passwordWarning.Expire >= 0 { + logStr += fmt.Sprintf(". Password expires in %d seconds\n", passwordWarning.Expire) + } + } + log.Print(logStr) + } +} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/filter.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/filter.go similarity index 66% rename from Godeps/_workspace/src/github.com/vanackere/ldap/filter.go rename to Godeps/_workspace/src/github.com/go-ldap/ldap/filter.go index 8f09316521..1ee1ff89d8 100644 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/filter.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/filter.go @@ -7,24 +7,25 @@ package ldap import ( "errors" "fmt" + "strings" - "github.com/vanackere/asn1-ber" + "gopkg.in/asn1-ber.v1" ) const ( - FilterAnd ber.Tag = 0 - FilterOr ber.Tag = 1 - FilterNot ber.Tag = 2 - FilterEqualityMatch ber.Tag = 3 - FilterSubstrings ber.Tag = 4 - FilterGreaterOrEqual ber.Tag = 5 - FilterLessOrEqual ber.Tag = 6 - FilterPresent ber.Tag = 7 - FilterApproxMatch ber.Tag = 8 - FilterExtensibleMatch ber.Tag = 9 + FilterAnd = 0 + FilterOr = 1 + FilterNot = 2 + FilterEqualityMatch = 3 + FilterSubstrings = 4 + FilterGreaterOrEqual = 5 + FilterLessOrEqual = 6 + FilterPresent = 7 + FilterApproxMatch = 8 + FilterExtensibleMatch = 9 ) -var filterMap = map[ber.Tag]string{ +var FilterMap = map[uint64]string{ FilterAnd: "And", FilterOr: "Or", FilterNot: "Not", @@ -43,6 +44,12 @@ const ( FilterSubstringsFinal = 2 ) +var FilterSubstringsMap = map[uint64]string{ + FilterSubstringsInitial: "Substrings Initial", + FilterSubstringsAny: "Substrings Any", + FilterSubstringsFinal: "Substrings Final", +} + func CompileFilter(filter string) (*ber.Packet, error) { if len(filter) == 0 || filter[0] != '(' { return nil, NewError(ErrorFilterCompile, errors.New("ldap: filter does not start with an '('")) @@ -97,13 +104,14 @@ func DecompileFilter(packet *ber.Packet) (ret string, err error) { case FilterSubstrings: ret += ber.DecodeString(packet.Children[0].Data.Bytes()) ret += "=" - switch packet.Children[1].Children[0].Tag { - case FilterSubstringsInitial: - ret += ber.DecodeString(packet.Children[1].Children[0].Data.Bytes()) + "*" - case FilterSubstringsAny: - ret += "*" + ber.DecodeString(packet.Children[1].Children[0].Data.Bytes()) + "*" - case FilterSubstringsFinal: - ret += "*" + ber.DecodeString(packet.Children[1].Children[0].Data.Bytes()) + for i, child := range packet.Children[1].Children { + if i == 0 && child.Tag != FilterSubstringsInitial { + ret += "*" + } + ret += ber.DecodeString(child.Data.Bytes()) + if child.Tag != FilterSubstringsFinal { + ret += "*" + } } case FilterEqualityMatch: ret += ber.DecodeString(packet.Children[0].Data.Bytes()) @@ -163,15 +171,15 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) { newPos++ return packet, newPos, err case '&': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterAnd, nil, filterMap[FilterAnd]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterAnd, nil, FilterMap[FilterAnd]) newPos, err = compileFilterSet(filter, pos+1, packet) return packet, newPos, err case '|': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterOr, nil, filterMap[FilterOr]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterOr, nil, FilterMap[FilterOr]) newPos, err = compileFilterSet(filter, pos+1, packet) return packet, newPos, err case '!': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterNot, nil, filterMap[FilterNot]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterNot, nil, FilterMap[FilterNot]) var child *ber.Packet child, newPos, err = compileFilter(filter, pos+1) packet.AppendChild(child) @@ -184,15 +192,15 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) { case packet != nil: condition += fmt.Sprintf("%c", filter[newPos]) case filter[newPos] == '=': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterEqualityMatch, nil, filterMap[FilterEqualityMatch]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterEqualityMatch, nil, FilterMap[FilterEqualityMatch]) case filter[newPos] == '>' && filter[newPos+1] == '=': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterGreaterOrEqual, nil, filterMap[FilterGreaterOrEqual]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterGreaterOrEqual, nil, FilterMap[FilterGreaterOrEqual]) newPos++ case filter[newPos] == '<' && filter[newPos+1] == '=': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterLessOrEqual, nil, filterMap[FilterLessOrEqual]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterLessOrEqual, nil, FilterMap[FilterLessOrEqual]) newPos++ case filter[newPos] == '~' && filter[newPos+1] == '=': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterApproxMatch, nil, filterMap[FilterLessOrEqual]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterApproxMatch, nil, FilterMap[FilterLessOrEqual]) newPos++ case packet == nil: attribute += fmt.Sprintf("%c", filter[newPos]) @@ -207,40 +215,37 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) { err = NewError(ErrorFilterCompile, errors.New("ldap: error parsing filter")) return packet, newPos, err } - // Handle FilterEqualityMatch as a separate case (is primitive, not constructed like the other filters) - if packet.Tag == FilterEqualityMatch && condition == "*" { - packet.TagType = ber.TypePrimitive - packet.Tag = FilterPresent - packet.Description = filterMap[packet.Tag] - packet.Data.WriteString(attribute) - return packet, newPos + 1, nil - } - packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, attribute, "Attribute")) + switch { - case packet.Tag == FilterEqualityMatch && condition[0] == '*' && condition[len(condition)-1] == '*': - // Any + case packet.Tag == FilterEqualityMatch && condition == "*": + packet = ber.NewString(ber.ClassContext, ber.TypePrimitive, FilterPresent, attribute, FilterMap[FilterPresent]) + case packet.Tag == FilterEqualityMatch && strings.Contains(condition, "*"): + packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, attribute, "Attribute")) packet.Tag = FilterSubstrings - packet.Description = filterMap[packet.Tag] + packet.Description = FilterMap[uint64(packet.Tag)] seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Substrings") - seq.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, FilterSubstringsAny, condition[1:len(condition)-1], "Any Substring")) - packet.AppendChild(seq) - case packet.Tag == FilterEqualityMatch && condition[0] == '*': - // Final - packet.Tag = FilterSubstrings - packet.Description = filterMap[packet.Tag] - seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Substrings") - seq.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, FilterSubstringsFinal, condition[1:], "Final Substring")) - packet.AppendChild(seq) - case packet.Tag == FilterEqualityMatch && condition[len(condition)-1] == '*': - // Initial - packet.Tag = FilterSubstrings - packet.Description = filterMap[packet.Tag] - seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Substrings") - seq.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, FilterSubstringsInitial, condition[:len(condition)-1], "Initial Substring")) + parts := strings.Split(condition, "*") + for i, part := range parts { + if part == "" { + continue + } + var tag ber.Tag + switch i { + case 0: + tag = FilterSubstringsInitial + case len(parts) - 1: + tag = FilterSubstringsFinal + default: + tag = FilterSubstringsAny + } + seq.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, tag, part, FilterSubstringsMap[uint64(tag)])) + } packet.AppendChild(seq) default: + packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, attribute, "Attribute")) packet.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, condition, "Condition")) } + newPos++ return packet, newPos, err } diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/filter_test.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/filter_test.go similarity index 65% rename from Godeps/_workspace/src/github.com/vanackere/ldap/filter_test.go rename to Godeps/_workspace/src/github.com/go-ldap/ldap/filter_test.go index b59232e95f..673ef08023 100644 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/filter_test.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/filter_test.go @@ -1,15 +1,14 @@ package ldap import ( - "reflect" "testing" - "github.com/vanackere/asn1-ber" + "gopkg.in/asn1-ber.v1" ) type compileTest struct { filterStr string - filterType ber.Tag + filterType int } var testFilters = []compileTest{ @@ -20,6 +19,10 @@ var testFilters = []compileTest{ compileTest{filterStr: "(sn=Mill*)", filterType: FilterSubstrings}, compileTest{filterStr: "(sn=*Mill)", filterType: FilterSubstrings}, compileTest{filterStr: "(sn=*Mill*)", filterType: FilterSubstrings}, + compileTest{filterStr: "(sn=*i*le*)", filterType: FilterSubstrings}, + compileTest{filterStr: "(sn=Mi*l*r)", filterType: FilterSubstrings}, + compileTest{filterStr: "(sn=Mi*le*)", filterType: FilterSubstrings}, + compileTest{filterStr: "(sn=*i*ler)", filterType: FilterSubstrings}, compileTest{filterStr: "(sn>=Miller)", filterType: FilterGreaterOrEqual}, compileTest{filterStr: "(sn<=Miller)", filterType: FilterLessOrEqual}, compileTest{filterStr: "(sn=*)", filterType: FilterPresent}, @@ -33,8 +36,8 @@ func TestFilter(t *testing.T) { filter, err := CompileFilter(i.filterStr) if err != nil { t.Errorf("Problem compiling %s - %s", i.filterStr, err.Error()) - } else if filter.Tag != i.filterType { - t.Errorf("%q Expected %q got %q", i.filterStr, filterMap[i.filterType], filterMap[filter.Tag]) + } else if filter.Tag != ber.Tag(i.filterType) { + t.Errorf("%q Expected %q got %q", i.filterStr, FilterMap[uint64(i.filterType)], FilterMap[uint64(filter.Tag)]) } else { o, err := DecompileFilter(filter) if err != nil { @@ -46,40 +49,6 @@ func TestFilter(t *testing.T) { } } -type binTestFilter struct { - bin []byte - str string -} - -var binTestFilters = []binTestFilter{ - {bin: []byte{0x87, 0x06, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72}, str: "(member=*)"}, -} - -func TestFiltersDecode(t *testing.T) { - for i, test := range binTestFilters { - p := ber.DecodePacket(test.bin) - if filter, err := DecompileFilter(p); err != nil { - t.Errorf("binTestFilters[%d], DecompileFilter returned : %s", i, err) - } else if filter != test.str { - t.Errorf("binTestFilters[%d], %q expected, got %q", i, test.str, filter) - } - } -} - -func TestFiltersEncode(t *testing.T) { - for i, test := range binTestFilters { - p, err := CompileFilter(test.str) - if err != nil { - t.Errorf("binTestFilters[%d], CompileFilter returned : %s", i, err) - continue - } - b := p.Bytes() - if !reflect.DeepEqual(b, test.bin) { - t.Errorf("binTestFilters[%d], %q expected for CompileFilter(%q), got %q", i, test.bin, test.str, b) - } - } -} - func BenchmarkFilterCompile(b *testing.B) { b.StopTimer() filters := make([]string, len(testFilters)) diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/ldap.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/ldap.go similarity index 71% rename from Godeps/_workspace/src/github.com/vanackere/ldap/ldap.go rename to Godeps/_workspace/src/github.com/go-ldap/ldap/ldap.go index 6259bb01af..e91972ff4c 100644 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/ldap.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/ldap.go @@ -10,34 +10,34 @@ import ( "io/ioutil" "os" - "github.com/vanackere/asn1-ber" + ber "gopkg.in/asn1-ber.v1" ) // LDAP Application Codes const ( - ApplicationBindRequest ber.Tag = 0 - ApplicationBindResponse ber.Tag = 1 - ApplicationUnbindRequest ber.Tag = 2 - ApplicationSearchRequest ber.Tag = 3 - ApplicationSearchResultEntry ber.Tag = 4 - ApplicationSearchResultDone ber.Tag = 5 - ApplicationModifyRequest ber.Tag = 6 - ApplicationModifyResponse ber.Tag = 7 - ApplicationAddRequest ber.Tag = 8 - ApplicationAddResponse ber.Tag = 9 - ApplicationDelRequest ber.Tag = 10 - ApplicationDelResponse ber.Tag = 11 - ApplicationModifyDNRequest ber.Tag = 12 - ApplicationModifyDNResponse ber.Tag = 13 - ApplicationCompareRequest ber.Tag = 14 - ApplicationCompareResponse ber.Tag = 15 - ApplicationAbandonRequest ber.Tag = 16 - ApplicationSearchResultReference ber.Tag = 19 - ApplicationExtendedRequest ber.Tag = 23 - ApplicationExtendedResponse ber.Tag = 24 + ApplicationBindRequest = 0 + ApplicationBindResponse = 1 + ApplicationUnbindRequest = 2 + ApplicationSearchRequest = 3 + ApplicationSearchResultEntry = 4 + ApplicationSearchResultDone = 5 + ApplicationModifyRequest = 6 + ApplicationModifyResponse = 7 + ApplicationAddRequest = 8 + ApplicationAddResponse = 9 + ApplicationDelRequest = 10 + ApplicationDelResponse = 11 + ApplicationModifyDNRequest = 12 + ApplicationModifyDNResponse = 13 + ApplicationCompareRequest = 14 + ApplicationCompareResponse = 15 + ApplicationAbandonRequest = 16 + ApplicationSearchResultReference = 19 + ApplicationExtendedRequest = 23 + ApplicationExtendedResponse = 24 ) -var ApplicationMap = map[ber.Tag]string{ +var ApplicationMap = map[uint8]string{ ApplicationBindRequest: "Bind Request", ApplicationBindResponse: "Bind Response", ApplicationUnbindRequest: "Unbind Request", @@ -102,10 +102,12 @@ const ( LDAPResultAffectsMultipleDSAs = 71 LDAPResultOther = 80 - ErrorNetwork = 200 - ErrorFilterCompile = 201 - ErrorFilterDecompile = 202 - ErrorDebugging = 203 + ErrorNetwork = 200 + ErrorFilterCompile = 201 + ErrorFilterDecompile = 202 + ErrorDebugging = 203 + ErrorUnexpectedMessage = 204 + ErrorUnexpectedResponse = 205 ) var LDAPResultCodeMap = map[uint8]string{ @@ -150,6 +152,31 @@ var LDAPResultCodeMap = map[uint8]string{ LDAPResultOther: "Other", } +// Ldap Behera Password Policy Draft 10 (https://tools.ietf.org/html/draft-behera-ldap-password-policy-10) +const ( + BeheraPasswordExpired = 0 + BeheraAccountLocked = 1 + BeheraChangeAfterReset = 2 + BeheraPasswordModNotAllowed = 3 + BeheraMustSupplyOldPassword = 4 + BeheraInsufficientPasswordQuality = 5 + BeheraPasswordTooShort = 6 + BeheraPasswordTooYoung = 7 + BeheraPasswordInHistory = 8 +) + +var BeheraPasswordPolicyErrorMap = map[int8]string{ + BeheraPasswordExpired: "Password expired", + BeheraAccountLocked: "Account locked", + BeheraChangeAfterReset: "Password must be changed", + BeheraPasswordModNotAllowed: "Policy prevents password modification", + BeheraMustSupplyOldPassword: "Policy requires old password in order to change password", + BeheraInsufficientPasswordQuality: "Password fails quality checks", + BeheraPasswordTooShort: "Password is too short for policy", + BeheraPasswordTooYoung: "Password has been changed too recently", + BeheraPasswordInHistory: "New password is in list of old passwords", +} + // Adds descriptions to an LDAP Response packet for debugging func addLDAPDescriptions(packet *ber.Packet) (err error) { defer func() { @@ -160,7 +187,7 @@ func addLDAPDescriptions(packet *ber.Packet) (err error) { packet.Description = "LDAP Response" packet.Children[0].Description = "Message ID" - application := packet.Children[1].Tag + application := uint8(packet.Children[1].Tag) packet.Children[1].Description = ApplicationMap[application] switch application { @@ -239,6 +266,44 @@ func addControlDescriptions(packet *ber.Packet) { value.Children[0].Description = "Real Search Control Value" value.Children[0].Children[0].Description = "Paging Size" value.Children[0].Children[1].Description = "Cookie" + + case ControlTypeBeheraPasswordPolicy: + value.Description += " (Password Policy - Behera Draft)" + if value.Value != nil { + valueChildren := ber.DecodePacket(value.Data.Bytes()) + value.Data.Truncate(0) + value.Value = nil + value.AppendChild(valueChildren) + } + sequence := value.Children[0] + for _, child := range sequence.Children { + if child.Tag == 0 { + //Warning + child := child.Children[0] + packet := ber.DecodePacket(child.Data.Bytes()) + val, ok := packet.Value.(int64) + if ok { + if child.Tag == 0 { + //timeBeforeExpiration + value.Description += " (TimeBeforeExpiration)" + child.Value = val + } else if child.Tag == 1 { + //graceAuthNsRemaining + value.Description += " (GraceAuthNsRemaining)" + child.Value = val + } + } + } else if child.Tag == 1 { + // Error + packet := ber.DecodePacket(child.Data.Bytes()) + val, ok := packet.Value.(int8) + if !ok { + val = -1 + } + child.Description = "Error" + child.Value = val + } + } } } } @@ -246,7 +311,7 @@ func addControlDescriptions(packet *ber.Packet) { func addRequestDescriptions(packet *ber.Packet) { packet.Description = "LDAP Request" packet.Children[0].Description = "Message ID" - packet.Children[1].Description = ApplicationMap[packet.Children[1].Tag] + packet.Children[1].Description = ApplicationMap[uint8(packet.Children[1].Tag)] if len(packet.Children) == 3 { addControlDescriptions(packet.Children[2]) } @@ -294,10 +359,45 @@ func NewError(resultCode uint8, err error) error { func getLDAPResultCode(packet *ber.Packet) (code uint8, description string) { if len(packet.Children) >= 2 { response := packet.Children[1] - if response.ClassType == ber.ClassApplication && response.TagType == ber.TypeConstructed && len(response.Children) == 3 { + if response.ClassType == ber.ClassApplication && response.TagType == ber.TypeConstructed && len(response.Children) >= 3 { return uint8(response.Children[0].Value.(int64)), response.Children[2].Value.(string) } } return ErrorNetwork, "Invalid packet format" } + +var hex = "0123456789abcdef" + +func mustEscape(c byte) bool { + return c > 0x7f || c == '(' || c == ')' || c == '\\' || c == '*' || c == 0 +} + +// EscapeFilter escapes from the provided LDAP filter string the special +// characters in the set `()*\` and those out of the range 0 < c < 0x80, +// as defined in RFC4515. +func EscapeFilter(filter string) string { + escape := 0 + for i := 0; i < len(filter); i++ { + if mustEscape(filter[i]) { + escape++ + } + } + if escape == 0 { + return filter + } + buf := make([]byte, len(filter)+escape*2) + for i, j := 0, 0; i < len(filter); i++ { + c := filter[i] + if mustEscape(c) { + buf[j+0] = '\\' + buf[j+1] = hex[c>>4] + buf[j+2] = hex[c&0xf] + j += 3 + } else { + buf[j] = c + j++ + } + } + return string(buf) +} diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/ldap_test.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/ldap_test.go new file mode 100644 index 0000000000..d6211bdc30 --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/ldap_test.go @@ -0,0 +1,226 @@ +package ldap + +import ( + "crypto/tls" + "fmt" + "testing" +) + +var ldapServer = "ldap.itd.umich.edu" +var ldapPort = uint16(389) +var ldapTLSPort = uint16(636) +var baseDN = "dc=umich,dc=edu" +var filter = []string{ + "(cn=cis-fac)", + "(&(owner=*)(cn=cis-fac))", + "(&(objectclass=rfc822mailgroup)(cn=*Computer*))", + "(&(objectclass=rfc822mailgroup)(cn=*Mathematics*))"} +var attributes = []string{ + "cn", + "description"} + +func TestDial(t *testing.T) { + fmt.Printf("TestDial: starting...\n") + l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) + if err != nil { + t.Errorf(err.Error()) + return + } + defer l.Close() + fmt.Printf("TestDial: finished...\n") +} + +func TestDialTLS(t *testing.T) { + fmt.Printf("TestDialTLS: starting...\n") + l, err := DialTLS("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapTLSPort), &tls.Config{InsecureSkipVerify: true}) + if err != nil { + t.Errorf(err.Error()) + return + } + defer l.Close() + fmt.Printf("TestDialTLS: finished...\n") +} + +func TestStartTLS(t *testing.T) { + fmt.Printf("TestStartTLS: starting...\n") + l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) + if err != nil { + t.Errorf(err.Error()) + return + } + err = l.StartTLS(&tls.Config{InsecureSkipVerify: true}) + if err != nil { + t.Errorf(err.Error()) + return + } + fmt.Printf("TestStartTLS: finished...\n") +} + +func TestSearch(t *testing.T) { + fmt.Printf("TestSearch: starting...\n") + l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) + if err != nil { + t.Errorf(err.Error()) + return + } + defer l.Close() + + searchRequest := NewSearchRequest( + baseDN, + ScopeWholeSubtree, DerefAlways, 0, 0, false, + filter[0], + attributes, + nil) + + sr, err := l.Search(searchRequest) + if err != nil { + t.Errorf(err.Error()) + return + } + + fmt.Printf("TestSearch: %s -> num of entries = %d\n", searchRequest.Filter, len(sr.Entries)) +} + +func TestSearchStartTLS(t *testing.T) { + fmt.Printf("TestSearchStartTLS: starting...\n") + l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) + if err != nil { + t.Errorf(err.Error()) + return + } + defer l.Close() + + searchRequest := NewSearchRequest( + baseDN, + ScopeWholeSubtree, DerefAlways, 0, 0, false, + filter[0], + attributes, + nil) + + sr, err := l.Search(searchRequest) + if err != nil { + t.Errorf(err.Error()) + return + } + + fmt.Printf("TestSearchStartTLS: %s -> num of entries = %d\n", searchRequest.Filter, len(sr.Entries)) + + fmt.Printf("TestSearchStartTLS: upgrading with startTLS\n") + err = l.StartTLS(&tls.Config{InsecureSkipVerify: true}) + if err != nil { + t.Errorf(err.Error()) + return + } + + sr, err = l.Search(searchRequest) + if err != nil { + t.Errorf(err.Error()) + return + } + + fmt.Printf("TestSearchStartTLS: %s -> num of entries = %d\n", searchRequest.Filter, len(sr.Entries)) +} + +func TestSearchWithPaging(t *testing.T) { + fmt.Printf("TestSearchWithPaging: starting...\n") + l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) + if err != nil { + t.Errorf(err.Error()) + return + } + defer l.Close() + + err = l.Bind("", "") + if err != nil { + t.Errorf(err.Error()) + return + } + + searchRequest := NewSearchRequest( + baseDN, + ScopeWholeSubtree, DerefAlways, 0, 0, false, + filter[2], + attributes, + nil) + sr, err := l.SearchWithPaging(searchRequest, 5) + if err != nil { + t.Errorf(err.Error()) + return + } + + fmt.Printf("TestSearchWithPaging: %s -> num of entries = %d\n", searchRequest.Filter, len(sr.Entries)) +} + +func searchGoroutine(t *testing.T, l *Conn, results chan *SearchResult, i int) { + searchRequest := NewSearchRequest( + baseDN, + ScopeWholeSubtree, DerefAlways, 0, 0, false, + filter[i], + attributes, + nil) + sr, err := l.Search(searchRequest) + if err != nil { + t.Errorf(err.Error()) + results <- nil + return + } + results <- sr +} + +func testMultiGoroutineSearch(t *testing.T, TLS bool, startTLS bool) { + fmt.Printf("TestMultiGoroutineSearch: starting...\n") + var l *Conn + var err error + if TLS { + l, err = DialTLS("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapTLSPort), &tls.Config{InsecureSkipVerify: true}) + if err != nil { + t.Errorf(err.Error()) + return + } + defer l.Close() + } else { + l, err = Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) + if err != nil { + t.Errorf(err.Error()) + return + } + if startTLS { + fmt.Printf("TestMultiGoroutineSearch: using StartTLS...\n") + err := l.StartTLS(&tls.Config{InsecureSkipVerify: true}) + if err != nil { + t.Errorf(err.Error()) + return + } + + } + } + + results := make([]chan *SearchResult, len(filter)) + for i := range filter { + results[i] = make(chan *SearchResult) + go searchGoroutine(t, l, results[i], i) + } + for i := range filter { + sr := <-results[i] + if sr == nil { + t.Errorf("Did not receive results from goroutine for %q", filter[i]) + } else { + fmt.Printf("TestMultiGoroutineSearch(%d): %s -> num of entries = %d\n", i, filter[i], len(sr.Entries)) + } + } +} + +func TestMultiGoroutineSearch(t *testing.T) { + testMultiGoroutineSearch(t, false, false) + testMultiGoroutineSearch(t, true, true) + testMultiGoroutineSearch(t, false, true) +} + +func TestEscapeFilter(t *testing.T) { + if got, want := EscapeFilter("a\x00b(c)d*e\\f"), `a\00b\28c\29d\2ae\5cf`; got != want { + t.Errorf("Got %s, expected %s", want, got) + } + if got, want := EscapeFilter("Lučić"), `Lu\c4\8di\c4\87`; got != want { + t.Errorf("Got %s, expected %s", want, got) + } +} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/modify.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/modify.go similarity index 94% rename from Godeps/_workspace/src/github.com/vanackere/ldap/modify.go rename to Godeps/_workspace/src/github.com/go-ldap/ldap/modify.go index 2070af1acf..4372a19dce 100644 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/modify.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/modify.go @@ -33,7 +33,7 @@ import ( "errors" "log" - "github.com/vanackere/asn1-ber" + "gopkg.in/asn1-ber.v1" ) const ( @@ -83,19 +83,19 @@ func (m ModifyRequest) encode() *ber.Packet { changes := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Changes") for _, attribute := range m.addAttributes { change := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Change") - change.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, int64(AddAttribute), "Operation")) + change.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, uint64(AddAttribute), "Operation")) change.AppendChild(attribute.encode()) changes.AppendChild(change) } for _, attribute := range m.deleteAttributes { change := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Change") - change.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, int64(DeleteAttribute), "Operation")) + change.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, uint64(DeleteAttribute), "Operation")) change.AppendChild(attribute.encode()) changes.AppendChild(change) } for _, attribute := range m.replaceAttributes { change := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Change") - change.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, int64(ReplaceAttribute), "Operation")) + change.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, uint64(ReplaceAttribute), "Operation")) change.AppendChild(attribute.encode()) changes.AppendChild(change) } @@ -114,7 +114,7 @@ func NewModifyRequest( func (l *Conn) Modify(modifyRequest *ModifyRequest) error { messageID := l.nextMessageID() packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") - packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, int64(messageID), "MessageID")) + packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, messageID, "MessageID")) packet.AppendChild(modifyRequest.encode()) l.Debug.PrintPacket(packet) diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/passwdmodify.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/passwdmodify.go new file mode 100644 index 0000000000..508b11ed72 --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/passwdmodify.go @@ -0,0 +1,137 @@ +// This file contains the password modify extended operation as specified in rfc 3062 +// +// https://tools.ietf.org/html/rfc3062 +// + +package ldap + +import ( + "errors" + "fmt" + + "gopkg.in/asn1-ber.v1" +) + +const ( + passwordModifyOID = "1.3.6.1.4.1.4203.1.11.1" +) + +type PasswordModifyRequest struct { + UserIdentity string + OldPassword string + NewPassword string +} + +type PasswordModifyResult struct { + GeneratedPassword string +} + +func (r *PasswordModifyRequest) encode() (*ber.Packet, error) { + request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationExtendedRequest, nil, "Password Modify Extended Operation") + request.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, 0, passwordModifyOID, "Extended Request Name: Password Modify OID")) + extendedRequestValue := ber.Encode(ber.ClassContext, ber.TypePrimitive, 1, nil, "Extended Request Value: Password Modify Request") + passwordModifyRequestValue := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Password Modify Request") + if r.UserIdentity != "" { + passwordModifyRequestValue.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, 0, r.UserIdentity, "User Identity")) + } + if r.OldPassword != "" { + passwordModifyRequestValue.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, 1, r.OldPassword, "Old Password")) + } + if r.NewPassword != "" { + passwordModifyRequestValue.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, 2, r.NewPassword, "New Password")) + } + + extendedRequestValue.AppendChild(passwordModifyRequestValue) + request.AppendChild(extendedRequestValue) + + return request, nil +} + +// Create a new PasswordModifyRequest +// +// According to the RFC 3602: +// userIdentity is a string representing the user associated with the request. +// This string may or may not be an LDAPDN (RFC 2253). +// If userIdentity is empty then the operation will act on the user associated +// with the session. +// +// oldPassword is the current user's password, it can be empty or it can be +// needed depending on the session user access rights (usually an administrator +// can change a user's password without knowing the current one) and the +// password policy (see pwdSafeModify password policy's attribute) +// +// newPassword is the desired user's password. If empty the server can return +// an error or generate a new password that will be available in the +// PasswordModifyResult.GeneratedPassword +// +func NewPasswordModifyRequest(userIdentity string, oldPassword string, newPassword string) *PasswordModifyRequest { + return &PasswordModifyRequest{ + UserIdentity: userIdentity, + OldPassword: oldPassword, + NewPassword: newPassword, + } +} + +func (l *Conn) PasswordModify(passwordModifyRequest *PasswordModifyRequest) (*PasswordModifyResult, error) { + messageID := l.nextMessageID() + + packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") + packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, messageID, "MessageID")) + + encodedPasswordModifyRequest, err := passwordModifyRequest.encode() + if err != nil { + return nil, err + } + packet.AppendChild(encodedPasswordModifyRequest) + + l.Debug.PrintPacket(packet) + + channel, err := l.sendMessage(packet) + if err != nil { + return nil, err + } + if channel == nil { + return nil, NewError(ErrorNetwork, errors.New("ldap: could not send message")) + } + defer l.finishMessage(messageID) + + result := &PasswordModifyResult{} + + l.Debug.Printf("%d: waiting for response", messageID) + packet = <-channel + l.Debug.Printf("%d: got response %p", messageID, packet) + + if packet == nil { + return nil, NewError(ErrorNetwork, errors.New("ldap: could not retrieve message")) + } + + if l.Debug { + if err := addLDAPDescriptions(packet); err != nil { + return nil, err + } + ber.PrintPacket(packet) + } + + if packet.Children[1].Tag == ApplicationExtendedResponse { + resultCode, resultDescription := getLDAPResultCode(packet) + if resultCode != 0 { + return nil, NewError(resultCode, errors.New(resultDescription)) + } + } else { + return nil, NewError(ErrorUnexpectedResponse, fmt.Errorf("Unexpected Response: %d", packet.Children[1].Tag)) + } + + extendedResponse := packet.Children[1] + for _, child := range extendedResponse.Children { + if child.Tag == 11 { + passwordModifyReponseValue := ber.DecodePacket(child.Data.Bytes()) + if len(passwordModifyReponseValue.Children) == 1 { + if passwordModifyReponseValue.Children[0].Tag == 0 { + result.GeneratedPassword = ber.DecodeString(passwordModifyReponseValue.Children[0].Data.Bytes()) + } + } + } + } + + return result, nil +} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/search.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/search.go similarity index 92% rename from Godeps/_workspace/src/github.com/vanackere/ldap/search.go rename to Godeps/_workspace/src/github.com/go-ldap/ldap/search.go index d37d96f760..5ae3c44947 100644 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/search.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/search.go @@ -64,7 +64,7 @@ import ( "fmt" "strings" - "github.com/vanackere/asn1-ber" + "gopkg.in/asn1-ber.v1" ) const ( @@ -107,6 +107,15 @@ func (e *Entry) GetAttributeValues(attribute string) []string { return []string{} } +func (e *Entry) GetRawAttributeValues(attribute string) [][]byte { + for _, attr := range e.Attributes { + if attr.Name == attribute { + return attr.ByteValues + } + } + return [][]byte{} +} + func (e *Entry) GetAttributeValue(attribute string) string { values := e.GetAttributeValues(attribute) if len(values) == 0 { @@ -115,6 +124,14 @@ func (e *Entry) GetAttributeValue(attribute string) string { return values[0] } +func (e *Entry) GetRawAttributeValue(attribute string) []byte { + values := e.GetRawAttributeValues(attribute) + if len(values) == 0 { + return []byte{} + } + return values[0] +} + func (e *Entry) Print() { fmt.Printf("DN: %s\n", e.DN) for _, attr := range e.Attributes { @@ -130,8 +147,9 @@ func (e *Entry) PrettyPrint(indent int) { } type EntryAttribute struct { - Name string - Values []string + Name string + Values []string + ByteValues [][]byte } func (e *EntryAttribute) Print() { @@ -175,10 +193,10 @@ type SearchRequest struct { func (s *SearchRequest) encode() (*ber.Packet, error) { request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationSearchRequest, nil, "Search Request") request.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, s.BaseDN, "Base DN")) - request.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, int64(s.Scope), "Scope")) - request.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, int64(s.DerefAliases), "Deref Aliases")) - request.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, int64(s.SizeLimit), "Size Limit")) - request.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, int64(s.TimeLimit), "Time Limit")) + request.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, uint64(s.Scope), "Scope")) + request.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagEnumerated, uint64(s.DerefAliases), "Deref Aliases")) + request.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, uint64(s.SizeLimit), "Size Limit")) + request.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, uint64(s.TimeLimit), "Time Limit")) request.AppendChild(ber.NewBoolean(ber.ClassUniversal, ber.TypePrimitive, ber.TagBoolean, s.TypesOnly, "Types Only")) // compile and encode filter filterPacket, err := CompileFilter(s.Filter) @@ -273,7 +291,7 @@ func (l *Conn) SearchWithPaging(searchRequest *SearchRequest, pagingSize uint32) func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) { messageID := l.nextMessageID() packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") - packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, int64(messageID), "MessageID")) + packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, messageID, "MessageID")) // encode search request encodedSearchRequest, err := searchRequest.encode() if err != nil { @@ -326,6 +344,7 @@ func (l *Conn) Search(searchRequest *SearchRequest) (*SearchResult, error) { attr.Name = child.Children[0].Value.(string) for _, value := range child.Children[1].Children { attr.Values = append(attr.Values, value.Value.(string)) + attr.ByteValues = append(attr.ByteValues, value.ByteValue) } entry.Attributes = append(entry.Attributes, attr) } diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/todo b/Godeps/_workspace/src/github.com/go-ldap/ldap/todo new file mode 100644 index 0000000000..4a7be3d26b --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/todo @@ -0,0 +1,19 @@ +"" => [] +sep is always , +multivalue is + + +type=value + +type is numericoid or keystring: + keystring = leadkeychar *keychar + leadkeychar = ALPHA + keychar = ALPHA / DIGIT / HYPHEN + numericoid = number 1*( DOT number ) + +example oid: +givenname = 2.5.4.42 + + If the AttributeType is of the dotted-decimal form, the + AttributeValue is represented by an number sign ('#' U+0023) + character followed by the hexadecimal encoding of each of the octets + of the BER encoding of the X.500 AttributeValue. diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/0doc.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/0doc.go new file mode 100644 index 0000000000..0f33922b73 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/0doc.go @@ -0,0 +1,150 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style 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. + - 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 idiosynchracies 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) + +*/ +package codec + diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/README.md b/Godeps/_workspace/src/github.com/ugorji/go/codec/README.md new file mode 100644 index 0000000000..a790a52bb9 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/README.md @@ -0,0 +1,148 @@ +# 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 idiosynchracies 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) + diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/binc.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/binc.go new file mode 100644 index 0000000000..dc3aa80a95 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/binc.go @@ -0,0 +1,901 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +import ( + "math" + "time" +) + +const bincDoPrune = true // No longer needed. Needed before as C lib did not support pruning. + +// vd as low 4 bits (there are 16 slots) +const ( + bincVdSpecial byte = iota + bincVdPosInt + bincVdNegInt + bincVdFloat + + bincVdString + bincVdByteArray + bincVdArray + bincVdMap + + bincVdTimestamp + bincVdSmallInt + bincVdUnicodeOther + bincVdSymbol + + bincVdDecimal + _ // open slot + _ // open slot + bincVdCustomExt = 0x0f +) + +const ( + bincSpNil byte = iota + bincSpFalse + bincSpTrue + bincSpNan + bincSpPosInf + bincSpNegInf + bincSpZeroFloat + bincSpZero + bincSpNegOne +) + +const ( + bincFlBin16 byte = iota + bincFlBin32 + _ // bincFlBin32e + bincFlBin64 + _ // bincFlBin64e + // others not currently supported +) + +type bincEncDriver struct { + e *Encoder + w encWriter + m map[string]uint16 // symbols + s uint16 // symbols sequencer + b [scratchByteArrayLen]byte + encNoSeparator +} + +func (e *bincEncDriver) IsBuiltinType(rt uintptr) bool { + return rt == timeTypId +} + +func (e *bincEncDriver) EncodeBuiltin(rt uintptr, v interface{}) { + if rt == timeTypId { + bs := encodeTime(v.(time.Time)) + e.w.writen1(bincVdTimestamp<<4 | uint8(len(bs))) + e.w.writeb(bs) + } +} + +func (e *bincEncDriver) EncodeNil() { + e.w.writen1(bincVdSpecial<<4 | bincSpNil) +} + +func (e *bincEncDriver) EncodeBool(b bool) { + if b { + e.w.writen1(bincVdSpecial<<4 | bincSpTrue) + } else { + e.w.writen1(bincVdSpecial<<4 | bincSpFalse) + } +} + +func (e *bincEncDriver) EncodeFloat32(f float32) { + if f == 0 { + e.w.writen1(bincVdSpecial<<4 | bincSpZeroFloat) + return + } + e.w.writen1(bincVdFloat<<4 | bincFlBin32) + bigenHelper{e.b[:4], e.w}.writeUint32(math.Float32bits(f)) +} + +func (e *bincEncDriver) EncodeFloat64(f float64) { + if f == 0 { + e.w.writen1(bincVdSpecial<<4 | bincSpZeroFloat) + return + } + bigen.PutUint64(e.b[:8], math.Float64bits(f)) + if bincDoPrune { + i := 7 + for ; i >= 0 && (e.b[i] == 0); i-- { + } + i++ + if i <= 6 { + e.w.writen1(bincVdFloat<<4 | 0x8 | bincFlBin64) + e.w.writen1(byte(i)) + e.w.writeb(e.b[:i]) + return + } + } + e.w.writen1(bincVdFloat<<4 | bincFlBin64) + e.w.writeb(e.b[:8]) +} + +func (e *bincEncDriver) encIntegerPrune(bd byte, pos bool, v uint64, lim uint8) { + if lim == 4 { + bigen.PutUint32(e.b[:lim], uint32(v)) + } else { + bigen.PutUint64(e.b[:lim], v) + } + if bincDoPrune { + i := pruneSignExt(e.b[:lim], pos) + e.w.writen1(bd | lim - 1 - byte(i)) + e.w.writeb(e.b[i:lim]) + } else { + e.w.writen1(bd | lim - 1) + e.w.writeb(e.b[:lim]) + } +} + +func (e *bincEncDriver) EncodeInt(v int64) { + const nbd byte = bincVdNegInt << 4 + if v >= 0 { + e.encUint(bincVdPosInt<<4, true, uint64(v)) + } else if v == -1 { + e.w.writen1(bincVdSpecial<<4 | bincSpNegOne) + } else { + e.encUint(bincVdNegInt<<4, false, uint64(-v)) + } +} + +func (e *bincEncDriver) EncodeUint(v uint64) { + e.encUint(bincVdPosInt<<4, true, v) +} + +func (e *bincEncDriver) encUint(bd byte, pos bool, v uint64) { + if v == 0 { + e.w.writen1(bincVdSpecial<<4 | bincSpZero) + } else if pos && v >= 1 && v <= 16 { + e.w.writen1(bincVdSmallInt<<4 | byte(v-1)) + } else if v <= math.MaxUint8 { + e.w.writen2(bd|0x0, byte(v)) + } else if v <= math.MaxUint16 { + e.w.writen1(bd | 0x01) + bigenHelper{e.b[:2], e.w}.writeUint16(uint16(v)) + } else if v <= math.MaxUint32 { + e.encIntegerPrune(bd, pos, v, 4) + } else { + e.encIntegerPrune(bd, pos, v, 8) + } +} + +func (e *bincEncDriver) EncodeExt(rv interface{}, xtag uint64, ext Ext, _ *Encoder) { + bs := ext.WriteExt(rv) + if bs == nil { + e.EncodeNil() + return + } + e.encodeExtPreamble(uint8(xtag), len(bs)) + e.w.writeb(bs) +} + +func (e *bincEncDriver) EncodeRawExt(re *RawExt, _ *Encoder) { + e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) + e.w.writeb(re.Data) +} + +func (e *bincEncDriver) encodeExtPreamble(xtag byte, length int) { + e.encLen(bincVdCustomExt<<4, uint64(length)) + e.w.writen1(xtag) +} + +func (e *bincEncDriver) EncodeArrayStart(length int) { + e.encLen(bincVdArray<<4, uint64(length)) +} + +func (e *bincEncDriver) EncodeMapStart(length int) { + e.encLen(bincVdMap<<4, uint64(length)) +} + +func (e *bincEncDriver) EncodeString(c charEncoding, v string) { + l := uint64(len(v)) + e.encBytesLen(c, l) + if l > 0 { + e.w.writestr(v) + } +} + +func (e *bincEncDriver) EncodeSymbol(v string) { + // if WriteSymbolsNoRefs { + // e.encodeString(c_UTF8, v) + // return + // } + + //symbols only offer benefit when string length > 1. + //This is because strings with length 1 take only 2 bytes to store + //(bd with embedded length, and single byte for string val). + + l := len(v) + if l == 0 { + e.encBytesLen(c_UTF8, 0) + return + } else if l == 1 { + e.encBytesLen(c_UTF8, 1) + e.w.writen1(v[0]) + return + } + if e.m == nil { + e.m = make(map[string]uint16, 16) + } + ui, ok := e.m[v] + if ok { + if ui <= math.MaxUint8 { + e.w.writen2(bincVdSymbol<<4, byte(ui)) + } else { + e.w.writen1(bincVdSymbol<<4 | 0x8) + bigenHelper{e.b[:2], e.w}.writeUint16(ui) + } + } else { + e.s++ + ui = e.s + //ui = uint16(atomic.AddUint32(&e.s, 1)) + e.m[v] = ui + var lenprec uint8 + if l <= math.MaxUint8 { + // lenprec = 0 + } else if l <= math.MaxUint16 { + lenprec = 1 + } else if int64(l) <= math.MaxUint32 { + lenprec = 2 + } else { + lenprec = 3 + } + if ui <= math.MaxUint8 { + e.w.writen2(bincVdSymbol<<4|0x0|0x4|lenprec, byte(ui)) + } else { + e.w.writen1(bincVdSymbol<<4 | 0x8 | 0x4 | lenprec) + bigenHelper{e.b[:2], e.w}.writeUint16(ui) + } + if lenprec == 0 { + e.w.writen1(byte(l)) + } else if lenprec == 1 { + bigenHelper{e.b[:2], e.w}.writeUint16(uint16(l)) + } else if lenprec == 2 { + bigenHelper{e.b[:4], e.w}.writeUint32(uint32(l)) + } else { + bigenHelper{e.b[:8], e.w}.writeUint64(uint64(l)) + } + e.w.writestr(v) + } +} + +func (e *bincEncDriver) EncodeStringBytes(c charEncoding, v []byte) { + l := uint64(len(v)) + e.encBytesLen(c, l) + if l > 0 { + e.w.writeb(v) + } +} + +func (e *bincEncDriver) encBytesLen(c charEncoding, length uint64) { + //TODO: support bincUnicodeOther (for now, just use string or bytearray) + if c == c_RAW { + e.encLen(bincVdByteArray<<4, length) + } else { + e.encLen(bincVdString<<4, length) + } +} + +func (e *bincEncDriver) encLen(bd byte, l uint64) { + if l < 12 { + e.w.writen1(bd | uint8(l+4)) + } else { + e.encLenNumber(bd, l) + } +} + +func (e *bincEncDriver) encLenNumber(bd byte, v uint64) { + if v <= math.MaxUint8 { + e.w.writen2(bd, byte(v)) + } else if v <= math.MaxUint16 { + e.w.writen1(bd | 0x01) + bigenHelper{e.b[:2], e.w}.writeUint16(uint16(v)) + } else if v <= math.MaxUint32 { + e.w.writen1(bd | 0x02) + bigenHelper{e.b[:4], e.w}.writeUint32(uint32(v)) + } else { + e.w.writen1(bd | 0x03) + bigenHelper{e.b[:8], e.w}.writeUint64(uint64(v)) + } +} + +//------------------------------------ + +type bincDecSymbol struct { + i uint16 + s string + b []byte +} + +type bincDecDriver struct { + d *Decoder + h *BincHandle + r decReader + br bool // bytes reader + bdRead bool + bdType valueType + bd byte + vd byte + vs byte + noStreamingCodec + decNoSeparator + b [scratchByteArrayLen]byte + + // linear searching on this slice is ok, + // because we typically expect < 32 symbols in each stream. + s []bincDecSymbol +} + +func (d *bincDecDriver) readNextBd() { + d.bd = d.r.readn1() + d.vd = d.bd >> 4 + d.vs = d.bd & 0x0f + d.bdRead = true + d.bdType = valueTypeUnset +} + +func (d *bincDecDriver) IsContainerType(vt valueType) (b bool) { + switch vt { + case valueTypeNil: + return d.vd == bincVdSpecial && d.vs == bincSpNil + case valueTypeBytes: + return d.vd == bincVdByteArray + case valueTypeString: + return d.vd == bincVdString + case valueTypeArray: + return d.vd == bincVdArray + case valueTypeMap: + return d.vd == bincVdMap + } + d.d.errorf("isContainerType: unsupported parameter: %v", vt) + return // "unreachable" +} + +func (d *bincDecDriver) TryDecodeAsNil() bool { + if !d.bdRead { + d.readNextBd() + } + if d.bd == bincVdSpecial<<4|bincSpNil { + d.bdRead = false + return true + } + return false +} + +func (d *bincDecDriver) IsBuiltinType(rt uintptr) bool { + return rt == timeTypId +} + +func (d *bincDecDriver) DecodeBuiltin(rt uintptr, v interface{}) { + if !d.bdRead { + d.readNextBd() + } + if rt == timeTypId { + if d.vd != bincVdTimestamp { + d.d.errorf("Invalid d.vd. Expecting 0x%x. Received: 0x%x", bincVdTimestamp, d.vd) + return + } + tt, err := decodeTime(d.r.readx(int(d.vs))) + if err != nil { + panic(err) + } + var vt *time.Time = v.(*time.Time) + *vt = tt + d.bdRead = false + } +} + +func (d *bincDecDriver) decFloatPre(vs, defaultLen byte) { + if vs&0x8 == 0 { + d.r.readb(d.b[0:defaultLen]) + } else { + l := d.r.readn1() + if l > 8 { + d.d.errorf("At most 8 bytes used to represent float. Received: %v bytes", l) + return + } + for i := l; i < 8; i++ { + d.b[i] = 0 + } + d.r.readb(d.b[0:l]) + } +} + +func (d *bincDecDriver) decFloat() (f float64) { + //if true { f = math.Float64frombits(bigen.Uint64(d.r.readx(8))); break; } + if x := d.vs & 0x7; x == bincFlBin32 { + d.decFloatPre(d.vs, 4) + f = float64(math.Float32frombits(bigen.Uint32(d.b[0:4]))) + } else if x == bincFlBin64 { + d.decFloatPre(d.vs, 8) + f = math.Float64frombits(bigen.Uint64(d.b[0:8])) + } else { + d.d.errorf("only float32 and float64 are supported. d.vd: 0x%x, d.vs: 0x%x", d.vd, d.vs) + return + } + return +} + +func (d *bincDecDriver) decUint() (v uint64) { + // need to inline the code (interface conversion and type assertion expensive) + switch d.vs { + case 0: + v = uint64(d.r.readn1()) + case 1: + d.r.readb(d.b[6:8]) + v = uint64(bigen.Uint16(d.b[6:8])) + case 2: + d.b[4] = 0 + d.r.readb(d.b[5:8]) + v = uint64(bigen.Uint32(d.b[4:8])) + case 3: + d.r.readb(d.b[4:8]) + v = uint64(bigen.Uint32(d.b[4:8])) + case 4, 5, 6: + lim := int(7 - d.vs) + d.r.readb(d.b[lim:8]) + for i := 0; i < lim; i++ { + d.b[i] = 0 + } + v = uint64(bigen.Uint64(d.b[:8])) + case 7: + d.r.readb(d.b[:8]) + v = uint64(bigen.Uint64(d.b[:8])) + default: + d.d.errorf("unsigned integers with greater than 64 bits of precision not supported") + return + } + return +} + +func (d *bincDecDriver) decCheckInteger() (ui uint64, neg bool) { + if !d.bdRead { + d.readNextBd() + } + vd, vs := d.vd, d.vs + if vd == bincVdPosInt { + ui = d.decUint() + } else if vd == bincVdNegInt { + ui = d.decUint() + neg = true + } else if vd == bincVdSmallInt { + ui = uint64(d.vs) + 1 + } else if vd == bincVdSpecial { + if vs == bincSpZero { + //i = 0 + } else if vs == bincSpNegOne { + neg = true + ui = 1 + } else { + d.d.errorf("numeric decode fails for special value: d.vs: 0x%x", d.vs) + return + } + } else { + d.d.errorf("number can only be decoded from uint or int values. d.bd: 0x%x, d.vd: 0x%x", d.bd, d.vd) + return + } + return +} + +func (d *bincDecDriver) DecodeInt(bitsize uint8) (i int64) { + ui, neg := d.decCheckInteger() + i, overflow := chkOvf.SignedInt(ui) + if overflow { + d.d.errorf("simple: overflow converting %v to signed integer", ui) + return + } + if neg { + i = -i + } + if chkOvf.Int(i, bitsize) { + d.d.errorf("binc: overflow integer: %v", i) + return + } + d.bdRead = false + return +} + +func (d *bincDecDriver) DecodeUint(bitsize uint8) (ui uint64) { + ui, neg := d.decCheckInteger() + if neg { + d.d.errorf("Assigning negative signed value to unsigned type") + return + } + if chkOvf.Uint(ui, bitsize) { + d.d.errorf("binc: overflow integer: %v", ui) + return + } + d.bdRead = false + return +} + +func (d *bincDecDriver) DecodeFloat(chkOverflow32 bool) (f float64) { + if !d.bdRead { + d.readNextBd() + } + vd, vs := d.vd, d.vs + if vd == bincVdSpecial { + d.bdRead = false + if vs == bincSpNan { + return math.NaN() + } else if vs == bincSpPosInf { + return math.Inf(1) + } else if vs == bincSpZeroFloat || vs == bincSpZero { + return + } else if vs == bincSpNegInf { + return math.Inf(-1) + } else { + d.d.errorf("Invalid d.vs decoding float where d.vd=bincVdSpecial: %v", d.vs) + return + } + } else if vd == bincVdFloat { + f = d.decFloat() + } else { + f = float64(d.DecodeInt(64)) + } + if chkOverflow32 && chkOvf.Float32(f) { + d.d.errorf("binc: float32 overflow: %v", f) + return + } + d.bdRead = false + return +} + +// bool can be decoded from bool only (single byte). +func (d *bincDecDriver) DecodeBool() (b bool) { + if !d.bdRead { + d.readNextBd() + } + if bd := d.bd; bd == (bincVdSpecial | bincSpFalse) { + // b = false + } else if bd == (bincVdSpecial | bincSpTrue) { + b = true + } else { + d.d.errorf("Invalid single-byte value for bool: %s: %x", msgBadDesc, d.bd) + return + } + d.bdRead = false + return +} + +func (d *bincDecDriver) ReadMapStart() (length int) { + if d.vd != bincVdMap { + d.d.errorf("Invalid d.vd for map. Expecting 0x%x. Got: 0x%x", bincVdMap, d.vd) + return + } + length = d.decLen() + d.bdRead = false + return +} + +func (d *bincDecDriver) ReadArrayStart() (length int) { + if d.vd != bincVdArray { + d.d.errorf("Invalid d.vd for array. Expecting 0x%x. Got: 0x%x", bincVdArray, d.vd) + return + } + length = d.decLen() + d.bdRead = false + return +} + +func (d *bincDecDriver) decLen() int { + if d.vs > 3 { + return int(d.vs - 4) + } + return int(d.decLenNumber()) +} + +func (d *bincDecDriver) decLenNumber() (v uint64) { + if x := d.vs; x == 0 { + v = uint64(d.r.readn1()) + } else if x == 1 { + d.r.readb(d.b[6:8]) + v = uint64(bigen.Uint16(d.b[6:8])) + } else if x == 2 { + d.r.readb(d.b[4:8]) + v = uint64(bigen.Uint32(d.b[4:8])) + } else { + d.r.readb(d.b[:8]) + v = bigen.Uint64(d.b[:8]) + } + return +} + +func (d *bincDecDriver) decStringAndBytes(bs []byte, withString, zerocopy bool) (bs2 []byte, s string) { + if !d.bdRead { + d.readNextBd() + } + if d.bd == bincVdSpecial<<4|bincSpNil { + d.bdRead = false + return + } + var slen int = -1 + // var ok bool + switch d.vd { + case bincVdString, bincVdByteArray: + slen = d.decLen() + if zerocopy { + if d.br { + bs2 = d.r.readx(slen) + } else if len(bs) == 0 { + bs2 = decByteSlice(d.r, slen, d.b[:]) + } else { + bs2 = decByteSlice(d.r, slen, bs) + } + } else { + bs2 = decByteSlice(d.r, slen, bs) + } + if withString { + s = string(bs2) + } + case bincVdSymbol: + // zerocopy doesn't apply for symbols, + // as the values must be stored in a table for later use. + // + //from vs: extract numSymbolBytes, containsStringVal, strLenPrecision, + //extract symbol + //if containsStringVal, read it and put in map + //else look in map for string value + var symbol uint16 + vs := d.vs + if vs&0x8 == 0 { + symbol = uint16(d.r.readn1()) + } else { + symbol = uint16(bigen.Uint16(d.r.readx(2))) + } + if d.s == nil { + d.s = make([]bincDecSymbol, 0, 16) + } + + if vs&0x4 == 0 { + for i := range d.s { + j := &d.s[i] + if j.i == symbol { + bs2 = j.b + if withString { + if j.s == "" && bs2 != nil { + j.s = string(bs2) + } + s = j.s + } + break + } + } + } else { + switch vs & 0x3 { + case 0: + slen = int(d.r.readn1()) + case 1: + slen = int(bigen.Uint16(d.r.readx(2))) + case 2: + slen = int(bigen.Uint32(d.r.readx(4))) + case 3: + slen = int(bigen.Uint64(d.r.readx(8))) + } + // since using symbols, do not store any part of + // the parameter bs in the map, as it might be a shared buffer. + // bs2 = decByteSlice(d.r, slen, bs) + bs2 = decByteSlice(d.r, slen, nil) + if withString { + s = string(bs2) + } + d.s = append(d.s, bincDecSymbol{symbol, s, bs2}) + } + default: + d.d.errorf("Invalid d.vd. Expecting string:0x%x, bytearray:0x%x or symbol: 0x%x. Got: 0x%x", + bincVdString, bincVdByteArray, bincVdSymbol, d.vd) + return + } + d.bdRead = false + return +} + +func (d *bincDecDriver) DecodeString() (s string) { + // DecodeBytes does not accomodate symbols, whose impl stores string version in map. + // Use decStringAndBytes directly. + // return string(d.DecodeBytes(d.b[:], true, true)) + _, s = d.decStringAndBytes(d.b[:], true, true) + return +} + +func (d *bincDecDriver) DecodeBytes(bs []byte, isstring, zerocopy bool) (bsOut []byte) { + if isstring { + bsOut, _ = d.decStringAndBytes(bs, false, zerocopy) + return + } + if !d.bdRead { + d.readNextBd() + } + if d.bd == bincVdSpecial<<4|bincSpNil { + d.bdRead = false + return nil + } + var clen int + if d.vd == bincVdString || d.vd == bincVdByteArray { + clen = d.decLen() + } else { + d.d.errorf("Invalid d.vd for bytes. Expecting string:0x%x or bytearray:0x%x. Got: 0x%x", + bincVdString, bincVdByteArray, d.vd) + return + } + d.bdRead = false + if zerocopy { + if d.br { + return d.r.readx(clen) + } else if len(bs) == 0 { + bs = d.b[:] + } + } + return decByteSlice(d.r, clen, bs) +} + +func (d *bincDecDriver) DecodeExt(rv interface{}, xtag uint64, ext Ext) (realxtag uint64) { + if xtag > 0xff { + d.d.errorf("decodeExt: tag must be <= 0xff; got: %v", xtag) + return + } + realxtag1, xbs := d.decodeExtV(ext != nil, uint8(xtag)) + realxtag = uint64(realxtag1) + if ext == nil { + re := rv.(*RawExt) + re.Tag = realxtag + re.Data = detachZeroCopyBytes(d.br, re.Data, xbs) + } else { + ext.ReadExt(rv, xbs) + } + return +} + +func (d *bincDecDriver) decodeExtV(verifyTag bool, tag byte) (xtag byte, xbs []byte) { + if !d.bdRead { + d.readNextBd() + } + if d.vd == bincVdCustomExt { + l := d.decLen() + xtag = d.r.readn1() + if verifyTag && xtag != tag { + d.d.errorf("Wrong extension tag. Got %b. Expecting: %v", xtag, tag) + return + } + xbs = d.r.readx(l) + } else if d.vd == bincVdByteArray { + xbs = d.DecodeBytes(nil, false, true) + } else { + d.d.errorf("Invalid d.vd for extensions (Expecting extensions or byte array). Got: 0x%x", d.vd) + return + } + d.bdRead = false + return +} + +func (d *bincDecDriver) DecodeNaked() (v interface{}, vt valueType, decodeFurther bool) { + if !d.bdRead { + d.readNextBd() + } + + switch d.vd { + case bincVdSpecial: + switch d.vs { + case bincSpNil: + vt = valueTypeNil + case bincSpFalse: + vt = valueTypeBool + v = false + case bincSpTrue: + vt = valueTypeBool + v = true + case bincSpNan: + vt = valueTypeFloat + v = math.NaN() + case bincSpPosInf: + vt = valueTypeFloat + v = math.Inf(1) + case bincSpNegInf: + vt = valueTypeFloat + v = math.Inf(-1) + case bincSpZeroFloat: + vt = valueTypeFloat + v = float64(0) + case bincSpZero: + vt = valueTypeUint + v = uint64(0) // int8(0) + case bincSpNegOne: + vt = valueTypeInt + v = int64(-1) // int8(-1) + default: + d.d.errorf("decodeNaked: Unrecognized special value 0x%x", d.vs) + return + } + case bincVdSmallInt: + vt = valueTypeUint + v = uint64(int8(d.vs)) + 1 // int8(d.vs) + 1 + case bincVdPosInt: + vt = valueTypeUint + v = d.decUint() + case bincVdNegInt: + vt = valueTypeInt + v = -(int64(d.decUint())) + case bincVdFloat: + vt = valueTypeFloat + v = d.decFloat() + case bincVdSymbol: + vt = valueTypeSymbol + v = d.DecodeString() + case bincVdString: + vt = valueTypeString + v = d.DecodeString() + case bincVdByteArray: + vt = valueTypeBytes + v = d.DecodeBytes(nil, false, false) + case bincVdTimestamp: + vt = valueTypeTimestamp + tt, err := decodeTime(d.r.readx(int(d.vs))) + if err != nil { + panic(err) + } + v = tt + case bincVdCustomExt: + vt = valueTypeExt + l := d.decLen() + var re RawExt + re.Tag = uint64(d.r.readn1()) + re.Data = d.r.readx(l) + v = &re + vt = valueTypeExt + case bincVdArray: + vt = valueTypeArray + decodeFurther = true + case bincVdMap: + vt = valueTypeMap + decodeFurther = true + default: + d.d.errorf("decodeNaked: Unrecognized d.vd: 0x%x", d.vd) + return + } + + if !decodeFurther { + d.bdRead = false + } + if vt == valueTypeUint && d.h.SignedInteger { + d.bdType = valueTypeInt + v = int64(v.(uint64)) + } + return +} + +//------------------------------------ + +//BincHandle is a Handle for the Binc Schema-Free Encoding Format +//defined at https://github.com/ugorji/binc . +// +//BincHandle currently supports all Binc features with the following EXCEPTIONS: +// - only integers up to 64 bits of precision are supported. +// big integers are unsupported. +// - Only IEEE 754 binary32 and binary64 floats are supported (ie Go float32 and float64 types). +// extended precision and decimal IEEE 754 floats are unsupported. +// - Only UTF-8 strings supported. +// Unicode_Other Binc types (UTF16, UTF32) are currently unsupported. +// +//Note that these EXCEPTIONS are temporary and full support is possible and may happen soon. +type BincHandle struct { + BasicHandle + binaryEncodingType +} + +func (h *BincHandle) newEncDriver(e *Encoder) encDriver { + return &bincEncDriver{e: e, w: e.w} +} + +func (h *BincHandle) newDecDriver(d *Decoder) decDriver { + return &bincDecDriver{d: d, r: d.r, h: h, br: d.bytes} +} + +var _ decDriver = (*bincDecDriver)(nil) +var _ encDriver = (*bincEncDriver)(nil) diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/cbor.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/cbor.go new file mode 100644 index 0000000000..b56bcef9ba --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/cbor.go @@ -0,0 +1,566 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +import "math" + +const ( + cborMajorUint byte = iota + cborMajorNegInt + cborMajorBytes + cborMajorText + cborMajorArray + cborMajorMap + cborMajorTag + cborMajorOther +) + +const ( + cborBdFalse byte = 0xf4 + iota + cborBdTrue + cborBdNil + cborBdUndefined + cborBdExt + cborBdFloat16 + cborBdFloat32 + cborBdFloat64 +) + +const ( + cborBdIndefiniteBytes byte = 0x5f + cborBdIndefiniteString = 0x7f + cborBdIndefiniteArray = 0x9f + cborBdIndefiniteMap = 0xbf + cborBdBreak = 0xff +) + +const ( + CborStreamBytes byte = 0x5f + CborStreamString = 0x7f + CborStreamArray = 0x9f + CborStreamMap = 0xbf + CborStreamBreak = 0xff +) + +const ( + cborBaseUint byte = 0x00 + cborBaseNegInt = 0x20 + cborBaseBytes = 0x40 + cborBaseString = 0x60 + cborBaseArray = 0x80 + cborBaseMap = 0xa0 + cborBaseTag = 0xc0 + cborBaseSimple = 0xe0 +) + +// ------------------- + +type cborEncDriver struct { + e *Encoder + w encWriter + h *CborHandle + noBuiltInTypes + encNoSeparator + x [8]byte +} + +func (e *cborEncDriver) EncodeNil() { + e.w.writen1(cborBdNil) +} + +func (e *cborEncDriver) EncodeBool(b bool) { + if b { + e.w.writen1(cborBdTrue) + } else { + e.w.writen1(cborBdFalse) + } +} + +func (e *cborEncDriver) EncodeFloat32(f float32) { + e.w.writen1(cborBdFloat32) + bigenHelper{e.x[:4], e.w}.writeUint32(math.Float32bits(f)) +} + +func (e *cborEncDriver) EncodeFloat64(f float64) { + e.w.writen1(cborBdFloat64) + bigenHelper{e.x[:8], e.w}.writeUint64(math.Float64bits(f)) +} + +func (e *cborEncDriver) encUint(v uint64, bd byte) { + if v <= 0x17 { + e.w.writen1(byte(v) + bd) + } else if v <= math.MaxUint8 { + e.w.writen2(bd+0x18, uint8(v)) + } else if v <= math.MaxUint16 { + e.w.writen1(bd + 0x19) + bigenHelper{e.x[:2], e.w}.writeUint16(uint16(v)) + } else if v <= math.MaxUint32 { + e.w.writen1(bd + 0x1a) + bigenHelper{e.x[:4], e.w}.writeUint32(uint32(v)) + } else if v <= math.MaxUint64 { + e.w.writen1(bd + 0x1b) + bigenHelper{e.x[:8], e.w}.writeUint64(v) + } +} + +func (e *cborEncDriver) EncodeInt(v int64) { + if v < 0 { + e.encUint(uint64(-1-v), cborBaseNegInt) + } else { + e.encUint(uint64(v), cborBaseUint) + } +} + +func (e *cborEncDriver) EncodeUint(v uint64) { + e.encUint(v, cborBaseUint) +} + +func (e *cborEncDriver) encLen(bd byte, length int) { + e.encUint(uint64(length), bd) +} + +func (e *cborEncDriver) EncodeExt(rv interface{}, xtag uint64, ext Ext, en *Encoder) { + e.encUint(uint64(xtag), cborBaseTag) + if v := ext.ConvertExt(rv); v == nil { + e.EncodeNil() + } else { + en.encode(v) + } +} + +func (e *cborEncDriver) EncodeRawExt(re *RawExt, en *Encoder) { + e.encUint(uint64(re.Tag), cborBaseTag) + if re.Data != nil { + en.encode(re.Data) + } else if re.Value == nil { + e.EncodeNil() + } else { + en.encode(re.Value) + } +} + +func (e *cborEncDriver) EncodeArrayStart(length int) { + e.encLen(cborBaseArray, length) +} + +func (e *cborEncDriver) EncodeMapStart(length int) { + e.encLen(cborBaseMap, length) +} + +func (e *cborEncDriver) EncodeString(c charEncoding, v string) { + e.encLen(cborBaseString, len(v)) + e.w.writestr(v) +} + +func (e *cborEncDriver) EncodeSymbol(v string) { + e.EncodeString(c_UTF8, v) +} + +func (e *cborEncDriver) EncodeStringBytes(c charEncoding, v []byte) { + e.encLen(cborBaseBytes, len(v)) + e.w.writeb(v) +} + +// ---------------------- + +type cborDecDriver struct { + d *Decoder + h *CborHandle + r decReader + br bool // bytes reader + bdRead bool + bdType valueType + bd byte + b [scratchByteArrayLen]byte + noBuiltInTypes + decNoSeparator +} + +func (d *cborDecDriver) readNextBd() { + d.bd = d.r.readn1() + d.bdRead = true + d.bdType = valueTypeUnset +} + +func (d *cborDecDriver) IsContainerType(vt valueType) (bv bool) { + switch vt { + case valueTypeNil: + return d.bd == cborBdNil + case valueTypeBytes: + return d.bd == cborBdIndefiniteBytes || (d.bd >= cborBaseBytes && d.bd < cborBaseString) + case valueTypeString: + return d.bd == cborBdIndefiniteString || (d.bd >= cborBaseString && d.bd < cborBaseArray) + case valueTypeArray: + return d.bd == cborBdIndefiniteArray || (d.bd >= cborBaseArray && d.bd < cborBaseMap) + case valueTypeMap: + return d.bd == cborBdIndefiniteMap || (d.bd >= cborBaseMap && d.bd < cborBaseTag) + } + d.d.errorf("isContainerType: unsupported parameter: %v", vt) + return // "unreachable" +} + +func (d *cborDecDriver) TryDecodeAsNil() bool { + if !d.bdRead { + d.readNextBd() + } + // treat Nil and Undefined as nil values + if d.bd == cborBdNil || d.bd == cborBdUndefined { + d.bdRead = false + return true + } + return false +} + +func (d *cborDecDriver) CheckBreak() bool { + if !d.bdRead { + d.readNextBd() + } + if d.bd == cborBdBreak { + d.bdRead = false + return true + } + return false +} + +func (d *cborDecDriver) decUint() (ui uint64) { + v := d.bd & 0x1f + if v <= 0x17 { + ui = uint64(v) + } else { + if v == 0x18 { + ui = uint64(d.r.readn1()) + } else if v == 0x19 { + ui = uint64(bigen.Uint16(d.r.readx(2))) + } else if v == 0x1a { + ui = uint64(bigen.Uint32(d.r.readx(4))) + } else if v == 0x1b { + ui = uint64(bigen.Uint64(d.r.readx(8))) + } else { + d.d.errorf("decUint: Invalid descriptor: %v", d.bd) + return + } + } + return +} + +func (d *cborDecDriver) decCheckInteger() (neg bool) { + if !d.bdRead { + d.readNextBd() + } + major := d.bd >> 5 + if major == cborMajorUint { + } else if major == cborMajorNegInt { + neg = true + } else { + d.d.errorf("invalid major: %v (bd: %v)", major, d.bd) + return + } + return +} + +func (d *cborDecDriver) DecodeInt(bitsize uint8) (i int64) { + neg := d.decCheckInteger() + ui := d.decUint() + // check if this number can be converted to an int without overflow + var overflow bool + if neg { + if i, overflow = chkOvf.SignedInt(ui + 1); overflow { + d.d.errorf("cbor: overflow converting %v to signed integer", ui+1) + return + } + i = -i + } else { + if i, overflow = chkOvf.SignedInt(ui); overflow { + d.d.errorf("cbor: overflow converting %v to signed integer", ui) + return + } + } + if chkOvf.Int(i, bitsize) { + d.d.errorf("cbor: overflow integer: %v", i) + return + } + d.bdRead = false + return +} + +func (d *cborDecDriver) DecodeUint(bitsize uint8) (ui uint64) { + if d.decCheckInteger() { + d.d.errorf("Assigning negative signed value to unsigned type") + return + } + ui = d.decUint() + if chkOvf.Uint(ui, bitsize) { + d.d.errorf("cbor: overflow integer: %v", ui) + return + } + d.bdRead = false + return +} + +func (d *cborDecDriver) DecodeFloat(chkOverflow32 bool) (f float64) { + if !d.bdRead { + d.readNextBd() + } + if bd := d.bd; bd == cborBdFloat16 { + f = float64(math.Float32frombits(halfFloatToFloatBits(bigen.Uint16(d.r.readx(2))))) + } else if bd == cborBdFloat32 { + f = float64(math.Float32frombits(bigen.Uint32(d.r.readx(4)))) + } else if bd == cborBdFloat64 { + f = math.Float64frombits(bigen.Uint64(d.r.readx(8))) + } else if bd >= cborBaseUint && bd < cborBaseBytes { + f = float64(d.DecodeInt(64)) + } else { + d.d.errorf("Float only valid from float16/32/64: Invalid descriptor: %v", bd) + return + } + if chkOverflow32 && chkOvf.Float32(f) { + d.d.errorf("cbor: float32 overflow: %v", f) + return + } + d.bdRead = false + return +} + +// bool can be decoded from bool only (single byte). +func (d *cborDecDriver) DecodeBool() (b bool) { + if !d.bdRead { + d.readNextBd() + } + if bd := d.bd; bd == cborBdTrue { + b = true + } else if bd == cborBdFalse { + } else { + d.d.errorf("Invalid single-byte value for bool: %s: %x", msgBadDesc, d.bd) + return + } + d.bdRead = false + return +} + +func (d *cborDecDriver) ReadMapStart() (length int) { + d.bdRead = false + if d.bd == cborBdIndefiniteMap { + return -1 + } + return d.decLen() +} + +func (d *cborDecDriver) ReadArrayStart() (length int) { + d.bdRead = false + if d.bd == cborBdIndefiniteArray { + return -1 + } + return d.decLen() +} + +func (d *cborDecDriver) decLen() int { + return int(d.decUint()) +} + +func (d *cborDecDriver) decAppendIndefiniteBytes(bs []byte) []byte { + d.bdRead = false + for { + if d.CheckBreak() { + break + } + if major := d.bd >> 5; major != cborMajorBytes && major != cborMajorText { + d.d.errorf("cbor: expect bytes or string major type in indefinite string/bytes; got: %v, byte: %v", major, d.bd) + return nil + } + n := d.decLen() + oldLen := len(bs) + newLen := oldLen + n + if newLen > cap(bs) { + bs2 := make([]byte, newLen, 2*cap(bs)+n) + copy(bs2, bs) + bs = bs2 + } else { + bs = bs[:newLen] + } + d.r.readb(bs[oldLen:newLen]) + // bs = append(bs, d.r.readn()...) + d.bdRead = false + } + d.bdRead = false + return bs +} + +func (d *cborDecDriver) DecodeBytes(bs []byte, isstring, zerocopy bool) (bsOut []byte) { + if !d.bdRead { + d.readNextBd() + } + if d.bd == cborBdNil || d.bd == cborBdUndefined { + d.bdRead = false + return nil + } + if d.bd == cborBdIndefiniteBytes || d.bd == cborBdIndefiniteString { + if bs == nil { + return d.decAppendIndefiniteBytes(nil) + } + return d.decAppendIndefiniteBytes(bs[:0]) + } + clen := d.decLen() + d.bdRead = false + if zerocopy { + if d.br { + return d.r.readx(clen) + } else if len(bs) == 0 { + bs = d.b[:] + } + } + return decByteSlice(d.r, clen, bs) +} + +func (d *cborDecDriver) DecodeString() (s string) { + return string(d.DecodeBytes(d.b[:], true, true)) +} + +func (d *cborDecDriver) DecodeExt(rv interface{}, xtag uint64, ext Ext) (realxtag uint64) { + if !d.bdRead { + d.readNextBd() + } + u := d.decUint() + d.bdRead = false + realxtag = u + if ext == nil { + re := rv.(*RawExt) + re.Tag = realxtag + d.d.decode(&re.Value) + } else if xtag != realxtag { + d.d.errorf("Wrong extension tag. Got %b. Expecting: %v", realxtag, xtag) + return + } else { + var v interface{} + d.d.decode(&v) + ext.UpdateExt(rv, v) + } + d.bdRead = false + return +} + +func (d *cborDecDriver) DecodeNaked() (v interface{}, vt valueType, decodeFurther bool) { + if !d.bdRead { + d.readNextBd() + } + + switch d.bd { + case cborBdNil: + vt = valueTypeNil + case cborBdFalse: + vt = valueTypeBool + v = false + case cborBdTrue: + vt = valueTypeBool + v = true + case cborBdFloat16, cborBdFloat32: + vt = valueTypeFloat + v = d.DecodeFloat(true) + case cborBdFloat64: + vt = valueTypeFloat + v = d.DecodeFloat(false) + case cborBdIndefiniteBytes: + vt = valueTypeBytes + v = d.DecodeBytes(nil, false, false) + case cborBdIndefiniteString: + vt = valueTypeString + v = d.DecodeString() + case cborBdIndefiniteArray: + vt = valueTypeArray + decodeFurther = true + case cborBdIndefiniteMap: + vt = valueTypeMap + decodeFurther = true + default: + switch { + case d.bd >= cborBaseUint && d.bd < cborBaseNegInt: + if d.h.SignedInteger { + vt = valueTypeInt + v = d.DecodeInt(64) + } else { + vt = valueTypeUint + v = d.DecodeUint(64) + } + case d.bd >= cborBaseNegInt && d.bd < cborBaseBytes: + vt = valueTypeInt + v = d.DecodeInt(64) + case d.bd >= cborBaseBytes && d.bd < cborBaseString: + vt = valueTypeBytes + v = d.DecodeBytes(nil, false, false) + case d.bd >= cborBaseString && d.bd < cborBaseArray: + vt = valueTypeString + v = d.DecodeString() + case d.bd >= cborBaseArray && d.bd < cborBaseMap: + vt = valueTypeArray + decodeFurther = true + case d.bd >= cborBaseMap && d.bd < cborBaseTag: + vt = valueTypeMap + decodeFurther = true + case d.bd >= cborBaseTag && d.bd < cborBaseSimple: + vt = valueTypeExt + var re RawExt + ui := d.decUint() + d.bdRead = false + re.Tag = ui + d.d.decode(&re.Value) + v = &re + // decodeFurther = true + default: + d.d.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd) + return + } + } + + if !decodeFurther { + d.bdRead = false + } + return +} + +// ------------------------- + +// CborHandle is a Handle for the CBOR encoding format, +// defined at http://tools.ietf.org/html/rfc7049 and documented further at http://cbor.io . +// +// CBOR is comprehensively supported, including support for: +// - indefinite-length arrays/maps/bytes/strings +// - (extension) tags in range 0..0xffff (0 .. 65535) +// - half, single and double-precision floats +// - all numbers (1, 2, 4 and 8-byte signed and unsigned integers) +// - nil, true, false, ... +// - arrays and maps, bytes and text strings +// +// None of the optional extensions (with tags) defined in the spec are supported out-of-the-box. +// Users can implement them as needed (using SetExt), including spec-documented ones: +// - timestamp, BigNum, BigFloat, Decimals, Encoded Text (e.g. URL, regexp, base64, MIME Message), etc. +// +// To encode with indefinite lengths (streaming), users will use +// (Must)Encode methods of *Encoder, along with writing CborStreamXXX constants. +// +// For example, to encode "one-byte" as an indefinite length string: +// var buf bytes.Buffer +// e := NewEncoder(&buf, new(CborHandle)) +// buf.WriteByte(CborStreamString) +// e.MustEncode("one-") +// e.MustEncode("byte") +// buf.WriteByte(CborStreamBreak) +// encodedBytes := buf.Bytes() +// var vv interface{} +// NewDecoderBytes(buf.Bytes(), new(CborHandle)).MustDecode(&vv) +// // Now, vv contains the same string "one-byte" +// +type CborHandle struct { + BasicHandle + binaryEncodingType +} + +func (h *CborHandle) newEncDriver(e *Encoder) encDriver { + return &cborEncDriver{e: e, w: e.w, h: h} +} + +func (h *CborHandle) newDecDriver(d *Decoder) decDriver { + return &cborDecDriver{d: d, r: d.r, h: h, br: d.bytes} +} + +var _ decDriver = (*cborDecDriver)(nil) +var _ encDriver = (*cborEncDriver)(nil) diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/cbor_test.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/cbor_test.go new file mode 100644 index 0000000000..b03a9da078 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/cbor_test.go @@ -0,0 +1,205 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +import ( + "bufio" + "bytes" + "encoding/hex" + "math" + "os" + "regexp" + "strings" + "testing" +) + +func TestCborIndefiniteLength(t *testing.T) { + oldMapType := testCborH.MapType + defer func() { + testCborH.MapType = oldMapType + }() + testCborH.MapType = testMapStrIntfTyp + // var ( + // M1 map[string][]byte + // M2 map[uint64]bool + // L1 []interface{} + // S1 []string + // B1 []byte + // ) + var v, vv interface{} + // define it (v), encode it using indefinite lengths, decode it (vv), compare v to vv + v = map[string]interface{}{ + "one-byte-key": []byte{1, 2, 3, 4, 5, 6}, + "two-string-key": "two-value", + "three-list-key": []interface{}{true, false, uint64(1), int64(-1)}, + } + var buf bytes.Buffer + // buf.Reset() + e := NewEncoder(&buf, testCborH) + buf.WriteByte(cborBdIndefiniteMap) + //---- + buf.WriteByte(cborBdIndefiniteString) + e.MustEncode("one-") + e.MustEncode("byte-") + e.MustEncode("key") + buf.WriteByte(cborBdBreak) + + buf.WriteByte(cborBdIndefiniteBytes) + e.MustEncode([]byte{1, 2, 3}) + e.MustEncode([]byte{4, 5, 6}) + buf.WriteByte(cborBdBreak) + + //---- + buf.WriteByte(cborBdIndefiniteString) + e.MustEncode("two-") + e.MustEncode("string-") + e.MustEncode("key") + buf.WriteByte(cborBdBreak) + + buf.WriteByte(cborBdIndefiniteString) + e.MustEncode([]byte("two-")) // encode as bytes, to check robustness of code + e.MustEncode([]byte("value")) + buf.WriteByte(cborBdBreak) + + //---- + buf.WriteByte(cborBdIndefiniteString) + e.MustEncode("three-") + e.MustEncode("list-") + e.MustEncode("key") + buf.WriteByte(cborBdBreak) + + buf.WriteByte(cborBdIndefiniteArray) + e.MustEncode(true) + e.MustEncode(false) + e.MustEncode(uint64(1)) + e.MustEncode(int64(-1)) + buf.WriteByte(cborBdBreak) + + buf.WriteByte(cborBdBreak) // close map + + NewDecoderBytes(buf.Bytes(), testCborH).MustDecode(&vv) + if err := deepEqual(v, vv); err != nil { + logT(t, "-------- Before and After marshal do not match: Error: %v", err) + logT(t, " ....... GOLDEN: (%T) %#v", v, v) + logT(t, " ....... DECODED: (%T) %#v", vv, vv) + failT(t) + } +} + +type testCborGolden struct { + Base64 string `codec:"cbor"` + Hex string `codec:"hex"` + Roundtrip bool `codec:"roundtrip"` + Decoded interface{} `codec:"decoded"` + Diagnostic string `codec:"diagnostic"` + Skip bool `codec:"skip"` +} + +// Some tests are skipped because they include numbers outside the range of int64/uint64 +func doTestCborGoldens(t *testing.T) { + oldMapType := testCborH.MapType + defer func() { + testCborH.MapType = oldMapType + }() + testCborH.MapType = testMapStrIntfTyp + // decode test-cbor-goldens.json into a list of []*testCborGolden + // for each one, + // - decode hex into []byte bs + // - decode bs into interface{} v + // - compare both using deepequal + // - for any miss, record it + var gs []*testCborGolden + f, err := os.Open("test-cbor-goldens.json") + if err != nil { + logT(t, "error opening test-cbor-goldens.json: %v", err) + failT(t) + } + defer f.Close() + jh := new(JsonHandle) + jh.MapType = testMapStrIntfTyp + // d := NewDecoder(f, jh) + d := NewDecoder(bufio.NewReader(f), jh) + // err = d.Decode(&gs) + d.MustDecode(&gs) + if err != nil { + logT(t, "error json decoding test-cbor-goldens.json: %v", err) + failT(t) + } + + tagregex := regexp.MustCompile(`[\d]+\(.+?\)`) + hexregex := regexp.MustCompile(`h'([0-9a-fA-F]*)'`) + for i, g := range gs { + // fmt.Printf("%v, skip: %v, isTag: %v, %s\n", i, g.Skip, tagregex.MatchString(g.Diagnostic), g.Diagnostic) + // skip tags or simple or those with prefix, as we can't verify them. + if g.Skip || strings.HasPrefix(g.Diagnostic, "simple(") || tagregex.MatchString(g.Diagnostic) { + // fmt.Printf("%v: skipped\n", i) + logT(t, "[%v] skipping because skip=true OR unsupported simple value or Tag Value", i) + continue + } + // println("++++++++++++", i, "g.Diagnostic", g.Diagnostic) + if hexregex.MatchString(g.Diagnostic) { + // println(i, "g.Diagnostic matched hex") + if s2 := g.Diagnostic[2 : len(g.Diagnostic)-1]; s2 == "" { + g.Decoded = zeroByteSlice + } else if bs2, err2 := hex.DecodeString(s2); err2 == nil { + g.Decoded = bs2 + } + // fmt.Printf("%v: hex: %v\n", i, g.Decoded) + } + bs, err := hex.DecodeString(g.Hex) + if err != nil { + logT(t, "[%v] error hex decoding %s [%v]: %v", i, g.Hex, err) + failT(t) + } + var v interface{} + NewDecoderBytes(bs, testCborH).MustDecode(&v) + if _, ok := v.(RawExt); ok { + continue + } + // check the diagnostics to compare + switch g.Diagnostic { + case "Infinity": + b := math.IsInf(v.(float64), 1) + testCborError(t, i, math.Inf(1), v, nil, &b) + case "-Infinity": + b := math.IsInf(v.(float64), -1) + testCborError(t, i, math.Inf(-1), v, nil, &b) + case "NaN": + // println(i, "checking NaN") + b := math.IsNaN(v.(float64)) + testCborError(t, i, math.NaN(), v, nil, &b) + case "undefined": + b := v == nil + testCborError(t, i, nil, v, nil, &b) + default: + v0 := g.Decoded + // testCborCoerceJsonNumber(reflect.ValueOf(&v0)) + testCborError(t, i, v0, v, deepEqual(v0, v), nil) + } + } +} + +func testCborError(t *testing.T, i int, v0, v1 interface{}, err error, equal *bool) { + if err == nil && equal == nil { + // fmt.Printf("%v testCborError passed (err and equal nil)\n", i) + return + } + if err != nil { + logT(t, "[%v] deepEqual error: %v", i, err) + logT(t, " ....... GOLDEN: (%T) %#v", v0, v0) + logT(t, " ....... DECODED: (%T) %#v", v1, v1) + failT(t) + } + if equal != nil && !*equal { + logT(t, "[%v] values not equal", i) + logT(t, " ....... GOLDEN: (%T) %#v", v0, v0) + logT(t, " ....... DECODED: (%T) %#v", v1, v1) + failT(t) + } + // fmt.Printf("%v testCborError passed (checks passed)\n", i) +} + +func TestCborGoldens(t *testing.T) { + doTestCborGoldens(t) +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/codec_test.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/codec_test.go new file mode 100644 index 0000000000..205af445a2 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/codec_test.go @@ -0,0 +1,1117 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +// Test works by using a slice of interfaces. +// It can test for encoding/decoding into/from a nil interface{} +// or passing the object to encode/decode into. +// +// There are basically 2 main tests here. +// First test internally encodes and decodes things and verifies that +// the artifact was as expected. +// Second test will use python msgpack to create a bunch of golden files, +// read those files, and compare them to what it should be. It then +// writes those files back out and compares the byte streams. +// +// Taken together, the tests are pretty extensive. +// +// The following manual tests must be done: +// - TestCodecUnderlyingType +// - Set fastpathEnabled to false and run tests (to ensure that regular reflection works). +// We don't want to use a variable there so that code is ellided. + +import ( + "bytes" + "encoding/gob" + "flag" + "fmt" + "io/ioutil" + "math" + "net" + "net/rpc" + "os" + "os/exec" + "path/filepath" + "reflect" + "runtime" + "strconv" + "sync/atomic" + "testing" + "time" +) + +func init() { + testInitFlags() + testPreInitFns = append(testPreInitFns, testInit) +} + +type testVerifyArg int + +const ( + testVerifyMapTypeSame testVerifyArg = iota + testVerifyMapTypeStrIntf + testVerifyMapTypeIntfIntf + // testVerifySliceIntf + testVerifyForPython +) + +const testSkipRPCTests = false + +var ( + testVerbose bool + testInitDebug bool + testUseIoEncDec bool + testStructToArray bool + testCanonical bool + testWriteNoSymbols bool + testSkipIntf bool + + skipVerifyVal interface{} = &(struct{}{}) + + testMapStrIntfTyp = reflect.TypeOf(map[string]interface{}(nil)) + + // For Go Time, do not use a descriptive timezone. + // It's unnecessary, and makes it harder to do a reflect.DeepEqual. + // The Offset already tells what the offset should be, if not on UTC and unknown zone name. + timeLoc = time.FixedZone("", -8*60*60) // UTC-08:00 //time.UTC-8 + timeToCompare1 = time.Date(2012, 2, 2, 2, 2, 2, 2000, timeLoc).UTC() + timeToCompare2 = time.Date(1900, 2, 2, 2, 2, 2, 2000, timeLoc).UTC() + timeToCompare3 = time.Unix(0, 270).UTC() // use value that must be encoded as uint64 for nanoseconds (for cbor/msgpack comparison) + //timeToCompare4 = time.Time{}.UTC() // does not work well with simple cbor time encoding (overflow) + timeToCompare4 = time.Unix(-2013855848, 4223).UTC() + + table []interface{} // main items we encode + tableVerify []interface{} // we verify encoded things against this after decode + tableTestNilVerify []interface{} // for nil interface, use this to verify (rules are different) + tablePythonVerify []interface{} // for verifying for python, since Python sometimes + // will encode a float32 as float64, or large int as uint + testRpcInt = new(TestRpcInt) +) + +func testInitFlags() { + // delete(testDecOpts.ExtFuncs, timeTyp) + flag.BoolVar(&testVerbose, "tv", false, "Test Verbose") + flag.BoolVar(&testInitDebug, "tg", false, "Test Init Debug") + flag.BoolVar(&testUseIoEncDec, "ti", false, "Use IO Reader/Writer for Marshal/Unmarshal") + flag.BoolVar(&testStructToArray, "ts", false, "Set StructToArray option") + flag.BoolVar(&testWriteNoSymbols, "tn", false, "Set NoSymbols option") + flag.BoolVar(&testCanonical, "tc", false, "Set Canonical option") + flag.BoolVar(&testSkipIntf, "tf", false, "Skip Interfaces") +} + +type TestABC struct { + A, B, C string +} + +type TestRpcInt struct { + i int +} + +func (r *TestRpcInt) Update(n int, res *int) error { r.i = n; *res = r.i; return nil } +func (r *TestRpcInt) Square(ignore int, res *int) error { *res = r.i * r.i; return nil } +func (r *TestRpcInt) Mult(n int, res *int) error { *res = r.i * n; return nil } +func (r *TestRpcInt) EchoStruct(arg TestABC, res *string) error { + *res = fmt.Sprintf("%#v", arg) + return nil +} +func (r *TestRpcInt) Echo123(args []string, res *string) error { + *res = fmt.Sprintf("%#v", args) + return nil +} + +type testUnixNanoTimeExt struct{} + +func (x testUnixNanoTimeExt) WriteExt(interface{}) []byte { panic("unsupported") } +func (x testUnixNanoTimeExt) ReadExt(interface{}, []byte) { panic("unsupported") } +func (x testUnixNanoTimeExt) ConvertExt(v interface{}) interface{} { + switch v2 := v.(type) { + case time.Time: + return v2.UTC().UnixNano() + case *time.Time: + return v2.UTC().UnixNano() + default: + panic(fmt.Sprintf("unsupported format for time conversion: expecting time.Time; got %T", v)) + } +} +func (x testUnixNanoTimeExt) UpdateExt(dest interface{}, v interface{}) { + // fmt.Printf("testUnixNanoTimeExt.UpdateExt: v: %v\n", v) + tt := dest.(*time.Time) + switch v2 := v.(type) { + case int64: + *tt = time.Unix(0, v2).UTC() + case uint64: + *tt = time.Unix(0, int64(v2)).UTC() + //case float64: + //case string: + default: + panic(fmt.Sprintf("unsupported format for time conversion: expecting int64/uint64; got %T", v)) + } + // fmt.Printf("testUnixNanoTimeExt.UpdateExt: v: %v, tt: %#v\n", v, tt) +} + +func testVerifyVal(v interface{}, arg testVerifyArg) (v2 interface{}) { + //for python msgpack, + // - all positive integers are unsigned 64-bit ints + // - all floats are float64 + switch iv := v.(type) { + case int8: + if iv >= 0 { + v2 = uint64(iv) + } else { + v2 = int64(iv) + } + case int16: + if iv >= 0 { + v2 = uint64(iv) + } else { + v2 = int64(iv) + } + case int32: + if iv >= 0 { + v2 = uint64(iv) + } else { + v2 = int64(iv) + } + case int64: + if iv >= 0 { + v2 = uint64(iv) + } else { + v2 = int64(iv) + } + case uint8: + v2 = uint64(iv) + case uint16: + v2 = uint64(iv) + case uint32: + v2 = uint64(iv) + case uint64: + v2 = uint64(iv) + case float32: + v2 = float64(iv) + case float64: + v2 = float64(iv) + case []interface{}: + m2 := make([]interface{}, len(iv)) + for j, vj := range iv { + m2[j] = testVerifyVal(vj, arg) + } + v2 = m2 + case map[string]bool: + switch arg { + case testVerifyMapTypeSame: + m2 := make(map[string]bool) + for kj, kv := range iv { + m2[kj] = kv + } + v2 = m2 + case testVerifyMapTypeStrIntf, testVerifyForPython: + m2 := make(map[string]interface{}) + for kj, kv := range iv { + m2[kj] = kv + } + v2 = m2 + case testVerifyMapTypeIntfIntf: + m2 := make(map[interface{}]interface{}) + for kj, kv := range iv { + m2[kj] = kv + } + v2 = m2 + } + case map[string]interface{}: + switch arg { + case testVerifyMapTypeSame: + m2 := make(map[string]interface{}) + for kj, kv := range iv { + m2[kj] = testVerifyVal(kv, arg) + } + v2 = m2 + case testVerifyMapTypeStrIntf, testVerifyForPython: + m2 := make(map[string]interface{}) + for kj, kv := range iv { + m2[kj] = testVerifyVal(kv, arg) + } + v2 = m2 + case testVerifyMapTypeIntfIntf: + m2 := make(map[interface{}]interface{}) + for kj, kv := range iv { + m2[kj] = testVerifyVal(kv, arg) + } + v2 = m2 + } + case map[interface{}]interface{}: + m2 := make(map[interface{}]interface{}) + for kj, kv := range iv { + m2[testVerifyVal(kj, arg)] = testVerifyVal(kv, arg) + } + v2 = m2 + case time.Time: + switch arg { + case testVerifyForPython: + if iv2 := iv.UnixNano(); iv2 >= 0 { + v2 = uint64(iv2) + } else { + v2 = int64(iv2) + } + default: + v2 = v + } + default: + v2 = v + } + return +} + +func testInit() { + gob.Register(new(TestStruc)) + if testInitDebug { + ts0 := newTestStruc(2, false, !testSkipIntf, false) + fmt.Printf("====> depth: %v, ts: %#v\n", 2, ts0) + } + + testJsonH.Canonical = testCanonical + testCborH.Canonical = testCanonical + testSimpleH.Canonical = testCanonical + testBincH.Canonical = testCanonical + testMsgpackH.Canonical = testCanonical + + testJsonH.StructToArray = testStructToArray + testCborH.StructToArray = testStructToArray + testSimpleH.StructToArray = testStructToArray + testBincH.StructToArray = testStructToArray + testMsgpackH.StructToArray = testStructToArray + + testMsgpackH.RawToString = true + + if testWriteNoSymbols { + testBincH.AsSymbols = AsSymbolNone + } else { + testBincH.AsSymbols = AsSymbolAll + } + + // testMsgpackH.AddExt(byteSliceTyp, 0, testMsgpackH.BinaryEncodeExt, testMsgpackH.BinaryDecodeExt) + // testMsgpackH.AddExt(timeTyp, 1, testMsgpackH.TimeEncodeExt, testMsgpackH.TimeDecodeExt) + timeEncExt := func(rv reflect.Value) (bs []byte, err error) { + switch v2 := rv.Interface().(type) { + case time.Time: + bs = encodeTime(v2) + case *time.Time: + bs = encodeTime(*v2) + default: + err = fmt.Errorf("unsupported format for time conversion: expecting time.Time; got %T", v2) + } + return + } + timeDecExt := func(rv reflect.Value, bs []byte) (err error) { + tt, err := decodeTime(bs) + if err == nil { + *(rv.Interface().(*time.Time)) = tt + } + return + } + + // add extensions for msgpack, simple for time.Time, so we can encode/decode same way. + testMsgpackH.AddExt(timeTyp, 1, timeEncExt, timeDecExt) + testSimpleH.AddExt(timeTyp, 1, timeEncExt, timeDecExt) + testCborH.SetExt(timeTyp, 1, &testUnixNanoTimeExt{}) + testJsonH.SetExt(timeTyp, 1, &testUnixNanoTimeExt{}) + + primitives := []interface{}{ + int8(-8), + int16(-1616), + int32(-32323232), + int64(-6464646464646464), + uint8(192), + uint16(1616), + uint32(32323232), + uint64(6464646464646464), + byte(192), + float32(-3232.0), + float64(-6464646464.0), + float32(3232.0), + float64(6464646464.0), + false, + true, + nil, + "someday", + "", + "bytestring", + timeToCompare1, + timeToCompare2, + timeToCompare3, + timeToCompare4, + } + mapsAndStrucs := []interface{}{ + map[string]bool{ + "true": true, + "false": false, + }, + map[string]interface{}{ + "true": "True", + "false": false, + "uint16(1616)": uint16(1616), + }, + //add a complex combo map in here. (map has list which has map) + //note that after the first thing, everything else should be generic. + map[string]interface{}{ + "list": []interface{}{ + int16(1616), + int32(32323232), + true, + float32(-3232.0), + map[string]interface{}{ + "TRUE": true, + "FALSE": false, + }, + []interface{}{true, false}, + }, + "int32": int32(32323232), + "bool": true, + "LONG STRING": "123456789012345678901234567890123456789012345678901234567890", + "SHORT STRING": "1234567890", + }, + map[interface{}]interface{}{ + true: "true", + uint8(138): false, + "false": uint8(200), + }, + newTestStruc(0, false, !testSkipIntf, false), + } + + table = []interface{}{} + table = append(table, primitives...) //0-19 are primitives + table = append(table, primitives) //20 is a list of primitives + table = append(table, mapsAndStrucs...) //21-24 are maps. 25 is a *struct + + tableVerify = make([]interface{}, len(table)) + tableTestNilVerify = make([]interface{}, len(table)) + tablePythonVerify = make([]interface{}, len(table)) + + lp := len(primitives) + av := tableVerify + for i, v := range table { + if i == lp+3 { + av[i] = skipVerifyVal + continue + } + //av[i] = testVerifyVal(v, testVerifyMapTypeSame) + switch v.(type) { + case []interface{}: + av[i] = testVerifyVal(v, testVerifyMapTypeSame) + case map[string]interface{}: + av[i] = testVerifyVal(v, testVerifyMapTypeSame) + case map[interface{}]interface{}: + av[i] = testVerifyVal(v, testVerifyMapTypeSame) + default: + av[i] = v + } + } + + av = tableTestNilVerify + for i, v := range table { + if i > lp+3 { + av[i] = skipVerifyVal + continue + } + av[i] = testVerifyVal(v, testVerifyMapTypeStrIntf) + } + + av = tablePythonVerify + for i, v := range table { + if i > lp+3 { + av[i] = skipVerifyVal + continue + } + av[i] = testVerifyVal(v, testVerifyForPython) + } + + tablePythonVerify = tablePythonVerify[:24] +} + +func testUnmarshal(v interface{}, data []byte, h Handle) (err error) { + if testUseIoEncDec { + NewDecoder(bytes.NewBuffer(data), h).MustDecode(v) + } else { + NewDecoderBytes(data, h).MustDecode(v) + } + return +} + +func testMarshal(v interface{}, h Handle) (bs []byte, err error) { + if testUseIoEncDec { + var buf bytes.Buffer + NewEncoder(&buf, h).MustEncode(v) + bs = buf.Bytes() + return + } + NewEncoderBytes(&bs, h).MustEncode(v) + return +} + +func testMarshalErr(v interface{}, h Handle, t *testing.T, name string) (bs []byte, err error) { + if bs, err = testMarshal(v, h); err != nil { + logT(t, "Error encoding %s: %v, Err: %v", name, v, err) + t.FailNow() + } + return +} + +func testUnmarshalErr(v interface{}, data []byte, h Handle, t *testing.T, name string) (err error) { + if err = testUnmarshal(v, data, h); err != nil { + logT(t, "Error Decoding into %s: %v, Err: %v", name, v, err) + t.FailNow() + } + return +} + +// doTestCodecTableOne allows us test for different variations based on arguments passed. +func doTestCodecTableOne(t *testing.T, testNil bool, h Handle, + vs []interface{}, vsVerify []interface{}) { + //if testNil, then just test for when a pointer to a nil interface{} is passed. It should work. + //Current setup allows us test (at least manually) the nil interface or typed interface. + logT(t, "================ TestNil: %v ================\n", testNil) + for i, v0 := range vs { + logT(t, "..............................................") + logT(t, " Testing: #%d:, %T, %#v\n", i, v0, v0) + b0, err := testMarshalErr(v0, h, t, "v0") + if err != nil { + continue + } + if h.isBinary() { + logT(t, " Encoded bytes: len: %v, %v\n", len(b0), b0) + } else { + logT(t, " Encoded string: len: %v, %v\n", len(string(b0)), string(b0)) + // println("########### encoded string: " + string(b0)) + } + var v1 interface{} + + if testNil { + err = testUnmarshal(&v1, b0, h) + } else { + if v0 != nil { + v0rt := reflect.TypeOf(v0) // ptr + rv1 := reflect.New(v0rt) + err = testUnmarshal(rv1.Interface(), b0, h) + v1 = rv1.Elem().Interface() + // v1 = reflect.Indirect(reflect.ValueOf(v1)).Interface() + } + } + + logT(t, " v1 returned: %T, %#v", v1, v1) + // if v1 != nil { + // logT(t, " v1 returned: %T, %#v", v1, v1) + // //we always indirect, because ptr to typed value may be passed (if not testNil) + // v1 = reflect.Indirect(reflect.ValueOf(v1)).Interface() + // } + if err != nil { + logT(t, "-------- Error: %v. Partial return: %v", err, v1) + failT(t) + continue + } + v0check := vsVerify[i] + if v0check == skipVerifyVal { + logT(t, " Nil Check skipped: Decoded: %T, %#v\n", v1, v1) + continue + } + + if err = deepEqual(v0check, v1); err == nil { + logT(t, "++++++++ Before and After marshal matched\n") + } else { + // logT(t, "-------- Before and After marshal do not match: Error: %v"+ + // " ====> GOLDEN: (%T) %#v, DECODED: (%T) %#v\n", err, v0check, v0check, v1, v1) + logT(t, "-------- Before and After marshal do not match: Error: %v", err) + logT(t, " ....... GOLDEN: (%T) %#v", v0check, v0check) + logT(t, " ....... DECODED: (%T) %#v", v1, v1) + failT(t) + } + } +} + +func testCodecTableOne(t *testing.T, h Handle) { + testOnce.Do(testInitAll) + // func TestMsgpackAllExperimental(t *testing.T) { + // dopts := testDecOpts(nil, nil, false, true, true), + + idxTime, numPrim, numMap := 19, 23, 4 + //println("#################") + switch v := h.(type) { + case *MsgpackHandle: + var oldWriteExt, oldRawToString bool + oldWriteExt, v.WriteExt = v.WriteExt, true + oldRawToString, v.RawToString = v.RawToString, true + doTestCodecTableOne(t, false, h, table, tableVerify) + v.WriteExt, v.RawToString = oldWriteExt, oldRawToString + case *JsonHandle: + //skip []interface{} containing time.Time, as it encodes as a number, but cannot decode back to time.Time. + //As there is no real support for extension tags in json, this must be skipped. + doTestCodecTableOne(t, false, h, table[:numPrim], tableVerify[:numPrim]) + doTestCodecTableOne(t, false, h, table[numPrim+1:], tableVerify[numPrim+1:]) + default: + doTestCodecTableOne(t, false, h, table, tableVerify) + } + // func TestMsgpackAll(t *testing.T) { + + // //skip []interface{} containing time.Time + // doTestCodecTableOne(t, false, h, table[:numPrim], tableVerify[:numPrim]) + // doTestCodecTableOne(t, false, h, table[numPrim+1:], tableVerify[numPrim+1:]) + // func TestMsgpackNilStringMap(t *testing.T) { + var oldMapType reflect.Type + v := h.getBasicHandle() + + oldMapType, v.MapType = v.MapType, testMapStrIntfTyp + + //skip time.Time, []interface{} containing time.Time, last map, and newStruc + doTestCodecTableOne(t, true, h, table[:idxTime], tableTestNilVerify[:idxTime]) + doTestCodecTableOne(t, true, h, table[numPrim+1:numPrim+numMap], tableTestNilVerify[numPrim+1:numPrim+numMap]) + + v.MapType = oldMapType + + // func TestMsgpackNilIntf(t *testing.T) { + + //do newTestStruc and last element of map + doTestCodecTableOne(t, true, h, table[numPrim+numMap:], tableTestNilVerify[numPrim+numMap:]) + //TODO? What is this one? + //doTestCodecTableOne(t, true, h, table[17:18], tableTestNilVerify[17:18]) +} + +func testCodecMiscOne(t *testing.T, h Handle) { + testOnce.Do(testInitAll) + b, err := testMarshalErr(32, h, t, "32") + // Cannot do this nil one, because faster type assertion decoding will panic + // var i *int32 + // if err = testUnmarshal(b, i, nil); err == nil { + // logT(t, "------- Expecting error because we cannot unmarshal to int32 nil ptr") + // t.FailNow() + // } + var i2 int32 = 0 + err = testUnmarshalErr(&i2, b, h, t, "int32-ptr") + if i2 != int32(32) { + logT(t, "------- didn't unmarshal to 32: Received: %d", i2) + t.FailNow() + } + + // func TestMsgpackDecodePtr(t *testing.T) { + ts := newTestStruc(0, false, !testSkipIntf, false) + b, err = testMarshalErr(ts, h, t, "pointer-to-struct") + if len(b) < 40 { + logT(t, "------- Size must be > 40. Size: %d", len(b)) + t.FailNow() + } + if h.isBinary() { + logT(t, "------- b: %v", b) + } else { + logT(t, "------- b: %s", b) + } + ts2 := new(TestStruc) + err = testUnmarshalErr(ts2, b, h, t, "pointer-to-struct") + if ts2.I64 != math.MaxInt64*2/3 { + logT(t, "------- Unmarshal wrong. Expect I64 = 64. Got: %v", ts2.I64) + t.FailNow() + } + + // func TestMsgpackIntfDecode(t *testing.T) { + m := map[string]int{"A": 2, "B": 3} + p := []interface{}{m} + bs, err := testMarshalErr(p, h, t, "p") + + m2 := map[string]int{} + p2 := []interface{}{m2} + err = testUnmarshalErr(&p2, bs, h, t, "&p2") + + if m2["A"] != 2 || m2["B"] != 3 { + logT(t, "m2 not as expected: expecting: %v, got: %v", m, m2) + t.FailNow() + } + // log("m: %v, m2: %v, p: %v, p2: %v", m, m2, p, p2) + checkEqualT(t, p, p2, "p=p2") + checkEqualT(t, m, m2, "m=m2") + if err = deepEqual(p, p2); err == nil { + logT(t, "p and p2 match") + } else { + logT(t, "Not Equal: %v. p: %v, p2: %v", err, p, p2) + t.FailNow() + } + if err = deepEqual(m, m2); err == nil { + logT(t, "m and m2 match") + } else { + logT(t, "Not Equal: %v. m: %v, m2: %v", err, m, m2) + t.FailNow() + } + + // func TestMsgpackDecodeStructSubset(t *testing.T) { + // test that we can decode a subset of the stream + mm := map[string]interface{}{"A": 5, "B": 99, "C": 333} + bs, err = testMarshalErr(mm, h, t, "mm") + type ttt struct { + A uint8 + C int32 + } + var t2 ttt + testUnmarshalErr(&t2, bs, h, t, "t2") + t3 := ttt{5, 333} + checkEqualT(t, t2, t3, "t2=t3") + + // println(">>>>>") + // test simple arrays, non-addressable arrays, slices + type tarr struct { + A int64 + B [3]int64 + C []byte + D [3]byte + } + var tarr0 = tarr{1, [3]int64{2, 3, 4}, []byte{4, 5, 6}, [3]byte{7, 8, 9}} + // test both pointer and non-pointer (value) + for _, tarr1 := range []interface{}{tarr0, &tarr0} { + bs, err = testMarshalErr(tarr1, h, t, "tarr1") + var tarr2 tarr + testUnmarshalErr(&tarr2, bs, h, t, "tarr2") + checkEqualT(t, tarr0, tarr2, "tarr0=tarr2") + // fmt.Printf(">>>> err: %v. tarr1: %v, tarr2: %v\n", err, tarr0, tarr2) + } + + // test byte array, even if empty (msgpack only) + if h == testMsgpackH { + type ystruct struct { + Anarray []byte + } + var ya = ystruct{} + testUnmarshalErr(&ya, []byte{0x91, 0x90}, h, t, "ya") + } +} + +func testCodecEmbeddedPointer(t *testing.T, h Handle) { + testOnce.Do(testInitAll) + type Z int + type A struct { + AnInt int + } + type B struct { + *Z + *A + MoreInt int + } + var z Z = 4 + x1 := &B{&z, &A{5}, 6} + bs, err := testMarshalErr(x1, h, t, "x1") + // fmt.Printf("buf: len(%v): %x\n", buf.Len(), buf.Bytes()) + var x2 = new(B) + err = testUnmarshalErr(x2, bs, h, t, "x2") + err = checkEqualT(t, x1, x2, "x1=x2") + _ = err +} + +func testCodecUnderlyingType(t *testing.T, h Handle) { + testOnce.Do(testInitAll) + // Manual Test. + // Run by hand, with accompanying print statements in fast-path.go + // to ensure that the fast functions are called. + type T1 map[string]string + v := T1{"1": "1s", "2": "2s"} + var bs []byte + var err error + NewEncoderBytes(&bs, h).MustEncode(v) + if err != nil { + logT(t, "Error during encode: %v", err) + failT(t) + } + var v2 T1 + NewDecoderBytes(bs, h).MustDecode(&v2) + if err != nil { + logT(t, "Error during decode: %v", err) + failT(t) + } +} + +func testCodecChan(t *testing.T, h Handle) { + // - send a slice []*int64 (sl1) into an chan (ch1) with cap > len(s1) + // - encode ch1 as a stream array + // - decode a chan (ch2), with cap > len(s1) from the stream array + // - receive from ch2 into slice sl2 + // - compare sl1 and sl2 + // - do this for codecs: json, cbor (covers all types) + sl1 := make([]*int64, 4) + for i := range sl1 { + var j int64 = int64(i) + sl1[i] = &j + } + ch1 := make(chan *int64, 4) + for _, j := range sl1 { + ch1 <- j + } + var bs []byte + NewEncoderBytes(&bs, h).MustEncode(ch1) + // if !h.isBinary() { + // fmt.Printf("before: len(ch1): %v, bs: %s\n", len(ch1), bs) + // } + // var ch2 chan *int64 // this will block if json, etc. + ch2 := make(chan *int64, 8) + NewDecoderBytes(bs, h).MustDecode(&ch2) + // logT(t, "Len(ch2): %v", len(ch2)) + // fmt.Printf("after: len(ch2): %v, ch2: %v\n", len(ch2), ch2) + close(ch2) + var sl2 []*int64 + for j := range ch2 { + sl2 = append(sl2, j) + } + if err := deepEqual(sl1, sl2); err != nil { + logT(t, "Not Match: %v; len: %v, %v", err, len(sl1), len(sl2)) + failT(t) + } +} + +func testCodecRpcOne(t *testing.T, rr Rpc, h Handle, doRequest bool, exitSleepMs time.Duration, +) (port int) { + testOnce.Do(testInitAll) + if testSkipRPCTests { + return + } + // rpc needs EOF, which is sent via a panic, and so must be recovered. + if !recoverPanicToErr { + logT(t, "EXPECTED. set recoverPanicToErr=true, since rpc needs EOF") + t.FailNow() + } + srv := rpc.NewServer() + srv.Register(testRpcInt) + ln, err := net.Listen("tcp", "127.0.0.1:0") + // log("listener: %v", ln.Addr()) + checkErrT(t, err) + port = (ln.Addr().(*net.TCPAddr)).Port + // var opts *DecoderOptions + // opts := testDecOpts + // opts.MapType = mapStrIntfTyp + // opts.RawToString = false + serverExitChan := make(chan bool, 1) + var serverExitFlag uint64 = 0 + serverFn := func() { + for { + conn1, err1 := ln.Accept() + // if err1 != nil { + // //fmt.Printf("accept err1: %v\n", err1) + // continue + // } + if atomic.LoadUint64(&serverExitFlag) == 1 { + serverExitChan <- true + conn1.Close() + return // exit serverFn goroutine + } + if err1 == nil { + var sc rpc.ServerCodec = rr.ServerCodec(conn1, h) + srv.ServeCodec(sc) + } + } + } + + clientFn := func(cc rpc.ClientCodec) { + cl := rpc.NewClientWithCodec(cc) + defer cl.Close() + // defer func() { println("##### client closing"); cl.Close() }() + var up, sq, mult int + var rstr string + // log("Calling client") + checkErrT(t, cl.Call("TestRpcInt.Update", 5, &up)) + // log("Called TestRpcInt.Update") + checkEqualT(t, testRpcInt.i, 5, "testRpcInt.i=5") + checkEqualT(t, up, 5, "up=5") + checkErrT(t, cl.Call("TestRpcInt.Square", 1, &sq)) + checkEqualT(t, sq, 25, "sq=25") + checkErrT(t, cl.Call("TestRpcInt.Mult", 20, &mult)) + checkEqualT(t, mult, 100, "mult=100") + checkErrT(t, cl.Call("TestRpcInt.EchoStruct", TestABC{"Aa", "Bb", "Cc"}, &rstr)) + checkEqualT(t, rstr, fmt.Sprintf("%#v", TestABC{"Aa", "Bb", "Cc"}), "rstr=") + checkErrT(t, cl.Call("TestRpcInt.Echo123", []string{"A1", "B2", "C3"}, &rstr)) + checkEqualT(t, rstr, fmt.Sprintf("%#v", []string{"A1", "B2", "C3"}), "rstr=") + } + + connFn := func() (bs net.Conn) { + // log("calling f1") + bs, err2 := net.Dial(ln.Addr().Network(), ln.Addr().String()) + //fmt.Printf("f1. bs: %v, err2: %v\n", bs, err2) + checkErrT(t, err2) + return + } + + exitFn := func() { + atomic.StoreUint64(&serverExitFlag, 1) + bs := connFn() + <-serverExitChan + bs.Close() + // serverExitChan <- true + } + + go serverFn() + runtime.Gosched() + //time.Sleep(100 * time.Millisecond) + if exitSleepMs == 0 { + defer ln.Close() + defer exitFn() + } + if doRequest { + bs := connFn() + cc := rr.ClientCodec(bs, h) + clientFn(cc) + } + if exitSleepMs != 0 { + go func() { + defer ln.Close() + time.Sleep(exitSleepMs) + exitFn() + }() + } + return +} + +// Comprehensive testing that generates data encoded from python handle (cbor, msgpack), +// and validates that our code can read and write it out accordingly. +// We keep this unexported here, and put actual test in ext_dep_test.go. +// This way, it can be excluded by excluding file completely. +func doTestPythonGenStreams(t *testing.T, name string, h Handle) { + logT(t, "TestPythonGenStreams-%v", name) + tmpdir, err := ioutil.TempDir("", "golang-"+name+"-test") + if err != nil { + logT(t, "-------- Unable to create temp directory\n") + t.FailNow() + } + defer os.RemoveAll(tmpdir) + logT(t, "tmpdir: %v", tmpdir) + cmd := exec.Command("python", "test.py", "testdata", tmpdir) + //cmd.Stdin = strings.NewReader("some input") + //cmd.Stdout = &out + var cmdout []byte + if cmdout, err = cmd.CombinedOutput(); err != nil { + logT(t, "-------- Error running test.py testdata. Err: %v", err) + logT(t, " %v", string(cmdout)) + t.FailNow() + } + + bh := h.getBasicHandle() + + oldMapType := bh.MapType + for i, v := range tablePythonVerify { + // if v == uint64(0) && h == testMsgpackH { + // v = int64(0) + // } + bh.MapType = oldMapType + //load up the golden file based on number + //decode it + //compare to in-mem object + //encode it again + //compare to output stream + logT(t, "..............................................") + logT(t, " Testing: #%d: %T, %#v\n", i, v, v) + var bss []byte + bss, err = ioutil.ReadFile(filepath.Join(tmpdir, strconv.Itoa(i)+"."+name+".golden")) + if err != nil { + logT(t, "-------- Error reading golden file: %d. Err: %v", i, err) + failT(t) + continue + } + bh.MapType = testMapStrIntfTyp + + var v1 interface{} + if err = testUnmarshal(&v1, bss, h); err != nil { + logT(t, "-------- Error decoding stream: %d: Err: %v", i, err) + failT(t) + continue + } + if v == skipVerifyVal { + continue + } + //no need to indirect, because we pass a nil ptr, so we already have the value + //if v1 != nil { v1 = reflect.Indirect(reflect.ValueOf(v1)).Interface() } + if err = deepEqual(v, v1); err == nil { + logT(t, "++++++++ Objects match: %T, %v", v, v) + } else { + logT(t, "-------- Objects do not match: %v. Source: %T. Decoded: %T", err, v, v1) + logT(t, "-------- GOLDEN: %#v", v) + // logT(t, "-------- DECODED: %#v <====> %#v", v1, reflect.Indirect(reflect.ValueOf(v1)).Interface()) + logT(t, "-------- DECODED: %#v <====> %#v", v1, reflect.Indirect(reflect.ValueOf(v1)).Interface()) + failT(t) + } + bsb, err := testMarshal(v1, h) + if err != nil { + logT(t, "Error encoding to stream: %d: Err: %v", i, err) + failT(t) + continue + } + if err = deepEqual(bsb, bss); err == nil { + logT(t, "++++++++ Bytes match") + } else { + logT(t, "???????? Bytes do not match. %v.", err) + xs := "--------" + if reflect.ValueOf(v).Kind() == reflect.Map { + xs = " " + logT(t, "%s It's a map. Ok that they don't match (dependent on ordering).", xs) + } else { + logT(t, "%s It's not a map. They should match.", xs) + failT(t) + } + logT(t, "%s FROM_FILE: %4d] %v", xs, len(bss), bss) + logT(t, "%s ENCODED: %4d] %v", xs, len(bsb), bsb) + } + } + bh.MapType = oldMapType +} + +// To test MsgpackSpecRpc, we test 3 scenarios: +// - Go Client to Go RPC Service (contained within TestMsgpackRpcSpec) +// - Go client to Python RPC Service (contained within doTestMsgpackRpcSpecGoClientToPythonSvc) +// - Python Client to Go RPC Service (contained within doTestMsgpackRpcSpecPythonClientToGoSvc) +// +// This allows us test the different calling conventions +// - Go Service requires only one argument +// - Python Service allows multiple arguments + +func doTestMsgpackRpcSpecGoClientToPythonSvc(t *testing.T) { + if testSkipRPCTests { + return + } + openPort := "6789" + cmd := exec.Command("python", "test.py", "rpc-server", openPort, "2") + checkErrT(t, cmd.Start()) + time.Sleep(100 * time.Millisecond) // time for python rpc server to start + bs, err2 := net.Dial("tcp", ":"+openPort) + checkErrT(t, err2) + cc := MsgpackSpecRpc.ClientCodec(bs, testMsgpackH) + cl := rpc.NewClientWithCodec(cc) + defer cl.Close() + var rstr string + checkErrT(t, cl.Call("EchoStruct", TestABC{"Aa", "Bb", "Cc"}, &rstr)) + //checkEqualT(t, rstr, "{'A': 'Aa', 'B': 'Bb', 'C': 'Cc'}") + var mArgs MsgpackSpecRpcMultiArgs = []interface{}{"A1", "B2", "C3"} + checkErrT(t, cl.Call("Echo123", mArgs, &rstr)) + checkEqualT(t, rstr, "1:A1 2:B2 3:C3", "rstr=") +} + +func doTestMsgpackRpcSpecPythonClientToGoSvc(t *testing.T) { + if testSkipRPCTests { + return + } + port := testCodecRpcOne(t, MsgpackSpecRpc, testMsgpackH, false, 1*time.Second) + //time.Sleep(1000 * time.Millisecond) + cmd := exec.Command("python", "test.py", "rpc-client-go-service", strconv.Itoa(port)) + var cmdout []byte + var err error + if cmdout, err = cmd.CombinedOutput(); err != nil { + logT(t, "-------- Error running test.py rpc-client-go-service. Err: %v", err) + logT(t, " %v", string(cmdout)) + t.FailNow() + } + checkEqualT(t, string(cmdout), + fmt.Sprintf("%#v\n%#v\n", []string{"A1", "B2", "C3"}, TestABC{"Aa", "Bb", "Cc"}), "cmdout=") +} + +func TestBincCodecsTable(t *testing.T) { + testCodecTableOne(t, testBincH) +} + +func TestBincCodecsMisc(t *testing.T) { + testCodecMiscOne(t, testBincH) +} + +func TestBincCodecsEmbeddedPointer(t *testing.T) { + testCodecEmbeddedPointer(t, testBincH) +} + +func TestSimpleCodecsTable(t *testing.T) { + testCodecTableOne(t, testSimpleH) +} + +func TestSimpleCodecsMisc(t *testing.T) { + testCodecMiscOne(t, testSimpleH) +} + +func TestSimpleCodecsEmbeddedPointer(t *testing.T) { + testCodecEmbeddedPointer(t, testSimpleH) +} + +func TestMsgpackCodecsTable(t *testing.T) { + testCodecTableOne(t, testMsgpackH) +} + +func TestMsgpackCodecsMisc(t *testing.T) { + testCodecMiscOne(t, testMsgpackH) +} + +func TestMsgpackCodecsEmbeddedPointer(t *testing.T) { + testCodecEmbeddedPointer(t, testMsgpackH) +} + +func TestCborCodecsTable(t *testing.T) { + testCodecTableOne(t, testCborH) +} + +func TestCborCodecsMisc(t *testing.T) { + testCodecMiscOne(t, testCborH) +} + +func TestCborCodecsEmbeddedPointer(t *testing.T) { + testCodecEmbeddedPointer(t, testCborH) +} + +func TestJsonCodecsTable(t *testing.T) { + testCodecTableOne(t, testJsonH) +} + +func TestJsonCodecsMisc(t *testing.T) { + testCodecMiscOne(t, testJsonH) +} + +func TestJsonCodecsEmbeddedPointer(t *testing.T) { + testCodecEmbeddedPointer(t, testJsonH) +} + +func TestJsonCodecChan(t *testing.T) { + testCodecChan(t, testJsonH) +} + +func TestCborCodecChan(t *testing.T) { + testCodecChan(t, testCborH) +} + +// ----- RPC ----- + +func TestBincRpcGo(t *testing.T) { + testCodecRpcOne(t, GoRpc, testBincH, true, 0) +} + +func TestSimpleRpcGo(t *testing.T) { + testCodecRpcOne(t, GoRpc, testSimpleH, true, 0) +} + +func TestMsgpackRpcGo(t *testing.T) { + testCodecRpcOne(t, GoRpc, testMsgpackH, true, 0) +} + +func TestCborRpcGo(t *testing.T) { + testCodecRpcOne(t, GoRpc, testCborH, true, 0) +} + +func TestJsonRpcGo(t *testing.T) { + testCodecRpcOne(t, GoRpc, testJsonH, true, 0) +} + +func TestMsgpackRpcSpec(t *testing.T) { + testCodecRpcOne(t, MsgpackSpecRpc, testMsgpackH, true, 0) +} + +func TestBincUnderlyingType(t *testing.T) { + testCodecUnderlyingType(t, testBincH) +} + +// TODO: +// Add Tests for: +// - decoding empty list/map in stream into a nil slice/map +// - binary(M|Unm)arsher support for time.Time (e.g. cbor encoding) +// - text(M|Unm)arshaler support for time.Time (e.g. json encoding) +// - non fast-path scenarios e.g. map[string]uint16, []customStruct. +// Expand cbor to include indefinite length stuff for this non-fast-path types. +// This may not be necessary, since we have the manual tests (fastpathEnabled=false) to test/validate with. +// - CodecSelfer +// Ensure it is called when (en|de)coding interface{} or reflect.Value (2 different codepaths). +// - interfaces: textMarshaler, binaryMarshaler, codecSelfer +// - struct tags: +// on anonymous fields, _struct (all fields), etc +// - codecgen of struct containing channels. +// +// Cleanup tests: +// - The are brittle in their handling of validation and skipping diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/README.md b/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/README.md new file mode 100644 index 0000000000..3ae8a056f9 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/README.md @@ -0,0 +1,36 @@ +# codecgen tool + +Generate is given a list of *.go files to parse, and an output file (fout), +codecgen will create an output file __file.go__ which +contains `codec.Selfer` implementations for the named types found +in the files parsed. + +Using codecgen is very straightforward. + +**Download and install the tool** + +`go get -u github.com/ugorji/go/codec/codecgen` + +**Run the tool on your files** + +The command line format is: + +`codecgen [options] (-o outfile) (infile ...)` + +```sh +% codecgen -? +Usage of codecgen: + -c="github.com/ugorji/go/codec": codec path + -o="": out file + -r=".*": regex for type name to match + -rt="": tags for go run + -t="": build tag to put in file + -u=false: Use unsafe, e.g. to avoid unnecessary allocation on []byte->string + -x=false: keep temp file + +% codecgen -o values_codecgen.go values.go values2.go moretypedefs.go +``` + +Please see the [blog article](http://ugorji.net/blog/go-codecgen) +for more information on how to use the tool. + diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/gen.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/gen.go new file mode 100644 index 0000000000..0a32b6cb3d --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/gen.go @@ -0,0 +1,271 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +// codecgen generates codec.Selfer implementations for a set of types. +package main + +import ( + "bufio" + "bytes" + "errors" + "flag" + "fmt" + "go/ast" + "go/build" + "go/parser" + "go/token" + "os" + "os/exec" + "path/filepath" + "regexp" + "strconv" + "text/template" + "time" +) + +const genFrunMainTmpl = `//+build ignore + +package main +{{ if .Types }}import "{{ .ImportPath }}"{{ end }} +func main() { + {{ $.PackageName }}.CodecGenTempWrite{{ .RandString }}() +} +` + +// const genFrunPkgTmpl = `//+build codecgen +const genFrunPkgTmpl = ` +package {{ $.PackageName }} + +import ( + {{ if not .CodecPkgFiles }}{{ .CodecPkgName }} "{{ .CodecImportPath }}"{{ end }} +{{/* + {{ if .Types }}"{{ .ImportPath }}"{{ end }} + "io" +*/}} + "os" + "reflect" + "bytes" + "go/format" +) + +{{/* This is not used anymore. Remove it. +func write(w io.Writer, s string) { + if _, err := io.WriteString(w, s); err != nil { + panic(err) + } +} +*/}} + +func CodecGenTempWrite{{ .RandString }}() { + fout, err := os.Create("{{ .OutFile }}") + if err != nil { + panic(err) + } + defer fout.Close() + var out bytes.Buffer + + var typs []reflect.Type +{{ range $index, $element := .Types }} + var t{{ $index }} {{ . }} + typs = append(typs, reflect.TypeOf(t{{ $index }})) +{{ end }} + {{ if not .CodecPkgFiles }}{{ .CodecPkgName }}.{{ end }}Gen(&out, "{{ .BuildTag }}", "{{ .PackageName }}", {{ .UseUnsafe }}, typs...) + bout, err := format.Source(out.Bytes()) + if err != nil { + fout.Write(out.Bytes()) + panic(err) + } + fout.Write(bout) +} + +` + +// Generate is given a list of *.go files to parse, and an output file (fout). +// +// It finds all types T in the files, and it creates 2 tmp files (frun). +// - main package file passed to 'go run' +// - package level file which calls *genRunner.Selfer to write Selfer impls for each T. +// We use a package level file so that it can reference unexported types in the package being worked on. +// Tool then executes: "go run __frun__" which creates fout. +// fout contains Codec(En|De)codeSelf implementations for every type T. +// +func Generate(outfile, buildTag, codecPkgPath string, useUnsafe bool, goRunTag string, + regexName *regexp.Regexp, deleteTempFile bool, infiles ...string) (err error) { + // For each file, grab AST, find each type, and write a call to it. + if len(infiles) == 0 { + return + } + if outfile == "" || codecPkgPath == "" { + err = errors.New("outfile and codec package path cannot be blank") + return + } + // We have to parse dir for package, before opening the temp file for writing (else ImportDir fails). + // Also, ImportDir(...) must take an absolute path. + lastdir := filepath.Dir(outfile) + absdir, err := filepath.Abs(lastdir) + if err != nil { + return + } + pkg, err := build.Default.ImportDir(absdir, build.AllowBinary) + if err != nil { + return + } + type tmplT struct { + CodecPkgName string + CodecImportPath string + ImportPath string + OutFile string + PackageName string + RandString string + BuildTag string + Types []string + CodecPkgFiles bool + UseUnsafe bool + } + tv := tmplT{ + CodecPkgName: "codec1978", + OutFile: outfile, + CodecImportPath: codecPkgPath, + BuildTag: buildTag, + UseUnsafe: useUnsafe, + RandString: strconv.FormatInt(time.Now().UnixNano(), 10), + } + tv.ImportPath = pkg.ImportPath + if tv.ImportPath == tv.CodecImportPath { + tv.CodecPkgFiles = true + tv.CodecPkgName = "codec" + } + astfiles := make([]*ast.File, len(infiles)) + for i, infile := range infiles { + if filepath.Dir(infile) != lastdir { + err = errors.New("in files must all be in same directory as outfile") + return + } + fset := token.NewFileSet() + astfiles[i], err = parser.ParseFile(fset, infile, nil, 0) + if err != nil { + return + } + if i == 0 { + tv.PackageName = astfiles[i].Name.Name + if tv.PackageName == "main" { + // codecgen cannot be run on types in the 'main' package. + // A temporary 'main' package must be created, and should reference the fully built + // package containing the types. + // Also, the temporary main package will conflict with the main package which already has a main method. + err = errors.New("codecgen cannot be run on types in the 'main' package") + return + } + } + } + + for _, f := range astfiles { + for _, d := range f.Decls { + if gd, ok := d.(*ast.GenDecl); ok { + for _, dd := range gd.Specs { + if td, ok := dd.(*ast.TypeSpec); ok { + // if len(td.Name.Name) == 0 || td.Name.Name[0] > 'Z' || td.Name.Name[0] < 'A' { + if len(td.Name.Name) == 0 { + continue + } + + // only generate for: + // struct: StructType + // primitives (numbers, bool, string): Ident + // map: MapType + // slice, array: ArrayType + // chan: ChanType + // do not generate: + // FuncType, InterfaceType, StarExpr (ptr), etc + switch td.Type.(type) { + case *ast.StructType, *ast.Ident, *ast.MapType, *ast.ArrayType, *ast.ChanType: + if regexName.FindStringIndex(td.Name.Name) != nil { + tv.Types = append(tv.Types, td.Name.Name) + } + } + } + } + } + } + } + + if len(tv.Types) == 0 { + return + } + + // we cannot use ioutil.TempFile, because we cannot guarantee the file suffix (.go). + // Also, we cannot create file in temp directory, + // because go run will not work (as it needs to see the types here). + // Consequently, create the temp file in the current directory, and remove when done. + + // frun, err = ioutil.TempFile("", "codecgen-") + // frunName := filepath.Join(os.TempDir(), "codecgen-"+strconv.FormatInt(time.Now().UnixNano(), 10)+".go") + + frunMainName := "codecgen-main-" + tv.RandString + ".generated.go" + frunPkgName := "codecgen-pkg-" + tv.RandString + ".generated.go" + if deleteTempFile { + defer os.Remove(frunMainName) + defer os.Remove(frunPkgName) + } + // var frunMain, frunPkg *os.File + if _, err = gen1(frunMainName, genFrunMainTmpl, &tv); err != nil { + return + } + if _, err = gen1(frunPkgName, genFrunPkgTmpl, &tv); err != nil { + return + } + + // remove outfile, so "go run ..." will not think that types in outfile already exist. + os.Remove(outfile) + + // execute go run frun + cmd := exec.Command("go", "run", "-tags="+goRunTag, frunMainName) //, frunPkg.Name()) + var buf bytes.Buffer + cmd.Stdout = &buf + cmd.Stderr = &buf + if err = cmd.Run(); err != nil { + err = fmt.Errorf("error running 'go run %s': %v, console: %s", + frunMainName, err, buf.Bytes()) + return + } + os.Stdout.Write(buf.Bytes()) + return +} + +func gen1(frunName, tmplStr string, tv interface{}) (frun *os.File, err error) { + os.Remove(frunName) + if frun, err = os.Create(frunName); err != nil { + return + } + defer frun.Close() + + t := template.New("") + if t, err = t.Parse(tmplStr); err != nil { + return + } + bw := bufio.NewWriter(frun) + if err = t.Execute(bw, tv); err != nil { + return + } + if err = bw.Flush(); err != nil { + return + } + return +} + +func main() { + o := flag.String("o", "", "out file") + c := flag.String("c", genCodecPath, "codec path") + t := flag.String("t", "", "build tag to put in file") + r := flag.String("r", ".*", "regex for type name to match") + rt := flag.String("rt", "", "tags for go run") + x := flag.Bool("x", false, "keep temp file") + u := flag.Bool("u", false, "Use unsafe, e.g. to avoid unnecessary allocation on []byte->string") + + flag.Parse() + if err := Generate(*o, *t, *c, *u, *rt, + regexp.MustCompile(*r), !*x, flag.Args()...); err != nil { + fmt.Fprintf(os.Stderr, "codecgen error: %v\n", err) + os.Exit(1) + } +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/z.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/z.go new file mode 100644 index 0000000000..e120a4eb9e --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen/z.go @@ -0,0 +1,3 @@ +package main + +const genCodecPath = "github.com/ugorji/go/codec" diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen_test.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen_test.go new file mode 100644 index 0000000000..2fdfd161d1 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/codecgen_test.go @@ -0,0 +1,22 @@ +//+build x,codecgen + +package codec + +import ( + "fmt" + "testing" +) + +func TestCodecgenJson1(t *testing.T) { + const callCodecgenDirect bool = true + v := newTestStruc(2, false, !testSkipIntf, false) + var bs []byte + e := NewEncoderBytes(&bs, testJsonH) + if callCodecgenDirect { + v.CodecEncodeSelf(e) + e.w.atEndOfEncode() + } else { + e.MustEncode(v) + } + fmt.Printf("%s\n", bs) +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/decode.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/decode.go new file mode 100644 index 0000000000..d6c0c6d18e --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/decode.go @@ -0,0 +1,1550 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +import ( + "encoding" + "errors" + "fmt" + "io" + "reflect" +) + +// Some tagging information for error messages. +const ( + msgBadDesc = "Unrecognized descriptor byte" + msgDecCannotExpandArr = "cannot expand go array from %v to stream length: %v" +) + +var ( + onlyMapOrArrayCanDecodeIntoStructErr = errors.New("only encoded map or array can be decoded into a struct") + cannotDecodeIntoNilErr = errors.New("cannot decode into nil") +) + +// decReader abstracts the reading source, allowing implementations that can +// read from an io.Reader or directly off a byte slice with zero-copying. +type decReader interface { + // TODO: + // Add method to get num bytes read. + // This will be used to annotate errors, so user knows at what point the error occurred. + + unreadn1() + + // readx will use the implementation scratch buffer if possible i.e. n < len(scratchbuf), OR + // just return a view of the []byte being decoded from. + // Ensure you call detachZeroCopyBytes later if this needs to be sent outside codec control. + readx(n int) []byte + readb([]byte) + readn1() uint8 + readn1eof() (v uint8, eof bool) +} + +type decReaderByteScanner interface { + io.Reader + io.ByteScanner +} + +type decDriver interface { + // this will check if the next token is a break. + CheckBreak() bool + TryDecodeAsNil() bool + // check if a container type: vt is one of: Bytes, String, Nil, Slice or Map. + // if vt param == valueTypeNil, and nil is seen in stream, consume the nil. + IsContainerType(vt valueType) bool + IsBuiltinType(rt uintptr) bool + DecodeBuiltin(rt uintptr, v interface{}) + //decodeNaked: Numbers are decoded as int64, uint64, float64 only (no smaller sized number types). + //for extensions, decodeNaked must completely decode them as a *RawExt. + //extensions should also use readx to decode them, for efficiency. + //kInterface will extract the detached byte slice if it has to pass it outside its realm. + DecodeNaked() (v interface{}, vt valueType, decodeFurther bool) + DecodeInt(bitsize uint8) (i int64) + DecodeUint(bitsize uint8) (ui uint64) + DecodeFloat(chkOverflow32 bool) (f float64) + DecodeBool() (b bool) + // DecodeString can also decode symbols. + // It looks redundant as DecodeBytes is available. + // However, some codecs (e.g. binc) support symbols and can + // return a pre-stored string value, meaning that it can bypass + // the cost of []byte->string conversion. + DecodeString() (s string) + + // DecodeBytes may be called directly, without going through reflection. + // Consequently, it must be designed to handle possible nil. + DecodeBytes(bs []byte, isstring, zerocopy bool) (bsOut []byte) + + // decodeExt will decode into a *RawExt or into an extension. + DecodeExt(v interface{}, xtag uint64, ext Ext) (realxtag uint64) + // decodeExt(verifyTag bool, tag byte) (xtag byte, xbs []byte) + ReadMapStart() int + ReadArrayStart() int + ReadMapEnd() + ReadArrayEnd() + ReadArrayEntrySeparator() + ReadMapEntrySeparator() + ReadMapKVSeparator() +} + +type decNoSeparator struct{} + +func (_ decNoSeparator) ReadMapEnd() {} +func (_ decNoSeparator) ReadArrayEnd() {} +func (_ decNoSeparator) ReadArrayEntrySeparator() {} +func (_ decNoSeparator) ReadMapEntrySeparator() {} +func (_ decNoSeparator) ReadMapKVSeparator() {} + +type DecodeOptions struct { + // MapType specifies type to use during schema-less decoding of a map in the stream. + // If nil, we use map[interface{}]interface{} + MapType reflect.Type + + // SliceType specifies type to use during schema-less decoding of an array in the stream. + // If nil, we use []interface{} + SliceType reflect.Type + + // If ErrorIfNoField, return an error when decoding a map + // from a codec stream into a struct, and no matching struct field is found. + ErrorIfNoField bool + + // If ErrorIfNoArrayExpand, return an error when decoding a slice/array that cannot be expanded. + // For example, the stream contains an array of 8 items, but you are decoding into a [4]T array, + // or you are decoding into a slice of length 4 which is non-addressable (and so cannot be set). + ErrorIfNoArrayExpand bool + + // If SignedInteger, use the int64 during schema-less decoding of unsigned values (not uint64). + SignedInteger bool +} + +// ------------------------------------ + +// ioDecByteScanner implements Read(), ReadByte(...), UnreadByte(...) methods +// of io.Reader, io.ByteScanner. +type ioDecByteScanner struct { + r io.Reader + l byte // last byte + ls byte // last byte status. 0: init-canDoNothing, 1: canRead, 2: canUnread + b [1]byte // tiny buffer for reading single bytes +} + +func (z *ioDecByteScanner) Read(p []byte) (n int, err error) { + var firstByte bool + if z.ls == 1 { + z.ls = 2 + p[0] = z.l + if len(p) == 1 { + n = 1 + return + } + firstByte = true + p = p[1:] + } + n, err = z.r.Read(p) + if n > 0 { + if err == io.EOF && n == len(p) { + err = nil // read was successful, so postpone EOF (till next time) + } + z.l = p[n-1] + z.ls = 2 + } + if firstByte { + n++ + } + return +} + +func (z *ioDecByteScanner) ReadByte() (c byte, err error) { + n, err := z.Read(z.b[:]) + if n == 1 { + c = z.b[0] + if err == io.EOF { + err = nil // read was successful, so postpone EOF (till next time) + } + } + return +} + +func (z *ioDecByteScanner) UnreadByte() (err error) { + x := z.ls + if x == 0 { + err = errors.New("cannot unread - nothing has been read") + } else if x == 1 { + err = errors.New("cannot unread - last byte has not been read") + } else if x == 2 { + z.ls = 1 + } + return +} + +// ioDecReader is a decReader that reads off an io.Reader +type ioDecReader struct { + br decReaderByteScanner + // temp byte array re-used internally for efficiency during read. + // shares buffer with Decoder, so we keep size of struct within 8 words. + x *[scratchByteArrayLen]byte + bs ioDecByteScanner +} + +func (z *ioDecReader) readx(n int) (bs []byte) { + if n <= 0 { + return + } + if n < len(z.x) { + bs = z.x[:n] + } else { + bs = make([]byte, n) + } + if _, err := io.ReadAtLeast(z.br, bs, n); err != nil { + panic(err) + } + return +} + +func (z *ioDecReader) readb(bs []byte) { + if len(bs) == 0 { + return + } + if _, err := io.ReadAtLeast(z.br, bs, len(bs)); err != nil { + panic(err) + } +} + +func (z *ioDecReader) readn1() (b uint8) { + b, err := z.br.ReadByte() + if err != nil { + panic(err) + } + return b +} + +func (z *ioDecReader) readn1eof() (b uint8, eof bool) { + b, err := z.br.ReadByte() + if err == nil { + } else if err == io.EOF { + eof = true + } else { + panic(err) + } + return +} + +func (z *ioDecReader) unreadn1() { + if err := z.br.UnreadByte(); err != nil { + panic(err) + } +} + +// ------------------------------------ + +var bytesDecReaderCannotUnreadErr = errors.New("cannot unread last byte read") + +// bytesDecReader is a decReader that reads off a byte slice with zero copying +type bytesDecReader struct { + b []byte // data + c int // cursor + a int // available +} + +func (z *bytesDecReader) unreadn1() { + if z.c == 0 || len(z.b) == 0 { + panic(bytesDecReaderCannotUnreadErr) + } + z.c-- + z.a++ + return +} + +func (z *bytesDecReader) readx(n int) (bs []byte) { + // slicing from a non-constant start position is more expensive, + // as more computation is required to decipher the pointer start position. + // However, we do it only once, and it's better than reslicing both z.b and return value. + + if n <= 0 { + } else if z.a == 0 { + panic(io.EOF) + } else if n > z.a { + panic(io.ErrUnexpectedEOF) + } else { + c0 := z.c + z.c = c0 + n + z.a = z.a - n + bs = z.b[c0:z.c] + } + return +} + +func (z *bytesDecReader) readn1() (v uint8) { + if z.a == 0 { + panic(io.EOF) + } + v = z.b[z.c] + z.c++ + z.a-- + return +} + +func (z *bytesDecReader) readn1eof() (v uint8, eof bool) { + if z.a == 0 { + eof = true + return + } + v = z.b[z.c] + z.c++ + z.a-- + return +} + +func (z *bytesDecReader) readb(bs []byte) { + copy(bs, z.readx(len(bs))) +} + +// ------------------------------------ + +type decFnInfoX struct { + d *Decoder + ti *typeInfo + xfFn Ext + xfTag uint64 + seq seqType +} + +// decFnInfo has methods for handling decoding of a specific type +// based on some characteristics (builtin, extension, reflect Kind, etc) +type decFnInfo struct { + // use decFnInfo as a value receiver. + // keep most of it less-used variables accessible via a pointer (*decFnInfoX). + // As sweet spot for value-receiver is 3 words, keep everything except + // decDriver (which everyone needs) directly accessible. + // ensure decFnInfoX is set for everyone who needs it i.e. + // rawExt, ext, builtin, (selfer|binary|text)Marshal, kSlice, kStruct, kMap, kInterface, fastpath + + dd decDriver + *decFnInfoX +} + +// ---------------------------------------- + +type decFn struct { + i decFnInfo + f func(decFnInfo, reflect.Value) +} + +func (f decFnInfo) builtin(rv reflect.Value) { + f.dd.DecodeBuiltin(f.ti.rtid, rv.Addr().Interface()) +} + +func (f decFnInfo) rawExt(rv reflect.Value) { + f.dd.DecodeExt(rv.Addr().Interface(), 0, nil) +} + +func (f decFnInfo) ext(rv reflect.Value) { + f.dd.DecodeExt(rv.Addr().Interface(), f.xfTag, f.xfFn) +} + +func (f decFnInfo) getValueForUnmarshalInterface(rv reflect.Value, indir int8) (v interface{}) { + if indir == -1 { + v = rv.Addr().Interface() + } else if indir == 0 { + v = rv.Interface() + } else { + for j := int8(0); j < indir; j++ { + if rv.IsNil() { + rv.Set(reflect.New(rv.Type().Elem())) + } + rv = rv.Elem() + } + v = rv.Interface() + } + return +} + +func (f decFnInfo) selferUnmarshal(rv reflect.Value) { + f.getValueForUnmarshalInterface(rv, f.ti.csIndir).(Selfer).CodecDecodeSelf(f.d) +} + +func (f decFnInfo) binaryUnmarshal(rv reflect.Value) { + bm := f.getValueForUnmarshalInterface(rv, f.ti.bunmIndir).(encoding.BinaryUnmarshaler) + xbs := f.dd.DecodeBytes(nil, false, true) + if fnerr := bm.UnmarshalBinary(xbs); fnerr != nil { + panic(fnerr) + } +} + +func (f decFnInfo) textUnmarshal(rv reflect.Value) { + tm := f.getValueForUnmarshalInterface(rv, f.ti.tunmIndir).(encoding.TextUnmarshaler) + fnerr := tm.UnmarshalText(f.dd.DecodeBytes(f.d.b[:], true, true)) + // fnerr := tm.UnmarshalText(f.dd.DecodeStringAsBytes(f.d.b[:])) + + // var fnerr error + // if sb, sbok := f.dd.(decDriverStringAsBytes); sbok { + // fnerr = tm.UnmarshalText(sb.decStringAsBytes(f.d.b[:0])) + // } else { + // fnerr = tm.UnmarshalText([]byte(f.dd.decodeString())) + // } + if fnerr != nil { + panic(fnerr) + } +} + +func (f decFnInfo) kErr(rv reflect.Value) { + f.d.errorf("no decoding function defined for kind %v", rv.Kind()) +} + +func (f decFnInfo) kString(rv reflect.Value) { + rv.SetString(f.dd.DecodeString()) +} + +func (f decFnInfo) kBool(rv reflect.Value) { + rv.SetBool(f.dd.DecodeBool()) +} + +func (f decFnInfo) kInt(rv reflect.Value) { + rv.SetInt(f.dd.DecodeInt(intBitsize)) +} + +func (f decFnInfo) kInt64(rv reflect.Value) { + rv.SetInt(f.dd.DecodeInt(64)) +} + +func (f decFnInfo) kInt32(rv reflect.Value) { + rv.SetInt(f.dd.DecodeInt(32)) +} + +func (f decFnInfo) kInt8(rv reflect.Value) { + rv.SetInt(f.dd.DecodeInt(8)) +} + +func (f decFnInfo) kInt16(rv reflect.Value) { + rv.SetInt(f.dd.DecodeInt(16)) +} + +func (f decFnInfo) kFloat32(rv reflect.Value) { + rv.SetFloat(f.dd.DecodeFloat(true)) +} + +func (f decFnInfo) kFloat64(rv reflect.Value) { + rv.SetFloat(f.dd.DecodeFloat(false)) +} + +func (f decFnInfo) kUint8(rv reflect.Value) { + rv.SetUint(f.dd.DecodeUint(8)) +} + +func (f decFnInfo) kUint64(rv reflect.Value) { + rv.SetUint(f.dd.DecodeUint(64)) +} + +func (f decFnInfo) kUint(rv reflect.Value) { + rv.SetUint(f.dd.DecodeUint(uintBitsize)) +} + +func (f decFnInfo) kUint32(rv reflect.Value) { + rv.SetUint(f.dd.DecodeUint(32)) +} + +func (f decFnInfo) kUint16(rv reflect.Value) { + rv.SetUint(f.dd.DecodeUint(16)) +} + +// func (f decFnInfo) kPtr(rv reflect.Value) { +// debugf(">>>>>>> ??? decode kPtr called - shouldn't get called") +// if rv.IsNil() { +// rv.Set(reflect.New(rv.Type().Elem())) +// } +// f.d.decodeValue(rv.Elem()) +// } + +// var kIntfCtr uint64 + +func (f decFnInfo) kInterfaceNaked() (rvn reflect.Value) { + // nil interface: + // use some hieristics to decode it appropriately + // based on the detected next value in the stream. + v, vt, decodeFurther := f.dd.DecodeNaked() + if vt == valueTypeNil { + return + } + // We cannot decode non-nil stream value into nil interface with methods (e.g. io.Reader). + if num := f.ti.rt.NumMethod(); num > 0 { + f.d.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, num) + return + } + var useRvn bool + switch vt { + case valueTypeMap: + if f.d.h.MapType == nil { + var m2 map[interface{}]interface{} + v = &m2 + } else { + rvn = reflect.New(f.d.h.MapType).Elem() + useRvn = true + } + case valueTypeArray: + if f.d.h.SliceType == nil { + var m2 []interface{} + v = &m2 + } else { + rvn = reflect.New(f.d.h.SliceType).Elem() + useRvn = true + } + case valueTypeExt: + re := v.(*RawExt) + bfn := f.d.h.getExtForTag(re.Tag) + if bfn == nil { + re.Data = detachZeroCopyBytes(f.d.bytes, nil, re.Data) + rvn = reflect.ValueOf(*re) + } else { + rvnA := reflect.New(bfn.rt) + rvn = rvnA.Elem() + if re.Data != nil { + bfn.ext.ReadExt(rvnA.Interface(), re.Data) + } else { + bfn.ext.UpdateExt(rvnA.Interface(), re.Value) + } + } + return + } + if decodeFurther { + if useRvn { + f.d.decodeValue(rvn, decFn{}) + } else if v != nil { + // this v is a pointer, so we need to dereference it when done + f.d.decode(v) + rvn = reflect.ValueOf(v).Elem() + useRvn = true + } + } + + if !useRvn && v != nil { + rvn = reflect.ValueOf(v) + } + return +} + +func (f decFnInfo) kInterface(rv reflect.Value) { + // debugf("\t===> kInterface") + + // Note: + // A consequence of how kInterface works, is that + // if an interface already contains something, we try + // to decode into what was there before. + // We do not replace with a generic value (as got from decodeNaked). + + if rv.IsNil() { + rvn := f.kInterfaceNaked() + if rvn.IsValid() { + rv.Set(rvn) + } + } else { + rve := rv.Elem() + // Note: interface{} is settable, but underlying type may not be. + // Consequently, we have to set the reflect.Value directly. + // if underlying type is settable (e.g. ptr or interface), + // we just decode into it. + // Else we create a settable value, decode into it, and set on the interface. + if rve.CanSet() { + f.d.decodeValue(rve, decFn{}) + } else { + rve2 := reflect.New(rve.Type()).Elem() + rve2.Set(rve) + f.d.decodeValue(rve2, decFn{}) + rv.Set(rve2) + } + } +} + +func (f decFnInfo) kStruct(rv reflect.Value) { + fti := f.ti + d := f.d + if f.dd.IsContainerType(valueTypeMap) { + containerLen := f.dd.ReadMapStart() + if containerLen == 0 { + f.dd.ReadMapEnd() + return + } + tisfi := fti.sfi + hasLen := containerLen >= 0 + if hasLen { + for j := 0; j < containerLen; j++ { + // rvkencname := f.dd.DecodeString() + rvkencname := stringView(f.dd.DecodeBytes(f.d.b[:], true, true)) + // rvksi := ti.getForEncName(rvkencname) + if k := fti.indexForEncName(rvkencname); k > -1 { + si := tisfi[k] + if f.dd.TryDecodeAsNil() { + si.setToZeroValue(rv) + } else { + d.decodeValue(si.field(rv, true), decFn{}) + } + } else { + d.structFieldNotFound(-1, rvkencname) + } + } + } else { + for j := 0; !f.dd.CheckBreak(); j++ { + if j > 0 { + f.dd.ReadMapEntrySeparator() + } + // rvkencname := f.dd.DecodeString() + rvkencname := stringView(f.dd.DecodeBytes(f.d.b[:], true, true)) + f.dd.ReadMapKVSeparator() + // rvksi := ti.getForEncName(rvkencname) + if k := fti.indexForEncName(rvkencname); k > -1 { + si := tisfi[k] + if f.dd.TryDecodeAsNil() { + si.setToZeroValue(rv) + } else { + d.decodeValue(si.field(rv, true), decFn{}) + } + } else { + d.structFieldNotFound(-1, rvkencname) + } + } + f.dd.ReadMapEnd() + } + } else if f.dd.IsContainerType(valueTypeArray) { + containerLen := f.dd.ReadArrayStart() + if containerLen == 0 { + f.dd.ReadArrayEnd() + return + } + // Not much gain from doing it two ways for array. + // Arrays are not used as much for structs. + hasLen := containerLen >= 0 + for j, si := range fti.sfip { + if hasLen { + if j == containerLen { + break + } + } else if f.dd.CheckBreak() { + break + } + if j > 0 { + f.dd.ReadArrayEntrySeparator() + } + if f.dd.TryDecodeAsNil() { + si.setToZeroValue(rv) + } else { + d.decodeValue(si.field(rv, true), decFn{}) + } + // if si.i != -1 { + // d.decodeValue(rv.Field(int(si.i)), decFn{}) + // } else { + // d.decEmbeddedField(rv, si.is) + // } + } + if containerLen > len(fti.sfip) { + // read remaining values and throw away + for j := len(fti.sfip); j < containerLen; j++ { + if j > 0 { + f.dd.ReadArrayEntrySeparator() + } + d.structFieldNotFound(j, "") + } + } + f.dd.ReadArrayEnd() + } else { + f.d.error(onlyMapOrArrayCanDecodeIntoStructErr) + return + } +} + +func (f decFnInfo) kSlice(rv reflect.Value) { + // A slice can be set from a map or array in stream. + // This way, the order can be kept (as order is lost with map). + ti := f.ti + d := f.d + if f.dd.IsContainerType(valueTypeBytes) || f.dd.IsContainerType(valueTypeString) { + if ti.rtid == uint8SliceTypId || ti.rt.Elem().Kind() == reflect.Uint8 { + if f.seq == seqTypeChan { + bs2 := f.dd.DecodeBytes(nil, false, true) + ch := rv.Interface().(chan<- byte) + for _, b := range bs2 { + ch <- b + } + } else { + rvbs := rv.Bytes() + bs2 := f.dd.DecodeBytes(rvbs, false, false) + if rvbs == nil && bs2 != nil || rvbs != nil && bs2 == nil || len(bs2) != len(rvbs) { + if rv.CanSet() { + rv.SetBytes(bs2) + } else { + copy(rvbs, bs2) + } + } + } + return + } + } + + // array := f.seq == seqTypeChan + + slh, containerLenS := d.decSliceHelperStart() + + // an array can never return a nil slice. so no need to check f.array here. + if rv.IsNil() { + // either chan or slice + if f.seq == seqTypeSlice { + if containerLenS <= 0 { + rv.Set(reflect.MakeSlice(ti.rt, 0, 0)) + } else { + rv.Set(reflect.MakeSlice(ti.rt, containerLenS, containerLenS)) + } + } else if f.seq == seqTypeChan { + if containerLenS <= 0 { + rv.Set(reflect.MakeChan(ti.rt, 0)) + } else { + rv.Set(reflect.MakeChan(ti.rt, containerLenS)) + } + } + } + + rvlen := rv.Len() + if containerLenS == 0 { + if f.seq == seqTypeSlice && rvlen != 0 { + rv.SetLen(0) + } + // slh.End() // f.dd.ReadArrayEnd() + return + } + + rtelem0 := ti.rt.Elem() + rtelem := rtelem0 + for rtelem.Kind() == reflect.Ptr { + rtelem = rtelem.Elem() + } + fn := d.getDecFn(rtelem, true, true) + + rv0 := rv + rvChanged := false + + rvcap := rv.Cap() + + // for j := 0; j < containerLenS; j++ { + + hasLen := containerLenS >= 0 + if hasLen { + if f.seq == seqTypeChan { + // handle chan specially: + for j := 0; j < containerLenS; j++ { + rv0 := reflect.New(rtelem0).Elem() + d.decodeValue(rv0, fn) + rv.Send(rv0) + } + } else { + numToRead := containerLenS + if containerLenS > rvcap { + if f.seq == seqTypeArray { + d.arrayCannotExpand(rv.Len(), containerLenS) + numToRead = rvlen + } else { + rv = reflect.MakeSlice(ti.rt, containerLenS, containerLenS) + if rvlen > 0 && !isMutableKind(ti.rt.Kind()) { + rv1 := rv0 + rv1.SetLen(rvcap) + reflect.Copy(rv, rv1) + } + rvChanged = true + rvlen = containerLenS + } + } else if containerLenS != rvlen { + rv.SetLen(containerLenS) + rvlen = containerLenS + } + j := 0 + for ; j < numToRead; j++ { + d.decodeValue(rv.Index(j), fn) + } + if f.seq == seqTypeArray { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } + } else { + for j := 0; !f.dd.CheckBreak(); j++ { + var decodeIntoBlank bool + // if indefinite, etc, then expand the slice if necessary + if j >= rvlen { + if f.seq == seqTypeArray { + d.arrayCannotExpand(rvlen, j+1) + decodeIntoBlank = true + } else if f.seq == seqTypeSlice { + rv = reflect.Append(rv, reflect.Zero(rtelem0)) + rvlen++ + rvChanged = true + } + } + if j > 0 { + slh.Sep(j) + } + if f.seq == seqTypeChan { + rv0 := reflect.New(rtelem0).Elem() + d.decodeValue(rv0, fn) + rv.Send(rv0) + } else if decodeIntoBlank { + d.swallow() + } else { + d.decodeValue(rv.Index(j), fn) + } + } + slh.End() + } + + if rvChanged { + rv0.Set(rv) + } +} + +func (f decFnInfo) kArray(rv reflect.Value) { + // f.d.decodeValue(rv.Slice(0, rv.Len())) + f.kSlice(rv.Slice(0, rv.Len())) +} + +func (f decFnInfo) kMap(rv reflect.Value) { + containerLen := f.dd.ReadMapStart() + + ti := f.ti + if rv.IsNil() { + rv.Set(reflect.MakeMap(ti.rt)) + } + + if containerLen == 0 { + // f.dd.ReadMapEnd() + return + } + + d := f.d + + ktype, vtype := ti.rt.Key(), ti.rt.Elem() + ktypeId := reflect.ValueOf(ktype).Pointer() + var keyFn, valFn decFn + var xtyp reflect.Type + for xtyp = ktype; xtyp.Kind() == reflect.Ptr; xtyp = xtyp.Elem() { + } + keyFn = d.getDecFn(xtyp, true, true) + for xtyp = vtype; xtyp.Kind() == reflect.Ptr; xtyp = xtyp.Elem() { + } + valFn = d.getDecFn(xtyp, true, true) + // for j := 0; j < containerLen; j++ { + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + rvk := reflect.New(ktype).Elem() + d.decodeValue(rvk, keyFn) + + // special case if a byte array. + if ktypeId == intfTypId { + rvk = rvk.Elem() + if rvk.Type() == uint8SliceTyp { + rvk = reflect.ValueOf(string(rvk.Bytes())) + } + } + rvv := rv.MapIndex(rvk) + // TODO: is !IsValid check required? + if !rvv.IsValid() { + rvv = reflect.New(vtype).Elem() + } + d.decodeValue(rvv, valFn) + rv.SetMapIndex(rvk, rvv) + } + } else { + for j := 0; !f.dd.CheckBreak(); j++ { + if j > 0 { + f.dd.ReadMapEntrySeparator() + } + rvk := reflect.New(ktype).Elem() + d.decodeValue(rvk, keyFn) + + // special case if a byte array. + if ktypeId == intfTypId { + rvk = rvk.Elem() + if rvk.Type() == uint8SliceTyp { + rvk = reflect.ValueOf(string(rvk.Bytes())) + } + } + rvv := rv.MapIndex(rvk) + if !rvv.IsValid() { + rvv = reflect.New(vtype).Elem() + } + f.dd.ReadMapKVSeparator() + d.decodeValue(rvv, valFn) + rv.SetMapIndex(rvk, rvv) + } + f.dd.ReadMapEnd() + } +} + +type rtidDecFn struct { + rtid uintptr + fn decFn +} + +// A Decoder reads and decodes an object from an input stream in the codec format. +type Decoder struct { + // hopefully, reduce derefencing cost by laying the decReader inside the Decoder. + // Try to put things that go together to fit within a cache line (8 words). + + d decDriver + r decReader + //sa [32]rtidDecFn + s []rtidDecFn + h *BasicHandle + + rb bytesDecReader + hh Handle + be bool // is binary encoding + bytes bool // is bytes reader + + ri ioDecReader + f map[uintptr]decFn + _ uintptr // for alignment purposes, so next one starts from a cache line + + b [scratchByteArrayLen]byte +} + +// NewDecoder returns a Decoder for decoding a stream of bytes from an io.Reader. +// +// For efficiency, Users are encouraged to pass in a memory buffered reader +// (eg bufio.Reader, bytes.Buffer). +func NewDecoder(r io.Reader, h Handle) (d *Decoder) { + d = &Decoder{hh: h, h: h.getBasicHandle(), be: h.isBinary()} + //d.s = d.sa[:0] + d.ri.x = &d.b + d.ri.bs.r = r + var ok bool + d.ri.br, ok = r.(decReaderByteScanner) + if !ok { + d.ri.br = &d.ri.bs + } + d.r = &d.ri + d.d = h.newDecDriver(d) + return +} + +// NewDecoderBytes returns a Decoder which efficiently decodes directly +// from a byte slice with zero copying. +func NewDecoderBytes(in []byte, h Handle) (d *Decoder) { + d = &Decoder{hh: h, h: h.getBasicHandle(), be: h.isBinary(), bytes: true} + //d.s = d.sa[:0] + d.rb.b = in + d.rb.a = len(in) + d.r = &d.rb + d.d = h.newDecDriver(d) + // d.d = h.newDecDriver(decReaderT{true, &d.rb, &d.ri}) + return +} + +// Decode decodes the stream from reader and stores the result in the +// value pointed to by v. v cannot be a nil pointer. v can also be +// a reflect.Value of a pointer. +// +// Note that a pointer to a nil interface is not a nil pointer. +// If you do not know what type of stream it is, pass in a pointer to a nil interface. +// We will decode and store a value in that nil interface. +// +// Sample usages: +// // Decoding into a non-nil typed value +// var f float32 +// err = codec.NewDecoder(r, handle).Decode(&f) +// +// // Decoding into nil interface +// var v interface{} +// dec := codec.NewDecoder(r, handle) +// err = dec.Decode(&v) +// +// When decoding into a nil interface{}, we will decode into an appropriate value based +// on the contents of the stream: +// - Numbers are decoded as float64, int64 or uint64. +// - Other values are decoded appropriately depending on the type: +// bool, string, []byte, time.Time, etc +// - Extensions are decoded as RawExt (if no ext function registered for the tag) +// Configurations exist on the Handle to override defaults +// (e.g. for MapType, SliceType and how to decode raw bytes). +// +// When decoding into a non-nil interface{} value, the mode of encoding is based on the +// type of the value. When a value is seen: +// - If an extension is registered for it, call that extension function +// - If it implements BinaryUnmarshaler, call its UnmarshalBinary(data []byte) error +// - Else decode it based on its reflect.Kind +// +// There are some special rules when decoding into containers (slice/array/map/struct). +// Decode will typically use the stream contents to UPDATE the container. +// - A map can be decoded from a stream map, by updating matching keys. +// - A slice can be decoded from a stream array, +// by updating the first n elements, where n is length of the stream. +// - A slice can be decoded from a stream map, by decoding as if +// it contains a sequence of key-value pairs. +// - A struct can be decoded from a stream map, by updating matching fields. +// - A struct can be decoded from a stream array, +// by updating fields as they occur in the struct (by index). +// +// When decoding a stream map or array with length of 0 into a nil map or slice, +// we reset the destination map or slice to a zero-length value. +// +// However, when decoding a stream nil, we reset the destination container +// to its "zero" value (e.g. nil for slice/map, etc). +// +func (d *Decoder) Decode(v interface{}) (err error) { + defer panicToErr(&err) + d.decode(v) + return +} + +// this is not a smart swallow, as it allocates objects and does unnecessary work. +func (d *Decoder) swallowViaHammer() { + var blank interface{} + d.decodeValue(reflect.ValueOf(&blank).Elem(), decFn{}) +} + +func (d *Decoder) swallow() { + // smarter decode that just swallows the content + dd := d.d + switch { + case dd.TryDecodeAsNil(): + case dd.IsContainerType(valueTypeMap): + containerLen := dd.ReadMapStart() + clenGtEqualZero := containerLen >= 0 + for j := 0; ; j++ { + if clenGtEqualZero { + if j >= containerLen { + break + } + } else if dd.CheckBreak() { + break + } + if j > 0 { + dd.ReadMapEntrySeparator() + } + d.swallow() + dd.ReadMapKVSeparator() + d.swallow() + } + dd.ReadMapEnd() + case dd.IsContainerType(valueTypeArray): + containerLenS := dd.ReadArrayStart() + clenGtEqualZero := containerLenS >= 0 + for j := 0; ; j++ { + if clenGtEqualZero { + if j >= containerLenS { + break + } + } else if dd.CheckBreak() { + break + } + if j > 0 { + dd.ReadArrayEntrySeparator() + } + d.swallow() + } + dd.ReadArrayEnd() + case dd.IsContainerType(valueTypeBytes): + dd.DecodeBytes(d.b[:], false, true) + case dd.IsContainerType(valueTypeString): + dd.DecodeBytes(d.b[:], true, true) + // dd.DecodeStringAsBytes(d.b[:]) + default: + // these are all primitives, which we can get from decodeNaked + dd.DecodeNaked() + } +} + +// MustDecode is like Decode, but panics if unable to Decode. +// This provides insight to the code location that triggered the error. +func (d *Decoder) MustDecode(v interface{}) { + d.decode(v) +} + +func (d *Decoder) decode(iv interface{}) { + // if ics, ok := iv.(Selfer); ok { + // ics.CodecDecodeSelf(d) + // return + // } + + if d.d.TryDecodeAsNil() { + switch v := iv.(type) { + case nil: + case *string: + *v = "" + case *bool: + *v = false + case *int: + *v = 0 + case *int8: + *v = 0 + case *int16: + *v = 0 + case *int32: + *v = 0 + case *int64: + *v = 0 + case *uint: + *v = 0 + case *uint8: + *v = 0 + case *uint16: + *v = 0 + case *uint32: + *v = 0 + case *uint64: + *v = 0 + case *float32: + *v = 0 + case *float64: + *v = 0 + case *[]uint8: + *v = nil + case reflect.Value: + d.chkPtrValue(v) + v = v.Elem() + if v.IsValid() { + v.Set(reflect.Zero(v.Type())) + } + default: + rv := reflect.ValueOf(iv) + d.chkPtrValue(rv) + rv = rv.Elem() + if rv.IsValid() { + rv.Set(reflect.Zero(rv.Type())) + } + } + return + } + + switch v := iv.(type) { + case nil: + d.error(cannotDecodeIntoNilErr) + return + + case Selfer: + v.CodecDecodeSelf(d) + + case reflect.Value: + d.chkPtrValue(v) + d.decodeValueNotNil(v.Elem(), decFn{}) + + case *string: + + *v = d.d.DecodeString() + case *bool: + *v = d.d.DecodeBool() + case *int: + *v = int(d.d.DecodeInt(intBitsize)) + case *int8: + *v = int8(d.d.DecodeInt(8)) + case *int16: + *v = int16(d.d.DecodeInt(16)) + case *int32: + *v = int32(d.d.DecodeInt(32)) + case *int64: + *v = d.d.DecodeInt(64) + case *uint: + *v = uint(d.d.DecodeUint(uintBitsize)) + case *uint8: + *v = uint8(d.d.DecodeUint(8)) + case *uint16: + *v = uint16(d.d.DecodeUint(16)) + case *uint32: + *v = uint32(d.d.DecodeUint(32)) + case *uint64: + *v = d.d.DecodeUint(64) + case *float32: + *v = float32(d.d.DecodeFloat(true)) + case *float64: + *v = d.d.DecodeFloat(false) + case *[]uint8: + *v = d.d.DecodeBytes(*v, false, false) + + case *interface{}: + d.decodeValueNotNil(reflect.ValueOf(iv).Elem(), decFn{}) + + default: + if !fastpathDecodeTypeSwitch(iv, d) { + d.decodeI(iv, true, false, false, false) + } + } +} + +func (d *Decoder) preDecodeValue(rv reflect.Value, tryNil bool) (rv2 reflect.Value, proceed bool) { + if tryNil && d.d.TryDecodeAsNil() { + // No need to check if a ptr, recursively, to determine + // whether to set value to nil. + // Just always set value to its zero type. + if rv.IsValid() { // rv.CanSet() // always settable, except it's invalid + rv.Set(reflect.Zero(rv.Type())) + } + return + } + + // If stream is not containing a nil value, then we can deref to the base + // non-pointer value, and decode into that. + for rv.Kind() == reflect.Ptr { + if rv.IsNil() { + rv.Set(reflect.New(rv.Type().Elem())) + } + rv = rv.Elem() + } + return rv, true +} + +func (d *Decoder) decodeI(iv interface{}, checkPtr, tryNil, checkFastpath, checkCodecSelfer bool) { + rv := reflect.ValueOf(iv) + if checkPtr { + d.chkPtrValue(rv) + } + rv, proceed := d.preDecodeValue(rv, tryNil) + if proceed { + fn := d.getDecFn(rv.Type(), checkFastpath, checkCodecSelfer) + fn.f(fn.i, rv) + } +} + +func (d *Decoder) decodeValue(rv reflect.Value, fn decFn) { + if rv, proceed := d.preDecodeValue(rv, true); proceed { + if fn.f == nil { + fn = d.getDecFn(rv.Type(), true, true) + } + fn.f(fn.i, rv) + } +} + +func (d *Decoder) decodeValueNotNil(rv reflect.Value, fn decFn) { + if rv, proceed := d.preDecodeValue(rv, false); proceed { + if fn.f == nil { + fn = d.getDecFn(rv.Type(), true, true) + } + fn.f(fn.i, rv) + } +} + +func (d *Decoder) getDecFn(rt reflect.Type, checkFastpath, checkCodecSelfer bool) (fn decFn) { + rtid := reflect.ValueOf(rt).Pointer() + + // retrieve or register a focus'ed function for this type + // to eliminate need to do the retrieval multiple times + + // if d.f == nil && d.s == nil { debugf("---->Creating new dec f map for type: %v\n", rt) } + var ok bool + if useMapForCodecCache { + fn, ok = d.f[rtid] + } else { + for _, v := range d.s { + if v.rtid == rtid { + fn, ok = v.fn, true + break + } + } + } + if ok { + return + } + + // debugf("\tCreating new dec fn for type: %v\n", rt) + ti := getTypeInfo(rtid, rt) + var fi decFnInfo + fi.dd = d.d + // fi.decFnInfoX = new(decFnInfoX) + + // An extension can be registered for any type, regardless of the Kind + // (e.g. type BitSet int64, type MyStruct { / * unexported fields * / }, type X []int, etc. + // + // We can't check if it's an extension byte here first, because the user may have + // registered a pointer or non-pointer type, meaning we may have to recurse first + // before matching a mapped type, even though the extension byte is already detected. + // + // NOTE: if decoding into a nil interface{}, we return a non-nil + // value except even if the container registers a length of 0. + if checkCodecSelfer && ti.cs { + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti} + fn.f = (decFnInfo).selferUnmarshal + } else if rtid == rawExtTypId { + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti} + fn.f = (decFnInfo).rawExt + } else if d.d.IsBuiltinType(rtid) { + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti} + fn.f = (decFnInfo).builtin + } else if xfFn := d.h.getExt(rtid); xfFn != nil { + // fi.decFnInfoX = &decFnInfoX{xfTag: xfFn.tag, xfFn: xfFn.ext} + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti} + fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext + fn.f = (decFnInfo).ext + } else if supportMarshalInterfaces && d.be && ti.bunm { + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti} + fn.f = (decFnInfo).binaryUnmarshal + } else if supportMarshalInterfaces && !d.be && ti.tunm { + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti} + fn.f = (decFnInfo).textUnmarshal + } else { + rk := rt.Kind() + if fastpathEnabled && checkFastpath && (rk == reflect.Map || rk == reflect.Slice) { + if rt.PkgPath() == "" { + if idx := fastpathAV.index(rtid); idx != -1 { + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti} + fn.f = fastpathAV[idx].decfn + } + } else { + // use mapping for underlying type if there + ok = false + var rtu reflect.Type + if rk == reflect.Map { + rtu = reflect.MapOf(rt.Key(), rt.Elem()) + } else { + rtu = reflect.SliceOf(rt.Elem()) + } + rtuid := reflect.ValueOf(rtu).Pointer() + if idx := fastpathAV.index(rtuid); idx != -1 { + xfnf := fastpathAV[idx].decfn + xrt := fastpathAV[idx].rt + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti} + fn.f = func(xf decFnInfo, xrv reflect.Value) { + // xfnf(xf, xrv.Convert(xrt)) + xfnf(xf, xrv.Addr().Convert(reflect.PtrTo(xrt)).Elem()) + } + } + } + } + if fn.f == nil { + switch rk { + case reflect.String: + fn.f = (decFnInfo).kString + case reflect.Bool: + fn.f = (decFnInfo).kBool + case reflect.Int: + fn.f = (decFnInfo).kInt + case reflect.Int64: + fn.f = (decFnInfo).kInt64 + case reflect.Int32: + fn.f = (decFnInfo).kInt32 + case reflect.Int8: + fn.f = (decFnInfo).kInt8 + case reflect.Int16: + fn.f = (decFnInfo).kInt16 + case reflect.Float32: + fn.f = (decFnInfo).kFloat32 + case reflect.Float64: + fn.f = (decFnInfo).kFloat64 + case reflect.Uint8: + fn.f = (decFnInfo).kUint8 + case reflect.Uint64: + fn.f = (decFnInfo).kUint64 + case reflect.Uint: + fn.f = (decFnInfo).kUint + case reflect.Uint32: + fn.f = (decFnInfo).kUint32 + case reflect.Uint16: + fn.f = (decFnInfo).kUint16 + // case reflect.Ptr: + // fn.f = (decFnInfo).kPtr + case reflect.Interface: + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti} + fn.f = (decFnInfo).kInterface + case reflect.Struct: + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti} + fn.f = (decFnInfo).kStruct + case reflect.Chan: + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti, seq: seqTypeChan} + fn.f = (decFnInfo).kSlice + case reflect.Slice: + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti, seq: seqTypeSlice} + fn.f = (decFnInfo).kSlice + case reflect.Array: + // fi.decFnInfoX = &decFnInfoX{array: true} + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti, seq: seqTypeArray} + fn.f = (decFnInfo).kArray + case reflect.Map: + fi.decFnInfoX = &decFnInfoX{d: d, ti: ti} + fn.f = (decFnInfo).kMap + default: + fn.f = (decFnInfo).kErr + } + } + } + fn.i = fi + + if useMapForCodecCache { + if d.f == nil { + d.f = make(map[uintptr]decFn, 32) + } + d.f[rtid] = fn + } else { + if d.s == nil { + d.s = make([]rtidDecFn, 0, 32) + } + d.s = append(d.s, rtidDecFn{rtid, fn}) + } + return +} + +func (d *Decoder) structFieldNotFound(index int, rvkencname string) { + if d.h.ErrorIfNoField { + if index >= 0 { + d.errorf("no matching struct field found when decoding stream array at index %v", index) + return + } else if rvkencname != "" { + d.errorf("no matching struct field found when decoding stream map with key %s", rvkencname) + return + } + } + d.swallow() +} + +func (d *Decoder) arrayCannotExpand(sliceLen, streamLen int) { + if d.h.ErrorIfNoArrayExpand { + d.errorf("cannot expand array len during decode from %v to %v", sliceLen, streamLen) + } +} + +func (d *Decoder) chkPtrValue(rv reflect.Value) { + // We can only decode into a non-nil pointer + if rv.Kind() == reflect.Ptr && !rv.IsNil() { + return + } + if !rv.IsValid() { + d.error(cannotDecodeIntoNilErr) + return + } + if !rv.CanInterface() { + d.errorf("cannot decode into a value without an interface: %v", rv) + return + } + rvi := rv.Interface() + d.errorf("cannot decode into non-pointer or nil pointer. Got: %v, %T, %v", rv.Kind(), rvi, rvi) +} + +func (d *Decoder) error(err error) { + panic(err) +} + +func (d *Decoder) errorf(format string, params ...interface{}) { + err := fmt.Errorf(format, params...) + panic(err) +} + +// -------------------------------------------------- + +// decSliceHelper assists when decoding into a slice, from a map or an array in the stream. +// A slice can be set from a map or array in stream. This supports the MapBySlice interface. +type decSliceHelper struct { + dd decDriver + ct valueType +} + +func (d *Decoder) decSliceHelperStart() (x decSliceHelper, clen int) { + x.dd = d.d + if x.dd.IsContainerType(valueTypeArray) { + x.ct = valueTypeArray + clen = x.dd.ReadArrayStart() + } else if x.dd.IsContainerType(valueTypeMap) { + x.ct = valueTypeMap + clen = x.dd.ReadMapStart() * 2 + } else { + d.errorf("only encoded map or array can be decoded into a slice") + } + return +} + +func (x decSliceHelper) Sep(index int) { + if x.ct == valueTypeArray { + x.dd.ReadArrayEntrySeparator() + } else { + if index%2 == 0 { + x.dd.ReadMapEntrySeparator() + } else { + x.dd.ReadMapKVSeparator() + } + } +} + +func (x decSliceHelper) End() { + if x.ct == valueTypeArray { + x.dd.ReadArrayEnd() + } else { + x.dd.ReadMapEnd() + } +} + +// func decErr(format string, params ...interface{}) { +// doPanic(msgTagDec, format, params...) +// } + +func decByteSlice(r decReader, clen int, bs []byte) (bsOut []byte) { + if clen == 0 { + return zeroByteSlice + } + if len(bs) == clen { + bsOut = bs + } else if cap(bs) >= clen { + bsOut = bs[:clen] + } else { + bsOut = make([]byte, clen) + } + r.readb(bsOut) + return +} + +func detachZeroCopyBytes(isBytesReader bool, dest []byte, in []byte) (out []byte) { + if xlen := len(in); xlen > 0 { + if isBytesReader || xlen <= scratchByteArrayLen { + if cap(dest) >= xlen { + out = dest[:xlen] + } else { + out = make([]byte, xlen) + } + copy(out, in) + return + } + } + return in +} + +// // implement overall decReader wrapping both, for possible use inline: +// type decReaderT struct { +// bytes bool +// rb *bytesDecReader +// ri *ioDecReader +// } +// +// // implement *Decoder as a decReader. +// // Using decReaderT (defined just above) caused performance degradation +// // possibly because of constant copying the value, +// // and some value->interface conversion causing allocation. +// func (d *Decoder) unreadn1() { +// if d.bytes { +// d.rb.unreadn1() +// } else { +// d.ri.unreadn1() +// } +// } + +// func (d *Decoder) readb(b []byte) { +// if d.bytes { +// d.rb.readb(b) +// } else { +// d.ri.readb(b) +// } +// } + +// func (d *Decoder) readx(n int) []byte { +// if d.bytes { +// return d.rb.readx(n) +// } else { +// return d.ri.readx(n) +// } +// } + +// func (d *Decoder) readn1() uint8 { +// if d.bytes { +// return d.rb.readn1() +// } else { +// return d.ri.readn1() +// } +// } + +// func (d *Decoder) readn1eof() (v uint8, eof bool) { +// if d.bytes { +// return d.rb.readn1eof() +// } else { +// return d.ri.readn1eof() +// } +// } + +// var _ decReader = (*Decoder)(nil) // decReaderT{} // diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/encode.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/encode.go new file mode 100644 index 0000000000..803c9d1827 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/encode.go @@ -0,0 +1,1232 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +import ( + "bytes" + "encoding" + "errors" + "fmt" + "io" + "reflect" + "sort" + "sync" +) + +const ( + defEncByteBufSize = 1 << 6 // 4:16, 6:64, 8:256, 10:1024 +) + +// AsSymbolFlag defines what should be encoded as symbols. +type AsSymbolFlag uint8 + +const ( + // AsSymbolDefault is default. + // Currently, this means only encode struct field names as symbols. + // The default is subject to change. + AsSymbolDefault AsSymbolFlag = iota + + // AsSymbolAll means encode anything which could be a symbol as a symbol. + AsSymbolAll = 0xfe + + // AsSymbolNone means do not encode anything as a symbol. + AsSymbolNone = 1 << iota + + // AsSymbolMapStringKeys means encode keys in map[string]XXX as symbols. + AsSymbolMapStringKeysFlag + + // AsSymbolStructFieldName means encode struct field names as symbols. + AsSymbolStructFieldNameFlag +) + +// encWriter abstracts writing to a byte array or to an io.Writer. +type encWriter interface { + writeb([]byte) + writestr(string) + writen1(byte) + writen2(byte, byte) + atEndOfEncode() +} + +// encDriver abstracts the actual codec (binc vs msgpack, etc) +type encDriver interface { + IsBuiltinType(rt uintptr) bool + EncodeBuiltin(rt uintptr, v interface{}) + EncodeNil() + EncodeInt(i int64) + EncodeUint(i uint64) + EncodeBool(b bool) + EncodeFloat32(f float32) + EncodeFloat64(f float64) + // encodeExtPreamble(xtag byte, length int) + EncodeRawExt(re *RawExt, e *Encoder) + EncodeExt(v interface{}, xtag uint64, ext Ext, e *Encoder) + EncodeArrayStart(length int) + EncodeArrayEnd() + EncodeArrayEntrySeparator() + EncodeMapStart(length int) + EncodeMapEnd() + EncodeMapEntrySeparator() + EncodeMapKVSeparator() + EncodeString(c charEncoding, v string) + EncodeSymbol(v string) + EncodeStringBytes(c charEncoding, v []byte) + //TODO + //encBignum(f *big.Int) + //encStringRunes(c charEncoding, v []rune) +} + +type encNoSeparator struct{} + +func (_ encNoSeparator) EncodeMapEnd() {} +func (_ encNoSeparator) EncodeArrayEnd() {} +func (_ encNoSeparator) EncodeArrayEntrySeparator() {} +func (_ encNoSeparator) EncodeMapEntrySeparator() {} +func (_ encNoSeparator) EncodeMapKVSeparator() {} + +type encStructFieldBytesV struct { + b []byte + v reflect.Value +} + +type encStructFieldBytesVslice []encStructFieldBytesV + +func (p encStructFieldBytesVslice) Len() int { return len(p) } +func (p encStructFieldBytesVslice) Less(i, j int) bool { return bytes.Compare(p[i].b, p[j].b) == -1 } +func (p encStructFieldBytesVslice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } + +type ioEncWriterWriter interface { + WriteByte(c byte) error + WriteString(s string) (n int, err error) + Write(p []byte) (n int, err error) +} + +type ioEncStringWriter interface { + WriteString(s string) (n int, err error) +} + +type EncodeOptions struct { + // Encode a struct as an array, and not as a map + StructToArray bool + + // Canonical representation means that encoding a value will always result in the same + // sequence of bytes. + // + // This mostly will apply to maps. In this case, codec will do more work to encode the + // map keys out of band, and then sort them, before writing out the map to the stream. + Canonical bool + + // AsSymbols defines what should be encoded as symbols. + // + // Encoding as symbols can reduce the encoded size significantly. + // + // However, during decoding, each string to be encoded as a symbol must + // be checked to see if it has been seen before. Consequently, encoding time + // will increase if using symbols, because string comparisons has a clear cost. + // + // Sample values: + // AsSymbolNone + // AsSymbolAll + // AsSymbolMapStringKeys + // AsSymbolMapStringKeysFlag | AsSymbolStructFieldNameFlag + AsSymbols AsSymbolFlag +} + +// --------------------------------------------- + +type simpleIoEncWriterWriter struct { + w io.Writer + bw io.ByteWriter + sw ioEncStringWriter +} + +func (o *simpleIoEncWriterWriter) WriteByte(c byte) (err error) { + if o.bw != nil { + return o.bw.WriteByte(c) + } + _, err = o.w.Write([]byte{c}) + return +} + +func (o *simpleIoEncWriterWriter) WriteString(s string) (n int, err error) { + if o.sw != nil { + return o.sw.WriteString(s) + } + // return o.w.Write([]byte(s)) + return o.w.Write(bytesView(s)) +} + +func (o *simpleIoEncWriterWriter) Write(p []byte) (n int, err error) { + return o.w.Write(p) +} + +// ---------------------------------------- + +// ioEncWriter implements encWriter and can write to an io.Writer implementation +type ioEncWriter struct { + w ioEncWriterWriter + // x [8]byte // temp byte array re-used internally for efficiency +} + +func (z *ioEncWriter) writeb(bs []byte) { + if len(bs) == 0 { + return + } + n, err := z.w.Write(bs) + if err != nil { + panic(err) + } + if n != len(bs) { + panic(fmt.Errorf("incorrect num bytes written. Expecting: %v, Wrote: %v", len(bs), n)) + } +} + +func (z *ioEncWriter) writestr(s string) { + n, err := z.w.WriteString(s) + if err != nil { + panic(err) + } + if n != len(s) { + panic(fmt.Errorf("incorrect num bytes written. Expecting: %v, Wrote: %v", len(s), n)) + } +} + +func (z *ioEncWriter) writen1(b byte) { + if err := z.w.WriteByte(b); err != nil { + panic(err) + } +} + +func (z *ioEncWriter) writen2(b1 byte, b2 byte) { + z.writen1(b1) + z.writen1(b2) +} + +func (z *ioEncWriter) atEndOfEncode() {} + +// ---------------------------------------- + +// bytesEncWriter implements encWriter and can write to an byte slice. +// It is used by Marshal function. +type bytesEncWriter struct { + b []byte + c int // cursor + out *[]byte // write out on atEndOfEncode +} + +func (z *bytesEncWriter) writeb(s []byte) { + if len(s) > 0 { + c := z.grow(len(s)) + copy(z.b[c:], s) + } +} + +func (z *bytesEncWriter) writestr(s string) { + if len(s) > 0 { + c := z.grow(len(s)) + copy(z.b[c:], s) + } +} + +func (z *bytesEncWriter) writen1(b1 byte) { + c := z.grow(1) + z.b[c] = b1 +} + +func (z *bytesEncWriter) writen2(b1 byte, b2 byte) { + c := z.grow(2) + z.b[c] = b1 + z.b[c+1] = b2 +} + +func (z *bytesEncWriter) atEndOfEncode() { + *(z.out) = z.b[:z.c] +} + +func (z *bytesEncWriter) grow(n int) (oldcursor int) { + oldcursor = z.c + z.c = oldcursor + n + if z.c > len(z.b) { + if z.c > cap(z.b) { + // Tried using appendslice logic: (if cap < 1024, *2, else *1.25). + // However, it was too expensive, causing too many iterations of copy. + // Using bytes.Buffer model was much better (2*cap + n) + bs := make([]byte, 2*cap(z.b)+n) + copy(bs, z.b[:oldcursor]) + z.b = bs + } else { + z.b = z.b[:cap(z.b)] + } + } + return +} + +// --------------------------------------------- + +type encFnInfoX struct { + e *Encoder + ti *typeInfo + xfFn Ext + xfTag uint64 + seq seqType +} + +type encFnInfo struct { + // use encFnInfo as a value receiver. + // keep most of it less-used variables accessible via a pointer (*encFnInfoX). + // As sweet spot for value-receiver is 3 words, keep everything except + // encDriver (which everyone needs) directly accessible. + // ensure encFnInfoX is set for everyone who needs it i.e. + // rawExt, ext, builtin, (selfer|binary|text)Marshal, kSlice, kStruct, kMap, kInterface, fastpath + + ee encDriver + *encFnInfoX +} + +func (f encFnInfo) builtin(rv reflect.Value) { + f.ee.EncodeBuiltin(f.ti.rtid, rv.Interface()) +} + +func (f encFnInfo) rawExt(rv reflect.Value) { + // rev := rv.Interface().(RawExt) + // f.ee.EncodeRawExt(&rev, f.e) + var re *RawExt + if rv.CanAddr() { + re = rv.Addr().Interface().(*RawExt) + } else { + rev := rv.Interface().(RawExt) + re = &rev + } + f.ee.EncodeRawExt(re, f.e) +} + +func (f encFnInfo) ext(rv reflect.Value) { + // if this is a struct and it was addressable, then pass the address directly (not the value) + if rv.CanAddr() && rv.Kind() == reflect.Struct { + rv = rv.Addr() + } + f.ee.EncodeExt(rv.Interface(), f.xfTag, f.xfFn, f.e) +} + +func (f encFnInfo) getValueForMarshalInterface(rv reflect.Value, indir int8) (v interface{}, proceed bool) { + if indir == 0 { + v = rv.Interface() + } else if indir == -1 { + v = rv.Addr().Interface() + } else { + for j := int8(0); j < indir; j++ { + if rv.IsNil() { + f.ee.EncodeNil() + return + } + rv = rv.Elem() + } + v = rv.Interface() + } + return v, true +} + +func (f encFnInfo) selferMarshal(rv reflect.Value) { + if v, proceed := f.getValueForMarshalInterface(rv, f.ti.csIndir); proceed { + v.(Selfer).CodecEncodeSelf(f.e) + } +} + +func (f encFnInfo) binaryMarshal(rv reflect.Value) { + if v, proceed := f.getValueForMarshalInterface(rv, f.ti.bmIndir); proceed { + bs, fnerr := v.(encoding.BinaryMarshaler).MarshalBinary() + if fnerr != nil { + panic(fnerr) + } + if bs == nil { + f.ee.EncodeNil() + } else { + f.ee.EncodeStringBytes(c_RAW, bs) + } + } +} + +func (f encFnInfo) textMarshal(rv reflect.Value) { + if v, proceed := f.getValueForMarshalInterface(rv, f.ti.tmIndir); proceed { + // debugf(">>>> encoding.TextMarshaler: %T", rv.Interface()) + bs, fnerr := v.(encoding.TextMarshaler).MarshalText() + if fnerr != nil { + panic(fnerr) + } + if bs == nil { + f.ee.EncodeNil() + } else { + f.ee.EncodeStringBytes(c_UTF8, bs) + } + } +} + +func (f encFnInfo) kBool(rv reflect.Value) { + f.ee.EncodeBool(rv.Bool()) +} + +func (f encFnInfo) kString(rv reflect.Value) { + f.ee.EncodeString(c_UTF8, rv.String()) +} + +func (f encFnInfo) kFloat64(rv reflect.Value) { + f.ee.EncodeFloat64(rv.Float()) +} + +func (f encFnInfo) kFloat32(rv reflect.Value) { + f.ee.EncodeFloat32(float32(rv.Float())) +} + +func (f encFnInfo) kInt(rv reflect.Value) { + f.ee.EncodeInt(rv.Int()) +} + +func (f encFnInfo) kUint(rv reflect.Value) { + f.ee.EncodeUint(rv.Uint()) +} + +func (f encFnInfo) kInvalid(rv reflect.Value) { + f.ee.EncodeNil() +} + +func (f encFnInfo) kErr(rv reflect.Value) { + f.e.errorf("unsupported kind %s, for %#v", rv.Kind(), rv) +} + +func (f encFnInfo) kSlice(rv reflect.Value) { + ti := f.ti + // array may be non-addressable, so we have to manage with care + // (don't call rv.Bytes, rv.Slice, etc). + // E.g. type struct S{B [2]byte}; + // Encode(S{}) will bomb on "panic: slice of unaddressable array". + if f.seq != seqTypeArray { + if rv.IsNil() { + f.ee.EncodeNil() + return + } + // If in this method, then there was no extension function defined. + // So it's okay to treat as []byte. + if ti.rtid == uint8SliceTypId { + f.ee.EncodeStringBytes(c_RAW, rv.Bytes()) + return + } + } + rtelem := ti.rt.Elem() + l := rv.Len() + if rtelem.Kind() == reflect.Uint8 { + switch f.seq { + case seqTypeArray: + // if l == 0 { f.ee.encodeStringBytes(c_RAW, nil) } else + if rv.CanAddr() { + f.ee.EncodeStringBytes(c_RAW, rv.Slice(0, l).Bytes()) + } else { + var bs []byte + if l <= cap(f.e.b) { + bs = f.e.b[:l] + } else { + bs = make([]byte, l) + } + reflect.Copy(reflect.ValueOf(bs), rv) + // TODO: Test that reflect.Copy works instead of manual one-by-one + // for i := 0; i < l; i++ { + // bs[i] = byte(rv.Index(i).Uint()) + // } + f.ee.EncodeStringBytes(c_RAW, bs) + } + case seqTypeSlice: + f.ee.EncodeStringBytes(c_RAW, rv.Bytes()) + case seqTypeChan: + bs := f.e.b[:0] + // do not use range, so that the number of elements encoded + // does not change, and encoding does not hang waiting on someone to close chan. + // for b := range rv.Interface().(<-chan byte) { + // bs = append(bs, b) + // } + ch := rv.Interface().(<-chan byte) + for i := 0; i < l; i++ { + bs = append(bs, <-ch) + } + f.ee.EncodeStringBytes(c_RAW, bs) + } + return + } + + if ti.mbs { + if l%2 == 1 { + f.e.errorf("mapBySlice requires even slice length, but got %v", l) + return + } + f.ee.EncodeMapStart(l / 2) + } else { + f.ee.EncodeArrayStart(l) + } + + e := f.e + sep := !e.be + if l > 0 { + for rtelem.Kind() == reflect.Ptr { + rtelem = rtelem.Elem() + } + // if kind is reflect.Interface, do not pre-determine the + // encoding type, because preEncodeValue may break it down to + // a concrete type and kInterface will bomb. + var fn encFn + if rtelem.Kind() != reflect.Interface { + rtelemid := reflect.ValueOf(rtelem).Pointer() + fn = e.getEncFn(rtelemid, rtelem, true, true) + } + // TODO: Consider perf implication of encoding odd index values as symbols if type is string + if sep { + for j := 0; j < l; j++ { + if j > 0 { + if ti.mbs { + if j%2 == 0 { + f.ee.EncodeMapEntrySeparator() + } else { + f.ee.EncodeMapKVSeparator() + } + } else { + f.ee.EncodeArrayEntrySeparator() + } + } + if f.seq == seqTypeChan { + if rv2, ok2 := rv.Recv(); ok2 { + e.encodeValue(rv2, fn) + } + } else { + e.encodeValue(rv.Index(j), fn) + } + } + } else { + for j := 0; j < l; j++ { + if f.seq == seqTypeChan { + if rv2, ok2 := rv.Recv(); ok2 { + e.encodeValue(rv2, fn) + } + } else { + e.encodeValue(rv.Index(j), fn) + } + } + } + } + + if sep { + if ti.mbs { + f.ee.EncodeMapEnd() + } else { + f.ee.EncodeArrayEnd() + } + } +} + +func (f encFnInfo) kStruct(rv reflect.Value) { + fti := f.ti + e := f.e + tisfi := fti.sfip + toMap := !(fti.toArray || e.h.StructToArray) + newlen := len(fti.sfi) + // Use sync.Pool to reduce allocating slices unnecessarily. + // The cost of the occasional locking is less than the cost of locking. + + var fkvs []encStructFieldKV + var pool *sync.Pool + var poolv interface{} + idxpool := newlen / 8 + if encStructPoolLen != 4 { + panic(errors.New("encStructPoolLen must be equal to 4")) // defensive, in case it is changed + } + if idxpool < encStructPoolLen { + pool = &encStructPool[idxpool] + poolv = pool.Get() + switch vv := poolv.(type) { + case *[8]encStructFieldKV: + fkvs = vv[:newlen] + case *[16]encStructFieldKV: + fkvs = vv[:newlen] + case *[32]encStructFieldKV: + fkvs = vv[:newlen] + case *[64]encStructFieldKV: + fkvs = vv[:newlen] + } + } + if fkvs == nil { + fkvs = make([]encStructFieldKV, newlen) + } + // if toMap, use the sorted array. If toArray, use unsorted array (to match sequence in struct) + if toMap { + tisfi = fti.sfi + } + newlen = 0 + var kv encStructFieldKV + for _, si := range tisfi { + kv.v = si.field(rv, false) + // if si.i != -1 { + // rvals[newlen] = rv.Field(int(si.i)) + // } else { + // rvals[newlen] = rv.FieldByIndex(si.is) + // } + if toMap { + if si.omitEmpty && isEmptyValue(kv.v) { + continue + } + kv.k = si.encName + } else { + // use the zero value. + // if a reference or struct, set to nil (so you do not output too much) + if si.omitEmpty && isEmptyValue(kv.v) { + switch kv.v.Kind() { + case reflect.Struct, reflect.Interface, reflect.Ptr, reflect.Array, + reflect.Map, reflect.Slice: + kv.v = reflect.Value{} //encode as nil + } + } + } + fkvs[newlen] = kv + newlen++ + } + + // debugf(">>>> kStruct: newlen: %v", newlen) + sep := !e.be + ee := f.ee //don't dereference everytime + if sep { + if toMap { + ee.EncodeMapStart(newlen) + // asSymbols := e.h.AsSymbols&AsSymbolStructFieldNameFlag != 0 + asSymbols := e.h.AsSymbols == AsSymbolDefault || e.h.AsSymbols&AsSymbolStructFieldNameFlag != 0 + for j := 0; j < newlen; j++ { + kv = fkvs[j] + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(kv.k) + } else { + ee.EncodeString(c_UTF8, kv.k) + } + ee.EncodeMapKVSeparator() + e.encodeValue(kv.v, encFn{}) + } + ee.EncodeMapEnd() + } else { + ee.EncodeArrayStart(newlen) + for j := 0; j < newlen; j++ { + kv = fkvs[j] + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + e.encodeValue(kv.v, encFn{}) + } + ee.EncodeArrayEnd() + } + } else { + if toMap { + ee.EncodeMapStart(newlen) + // asSymbols := e.h.AsSymbols&AsSymbolStructFieldNameFlag != 0 + asSymbols := e.h.AsSymbols == AsSymbolDefault || e.h.AsSymbols&AsSymbolStructFieldNameFlag != 0 + for j := 0; j < newlen; j++ { + kv = fkvs[j] + if asSymbols { + ee.EncodeSymbol(kv.k) + } else { + ee.EncodeString(c_UTF8, kv.k) + } + e.encodeValue(kv.v, encFn{}) + } + } else { + ee.EncodeArrayStart(newlen) + for j := 0; j < newlen; j++ { + kv = fkvs[j] + e.encodeValue(kv.v, encFn{}) + } + } + } + + // do not use defer. Instead, use explicit pool return at end of function. + // defer has a cost we are trying to avoid. + // If there is a panic and these slices are not returned, it is ok. + if pool != nil { + pool.Put(poolv) + } +} + +// func (f encFnInfo) kPtr(rv reflect.Value) { +// debugf(">>>>>>> ??? encode kPtr called - shouldn't get called") +// if rv.IsNil() { +// f.ee.encodeNil() +// return +// } +// f.e.encodeValue(rv.Elem()) +// } + +func (f encFnInfo) kInterface(rv reflect.Value) { + if rv.IsNil() { + f.ee.EncodeNil() + return + } + f.e.encodeValue(rv.Elem(), encFn{}) +} + +func (f encFnInfo) kMap(rv reflect.Value) { + if rv.IsNil() { + f.ee.EncodeNil() + return + } + + l := rv.Len() + f.ee.EncodeMapStart(l) + e := f.e + sep := !e.be + if l == 0 { + if sep { + f.ee.EncodeMapEnd() + } + return + } + var asSymbols bool + // determine the underlying key and val encFn's for the map. + // This eliminates some work which is done for each loop iteration i.e. + // rv.Type(), ref.ValueOf(rt).Pointer(), then check map/list for fn. + // + // However, if kind is reflect.Interface, do not pre-determine the + // encoding type, because preEncodeValue may break it down to + // a concrete type and kInterface will bomb. + var keyFn, valFn encFn + ti := f.ti + rtkey := ti.rt.Key() + rtval := ti.rt.Elem() + rtkeyid := reflect.ValueOf(rtkey).Pointer() + // keyTypeIsString := f.ti.rt.Key().Kind() == reflect.String + var keyTypeIsString = rtkeyid == stringTypId + if keyTypeIsString { + asSymbols = e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + } else { + for rtkey.Kind() == reflect.Ptr { + rtkey = rtkey.Elem() + } + if rtkey.Kind() != reflect.Interface { + rtkeyid = reflect.ValueOf(rtkey).Pointer() + keyFn = e.getEncFn(rtkeyid, rtkey, true, true) + } + } + for rtval.Kind() == reflect.Ptr { + rtval = rtval.Elem() + } + if rtval.Kind() != reflect.Interface { + rtvalid := reflect.ValueOf(rtval).Pointer() + valFn = e.getEncFn(rtvalid, rtval, true, true) + } + mks := rv.MapKeys() + // for j, lmks := 0, len(mks); j < lmks; j++ { + ee := f.ee //don't dereference everytime + if e.h.Canonical { + // first encode each key to a []byte first, then sort them, then record + // println(">>>>>>>> CANONICAL <<<<<<<<") + var mksv []byte // temporary byte slice for the encoding + e2 := NewEncoderBytes(&mksv, e.hh) + mksbv := make([]encStructFieldBytesV, len(mks)) + for i, k := range mks { + l := len(mksv) + e2.MustEncode(k) + mksbv[i].v = k + mksbv[i].b = mksv[l:] + } + sort.Sort(encStructFieldBytesVslice(mksbv)) + for j := range mksbv { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.w.writeb(mksbv[j].b) + ee.EncodeMapKVSeparator() + e.encodeValue(rv.MapIndex(mksbv[j].v), valFn) + } + ee.EncodeMapEnd() + } else if sep { + for j := range mks { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if keyTypeIsString { + if asSymbols { + ee.EncodeSymbol(mks[j].String()) + } else { + ee.EncodeString(c_UTF8, mks[j].String()) + } + } else { + e.encodeValue(mks[j], keyFn) + } + ee.EncodeMapKVSeparator() + e.encodeValue(rv.MapIndex(mks[j]), valFn) + } + ee.EncodeMapEnd() + } else { + for j := range mks { + if keyTypeIsString { + if asSymbols { + ee.EncodeSymbol(mks[j].String()) + } else { + ee.EncodeString(c_UTF8, mks[j].String()) + } + } else { + e.encodeValue(mks[j], keyFn) + } + e.encodeValue(rv.MapIndex(mks[j]), valFn) + } + } +} + +// -------------------------------------------------- + +// encFn encapsulates the captured variables and the encode function. +// This way, we only do some calculations one times, and pass to the +// code block that should be called (encapsulated in a function) +// instead of executing the checks every time. +type encFn struct { + i encFnInfo + f func(encFnInfo, reflect.Value) +} + +// -------------------------------------------------- + +type rtidEncFn struct { + rtid uintptr + fn encFn +} + +// An Encoder writes an object to an output stream in the codec format. +type Encoder struct { + // hopefully, reduce derefencing cost by laying the encWriter inside the Encoder + e encDriver + w encWriter + s []rtidEncFn + be bool // is binary encoding + + wi ioEncWriter + wb bytesEncWriter + h *BasicHandle + + hh Handle + f map[uintptr]encFn + b [scratchByteArrayLen]byte +} + +// NewEncoder returns an Encoder for encoding into an io.Writer. +// +// For efficiency, Users are encouraged to pass in a memory buffered writer +// (eg bufio.Writer, bytes.Buffer). +func NewEncoder(w io.Writer, h Handle) *Encoder { + e := &Encoder{hh: h, h: h.getBasicHandle(), be: h.isBinary()} + ww, ok := w.(ioEncWriterWriter) + if !ok { + sww := simpleIoEncWriterWriter{w: w} + sww.bw, _ = w.(io.ByteWriter) + sww.sw, _ = w.(ioEncStringWriter) + ww = &sww + //ww = bufio.NewWriterSize(w, defEncByteBufSize) + } + e.wi.w = ww + e.w = &e.wi + e.e = h.newEncDriver(e) + return e +} + +// NewEncoderBytes returns an encoder for encoding directly and efficiently +// into a byte slice, using zero-copying to temporary slices. +// +// It will potentially replace the output byte slice pointed to. +// After encoding, the out parameter contains the encoded contents. +func NewEncoderBytes(out *[]byte, h Handle) *Encoder { + e := &Encoder{hh: h, h: h.getBasicHandle(), be: h.isBinary()} + in := *out + if in == nil { + in = make([]byte, defEncByteBufSize) + } + e.wb.b, e.wb.out = in, out + e.w = &e.wb + e.e = h.newEncDriver(e) + return e +} + +// Encode writes an object into a stream. +// +// Encoding can be configured via the struct tag for the fields. +// The "codec" key in struct field's tag value is the key name, +// followed by an optional comma and options. +// Note that the "json" key is used in the absence of the "codec" key. +// +// To set an option on all fields (e.g. omitempty on all fields), you +// can create a field called _struct, and set flags on it. +// +// Struct values "usually" encode as maps. Each exported struct field is encoded unless: +// - the field's tag is "-", OR +// - the field is empty (empty or the zero value) and its tag specifies the "omitempty" option. +// +// When encoding as a map, the first string in the tag (before the comma) +// is the map key string to use when encoding. +// +// However, struct values may encode as arrays. This happens when: +// - StructToArray Encode option is set, OR +// - the tag on the _struct field sets the "toarray" option +// +// Values with types that implement MapBySlice are encoded as stream maps. +// +// The empty values (for omitempty option) are false, 0, any nil pointer +// or interface value, and any array, slice, map, or string of length zero. +// +// Anonymous fields are encoded inline if no struct tag is present. +// Else they are encoded as regular fields. +// +// Examples: +// +// // NOTE: 'json:' can be used as struct tag key, in place 'codec:' below. +// type MyStruct struct { +// _struct bool `codec:",omitempty"` //set omitempty for every field +// Field1 string `codec:"-"` //skip this field +// Field2 int `codec:"myName"` //Use key "myName" in encode stream +// Field3 int32 `codec:",omitempty"` //use key "Field3". Omit if empty. +// Field4 bool `codec:"f4,omitempty"` //use key "f4". Omit if empty. +// ... +// } +// +// type MyStruct struct { +// _struct bool `codec:",omitempty,toarray"` //set omitempty for every field +// //and encode struct as an array +// } +// +// The mode of encoding is based on the type of the value. When a value is seen: +// - If an extension is registered for it, call that extension function +// - If it implements BinaryMarshaler, call its MarshalBinary() (data []byte, err error) +// - Else encode it based on its reflect.Kind +// +// Note that struct field names and keys in map[string]XXX will be treated as symbols. +// Some formats support symbols (e.g. binc) and will properly encode the string +// only once in the stream, and use a tag to refer to it thereafter. +func (e *Encoder) Encode(v interface{}) (err error) { + defer panicToErr(&err) + e.encode(v) + e.w.atEndOfEncode() + return +} + +// MustEncode is like Encode, but panics if unable to Encode. +// This provides insight to the code location that triggered the error. +func (e *Encoder) MustEncode(v interface{}) { + e.encode(v) + e.w.atEndOfEncode() +} + +// comment out these (Must)Write methods. They were only put there to support cbor. +// However, users already have access to the streams, and can write directly. +// +// // Write allows users write to the Encoder stream directly. +// func (e *Encoder) Write(bs []byte) (err error) { +// defer panicToErr(&err) +// e.w.writeb(bs) +// return +// } +// // MustWrite is like write, but panics if unable to Write. +// func (e *Encoder) MustWrite(bs []byte) { +// e.w.writeb(bs) +// } + +func (e *Encoder) encode(iv interface{}) { + // if ics, ok := iv.(Selfer); ok { + // ics.CodecEncodeSelf(e) + // return + // } + + switch v := iv.(type) { + case nil: + e.e.EncodeNil() + case Selfer: + v.CodecEncodeSelf(e) + + case reflect.Value: + e.encodeValue(v, encFn{}) + + case string: + e.e.EncodeString(c_UTF8, v) + case bool: + e.e.EncodeBool(v) + case int: + e.e.EncodeInt(int64(v)) + case int8: + e.e.EncodeInt(int64(v)) + case int16: + e.e.EncodeInt(int64(v)) + case int32: + e.e.EncodeInt(int64(v)) + case int64: + e.e.EncodeInt(v) + case uint: + e.e.EncodeUint(uint64(v)) + case uint8: + e.e.EncodeUint(uint64(v)) + case uint16: + e.e.EncodeUint(uint64(v)) + case uint32: + e.e.EncodeUint(uint64(v)) + case uint64: + e.e.EncodeUint(v) + case float32: + e.e.EncodeFloat32(v) + case float64: + e.e.EncodeFloat64(v) + + case []uint8: + e.e.EncodeStringBytes(c_RAW, v) + + case *string: + e.e.EncodeString(c_UTF8, *v) + case *bool: + e.e.EncodeBool(*v) + case *int: + e.e.EncodeInt(int64(*v)) + case *int8: + e.e.EncodeInt(int64(*v)) + case *int16: + e.e.EncodeInt(int64(*v)) + case *int32: + e.e.EncodeInt(int64(*v)) + case *int64: + e.e.EncodeInt(*v) + case *uint: + e.e.EncodeUint(uint64(*v)) + case *uint8: + e.e.EncodeUint(uint64(*v)) + case *uint16: + e.e.EncodeUint(uint64(*v)) + case *uint32: + e.e.EncodeUint(uint64(*v)) + case *uint64: + e.e.EncodeUint(*v) + case *float32: + e.e.EncodeFloat32(*v) + case *float64: + e.e.EncodeFloat64(*v) + + case *[]uint8: + e.e.EncodeStringBytes(c_RAW, *v) + + default: + // canonical mode is not supported for fastpath of maps (but is fine for slices) + if e.h.Canonical { + if !fastpathEncodeTypeSwitchSlice(iv, e) { + e.encodeI(iv, false, false) + } + } else if !fastpathEncodeTypeSwitch(iv, e) { + e.encodeI(iv, false, false) + } + } +} + +func (e *Encoder) encodeI(iv interface{}, checkFastpath, checkCodecSelfer bool) { + if rv, proceed := e.preEncodeValue(reflect.ValueOf(iv)); proceed { + rt := rv.Type() + rtid := reflect.ValueOf(rt).Pointer() + fn := e.getEncFn(rtid, rt, checkFastpath, checkCodecSelfer) + fn.f(fn.i, rv) + } +} + +func (e *Encoder) preEncodeValue(rv reflect.Value) (rv2 reflect.Value, proceed bool) { +LOOP: + for { + switch rv.Kind() { + case reflect.Ptr, reflect.Interface: + if rv.IsNil() { + e.e.EncodeNil() + return + } + rv = rv.Elem() + continue LOOP + case reflect.Slice, reflect.Map: + if rv.IsNil() { + e.e.EncodeNil() + return + } + case reflect.Invalid, reflect.Func: + e.e.EncodeNil() + return + } + break + } + + return rv, true +} + +func (e *Encoder) encodeValue(rv reflect.Value, fn encFn) { + // if a valid fn is passed, it MUST BE for the dereferenced type of rv + if rv, proceed := e.preEncodeValue(rv); proceed { + if fn.f == nil { + rt := rv.Type() + rtid := reflect.ValueOf(rt).Pointer() + fn = e.getEncFn(rtid, rt, true, true) + } + fn.f(fn.i, rv) + } +} + +func (e *Encoder) getEncFn(rtid uintptr, rt reflect.Type, checkFastpath, checkCodecSelfer bool) (fn encFn) { + // rtid := reflect.ValueOf(rt).Pointer() + var ok bool + if useMapForCodecCache { + fn, ok = e.f[rtid] + } else { + for _, v := range e.s { + if v.rtid == rtid { + fn, ok = v.fn, true + break + } + } + } + if ok { + return + } + // fi.encFnInfoX = new(encFnInfoX) + ti := getTypeInfo(rtid, rt) + var fi encFnInfo + fi.ee = e.e + + if checkCodecSelfer && ti.cs { + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti} + fn.f = (encFnInfo).selferMarshal + } else if rtid == rawExtTypId { + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti} + fn.f = (encFnInfo).rawExt + } else if e.e.IsBuiltinType(rtid) { + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti} + fn.f = (encFnInfo).builtin + } else if xfFn := e.h.getExt(rtid); xfFn != nil { + // fi.encFnInfoX = new(encFnInfoX) + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti} + fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext + fn.f = (encFnInfo).ext + } else if supportMarshalInterfaces && e.be && ti.bm { + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti} + fn.f = (encFnInfo).binaryMarshal + } else if supportMarshalInterfaces && !e.be && ti.tm { + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti} + fn.f = (encFnInfo).textMarshal + } else { + rk := rt.Kind() + if fastpathEnabled && checkFastpath && (rk == reflect.Map || rk == reflect.Slice) { + if rt.PkgPath() == "" { + if idx := fastpathAV.index(rtid); idx != -1 { + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti} + fn.f = fastpathAV[idx].encfn + } + } else { + ok = false + // use mapping for underlying type if there + var rtu reflect.Type + if rk == reflect.Map { + rtu = reflect.MapOf(rt.Key(), rt.Elem()) + } else { + rtu = reflect.SliceOf(rt.Elem()) + } + rtuid := reflect.ValueOf(rtu).Pointer() + if idx := fastpathAV.index(rtuid); idx != -1 { + xfnf := fastpathAV[idx].encfn + xrt := fastpathAV[idx].rt + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti} + fn.f = func(xf encFnInfo, xrv reflect.Value) { + xfnf(xf, xrv.Convert(xrt)) + } + } + } + } + if fn.f == nil { + switch rk { + case reflect.Bool: + fn.f = (encFnInfo).kBool + case reflect.String: + fn.f = (encFnInfo).kString + case reflect.Float64: + fn.f = (encFnInfo).kFloat64 + case reflect.Float32: + fn.f = (encFnInfo).kFloat32 + case reflect.Int, reflect.Int8, reflect.Int64, reflect.Int32, reflect.Int16: + fn.f = (encFnInfo).kInt + case reflect.Uint8, reflect.Uint64, reflect.Uint, reflect.Uint32, reflect.Uint16: + fn.f = (encFnInfo).kUint + case reflect.Invalid: + fn.f = (encFnInfo).kInvalid + case reflect.Chan: + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti, seq: seqTypeChan} + fn.f = (encFnInfo).kSlice + case reflect.Slice: + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti, seq: seqTypeSlice} + fn.f = (encFnInfo).kSlice + case reflect.Array: + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti, seq: seqTypeArray} + fn.f = (encFnInfo).kSlice + case reflect.Struct: + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti} + fn.f = (encFnInfo).kStruct + // case reflect.Ptr: + // fn.f = (encFnInfo).kPtr + case reflect.Interface: + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti} + fn.f = (encFnInfo).kInterface + case reflect.Map: + fi.encFnInfoX = &encFnInfoX{e: e, ti: ti} + fn.f = (encFnInfo).kMap + default: + fn.f = (encFnInfo).kErr + } + } + } + fn.i = fi + + if useMapForCodecCache { + if e.f == nil { + e.f = make(map[uintptr]encFn, 32) + } + e.f[rtid] = fn + } else { + if e.s == nil { + e.s = make([]rtidEncFn, 0, 32) + } + e.s = append(e.s, rtidEncFn{rtid, fn}) + } + return +} + +func (e *Encoder) errorf(format string, params ...interface{}) { + err := fmt.Errorf(format, params...) + panic(err) +} + +// ---------------------------------------- + +type encStructFieldKV struct { + k string + v reflect.Value +} + +const encStructPoolLen = 4 + +// encStructPool is an array of sync.Pool. +// Each element of the array pools one of encStructPool(8|16|32|64). +// It allows the re-use of slices up to 64 in length. +// A performance cost of encoding structs was collecting +// which values were empty and should be omitted. +// We needed slices of reflect.Value and string to collect them. +// This shared pool reduces the amount of unnecessary creation we do. +// The cost is that of locking sometimes, but sync.Pool is efficient +// enough to reduce thread contention. +var encStructPool [encStructPoolLen]sync.Pool + +func init() { + encStructPool[0].New = func() interface{} { return new([8]encStructFieldKV) } + encStructPool[1].New = func() interface{} { return new([16]encStructFieldKV) } + encStructPool[2].New = func() interface{} { return new([32]encStructFieldKV) } + encStructPool[3].New = func() interface{} { return new([64]encStructFieldKV) } +} + +// ---------------------------------------- + +// func encErr(format string, params ...interface{}) { +// doPanic(msgTagEnc, format, params...) +// } diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/fast-path.generated.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/fast-path.generated.go new file mode 100644 index 0000000000..efd81da29f --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/fast-path.generated.go @@ -0,0 +1,28307 @@ +// //+build ignore + +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +// ************************************************************ +// DO NOT EDIT. +// THIS FILE IS AUTO-GENERATED from fast-path.go.tmpl +// ************************************************************ + +package codec + +// Fast path functions try to create a fast path encode or decode implementation +// for common maps and slices. +// +// We define the functions and register then in this single file +// so as not to pollute the encode.go and decode.go, and create a dependency in there. +// This file can be omitted without causing a build failure. +// +// The advantage of fast paths is: +// - Many calls bypass reflection altogether +// +// Currently support +// - slice of all builtin types, +// - map of all builtin types to string or interface value +// - symetrical maps of all builtin types (e.g. str-str, uint8-uint8) +// This should provide adequate "typical" implementations. +// +// Note that fast track decode functions must handle values for which an address cannot be obtained. +// For example: +// m2 := map[string]int{} +// p2 := []interface{}{m2} +// // decoding into p2 will bomb if fast track functions do not treat like unaddressable. +// + +import ( + "reflect" + "sort" +) + +const fastpathCheckNilFalse = false // for reflect +const fastpathCheckNilTrue = true // for type switch + +type fastpathT struct{} + +var fastpathTV fastpathT + +type fastpathE struct { + rtid uintptr + rt reflect.Type + encfn func(encFnInfo, reflect.Value) + decfn func(decFnInfo, reflect.Value) +} + +type fastpathA [239]fastpathE + +func (x *fastpathA) index(rtid uintptr) int { + // use binary search to grab the index (adapted from sort/search.go) + h, i, j := 0, 0, 239 // len(x) + for i < j { + h = i + (j-i)/2 + if x[h].rtid < rtid { + i = h + 1 + } else { + j = h + } + } + if i < 239 && x[i].rtid == rtid { + return i + } + return -1 +} + +type fastpathAslice []fastpathE + +func (x fastpathAslice) Len() int { return len(x) } +func (x fastpathAslice) Less(i, j int) bool { return x[i].rtid < x[j].rtid } +func (x fastpathAslice) Swap(i, j int) { x[i], x[j] = x[j], x[i] } + +var fastpathAV fastpathA + +// due to possible initialization loop error, make fastpath in an init() +func init() { + if !fastpathEnabled { + return + } + i := 0 + fn := func(v interface{}, fe func(encFnInfo, reflect.Value), fd func(decFnInfo, reflect.Value)) (f fastpathE) { + xrt := reflect.TypeOf(v) + xptr := reflect.ValueOf(xrt).Pointer() + fastpathAV[i] = fastpathE{xptr, xrt, fe, fd} + i++ + return + } + + fn([]interface{}(nil), (encFnInfo).fastpathEncSliceIntfR, (decFnInfo).fastpathDecSliceIntfR) + fn([]string(nil), (encFnInfo).fastpathEncSliceStringR, (decFnInfo).fastpathDecSliceStringR) + fn([]float32(nil), (encFnInfo).fastpathEncSliceFloat32R, (decFnInfo).fastpathDecSliceFloat32R) + fn([]float64(nil), (encFnInfo).fastpathEncSliceFloat64R, (decFnInfo).fastpathDecSliceFloat64R) + fn([]uint(nil), (encFnInfo).fastpathEncSliceUintR, (decFnInfo).fastpathDecSliceUintR) + fn([]uint16(nil), (encFnInfo).fastpathEncSliceUint16R, (decFnInfo).fastpathDecSliceUint16R) + fn([]uint32(nil), (encFnInfo).fastpathEncSliceUint32R, (decFnInfo).fastpathDecSliceUint32R) + fn([]uint64(nil), (encFnInfo).fastpathEncSliceUint64R, (decFnInfo).fastpathDecSliceUint64R) + fn([]int(nil), (encFnInfo).fastpathEncSliceIntR, (decFnInfo).fastpathDecSliceIntR) + fn([]int8(nil), (encFnInfo).fastpathEncSliceInt8R, (decFnInfo).fastpathDecSliceInt8R) + fn([]int16(nil), (encFnInfo).fastpathEncSliceInt16R, (decFnInfo).fastpathDecSliceInt16R) + fn([]int32(nil), (encFnInfo).fastpathEncSliceInt32R, (decFnInfo).fastpathDecSliceInt32R) + fn([]int64(nil), (encFnInfo).fastpathEncSliceInt64R, (decFnInfo).fastpathDecSliceInt64R) + fn([]bool(nil), (encFnInfo).fastpathEncSliceBoolR, (decFnInfo).fastpathDecSliceBoolR) + + fn(map[interface{}]interface{}(nil), (encFnInfo).fastpathEncMapIntfIntfR, (decFnInfo).fastpathDecMapIntfIntfR) + fn(map[interface{}]string(nil), (encFnInfo).fastpathEncMapIntfStringR, (decFnInfo).fastpathDecMapIntfStringR) + fn(map[interface{}]uint(nil), (encFnInfo).fastpathEncMapIntfUintR, (decFnInfo).fastpathDecMapIntfUintR) + fn(map[interface{}]uint8(nil), (encFnInfo).fastpathEncMapIntfUint8R, (decFnInfo).fastpathDecMapIntfUint8R) + fn(map[interface{}]uint16(nil), (encFnInfo).fastpathEncMapIntfUint16R, (decFnInfo).fastpathDecMapIntfUint16R) + fn(map[interface{}]uint32(nil), (encFnInfo).fastpathEncMapIntfUint32R, (decFnInfo).fastpathDecMapIntfUint32R) + fn(map[interface{}]uint64(nil), (encFnInfo).fastpathEncMapIntfUint64R, (decFnInfo).fastpathDecMapIntfUint64R) + fn(map[interface{}]int(nil), (encFnInfo).fastpathEncMapIntfIntR, (decFnInfo).fastpathDecMapIntfIntR) + fn(map[interface{}]int8(nil), (encFnInfo).fastpathEncMapIntfInt8R, (decFnInfo).fastpathDecMapIntfInt8R) + fn(map[interface{}]int16(nil), (encFnInfo).fastpathEncMapIntfInt16R, (decFnInfo).fastpathDecMapIntfInt16R) + fn(map[interface{}]int32(nil), (encFnInfo).fastpathEncMapIntfInt32R, (decFnInfo).fastpathDecMapIntfInt32R) + fn(map[interface{}]int64(nil), (encFnInfo).fastpathEncMapIntfInt64R, (decFnInfo).fastpathDecMapIntfInt64R) + fn(map[interface{}]float32(nil), (encFnInfo).fastpathEncMapIntfFloat32R, (decFnInfo).fastpathDecMapIntfFloat32R) + fn(map[interface{}]float64(nil), (encFnInfo).fastpathEncMapIntfFloat64R, (decFnInfo).fastpathDecMapIntfFloat64R) + fn(map[interface{}]bool(nil), (encFnInfo).fastpathEncMapIntfBoolR, (decFnInfo).fastpathDecMapIntfBoolR) + fn(map[string]interface{}(nil), (encFnInfo).fastpathEncMapStringIntfR, (decFnInfo).fastpathDecMapStringIntfR) + fn(map[string]string(nil), (encFnInfo).fastpathEncMapStringStringR, (decFnInfo).fastpathDecMapStringStringR) + fn(map[string]uint(nil), (encFnInfo).fastpathEncMapStringUintR, (decFnInfo).fastpathDecMapStringUintR) + fn(map[string]uint8(nil), (encFnInfo).fastpathEncMapStringUint8R, (decFnInfo).fastpathDecMapStringUint8R) + fn(map[string]uint16(nil), (encFnInfo).fastpathEncMapStringUint16R, (decFnInfo).fastpathDecMapStringUint16R) + fn(map[string]uint32(nil), (encFnInfo).fastpathEncMapStringUint32R, (decFnInfo).fastpathDecMapStringUint32R) + fn(map[string]uint64(nil), (encFnInfo).fastpathEncMapStringUint64R, (decFnInfo).fastpathDecMapStringUint64R) + fn(map[string]int(nil), (encFnInfo).fastpathEncMapStringIntR, (decFnInfo).fastpathDecMapStringIntR) + fn(map[string]int8(nil), (encFnInfo).fastpathEncMapStringInt8R, (decFnInfo).fastpathDecMapStringInt8R) + fn(map[string]int16(nil), (encFnInfo).fastpathEncMapStringInt16R, (decFnInfo).fastpathDecMapStringInt16R) + fn(map[string]int32(nil), (encFnInfo).fastpathEncMapStringInt32R, (decFnInfo).fastpathDecMapStringInt32R) + fn(map[string]int64(nil), (encFnInfo).fastpathEncMapStringInt64R, (decFnInfo).fastpathDecMapStringInt64R) + fn(map[string]float32(nil), (encFnInfo).fastpathEncMapStringFloat32R, (decFnInfo).fastpathDecMapStringFloat32R) + fn(map[string]float64(nil), (encFnInfo).fastpathEncMapStringFloat64R, (decFnInfo).fastpathDecMapStringFloat64R) + fn(map[string]bool(nil), (encFnInfo).fastpathEncMapStringBoolR, (decFnInfo).fastpathDecMapStringBoolR) + fn(map[float32]interface{}(nil), (encFnInfo).fastpathEncMapFloat32IntfR, (decFnInfo).fastpathDecMapFloat32IntfR) + fn(map[float32]string(nil), (encFnInfo).fastpathEncMapFloat32StringR, (decFnInfo).fastpathDecMapFloat32StringR) + fn(map[float32]uint(nil), (encFnInfo).fastpathEncMapFloat32UintR, (decFnInfo).fastpathDecMapFloat32UintR) + fn(map[float32]uint8(nil), (encFnInfo).fastpathEncMapFloat32Uint8R, (decFnInfo).fastpathDecMapFloat32Uint8R) + fn(map[float32]uint16(nil), (encFnInfo).fastpathEncMapFloat32Uint16R, (decFnInfo).fastpathDecMapFloat32Uint16R) + fn(map[float32]uint32(nil), (encFnInfo).fastpathEncMapFloat32Uint32R, (decFnInfo).fastpathDecMapFloat32Uint32R) + fn(map[float32]uint64(nil), (encFnInfo).fastpathEncMapFloat32Uint64R, (decFnInfo).fastpathDecMapFloat32Uint64R) + fn(map[float32]int(nil), (encFnInfo).fastpathEncMapFloat32IntR, (decFnInfo).fastpathDecMapFloat32IntR) + fn(map[float32]int8(nil), (encFnInfo).fastpathEncMapFloat32Int8R, (decFnInfo).fastpathDecMapFloat32Int8R) + fn(map[float32]int16(nil), (encFnInfo).fastpathEncMapFloat32Int16R, (decFnInfo).fastpathDecMapFloat32Int16R) + fn(map[float32]int32(nil), (encFnInfo).fastpathEncMapFloat32Int32R, (decFnInfo).fastpathDecMapFloat32Int32R) + fn(map[float32]int64(nil), (encFnInfo).fastpathEncMapFloat32Int64R, (decFnInfo).fastpathDecMapFloat32Int64R) + fn(map[float32]float32(nil), (encFnInfo).fastpathEncMapFloat32Float32R, (decFnInfo).fastpathDecMapFloat32Float32R) + fn(map[float32]float64(nil), (encFnInfo).fastpathEncMapFloat32Float64R, (decFnInfo).fastpathDecMapFloat32Float64R) + fn(map[float32]bool(nil), (encFnInfo).fastpathEncMapFloat32BoolR, (decFnInfo).fastpathDecMapFloat32BoolR) + fn(map[float64]interface{}(nil), (encFnInfo).fastpathEncMapFloat64IntfR, (decFnInfo).fastpathDecMapFloat64IntfR) + fn(map[float64]string(nil), (encFnInfo).fastpathEncMapFloat64StringR, (decFnInfo).fastpathDecMapFloat64StringR) + fn(map[float64]uint(nil), (encFnInfo).fastpathEncMapFloat64UintR, (decFnInfo).fastpathDecMapFloat64UintR) + fn(map[float64]uint8(nil), (encFnInfo).fastpathEncMapFloat64Uint8R, (decFnInfo).fastpathDecMapFloat64Uint8R) + fn(map[float64]uint16(nil), (encFnInfo).fastpathEncMapFloat64Uint16R, (decFnInfo).fastpathDecMapFloat64Uint16R) + fn(map[float64]uint32(nil), (encFnInfo).fastpathEncMapFloat64Uint32R, (decFnInfo).fastpathDecMapFloat64Uint32R) + fn(map[float64]uint64(nil), (encFnInfo).fastpathEncMapFloat64Uint64R, (decFnInfo).fastpathDecMapFloat64Uint64R) + fn(map[float64]int(nil), (encFnInfo).fastpathEncMapFloat64IntR, (decFnInfo).fastpathDecMapFloat64IntR) + fn(map[float64]int8(nil), (encFnInfo).fastpathEncMapFloat64Int8R, (decFnInfo).fastpathDecMapFloat64Int8R) + fn(map[float64]int16(nil), (encFnInfo).fastpathEncMapFloat64Int16R, (decFnInfo).fastpathDecMapFloat64Int16R) + fn(map[float64]int32(nil), (encFnInfo).fastpathEncMapFloat64Int32R, (decFnInfo).fastpathDecMapFloat64Int32R) + fn(map[float64]int64(nil), (encFnInfo).fastpathEncMapFloat64Int64R, (decFnInfo).fastpathDecMapFloat64Int64R) + fn(map[float64]float32(nil), (encFnInfo).fastpathEncMapFloat64Float32R, (decFnInfo).fastpathDecMapFloat64Float32R) + fn(map[float64]float64(nil), (encFnInfo).fastpathEncMapFloat64Float64R, (decFnInfo).fastpathDecMapFloat64Float64R) + fn(map[float64]bool(nil), (encFnInfo).fastpathEncMapFloat64BoolR, (decFnInfo).fastpathDecMapFloat64BoolR) + fn(map[uint]interface{}(nil), (encFnInfo).fastpathEncMapUintIntfR, (decFnInfo).fastpathDecMapUintIntfR) + fn(map[uint]string(nil), (encFnInfo).fastpathEncMapUintStringR, (decFnInfo).fastpathDecMapUintStringR) + fn(map[uint]uint(nil), (encFnInfo).fastpathEncMapUintUintR, (decFnInfo).fastpathDecMapUintUintR) + fn(map[uint]uint8(nil), (encFnInfo).fastpathEncMapUintUint8R, (decFnInfo).fastpathDecMapUintUint8R) + fn(map[uint]uint16(nil), (encFnInfo).fastpathEncMapUintUint16R, (decFnInfo).fastpathDecMapUintUint16R) + fn(map[uint]uint32(nil), (encFnInfo).fastpathEncMapUintUint32R, (decFnInfo).fastpathDecMapUintUint32R) + fn(map[uint]uint64(nil), (encFnInfo).fastpathEncMapUintUint64R, (decFnInfo).fastpathDecMapUintUint64R) + fn(map[uint]int(nil), (encFnInfo).fastpathEncMapUintIntR, (decFnInfo).fastpathDecMapUintIntR) + fn(map[uint]int8(nil), (encFnInfo).fastpathEncMapUintInt8R, (decFnInfo).fastpathDecMapUintInt8R) + fn(map[uint]int16(nil), (encFnInfo).fastpathEncMapUintInt16R, (decFnInfo).fastpathDecMapUintInt16R) + fn(map[uint]int32(nil), (encFnInfo).fastpathEncMapUintInt32R, (decFnInfo).fastpathDecMapUintInt32R) + fn(map[uint]int64(nil), (encFnInfo).fastpathEncMapUintInt64R, (decFnInfo).fastpathDecMapUintInt64R) + fn(map[uint]float32(nil), (encFnInfo).fastpathEncMapUintFloat32R, (decFnInfo).fastpathDecMapUintFloat32R) + fn(map[uint]float64(nil), (encFnInfo).fastpathEncMapUintFloat64R, (decFnInfo).fastpathDecMapUintFloat64R) + fn(map[uint]bool(nil), (encFnInfo).fastpathEncMapUintBoolR, (decFnInfo).fastpathDecMapUintBoolR) + fn(map[uint8]interface{}(nil), (encFnInfo).fastpathEncMapUint8IntfR, (decFnInfo).fastpathDecMapUint8IntfR) + fn(map[uint8]string(nil), (encFnInfo).fastpathEncMapUint8StringR, (decFnInfo).fastpathDecMapUint8StringR) + fn(map[uint8]uint(nil), (encFnInfo).fastpathEncMapUint8UintR, (decFnInfo).fastpathDecMapUint8UintR) + fn(map[uint8]uint8(nil), (encFnInfo).fastpathEncMapUint8Uint8R, (decFnInfo).fastpathDecMapUint8Uint8R) + fn(map[uint8]uint16(nil), (encFnInfo).fastpathEncMapUint8Uint16R, (decFnInfo).fastpathDecMapUint8Uint16R) + fn(map[uint8]uint32(nil), (encFnInfo).fastpathEncMapUint8Uint32R, (decFnInfo).fastpathDecMapUint8Uint32R) + fn(map[uint8]uint64(nil), (encFnInfo).fastpathEncMapUint8Uint64R, (decFnInfo).fastpathDecMapUint8Uint64R) + fn(map[uint8]int(nil), (encFnInfo).fastpathEncMapUint8IntR, (decFnInfo).fastpathDecMapUint8IntR) + fn(map[uint8]int8(nil), (encFnInfo).fastpathEncMapUint8Int8R, (decFnInfo).fastpathDecMapUint8Int8R) + fn(map[uint8]int16(nil), (encFnInfo).fastpathEncMapUint8Int16R, (decFnInfo).fastpathDecMapUint8Int16R) + fn(map[uint8]int32(nil), (encFnInfo).fastpathEncMapUint8Int32R, (decFnInfo).fastpathDecMapUint8Int32R) + fn(map[uint8]int64(nil), (encFnInfo).fastpathEncMapUint8Int64R, (decFnInfo).fastpathDecMapUint8Int64R) + fn(map[uint8]float32(nil), (encFnInfo).fastpathEncMapUint8Float32R, (decFnInfo).fastpathDecMapUint8Float32R) + fn(map[uint8]float64(nil), (encFnInfo).fastpathEncMapUint8Float64R, (decFnInfo).fastpathDecMapUint8Float64R) + fn(map[uint8]bool(nil), (encFnInfo).fastpathEncMapUint8BoolR, (decFnInfo).fastpathDecMapUint8BoolR) + fn(map[uint16]interface{}(nil), (encFnInfo).fastpathEncMapUint16IntfR, (decFnInfo).fastpathDecMapUint16IntfR) + fn(map[uint16]string(nil), (encFnInfo).fastpathEncMapUint16StringR, (decFnInfo).fastpathDecMapUint16StringR) + fn(map[uint16]uint(nil), (encFnInfo).fastpathEncMapUint16UintR, (decFnInfo).fastpathDecMapUint16UintR) + fn(map[uint16]uint8(nil), (encFnInfo).fastpathEncMapUint16Uint8R, (decFnInfo).fastpathDecMapUint16Uint8R) + fn(map[uint16]uint16(nil), (encFnInfo).fastpathEncMapUint16Uint16R, (decFnInfo).fastpathDecMapUint16Uint16R) + fn(map[uint16]uint32(nil), (encFnInfo).fastpathEncMapUint16Uint32R, (decFnInfo).fastpathDecMapUint16Uint32R) + fn(map[uint16]uint64(nil), (encFnInfo).fastpathEncMapUint16Uint64R, (decFnInfo).fastpathDecMapUint16Uint64R) + fn(map[uint16]int(nil), (encFnInfo).fastpathEncMapUint16IntR, (decFnInfo).fastpathDecMapUint16IntR) + fn(map[uint16]int8(nil), (encFnInfo).fastpathEncMapUint16Int8R, (decFnInfo).fastpathDecMapUint16Int8R) + fn(map[uint16]int16(nil), (encFnInfo).fastpathEncMapUint16Int16R, (decFnInfo).fastpathDecMapUint16Int16R) + fn(map[uint16]int32(nil), (encFnInfo).fastpathEncMapUint16Int32R, (decFnInfo).fastpathDecMapUint16Int32R) + fn(map[uint16]int64(nil), (encFnInfo).fastpathEncMapUint16Int64R, (decFnInfo).fastpathDecMapUint16Int64R) + fn(map[uint16]float32(nil), (encFnInfo).fastpathEncMapUint16Float32R, (decFnInfo).fastpathDecMapUint16Float32R) + fn(map[uint16]float64(nil), (encFnInfo).fastpathEncMapUint16Float64R, (decFnInfo).fastpathDecMapUint16Float64R) + fn(map[uint16]bool(nil), (encFnInfo).fastpathEncMapUint16BoolR, (decFnInfo).fastpathDecMapUint16BoolR) + fn(map[uint32]interface{}(nil), (encFnInfo).fastpathEncMapUint32IntfR, (decFnInfo).fastpathDecMapUint32IntfR) + fn(map[uint32]string(nil), (encFnInfo).fastpathEncMapUint32StringR, (decFnInfo).fastpathDecMapUint32StringR) + fn(map[uint32]uint(nil), (encFnInfo).fastpathEncMapUint32UintR, (decFnInfo).fastpathDecMapUint32UintR) + fn(map[uint32]uint8(nil), (encFnInfo).fastpathEncMapUint32Uint8R, (decFnInfo).fastpathDecMapUint32Uint8R) + fn(map[uint32]uint16(nil), (encFnInfo).fastpathEncMapUint32Uint16R, (decFnInfo).fastpathDecMapUint32Uint16R) + fn(map[uint32]uint32(nil), (encFnInfo).fastpathEncMapUint32Uint32R, (decFnInfo).fastpathDecMapUint32Uint32R) + fn(map[uint32]uint64(nil), (encFnInfo).fastpathEncMapUint32Uint64R, (decFnInfo).fastpathDecMapUint32Uint64R) + fn(map[uint32]int(nil), (encFnInfo).fastpathEncMapUint32IntR, (decFnInfo).fastpathDecMapUint32IntR) + fn(map[uint32]int8(nil), (encFnInfo).fastpathEncMapUint32Int8R, (decFnInfo).fastpathDecMapUint32Int8R) + fn(map[uint32]int16(nil), (encFnInfo).fastpathEncMapUint32Int16R, (decFnInfo).fastpathDecMapUint32Int16R) + fn(map[uint32]int32(nil), (encFnInfo).fastpathEncMapUint32Int32R, (decFnInfo).fastpathDecMapUint32Int32R) + fn(map[uint32]int64(nil), (encFnInfo).fastpathEncMapUint32Int64R, (decFnInfo).fastpathDecMapUint32Int64R) + fn(map[uint32]float32(nil), (encFnInfo).fastpathEncMapUint32Float32R, (decFnInfo).fastpathDecMapUint32Float32R) + fn(map[uint32]float64(nil), (encFnInfo).fastpathEncMapUint32Float64R, (decFnInfo).fastpathDecMapUint32Float64R) + fn(map[uint32]bool(nil), (encFnInfo).fastpathEncMapUint32BoolR, (decFnInfo).fastpathDecMapUint32BoolR) + fn(map[uint64]interface{}(nil), (encFnInfo).fastpathEncMapUint64IntfR, (decFnInfo).fastpathDecMapUint64IntfR) + fn(map[uint64]string(nil), (encFnInfo).fastpathEncMapUint64StringR, (decFnInfo).fastpathDecMapUint64StringR) + fn(map[uint64]uint(nil), (encFnInfo).fastpathEncMapUint64UintR, (decFnInfo).fastpathDecMapUint64UintR) + fn(map[uint64]uint8(nil), (encFnInfo).fastpathEncMapUint64Uint8R, (decFnInfo).fastpathDecMapUint64Uint8R) + fn(map[uint64]uint16(nil), (encFnInfo).fastpathEncMapUint64Uint16R, (decFnInfo).fastpathDecMapUint64Uint16R) + fn(map[uint64]uint32(nil), (encFnInfo).fastpathEncMapUint64Uint32R, (decFnInfo).fastpathDecMapUint64Uint32R) + fn(map[uint64]uint64(nil), (encFnInfo).fastpathEncMapUint64Uint64R, (decFnInfo).fastpathDecMapUint64Uint64R) + fn(map[uint64]int(nil), (encFnInfo).fastpathEncMapUint64IntR, (decFnInfo).fastpathDecMapUint64IntR) + fn(map[uint64]int8(nil), (encFnInfo).fastpathEncMapUint64Int8R, (decFnInfo).fastpathDecMapUint64Int8R) + fn(map[uint64]int16(nil), (encFnInfo).fastpathEncMapUint64Int16R, (decFnInfo).fastpathDecMapUint64Int16R) + fn(map[uint64]int32(nil), (encFnInfo).fastpathEncMapUint64Int32R, (decFnInfo).fastpathDecMapUint64Int32R) + fn(map[uint64]int64(nil), (encFnInfo).fastpathEncMapUint64Int64R, (decFnInfo).fastpathDecMapUint64Int64R) + fn(map[uint64]float32(nil), (encFnInfo).fastpathEncMapUint64Float32R, (decFnInfo).fastpathDecMapUint64Float32R) + fn(map[uint64]float64(nil), (encFnInfo).fastpathEncMapUint64Float64R, (decFnInfo).fastpathDecMapUint64Float64R) + fn(map[uint64]bool(nil), (encFnInfo).fastpathEncMapUint64BoolR, (decFnInfo).fastpathDecMapUint64BoolR) + fn(map[int]interface{}(nil), (encFnInfo).fastpathEncMapIntIntfR, (decFnInfo).fastpathDecMapIntIntfR) + fn(map[int]string(nil), (encFnInfo).fastpathEncMapIntStringR, (decFnInfo).fastpathDecMapIntStringR) + fn(map[int]uint(nil), (encFnInfo).fastpathEncMapIntUintR, (decFnInfo).fastpathDecMapIntUintR) + fn(map[int]uint8(nil), (encFnInfo).fastpathEncMapIntUint8R, (decFnInfo).fastpathDecMapIntUint8R) + fn(map[int]uint16(nil), (encFnInfo).fastpathEncMapIntUint16R, (decFnInfo).fastpathDecMapIntUint16R) + fn(map[int]uint32(nil), (encFnInfo).fastpathEncMapIntUint32R, (decFnInfo).fastpathDecMapIntUint32R) + fn(map[int]uint64(nil), (encFnInfo).fastpathEncMapIntUint64R, (decFnInfo).fastpathDecMapIntUint64R) + fn(map[int]int(nil), (encFnInfo).fastpathEncMapIntIntR, (decFnInfo).fastpathDecMapIntIntR) + fn(map[int]int8(nil), (encFnInfo).fastpathEncMapIntInt8R, (decFnInfo).fastpathDecMapIntInt8R) + fn(map[int]int16(nil), (encFnInfo).fastpathEncMapIntInt16R, (decFnInfo).fastpathDecMapIntInt16R) + fn(map[int]int32(nil), (encFnInfo).fastpathEncMapIntInt32R, (decFnInfo).fastpathDecMapIntInt32R) + fn(map[int]int64(nil), (encFnInfo).fastpathEncMapIntInt64R, (decFnInfo).fastpathDecMapIntInt64R) + fn(map[int]float32(nil), (encFnInfo).fastpathEncMapIntFloat32R, (decFnInfo).fastpathDecMapIntFloat32R) + fn(map[int]float64(nil), (encFnInfo).fastpathEncMapIntFloat64R, (decFnInfo).fastpathDecMapIntFloat64R) + fn(map[int]bool(nil), (encFnInfo).fastpathEncMapIntBoolR, (decFnInfo).fastpathDecMapIntBoolR) + fn(map[int8]interface{}(nil), (encFnInfo).fastpathEncMapInt8IntfR, (decFnInfo).fastpathDecMapInt8IntfR) + fn(map[int8]string(nil), (encFnInfo).fastpathEncMapInt8StringR, (decFnInfo).fastpathDecMapInt8StringR) + fn(map[int8]uint(nil), (encFnInfo).fastpathEncMapInt8UintR, (decFnInfo).fastpathDecMapInt8UintR) + fn(map[int8]uint8(nil), (encFnInfo).fastpathEncMapInt8Uint8R, (decFnInfo).fastpathDecMapInt8Uint8R) + fn(map[int8]uint16(nil), (encFnInfo).fastpathEncMapInt8Uint16R, (decFnInfo).fastpathDecMapInt8Uint16R) + fn(map[int8]uint32(nil), (encFnInfo).fastpathEncMapInt8Uint32R, (decFnInfo).fastpathDecMapInt8Uint32R) + fn(map[int8]uint64(nil), (encFnInfo).fastpathEncMapInt8Uint64R, (decFnInfo).fastpathDecMapInt8Uint64R) + fn(map[int8]int(nil), (encFnInfo).fastpathEncMapInt8IntR, (decFnInfo).fastpathDecMapInt8IntR) + fn(map[int8]int8(nil), (encFnInfo).fastpathEncMapInt8Int8R, (decFnInfo).fastpathDecMapInt8Int8R) + fn(map[int8]int16(nil), (encFnInfo).fastpathEncMapInt8Int16R, (decFnInfo).fastpathDecMapInt8Int16R) + fn(map[int8]int32(nil), (encFnInfo).fastpathEncMapInt8Int32R, (decFnInfo).fastpathDecMapInt8Int32R) + fn(map[int8]int64(nil), (encFnInfo).fastpathEncMapInt8Int64R, (decFnInfo).fastpathDecMapInt8Int64R) + fn(map[int8]float32(nil), (encFnInfo).fastpathEncMapInt8Float32R, (decFnInfo).fastpathDecMapInt8Float32R) + fn(map[int8]float64(nil), (encFnInfo).fastpathEncMapInt8Float64R, (decFnInfo).fastpathDecMapInt8Float64R) + fn(map[int8]bool(nil), (encFnInfo).fastpathEncMapInt8BoolR, (decFnInfo).fastpathDecMapInt8BoolR) + fn(map[int16]interface{}(nil), (encFnInfo).fastpathEncMapInt16IntfR, (decFnInfo).fastpathDecMapInt16IntfR) + fn(map[int16]string(nil), (encFnInfo).fastpathEncMapInt16StringR, (decFnInfo).fastpathDecMapInt16StringR) + fn(map[int16]uint(nil), (encFnInfo).fastpathEncMapInt16UintR, (decFnInfo).fastpathDecMapInt16UintR) + fn(map[int16]uint8(nil), (encFnInfo).fastpathEncMapInt16Uint8R, (decFnInfo).fastpathDecMapInt16Uint8R) + fn(map[int16]uint16(nil), (encFnInfo).fastpathEncMapInt16Uint16R, (decFnInfo).fastpathDecMapInt16Uint16R) + fn(map[int16]uint32(nil), (encFnInfo).fastpathEncMapInt16Uint32R, (decFnInfo).fastpathDecMapInt16Uint32R) + fn(map[int16]uint64(nil), (encFnInfo).fastpathEncMapInt16Uint64R, (decFnInfo).fastpathDecMapInt16Uint64R) + fn(map[int16]int(nil), (encFnInfo).fastpathEncMapInt16IntR, (decFnInfo).fastpathDecMapInt16IntR) + fn(map[int16]int8(nil), (encFnInfo).fastpathEncMapInt16Int8R, (decFnInfo).fastpathDecMapInt16Int8R) + fn(map[int16]int16(nil), (encFnInfo).fastpathEncMapInt16Int16R, (decFnInfo).fastpathDecMapInt16Int16R) + fn(map[int16]int32(nil), (encFnInfo).fastpathEncMapInt16Int32R, (decFnInfo).fastpathDecMapInt16Int32R) + fn(map[int16]int64(nil), (encFnInfo).fastpathEncMapInt16Int64R, (decFnInfo).fastpathDecMapInt16Int64R) + fn(map[int16]float32(nil), (encFnInfo).fastpathEncMapInt16Float32R, (decFnInfo).fastpathDecMapInt16Float32R) + fn(map[int16]float64(nil), (encFnInfo).fastpathEncMapInt16Float64R, (decFnInfo).fastpathDecMapInt16Float64R) + fn(map[int16]bool(nil), (encFnInfo).fastpathEncMapInt16BoolR, (decFnInfo).fastpathDecMapInt16BoolR) + fn(map[int32]interface{}(nil), (encFnInfo).fastpathEncMapInt32IntfR, (decFnInfo).fastpathDecMapInt32IntfR) + fn(map[int32]string(nil), (encFnInfo).fastpathEncMapInt32StringR, (decFnInfo).fastpathDecMapInt32StringR) + fn(map[int32]uint(nil), (encFnInfo).fastpathEncMapInt32UintR, (decFnInfo).fastpathDecMapInt32UintR) + fn(map[int32]uint8(nil), (encFnInfo).fastpathEncMapInt32Uint8R, (decFnInfo).fastpathDecMapInt32Uint8R) + fn(map[int32]uint16(nil), (encFnInfo).fastpathEncMapInt32Uint16R, (decFnInfo).fastpathDecMapInt32Uint16R) + fn(map[int32]uint32(nil), (encFnInfo).fastpathEncMapInt32Uint32R, (decFnInfo).fastpathDecMapInt32Uint32R) + fn(map[int32]uint64(nil), (encFnInfo).fastpathEncMapInt32Uint64R, (decFnInfo).fastpathDecMapInt32Uint64R) + fn(map[int32]int(nil), (encFnInfo).fastpathEncMapInt32IntR, (decFnInfo).fastpathDecMapInt32IntR) + fn(map[int32]int8(nil), (encFnInfo).fastpathEncMapInt32Int8R, (decFnInfo).fastpathDecMapInt32Int8R) + fn(map[int32]int16(nil), (encFnInfo).fastpathEncMapInt32Int16R, (decFnInfo).fastpathDecMapInt32Int16R) + fn(map[int32]int32(nil), (encFnInfo).fastpathEncMapInt32Int32R, (decFnInfo).fastpathDecMapInt32Int32R) + fn(map[int32]int64(nil), (encFnInfo).fastpathEncMapInt32Int64R, (decFnInfo).fastpathDecMapInt32Int64R) + fn(map[int32]float32(nil), (encFnInfo).fastpathEncMapInt32Float32R, (decFnInfo).fastpathDecMapInt32Float32R) + fn(map[int32]float64(nil), (encFnInfo).fastpathEncMapInt32Float64R, (decFnInfo).fastpathDecMapInt32Float64R) + fn(map[int32]bool(nil), (encFnInfo).fastpathEncMapInt32BoolR, (decFnInfo).fastpathDecMapInt32BoolR) + fn(map[int64]interface{}(nil), (encFnInfo).fastpathEncMapInt64IntfR, (decFnInfo).fastpathDecMapInt64IntfR) + fn(map[int64]string(nil), (encFnInfo).fastpathEncMapInt64StringR, (decFnInfo).fastpathDecMapInt64StringR) + fn(map[int64]uint(nil), (encFnInfo).fastpathEncMapInt64UintR, (decFnInfo).fastpathDecMapInt64UintR) + fn(map[int64]uint8(nil), (encFnInfo).fastpathEncMapInt64Uint8R, (decFnInfo).fastpathDecMapInt64Uint8R) + fn(map[int64]uint16(nil), (encFnInfo).fastpathEncMapInt64Uint16R, (decFnInfo).fastpathDecMapInt64Uint16R) + fn(map[int64]uint32(nil), (encFnInfo).fastpathEncMapInt64Uint32R, (decFnInfo).fastpathDecMapInt64Uint32R) + fn(map[int64]uint64(nil), (encFnInfo).fastpathEncMapInt64Uint64R, (decFnInfo).fastpathDecMapInt64Uint64R) + fn(map[int64]int(nil), (encFnInfo).fastpathEncMapInt64IntR, (decFnInfo).fastpathDecMapInt64IntR) + fn(map[int64]int8(nil), (encFnInfo).fastpathEncMapInt64Int8R, (decFnInfo).fastpathDecMapInt64Int8R) + fn(map[int64]int16(nil), (encFnInfo).fastpathEncMapInt64Int16R, (decFnInfo).fastpathDecMapInt64Int16R) + fn(map[int64]int32(nil), (encFnInfo).fastpathEncMapInt64Int32R, (decFnInfo).fastpathDecMapInt64Int32R) + fn(map[int64]int64(nil), (encFnInfo).fastpathEncMapInt64Int64R, (decFnInfo).fastpathDecMapInt64Int64R) + fn(map[int64]float32(nil), (encFnInfo).fastpathEncMapInt64Float32R, (decFnInfo).fastpathDecMapInt64Float32R) + fn(map[int64]float64(nil), (encFnInfo).fastpathEncMapInt64Float64R, (decFnInfo).fastpathDecMapInt64Float64R) + fn(map[int64]bool(nil), (encFnInfo).fastpathEncMapInt64BoolR, (decFnInfo).fastpathDecMapInt64BoolR) + fn(map[bool]interface{}(nil), (encFnInfo).fastpathEncMapBoolIntfR, (decFnInfo).fastpathDecMapBoolIntfR) + fn(map[bool]string(nil), (encFnInfo).fastpathEncMapBoolStringR, (decFnInfo).fastpathDecMapBoolStringR) + fn(map[bool]uint(nil), (encFnInfo).fastpathEncMapBoolUintR, (decFnInfo).fastpathDecMapBoolUintR) + fn(map[bool]uint8(nil), (encFnInfo).fastpathEncMapBoolUint8R, (decFnInfo).fastpathDecMapBoolUint8R) + fn(map[bool]uint16(nil), (encFnInfo).fastpathEncMapBoolUint16R, (decFnInfo).fastpathDecMapBoolUint16R) + fn(map[bool]uint32(nil), (encFnInfo).fastpathEncMapBoolUint32R, (decFnInfo).fastpathDecMapBoolUint32R) + fn(map[bool]uint64(nil), (encFnInfo).fastpathEncMapBoolUint64R, (decFnInfo).fastpathDecMapBoolUint64R) + fn(map[bool]int(nil), (encFnInfo).fastpathEncMapBoolIntR, (decFnInfo).fastpathDecMapBoolIntR) + fn(map[bool]int8(nil), (encFnInfo).fastpathEncMapBoolInt8R, (decFnInfo).fastpathDecMapBoolInt8R) + fn(map[bool]int16(nil), (encFnInfo).fastpathEncMapBoolInt16R, (decFnInfo).fastpathDecMapBoolInt16R) + fn(map[bool]int32(nil), (encFnInfo).fastpathEncMapBoolInt32R, (decFnInfo).fastpathDecMapBoolInt32R) + fn(map[bool]int64(nil), (encFnInfo).fastpathEncMapBoolInt64R, (decFnInfo).fastpathDecMapBoolInt64R) + fn(map[bool]float32(nil), (encFnInfo).fastpathEncMapBoolFloat32R, (decFnInfo).fastpathDecMapBoolFloat32R) + fn(map[bool]float64(nil), (encFnInfo).fastpathEncMapBoolFloat64R, (decFnInfo).fastpathDecMapBoolFloat64R) + fn(map[bool]bool(nil), (encFnInfo).fastpathEncMapBoolBoolR, (decFnInfo).fastpathDecMapBoolBoolR) + + sort.Sort(fastpathAslice(fastpathAV[:])) +} + +// -- encode + +// -- -- fast path type switch +func fastpathEncodeTypeSwitch(iv interface{}, e *Encoder) bool { + switch v := iv.(type) { + + case []interface{}: + fastpathTV.EncSliceIntfV(v, fastpathCheckNilTrue, e) + case *[]interface{}: + fastpathTV.EncSliceIntfV(*v, fastpathCheckNilTrue, e) + + case map[interface{}]interface{}: + fastpathTV.EncMapIntfIntfV(v, fastpathCheckNilTrue, e) + case *map[interface{}]interface{}: + fastpathTV.EncMapIntfIntfV(*v, fastpathCheckNilTrue, e) + + case map[interface{}]string: + fastpathTV.EncMapIntfStringV(v, fastpathCheckNilTrue, e) + case *map[interface{}]string: + fastpathTV.EncMapIntfStringV(*v, fastpathCheckNilTrue, e) + + case map[interface{}]uint: + fastpathTV.EncMapIntfUintV(v, fastpathCheckNilTrue, e) + case *map[interface{}]uint: + fastpathTV.EncMapIntfUintV(*v, fastpathCheckNilTrue, e) + + case map[interface{}]uint8: + fastpathTV.EncMapIntfUint8V(v, fastpathCheckNilTrue, e) + case *map[interface{}]uint8: + fastpathTV.EncMapIntfUint8V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]uint16: + fastpathTV.EncMapIntfUint16V(v, fastpathCheckNilTrue, e) + case *map[interface{}]uint16: + fastpathTV.EncMapIntfUint16V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]uint32: + fastpathTV.EncMapIntfUint32V(v, fastpathCheckNilTrue, e) + case *map[interface{}]uint32: + fastpathTV.EncMapIntfUint32V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]uint64: + fastpathTV.EncMapIntfUint64V(v, fastpathCheckNilTrue, e) + case *map[interface{}]uint64: + fastpathTV.EncMapIntfUint64V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]int: + fastpathTV.EncMapIntfIntV(v, fastpathCheckNilTrue, e) + case *map[interface{}]int: + fastpathTV.EncMapIntfIntV(*v, fastpathCheckNilTrue, e) + + case map[interface{}]int8: + fastpathTV.EncMapIntfInt8V(v, fastpathCheckNilTrue, e) + case *map[interface{}]int8: + fastpathTV.EncMapIntfInt8V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]int16: + fastpathTV.EncMapIntfInt16V(v, fastpathCheckNilTrue, e) + case *map[interface{}]int16: + fastpathTV.EncMapIntfInt16V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]int32: + fastpathTV.EncMapIntfInt32V(v, fastpathCheckNilTrue, e) + case *map[interface{}]int32: + fastpathTV.EncMapIntfInt32V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]int64: + fastpathTV.EncMapIntfInt64V(v, fastpathCheckNilTrue, e) + case *map[interface{}]int64: + fastpathTV.EncMapIntfInt64V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]float32: + fastpathTV.EncMapIntfFloat32V(v, fastpathCheckNilTrue, e) + case *map[interface{}]float32: + fastpathTV.EncMapIntfFloat32V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]float64: + fastpathTV.EncMapIntfFloat64V(v, fastpathCheckNilTrue, e) + case *map[interface{}]float64: + fastpathTV.EncMapIntfFloat64V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]bool: + fastpathTV.EncMapIntfBoolV(v, fastpathCheckNilTrue, e) + case *map[interface{}]bool: + fastpathTV.EncMapIntfBoolV(*v, fastpathCheckNilTrue, e) + + case []string: + fastpathTV.EncSliceStringV(v, fastpathCheckNilTrue, e) + case *[]string: + fastpathTV.EncSliceStringV(*v, fastpathCheckNilTrue, e) + + case map[string]interface{}: + fastpathTV.EncMapStringIntfV(v, fastpathCheckNilTrue, e) + case *map[string]interface{}: + fastpathTV.EncMapStringIntfV(*v, fastpathCheckNilTrue, e) + + case map[string]string: + fastpathTV.EncMapStringStringV(v, fastpathCheckNilTrue, e) + case *map[string]string: + fastpathTV.EncMapStringStringV(*v, fastpathCheckNilTrue, e) + + case map[string]uint: + fastpathTV.EncMapStringUintV(v, fastpathCheckNilTrue, e) + case *map[string]uint: + fastpathTV.EncMapStringUintV(*v, fastpathCheckNilTrue, e) + + case map[string]uint8: + fastpathTV.EncMapStringUint8V(v, fastpathCheckNilTrue, e) + case *map[string]uint8: + fastpathTV.EncMapStringUint8V(*v, fastpathCheckNilTrue, e) + + case map[string]uint16: + fastpathTV.EncMapStringUint16V(v, fastpathCheckNilTrue, e) + case *map[string]uint16: + fastpathTV.EncMapStringUint16V(*v, fastpathCheckNilTrue, e) + + case map[string]uint32: + fastpathTV.EncMapStringUint32V(v, fastpathCheckNilTrue, e) + case *map[string]uint32: + fastpathTV.EncMapStringUint32V(*v, fastpathCheckNilTrue, e) + + case map[string]uint64: + fastpathTV.EncMapStringUint64V(v, fastpathCheckNilTrue, e) + case *map[string]uint64: + fastpathTV.EncMapStringUint64V(*v, fastpathCheckNilTrue, e) + + case map[string]int: + fastpathTV.EncMapStringIntV(v, fastpathCheckNilTrue, e) + case *map[string]int: + fastpathTV.EncMapStringIntV(*v, fastpathCheckNilTrue, e) + + case map[string]int8: + fastpathTV.EncMapStringInt8V(v, fastpathCheckNilTrue, e) + case *map[string]int8: + fastpathTV.EncMapStringInt8V(*v, fastpathCheckNilTrue, e) + + case map[string]int16: + fastpathTV.EncMapStringInt16V(v, fastpathCheckNilTrue, e) + case *map[string]int16: + fastpathTV.EncMapStringInt16V(*v, fastpathCheckNilTrue, e) + + case map[string]int32: + fastpathTV.EncMapStringInt32V(v, fastpathCheckNilTrue, e) + case *map[string]int32: + fastpathTV.EncMapStringInt32V(*v, fastpathCheckNilTrue, e) + + case map[string]int64: + fastpathTV.EncMapStringInt64V(v, fastpathCheckNilTrue, e) + case *map[string]int64: + fastpathTV.EncMapStringInt64V(*v, fastpathCheckNilTrue, e) + + case map[string]float32: + fastpathTV.EncMapStringFloat32V(v, fastpathCheckNilTrue, e) + case *map[string]float32: + fastpathTV.EncMapStringFloat32V(*v, fastpathCheckNilTrue, e) + + case map[string]float64: + fastpathTV.EncMapStringFloat64V(v, fastpathCheckNilTrue, e) + case *map[string]float64: + fastpathTV.EncMapStringFloat64V(*v, fastpathCheckNilTrue, e) + + case map[string]bool: + fastpathTV.EncMapStringBoolV(v, fastpathCheckNilTrue, e) + case *map[string]bool: + fastpathTV.EncMapStringBoolV(*v, fastpathCheckNilTrue, e) + + case []float32: + fastpathTV.EncSliceFloat32V(v, fastpathCheckNilTrue, e) + case *[]float32: + fastpathTV.EncSliceFloat32V(*v, fastpathCheckNilTrue, e) + + case map[float32]interface{}: + fastpathTV.EncMapFloat32IntfV(v, fastpathCheckNilTrue, e) + case *map[float32]interface{}: + fastpathTV.EncMapFloat32IntfV(*v, fastpathCheckNilTrue, e) + + case map[float32]string: + fastpathTV.EncMapFloat32StringV(v, fastpathCheckNilTrue, e) + case *map[float32]string: + fastpathTV.EncMapFloat32StringV(*v, fastpathCheckNilTrue, e) + + case map[float32]uint: + fastpathTV.EncMapFloat32UintV(v, fastpathCheckNilTrue, e) + case *map[float32]uint: + fastpathTV.EncMapFloat32UintV(*v, fastpathCheckNilTrue, e) + + case map[float32]uint8: + fastpathTV.EncMapFloat32Uint8V(v, fastpathCheckNilTrue, e) + case *map[float32]uint8: + fastpathTV.EncMapFloat32Uint8V(*v, fastpathCheckNilTrue, e) + + case map[float32]uint16: + fastpathTV.EncMapFloat32Uint16V(v, fastpathCheckNilTrue, e) + case *map[float32]uint16: + fastpathTV.EncMapFloat32Uint16V(*v, fastpathCheckNilTrue, e) + + case map[float32]uint32: + fastpathTV.EncMapFloat32Uint32V(v, fastpathCheckNilTrue, e) + case *map[float32]uint32: + fastpathTV.EncMapFloat32Uint32V(*v, fastpathCheckNilTrue, e) + + case map[float32]uint64: + fastpathTV.EncMapFloat32Uint64V(v, fastpathCheckNilTrue, e) + case *map[float32]uint64: + fastpathTV.EncMapFloat32Uint64V(*v, fastpathCheckNilTrue, e) + + case map[float32]int: + fastpathTV.EncMapFloat32IntV(v, fastpathCheckNilTrue, e) + case *map[float32]int: + fastpathTV.EncMapFloat32IntV(*v, fastpathCheckNilTrue, e) + + case map[float32]int8: + fastpathTV.EncMapFloat32Int8V(v, fastpathCheckNilTrue, e) + case *map[float32]int8: + fastpathTV.EncMapFloat32Int8V(*v, fastpathCheckNilTrue, e) + + case map[float32]int16: + fastpathTV.EncMapFloat32Int16V(v, fastpathCheckNilTrue, e) + case *map[float32]int16: + fastpathTV.EncMapFloat32Int16V(*v, fastpathCheckNilTrue, e) + + case map[float32]int32: + fastpathTV.EncMapFloat32Int32V(v, fastpathCheckNilTrue, e) + case *map[float32]int32: + fastpathTV.EncMapFloat32Int32V(*v, fastpathCheckNilTrue, e) + + case map[float32]int64: + fastpathTV.EncMapFloat32Int64V(v, fastpathCheckNilTrue, e) + case *map[float32]int64: + fastpathTV.EncMapFloat32Int64V(*v, fastpathCheckNilTrue, e) + + case map[float32]float32: + fastpathTV.EncMapFloat32Float32V(v, fastpathCheckNilTrue, e) + case *map[float32]float32: + fastpathTV.EncMapFloat32Float32V(*v, fastpathCheckNilTrue, e) + + case map[float32]float64: + fastpathTV.EncMapFloat32Float64V(v, fastpathCheckNilTrue, e) + case *map[float32]float64: + fastpathTV.EncMapFloat32Float64V(*v, fastpathCheckNilTrue, e) + + case map[float32]bool: + fastpathTV.EncMapFloat32BoolV(v, fastpathCheckNilTrue, e) + case *map[float32]bool: + fastpathTV.EncMapFloat32BoolV(*v, fastpathCheckNilTrue, e) + + case []float64: + fastpathTV.EncSliceFloat64V(v, fastpathCheckNilTrue, e) + case *[]float64: + fastpathTV.EncSliceFloat64V(*v, fastpathCheckNilTrue, e) + + case map[float64]interface{}: + fastpathTV.EncMapFloat64IntfV(v, fastpathCheckNilTrue, e) + case *map[float64]interface{}: + fastpathTV.EncMapFloat64IntfV(*v, fastpathCheckNilTrue, e) + + case map[float64]string: + fastpathTV.EncMapFloat64StringV(v, fastpathCheckNilTrue, e) + case *map[float64]string: + fastpathTV.EncMapFloat64StringV(*v, fastpathCheckNilTrue, e) + + case map[float64]uint: + fastpathTV.EncMapFloat64UintV(v, fastpathCheckNilTrue, e) + case *map[float64]uint: + fastpathTV.EncMapFloat64UintV(*v, fastpathCheckNilTrue, e) + + case map[float64]uint8: + fastpathTV.EncMapFloat64Uint8V(v, fastpathCheckNilTrue, e) + case *map[float64]uint8: + fastpathTV.EncMapFloat64Uint8V(*v, fastpathCheckNilTrue, e) + + case map[float64]uint16: + fastpathTV.EncMapFloat64Uint16V(v, fastpathCheckNilTrue, e) + case *map[float64]uint16: + fastpathTV.EncMapFloat64Uint16V(*v, fastpathCheckNilTrue, e) + + case map[float64]uint32: + fastpathTV.EncMapFloat64Uint32V(v, fastpathCheckNilTrue, e) + case *map[float64]uint32: + fastpathTV.EncMapFloat64Uint32V(*v, fastpathCheckNilTrue, e) + + case map[float64]uint64: + fastpathTV.EncMapFloat64Uint64V(v, fastpathCheckNilTrue, e) + case *map[float64]uint64: + fastpathTV.EncMapFloat64Uint64V(*v, fastpathCheckNilTrue, e) + + case map[float64]int: + fastpathTV.EncMapFloat64IntV(v, fastpathCheckNilTrue, e) + case *map[float64]int: + fastpathTV.EncMapFloat64IntV(*v, fastpathCheckNilTrue, e) + + case map[float64]int8: + fastpathTV.EncMapFloat64Int8V(v, fastpathCheckNilTrue, e) + case *map[float64]int8: + fastpathTV.EncMapFloat64Int8V(*v, fastpathCheckNilTrue, e) + + case map[float64]int16: + fastpathTV.EncMapFloat64Int16V(v, fastpathCheckNilTrue, e) + case *map[float64]int16: + fastpathTV.EncMapFloat64Int16V(*v, fastpathCheckNilTrue, e) + + case map[float64]int32: + fastpathTV.EncMapFloat64Int32V(v, fastpathCheckNilTrue, e) + case *map[float64]int32: + fastpathTV.EncMapFloat64Int32V(*v, fastpathCheckNilTrue, e) + + case map[float64]int64: + fastpathTV.EncMapFloat64Int64V(v, fastpathCheckNilTrue, e) + case *map[float64]int64: + fastpathTV.EncMapFloat64Int64V(*v, fastpathCheckNilTrue, e) + + case map[float64]float32: + fastpathTV.EncMapFloat64Float32V(v, fastpathCheckNilTrue, e) + case *map[float64]float32: + fastpathTV.EncMapFloat64Float32V(*v, fastpathCheckNilTrue, e) + + case map[float64]float64: + fastpathTV.EncMapFloat64Float64V(v, fastpathCheckNilTrue, e) + case *map[float64]float64: + fastpathTV.EncMapFloat64Float64V(*v, fastpathCheckNilTrue, e) + + case map[float64]bool: + fastpathTV.EncMapFloat64BoolV(v, fastpathCheckNilTrue, e) + case *map[float64]bool: + fastpathTV.EncMapFloat64BoolV(*v, fastpathCheckNilTrue, e) + + case []uint: + fastpathTV.EncSliceUintV(v, fastpathCheckNilTrue, e) + case *[]uint: + fastpathTV.EncSliceUintV(*v, fastpathCheckNilTrue, e) + + case map[uint]interface{}: + fastpathTV.EncMapUintIntfV(v, fastpathCheckNilTrue, e) + case *map[uint]interface{}: + fastpathTV.EncMapUintIntfV(*v, fastpathCheckNilTrue, e) + + case map[uint]string: + fastpathTV.EncMapUintStringV(v, fastpathCheckNilTrue, e) + case *map[uint]string: + fastpathTV.EncMapUintStringV(*v, fastpathCheckNilTrue, e) + + case map[uint]uint: + fastpathTV.EncMapUintUintV(v, fastpathCheckNilTrue, e) + case *map[uint]uint: + fastpathTV.EncMapUintUintV(*v, fastpathCheckNilTrue, e) + + case map[uint]uint8: + fastpathTV.EncMapUintUint8V(v, fastpathCheckNilTrue, e) + case *map[uint]uint8: + fastpathTV.EncMapUintUint8V(*v, fastpathCheckNilTrue, e) + + case map[uint]uint16: + fastpathTV.EncMapUintUint16V(v, fastpathCheckNilTrue, e) + case *map[uint]uint16: + fastpathTV.EncMapUintUint16V(*v, fastpathCheckNilTrue, e) + + case map[uint]uint32: + fastpathTV.EncMapUintUint32V(v, fastpathCheckNilTrue, e) + case *map[uint]uint32: + fastpathTV.EncMapUintUint32V(*v, fastpathCheckNilTrue, e) + + case map[uint]uint64: + fastpathTV.EncMapUintUint64V(v, fastpathCheckNilTrue, e) + case *map[uint]uint64: + fastpathTV.EncMapUintUint64V(*v, fastpathCheckNilTrue, e) + + case map[uint]int: + fastpathTV.EncMapUintIntV(v, fastpathCheckNilTrue, e) + case *map[uint]int: + fastpathTV.EncMapUintIntV(*v, fastpathCheckNilTrue, e) + + case map[uint]int8: + fastpathTV.EncMapUintInt8V(v, fastpathCheckNilTrue, e) + case *map[uint]int8: + fastpathTV.EncMapUintInt8V(*v, fastpathCheckNilTrue, e) + + case map[uint]int16: + fastpathTV.EncMapUintInt16V(v, fastpathCheckNilTrue, e) + case *map[uint]int16: + fastpathTV.EncMapUintInt16V(*v, fastpathCheckNilTrue, e) + + case map[uint]int32: + fastpathTV.EncMapUintInt32V(v, fastpathCheckNilTrue, e) + case *map[uint]int32: + fastpathTV.EncMapUintInt32V(*v, fastpathCheckNilTrue, e) + + case map[uint]int64: + fastpathTV.EncMapUintInt64V(v, fastpathCheckNilTrue, e) + case *map[uint]int64: + fastpathTV.EncMapUintInt64V(*v, fastpathCheckNilTrue, e) + + case map[uint]float32: + fastpathTV.EncMapUintFloat32V(v, fastpathCheckNilTrue, e) + case *map[uint]float32: + fastpathTV.EncMapUintFloat32V(*v, fastpathCheckNilTrue, e) + + case map[uint]float64: + fastpathTV.EncMapUintFloat64V(v, fastpathCheckNilTrue, e) + case *map[uint]float64: + fastpathTV.EncMapUintFloat64V(*v, fastpathCheckNilTrue, e) + + case map[uint]bool: + fastpathTV.EncMapUintBoolV(v, fastpathCheckNilTrue, e) + case *map[uint]bool: + fastpathTV.EncMapUintBoolV(*v, fastpathCheckNilTrue, e) + + case map[uint8]interface{}: + fastpathTV.EncMapUint8IntfV(v, fastpathCheckNilTrue, e) + case *map[uint8]interface{}: + fastpathTV.EncMapUint8IntfV(*v, fastpathCheckNilTrue, e) + + case map[uint8]string: + fastpathTV.EncMapUint8StringV(v, fastpathCheckNilTrue, e) + case *map[uint8]string: + fastpathTV.EncMapUint8StringV(*v, fastpathCheckNilTrue, e) + + case map[uint8]uint: + fastpathTV.EncMapUint8UintV(v, fastpathCheckNilTrue, e) + case *map[uint8]uint: + fastpathTV.EncMapUint8UintV(*v, fastpathCheckNilTrue, e) + + case map[uint8]uint8: + fastpathTV.EncMapUint8Uint8V(v, fastpathCheckNilTrue, e) + case *map[uint8]uint8: + fastpathTV.EncMapUint8Uint8V(*v, fastpathCheckNilTrue, e) + + case map[uint8]uint16: + fastpathTV.EncMapUint8Uint16V(v, fastpathCheckNilTrue, e) + case *map[uint8]uint16: + fastpathTV.EncMapUint8Uint16V(*v, fastpathCheckNilTrue, e) + + case map[uint8]uint32: + fastpathTV.EncMapUint8Uint32V(v, fastpathCheckNilTrue, e) + case *map[uint8]uint32: + fastpathTV.EncMapUint8Uint32V(*v, fastpathCheckNilTrue, e) + + case map[uint8]uint64: + fastpathTV.EncMapUint8Uint64V(v, fastpathCheckNilTrue, e) + case *map[uint8]uint64: + fastpathTV.EncMapUint8Uint64V(*v, fastpathCheckNilTrue, e) + + case map[uint8]int: + fastpathTV.EncMapUint8IntV(v, fastpathCheckNilTrue, e) + case *map[uint8]int: + fastpathTV.EncMapUint8IntV(*v, fastpathCheckNilTrue, e) + + case map[uint8]int8: + fastpathTV.EncMapUint8Int8V(v, fastpathCheckNilTrue, e) + case *map[uint8]int8: + fastpathTV.EncMapUint8Int8V(*v, fastpathCheckNilTrue, e) + + case map[uint8]int16: + fastpathTV.EncMapUint8Int16V(v, fastpathCheckNilTrue, e) + case *map[uint8]int16: + fastpathTV.EncMapUint8Int16V(*v, fastpathCheckNilTrue, e) + + case map[uint8]int32: + fastpathTV.EncMapUint8Int32V(v, fastpathCheckNilTrue, e) + case *map[uint8]int32: + fastpathTV.EncMapUint8Int32V(*v, fastpathCheckNilTrue, e) + + case map[uint8]int64: + fastpathTV.EncMapUint8Int64V(v, fastpathCheckNilTrue, e) + case *map[uint8]int64: + fastpathTV.EncMapUint8Int64V(*v, fastpathCheckNilTrue, e) + + case map[uint8]float32: + fastpathTV.EncMapUint8Float32V(v, fastpathCheckNilTrue, e) + case *map[uint8]float32: + fastpathTV.EncMapUint8Float32V(*v, fastpathCheckNilTrue, e) + + case map[uint8]float64: + fastpathTV.EncMapUint8Float64V(v, fastpathCheckNilTrue, e) + case *map[uint8]float64: + fastpathTV.EncMapUint8Float64V(*v, fastpathCheckNilTrue, e) + + case map[uint8]bool: + fastpathTV.EncMapUint8BoolV(v, fastpathCheckNilTrue, e) + case *map[uint8]bool: + fastpathTV.EncMapUint8BoolV(*v, fastpathCheckNilTrue, e) + + case []uint16: + fastpathTV.EncSliceUint16V(v, fastpathCheckNilTrue, e) + case *[]uint16: + fastpathTV.EncSliceUint16V(*v, fastpathCheckNilTrue, e) + + case map[uint16]interface{}: + fastpathTV.EncMapUint16IntfV(v, fastpathCheckNilTrue, e) + case *map[uint16]interface{}: + fastpathTV.EncMapUint16IntfV(*v, fastpathCheckNilTrue, e) + + case map[uint16]string: + fastpathTV.EncMapUint16StringV(v, fastpathCheckNilTrue, e) + case *map[uint16]string: + fastpathTV.EncMapUint16StringV(*v, fastpathCheckNilTrue, e) + + case map[uint16]uint: + fastpathTV.EncMapUint16UintV(v, fastpathCheckNilTrue, e) + case *map[uint16]uint: + fastpathTV.EncMapUint16UintV(*v, fastpathCheckNilTrue, e) + + case map[uint16]uint8: + fastpathTV.EncMapUint16Uint8V(v, fastpathCheckNilTrue, e) + case *map[uint16]uint8: + fastpathTV.EncMapUint16Uint8V(*v, fastpathCheckNilTrue, e) + + case map[uint16]uint16: + fastpathTV.EncMapUint16Uint16V(v, fastpathCheckNilTrue, e) + case *map[uint16]uint16: + fastpathTV.EncMapUint16Uint16V(*v, fastpathCheckNilTrue, e) + + case map[uint16]uint32: + fastpathTV.EncMapUint16Uint32V(v, fastpathCheckNilTrue, e) + case *map[uint16]uint32: + fastpathTV.EncMapUint16Uint32V(*v, fastpathCheckNilTrue, e) + + case map[uint16]uint64: + fastpathTV.EncMapUint16Uint64V(v, fastpathCheckNilTrue, e) + case *map[uint16]uint64: + fastpathTV.EncMapUint16Uint64V(*v, fastpathCheckNilTrue, e) + + case map[uint16]int: + fastpathTV.EncMapUint16IntV(v, fastpathCheckNilTrue, e) + case *map[uint16]int: + fastpathTV.EncMapUint16IntV(*v, fastpathCheckNilTrue, e) + + case map[uint16]int8: + fastpathTV.EncMapUint16Int8V(v, fastpathCheckNilTrue, e) + case *map[uint16]int8: + fastpathTV.EncMapUint16Int8V(*v, fastpathCheckNilTrue, e) + + case map[uint16]int16: + fastpathTV.EncMapUint16Int16V(v, fastpathCheckNilTrue, e) + case *map[uint16]int16: + fastpathTV.EncMapUint16Int16V(*v, fastpathCheckNilTrue, e) + + case map[uint16]int32: + fastpathTV.EncMapUint16Int32V(v, fastpathCheckNilTrue, e) + case *map[uint16]int32: + fastpathTV.EncMapUint16Int32V(*v, fastpathCheckNilTrue, e) + + case map[uint16]int64: + fastpathTV.EncMapUint16Int64V(v, fastpathCheckNilTrue, e) + case *map[uint16]int64: + fastpathTV.EncMapUint16Int64V(*v, fastpathCheckNilTrue, e) + + case map[uint16]float32: + fastpathTV.EncMapUint16Float32V(v, fastpathCheckNilTrue, e) + case *map[uint16]float32: + fastpathTV.EncMapUint16Float32V(*v, fastpathCheckNilTrue, e) + + case map[uint16]float64: + fastpathTV.EncMapUint16Float64V(v, fastpathCheckNilTrue, e) + case *map[uint16]float64: + fastpathTV.EncMapUint16Float64V(*v, fastpathCheckNilTrue, e) + + case map[uint16]bool: + fastpathTV.EncMapUint16BoolV(v, fastpathCheckNilTrue, e) + case *map[uint16]bool: + fastpathTV.EncMapUint16BoolV(*v, fastpathCheckNilTrue, e) + + case []uint32: + fastpathTV.EncSliceUint32V(v, fastpathCheckNilTrue, e) + case *[]uint32: + fastpathTV.EncSliceUint32V(*v, fastpathCheckNilTrue, e) + + case map[uint32]interface{}: + fastpathTV.EncMapUint32IntfV(v, fastpathCheckNilTrue, e) + case *map[uint32]interface{}: + fastpathTV.EncMapUint32IntfV(*v, fastpathCheckNilTrue, e) + + case map[uint32]string: + fastpathTV.EncMapUint32StringV(v, fastpathCheckNilTrue, e) + case *map[uint32]string: + fastpathTV.EncMapUint32StringV(*v, fastpathCheckNilTrue, e) + + case map[uint32]uint: + fastpathTV.EncMapUint32UintV(v, fastpathCheckNilTrue, e) + case *map[uint32]uint: + fastpathTV.EncMapUint32UintV(*v, fastpathCheckNilTrue, e) + + case map[uint32]uint8: + fastpathTV.EncMapUint32Uint8V(v, fastpathCheckNilTrue, e) + case *map[uint32]uint8: + fastpathTV.EncMapUint32Uint8V(*v, fastpathCheckNilTrue, e) + + case map[uint32]uint16: + fastpathTV.EncMapUint32Uint16V(v, fastpathCheckNilTrue, e) + case *map[uint32]uint16: + fastpathTV.EncMapUint32Uint16V(*v, fastpathCheckNilTrue, e) + + case map[uint32]uint32: + fastpathTV.EncMapUint32Uint32V(v, fastpathCheckNilTrue, e) + case *map[uint32]uint32: + fastpathTV.EncMapUint32Uint32V(*v, fastpathCheckNilTrue, e) + + case map[uint32]uint64: + fastpathTV.EncMapUint32Uint64V(v, fastpathCheckNilTrue, e) + case *map[uint32]uint64: + fastpathTV.EncMapUint32Uint64V(*v, fastpathCheckNilTrue, e) + + case map[uint32]int: + fastpathTV.EncMapUint32IntV(v, fastpathCheckNilTrue, e) + case *map[uint32]int: + fastpathTV.EncMapUint32IntV(*v, fastpathCheckNilTrue, e) + + case map[uint32]int8: + fastpathTV.EncMapUint32Int8V(v, fastpathCheckNilTrue, e) + case *map[uint32]int8: + fastpathTV.EncMapUint32Int8V(*v, fastpathCheckNilTrue, e) + + case map[uint32]int16: + fastpathTV.EncMapUint32Int16V(v, fastpathCheckNilTrue, e) + case *map[uint32]int16: + fastpathTV.EncMapUint32Int16V(*v, fastpathCheckNilTrue, e) + + case map[uint32]int32: + fastpathTV.EncMapUint32Int32V(v, fastpathCheckNilTrue, e) + case *map[uint32]int32: + fastpathTV.EncMapUint32Int32V(*v, fastpathCheckNilTrue, e) + + case map[uint32]int64: + fastpathTV.EncMapUint32Int64V(v, fastpathCheckNilTrue, e) + case *map[uint32]int64: + fastpathTV.EncMapUint32Int64V(*v, fastpathCheckNilTrue, e) + + case map[uint32]float32: + fastpathTV.EncMapUint32Float32V(v, fastpathCheckNilTrue, e) + case *map[uint32]float32: + fastpathTV.EncMapUint32Float32V(*v, fastpathCheckNilTrue, e) + + case map[uint32]float64: + fastpathTV.EncMapUint32Float64V(v, fastpathCheckNilTrue, e) + case *map[uint32]float64: + fastpathTV.EncMapUint32Float64V(*v, fastpathCheckNilTrue, e) + + case map[uint32]bool: + fastpathTV.EncMapUint32BoolV(v, fastpathCheckNilTrue, e) + case *map[uint32]bool: + fastpathTV.EncMapUint32BoolV(*v, fastpathCheckNilTrue, e) + + case []uint64: + fastpathTV.EncSliceUint64V(v, fastpathCheckNilTrue, e) + case *[]uint64: + fastpathTV.EncSliceUint64V(*v, fastpathCheckNilTrue, e) + + case map[uint64]interface{}: + fastpathTV.EncMapUint64IntfV(v, fastpathCheckNilTrue, e) + case *map[uint64]interface{}: + fastpathTV.EncMapUint64IntfV(*v, fastpathCheckNilTrue, e) + + case map[uint64]string: + fastpathTV.EncMapUint64StringV(v, fastpathCheckNilTrue, e) + case *map[uint64]string: + fastpathTV.EncMapUint64StringV(*v, fastpathCheckNilTrue, e) + + case map[uint64]uint: + fastpathTV.EncMapUint64UintV(v, fastpathCheckNilTrue, e) + case *map[uint64]uint: + fastpathTV.EncMapUint64UintV(*v, fastpathCheckNilTrue, e) + + case map[uint64]uint8: + fastpathTV.EncMapUint64Uint8V(v, fastpathCheckNilTrue, e) + case *map[uint64]uint8: + fastpathTV.EncMapUint64Uint8V(*v, fastpathCheckNilTrue, e) + + case map[uint64]uint16: + fastpathTV.EncMapUint64Uint16V(v, fastpathCheckNilTrue, e) + case *map[uint64]uint16: + fastpathTV.EncMapUint64Uint16V(*v, fastpathCheckNilTrue, e) + + case map[uint64]uint32: + fastpathTV.EncMapUint64Uint32V(v, fastpathCheckNilTrue, e) + case *map[uint64]uint32: + fastpathTV.EncMapUint64Uint32V(*v, fastpathCheckNilTrue, e) + + case map[uint64]uint64: + fastpathTV.EncMapUint64Uint64V(v, fastpathCheckNilTrue, e) + case *map[uint64]uint64: + fastpathTV.EncMapUint64Uint64V(*v, fastpathCheckNilTrue, e) + + case map[uint64]int: + fastpathTV.EncMapUint64IntV(v, fastpathCheckNilTrue, e) + case *map[uint64]int: + fastpathTV.EncMapUint64IntV(*v, fastpathCheckNilTrue, e) + + case map[uint64]int8: + fastpathTV.EncMapUint64Int8V(v, fastpathCheckNilTrue, e) + case *map[uint64]int8: + fastpathTV.EncMapUint64Int8V(*v, fastpathCheckNilTrue, e) + + case map[uint64]int16: + fastpathTV.EncMapUint64Int16V(v, fastpathCheckNilTrue, e) + case *map[uint64]int16: + fastpathTV.EncMapUint64Int16V(*v, fastpathCheckNilTrue, e) + + case map[uint64]int32: + fastpathTV.EncMapUint64Int32V(v, fastpathCheckNilTrue, e) + case *map[uint64]int32: + fastpathTV.EncMapUint64Int32V(*v, fastpathCheckNilTrue, e) + + case map[uint64]int64: + fastpathTV.EncMapUint64Int64V(v, fastpathCheckNilTrue, e) + case *map[uint64]int64: + fastpathTV.EncMapUint64Int64V(*v, fastpathCheckNilTrue, e) + + case map[uint64]float32: + fastpathTV.EncMapUint64Float32V(v, fastpathCheckNilTrue, e) + case *map[uint64]float32: + fastpathTV.EncMapUint64Float32V(*v, fastpathCheckNilTrue, e) + + case map[uint64]float64: + fastpathTV.EncMapUint64Float64V(v, fastpathCheckNilTrue, e) + case *map[uint64]float64: + fastpathTV.EncMapUint64Float64V(*v, fastpathCheckNilTrue, e) + + case map[uint64]bool: + fastpathTV.EncMapUint64BoolV(v, fastpathCheckNilTrue, e) + case *map[uint64]bool: + fastpathTV.EncMapUint64BoolV(*v, fastpathCheckNilTrue, e) + + case []int: + fastpathTV.EncSliceIntV(v, fastpathCheckNilTrue, e) + case *[]int: + fastpathTV.EncSliceIntV(*v, fastpathCheckNilTrue, e) + + case map[int]interface{}: + fastpathTV.EncMapIntIntfV(v, fastpathCheckNilTrue, e) + case *map[int]interface{}: + fastpathTV.EncMapIntIntfV(*v, fastpathCheckNilTrue, e) + + case map[int]string: + fastpathTV.EncMapIntStringV(v, fastpathCheckNilTrue, e) + case *map[int]string: + fastpathTV.EncMapIntStringV(*v, fastpathCheckNilTrue, e) + + case map[int]uint: + fastpathTV.EncMapIntUintV(v, fastpathCheckNilTrue, e) + case *map[int]uint: + fastpathTV.EncMapIntUintV(*v, fastpathCheckNilTrue, e) + + case map[int]uint8: + fastpathTV.EncMapIntUint8V(v, fastpathCheckNilTrue, e) + case *map[int]uint8: + fastpathTV.EncMapIntUint8V(*v, fastpathCheckNilTrue, e) + + case map[int]uint16: + fastpathTV.EncMapIntUint16V(v, fastpathCheckNilTrue, e) + case *map[int]uint16: + fastpathTV.EncMapIntUint16V(*v, fastpathCheckNilTrue, e) + + case map[int]uint32: + fastpathTV.EncMapIntUint32V(v, fastpathCheckNilTrue, e) + case *map[int]uint32: + fastpathTV.EncMapIntUint32V(*v, fastpathCheckNilTrue, e) + + case map[int]uint64: + fastpathTV.EncMapIntUint64V(v, fastpathCheckNilTrue, e) + case *map[int]uint64: + fastpathTV.EncMapIntUint64V(*v, fastpathCheckNilTrue, e) + + case map[int]int: + fastpathTV.EncMapIntIntV(v, fastpathCheckNilTrue, e) + case *map[int]int: + fastpathTV.EncMapIntIntV(*v, fastpathCheckNilTrue, e) + + case map[int]int8: + fastpathTV.EncMapIntInt8V(v, fastpathCheckNilTrue, e) + case *map[int]int8: + fastpathTV.EncMapIntInt8V(*v, fastpathCheckNilTrue, e) + + case map[int]int16: + fastpathTV.EncMapIntInt16V(v, fastpathCheckNilTrue, e) + case *map[int]int16: + fastpathTV.EncMapIntInt16V(*v, fastpathCheckNilTrue, e) + + case map[int]int32: + fastpathTV.EncMapIntInt32V(v, fastpathCheckNilTrue, e) + case *map[int]int32: + fastpathTV.EncMapIntInt32V(*v, fastpathCheckNilTrue, e) + + case map[int]int64: + fastpathTV.EncMapIntInt64V(v, fastpathCheckNilTrue, e) + case *map[int]int64: + fastpathTV.EncMapIntInt64V(*v, fastpathCheckNilTrue, e) + + case map[int]float32: + fastpathTV.EncMapIntFloat32V(v, fastpathCheckNilTrue, e) + case *map[int]float32: + fastpathTV.EncMapIntFloat32V(*v, fastpathCheckNilTrue, e) + + case map[int]float64: + fastpathTV.EncMapIntFloat64V(v, fastpathCheckNilTrue, e) + case *map[int]float64: + fastpathTV.EncMapIntFloat64V(*v, fastpathCheckNilTrue, e) + + case map[int]bool: + fastpathTV.EncMapIntBoolV(v, fastpathCheckNilTrue, e) + case *map[int]bool: + fastpathTV.EncMapIntBoolV(*v, fastpathCheckNilTrue, e) + + case []int8: + fastpathTV.EncSliceInt8V(v, fastpathCheckNilTrue, e) + case *[]int8: + fastpathTV.EncSliceInt8V(*v, fastpathCheckNilTrue, e) + + case map[int8]interface{}: + fastpathTV.EncMapInt8IntfV(v, fastpathCheckNilTrue, e) + case *map[int8]interface{}: + fastpathTV.EncMapInt8IntfV(*v, fastpathCheckNilTrue, e) + + case map[int8]string: + fastpathTV.EncMapInt8StringV(v, fastpathCheckNilTrue, e) + case *map[int8]string: + fastpathTV.EncMapInt8StringV(*v, fastpathCheckNilTrue, e) + + case map[int8]uint: + fastpathTV.EncMapInt8UintV(v, fastpathCheckNilTrue, e) + case *map[int8]uint: + fastpathTV.EncMapInt8UintV(*v, fastpathCheckNilTrue, e) + + case map[int8]uint8: + fastpathTV.EncMapInt8Uint8V(v, fastpathCheckNilTrue, e) + case *map[int8]uint8: + fastpathTV.EncMapInt8Uint8V(*v, fastpathCheckNilTrue, e) + + case map[int8]uint16: + fastpathTV.EncMapInt8Uint16V(v, fastpathCheckNilTrue, e) + case *map[int8]uint16: + fastpathTV.EncMapInt8Uint16V(*v, fastpathCheckNilTrue, e) + + case map[int8]uint32: + fastpathTV.EncMapInt8Uint32V(v, fastpathCheckNilTrue, e) + case *map[int8]uint32: + fastpathTV.EncMapInt8Uint32V(*v, fastpathCheckNilTrue, e) + + case map[int8]uint64: + fastpathTV.EncMapInt8Uint64V(v, fastpathCheckNilTrue, e) + case *map[int8]uint64: + fastpathTV.EncMapInt8Uint64V(*v, fastpathCheckNilTrue, e) + + case map[int8]int: + fastpathTV.EncMapInt8IntV(v, fastpathCheckNilTrue, e) + case *map[int8]int: + fastpathTV.EncMapInt8IntV(*v, fastpathCheckNilTrue, e) + + case map[int8]int8: + fastpathTV.EncMapInt8Int8V(v, fastpathCheckNilTrue, e) + case *map[int8]int8: + fastpathTV.EncMapInt8Int8V(*v, fastpathCheckNilTrue, e) + + case map[int8]int16: + fastpathTV.EncMapInt8Int16V(v, fastpathCheckNilTrue, e) + case *map[int8]int16: + fastpathTV.EncMapInt8Int16V(*v, fastpathCheckNilTrue, e) + + case map[int8]int32: + fastpathTV.EncMapInt8Int32V(v, fastpathCheckNilTrue, e) + case *map[int8]int32: + fastpathTV.EncMapInt8Int32V(*v, fastpathCheckNilTrue, e) + + case map[int8]int64: + fastpathTV.EncMapInt8Int64V(v, fastpathCheckNilTrue, e) + case *map[int8]int64: + fastpathTV.EncMapInt8Int64V(*v, fastpathCheckNilTrue, e) + + case map[int8]float32: + fastpathTV.EncMapInt8Float32V(v, fastpathCheckNilTrue, e) + case *map[int8]float32: + fastpathTV.EncMapInt8Float32V(*v, fastpathCheckNilTrue, e) + + case map[int8]float64: + fastpathTV.EncMapInt8Float64V(v, fastpathCheckNilTrue, e) + case *map[int8]float64: + fastpathTV.EncMapInt8Float64V(*v, fastpathCheckNilTrue, e) + + case map[int8]bool: + fastpathTV.EncMapInt8BoolV(v, fastpathCheckNilTrue, e) + case *map[int8]bool: + fastpathTV.EncMapInt8BoolV(*v, fastpathCheckNilTrue, e) + + case []int16: + fastpathTV.EncSliceInt16V(v, fastpathCheckNilTrue, e) + case *[]int16: + fastpathTV.EncSliceInt16V(*v, fastpathCheckNilTrue, e) + + case map[int16]interface{}: + fastpathTV.EncMapInt16IntfV(v, fastpathCheckNilTrue, e) + case *map[int16]interface{}: + fastpathTV.EncMapInt16IntfV(*v, fastpathCheckNilTrue, e) + + case map[int16]string: + fastpathTV.EncMapInt16StringV(v, fastpathCheckNilTrue, e) + case *map[int16]string: + fastpathTV.EncMapInt16StringV(*v, fastpathCheckNilTrue, e) + + case map[int16]uint: + fastpathTV.EncMapInt16UintV(v, fastpathCheckNilTrue, e) + case *map[int16]uint: + fastpathTV.EncMapInt16UintV(*v, fastpathCheckNilTrue, e) + + case map[int16]uint8: + fastpathTV.EncMapInt16Uint8V(v, fastpathCheckNilTrue, e) + case *map[int16]uint8: + fastpathTV.EncMapInt16Uint8V(*v, fastpathCheckNilTrue, e) + + case map[int16]uint16: + fastpathTV.EncMapInt16Uint16V(v, fastpathCheckNilTrue, e) + case *map[int16]uint16: + fastpathTV.EncMapInt16Uint16V(*v, fastpathCheckNilTrue, e) + + case map[int16]uint32: + fastpathTV.EncMapInt16Uint32V(v, fastpathCheckNilTrue, e) + case *map[int16]uint32: + fastpathTV.EncMapInt16Uint32V(*v, fastpathCheckNilTrue, e) + + case map[int16]uint64: + fastpathTV.EncMapInt16Uint64V(v, fastpathCheckNilTrue, e) + case *map[int16]uint64: + fastpathTV.EncMapInt16Uint64V(*v, fastpathCheckNilTrue, e) + + case map[int16]int: + fastpathTV.EncMapInt16IntV(v, fastpathCheckNilTrue, e) + case *map[int16]int: + fastpathTV.EncMapInt16IntV(*v, fastpathCheckNilTrue, e) + + case map[int16]int8: + fastpathTV.EncMapInt16Int8V(v, fastpathCheckNilTrue, e) + case *map[int16]int8: + fastpathTV.EncMapInt16Int8V(*v, fastpathCheckNilTrue, e) + + case map[int16]int16: + fastpathTV.EncMapInt16Int16V(v, fastpathCheckNilTrue, e) + case *map[int16]int16: + fastpathTV.EncMapInt16Int16V(*v, fastpathCheckNilTrue, e) + + case map[int16]int32: + fastpathTV.EncMapInt16Int32V(v, fastpathCheckNilTrue, e) + case *map[int16]int32: + fastpathTV.EncMapInt16Int32V(*v, fastpathCheckNilTrue, e) + + case map[int16]int64: + fastpathTV.EncMapInt16Int64V(v, fastpathCheckNilTrue, e) + case *map[int16]int64: + fastpathTV.EncMapInt16Int64V(*v, fastpathCheckNilTrue, e) + + case map[int16]float32: + fastpathTV.EncMapInt16Float32V(v, fastpathCheckNilTrue, e) + case *map[int16]float32: + fastpathTV.EncMapInt16Float32V(*v, fastpathCheckNilTrue, e) + + case map[int16]float64: + fastpathTV.EncMapInt16Float64V(v, fastpathCheckNilTrue, e) + case *map[int16]float64: + fastpathTV.EncMapInt16Float64V(*v, fastpathCheckNilTrue, e) + + case map[int16]bool: + fastpathTV.EncMapInt16BoolV(v, fastpathCheckNilTrue, e) + case *map[int16]bool: + fastpathTV.EncMapInt16BoolV(*v, fastpathCheckNilTrue, e) + + case []int32: + fastpathTV.EncSliceInt32V(v, fastpathCheckNilTrue, e) + case *[]int32: + fastpathTV.EncSliceInt32V(*v, fastpathCheckNilTrue, e) + + case map[int32]interface{}: + fastpathTV.EncMapInt32IntfV(v, fastpathCheckNilTrue, e) + case *map[int32]interface{}: + fastpathTV.EncMapInt32IntfV(*v, fastpathCheckNilTrue, e) + + case map[int32]string: + fastpathTV.EncMapInt32StringV(v, fastpathCheckNilTrue, e) + case *map[int32]string: + fastpathTV.EncMapInt32StringV(*v, fastpathCheckNilTrue, e) + + case map[int32]uint: + fastpathTV.EncMapInt32UintV(v, fastpathCheckNilTrue, e) + case *map[int32]uint: + fastpathTV.EncMapInt32UintV(*v, fastpathCheckNilTrue, e) + + case map[int32]uint8: + fastpathTV.EncMapInt32Uint8V(v, fastpathCheckNilTrue, e) + case *map[int32]uint8: + fastpathTV.EncMapInt32Uint8V(*v, fastpathCheckNilTrue, e) + + case map[int32]uint16: + fastpathTV.EncMapInt32Uint16V(v, fastpathCheckNilTrue, e) + case *map[int32]uint16: + fastpathTV.EncMapInt32Uint16V(*v, fastpathCheckNilTrue, e) + + case map[int32]uint32: + fastpathTV.EncMapInt32Uint32V(v, fastpathCheckNilTrue, e) + case *map[int32]uint32: + fastpathTV.EncMapInt32Uint32V(*v, fastpathCheckNilTrue, e) + + case map[int32]uint64: + fastpathTV.EncMapInt32Uint64V(v, fastpathCheckNilTrue, e) + case *map[int32]uint64: + fastpathTV.EncMapInt32Uint64V(*v, fastpathCheckNilTrue, e) + + case map[int32]int: + fastpathTV.EncMapInt32IntV(v, fastpathCheckNilTrue, e) + case *map[int32]int: + fastpathTV.EncMapInt32IntV(*v, fastpathCheckNilTrue, e) + + case map[int32]int8: + fastpathTV.EncMapInt32Int8V(v, fastpathCheckNilTrue, e) + case *map[int32]int8: + fastpathTV.EncMapInt32Int8V(*v, fastpathCheckNilTrue, e) + + case map[int32]int16: + fastpathTV.EncMapInt32Int16V(v, fastpathCheckNilTrue, e) + case *map[int32]int16: + fastpathTV.EncMapInt32Int16V(*v, fastpathCheckNilTrue, e) + + case map[int32]int32: + fastpathTV.EncMapInt32Int32V(v, fastpathCheckNilTrue, e) + case *map[int32]int32: + fastpathTV.EncMapInt32Int32V(*v, fastpathCheckNilTrue, e) + + case map[int32]int64: + fastpathTV.EncMapInt32Int64V(v, fastpathCheckNilTrue, e) + case *map[int32]int64: + fastpathTV.EncMapInt32Int64V(*v, fastpathCheckNilTrue, e) + + case map[int32]float32: + fastpathTV.EncMapInt32Float32V(v, fastpathCheckNilTrue, e) + case *map[int32]float32: + fastpathTV.EncMapInt32Float32V(*v, fastpathCheckNilTrue, e) + + case map[int32]float64: + fastpathTV.EncMapInt32Float64V(v, fastpathCheckNilTrue, e) + case *map[int32]float64: + fastpathTV.EncMapInt32Float64V(*v, fastpathCheckNilTrue, e) + + case map[int32]bool: + fastpathTV.EncMapInt32BoolV(v, fastpathCheckNilTrue, e) + case *map[int32]bool: + fastpathTV.EncMapInt32BoolV(*v, fastpathCheckNilTrue, e) + + case []int64: + fastpathTV.EncSliceInt64V(v, fastpathCheckNilTrue, e) + case *[]int64: + fastpathTV.EncSliceInt64V(*v, fastpathCheckNilTrue, e) + + case map[int64]interface{}: + fastpathTV.EncMapInt64IntfV(v, fastpathCheckNilTrue, e) + case *map[int64]interface{}: + fastpathTV.EncMapInt64IntfV(*v, fastpathCheckNilTrue, e) + + case map[int64]string: + fastpathTV.EncMapInt64StringV(v, fastpathCheckNilTrue, e) + case *map[int64]string: + fastpathTV.EncMapInt64StringV(*v, fastpathCheckNilTrue, e) + + case map[int64]uint: + fastpathTV.EncMapInt64UintV(v, fastpathCheckNilTrue, e) + case *map[int64]uint: + fastpathTV.EncMapInt64UintV(*v, fastpathCheckNilTrue, e) + + case map[int64]uint8: + fastpathTV.EncMapInt64Uint8V(v, fastpathCheckNilTrue, e) + case *map[int64]uint8: + fastpathTV.EncMapInt64Uint8V(*v, fastpathCheckNilTrue, e) + + case map[int64]uint16: + fastpathTV.EncMapInt64Uint16V(v, fastpathCheckNilTrue, e) + case *map[int64]uint16: + fastpathTV.EncMapInt64Uint16V(*v, fastpathCheckNilTrue, e) + + case map[int64]uint32: + fastpathTV.EncMapInt64Uint32V(v, fastpathCheckNilTrue, e) + case *map[int64]uint32: + fastpathTV.EncMapInt64Uint32V(*v, fastpathCheckNilTrue, e) + + case map[int64]uint64: + fastpathTV.EncMapInt64Uint64V(v, fastpathCheckNilTrue, e) + case *map[int64]uint64: + fastpathTV.EncMapInt64Uint64V(*v, fastpathCheckNilTrue, e) + + case map[int64]int: + fastpathTV.EncMapInt64IntV(v, fastpathCheckNilTrue, e) + case *map[int64]int: + fastpathTV.EncMapInt64IntV(*v, fastpathCheckNilTrue, e) + + case map[int64]int8: + fastpathTV.EncMapInt64Int8V(v, fastpathCheckNilTrue, e) + case *map[int64]int8: + fastpathTV.EncMapInt64Int8V(*v, fastpathCheckNilTrue, e) + + case map[int64]int16: + fastpathTV.EncMapInt64Int16V(v, fastpathCheckNilTrue, e) + case *map[int64]int16: + fastpathTV.EncMapInt64Int16V(*v, fastpathCheckNilTrue, e) + + case map[int64]int32: + fastpathTV.EncMapInt64Int32V(v, fastpathCheckNilTrue, e) + case *map[int64]int32: + fastpathTV.EncMapInt64Int32V(*v, fastpathCheckNilTrue, e) + + case map[int64]int64: + fastpathTV.EncMapInt64Int64V(v, fastpathCheckNilTrue, e) + case *map[int64]int64: + fastpathTV.EncMapInt64Int64V(*v, fastpathCheckNilTrue, e) + + case map[int64]float32: + fastpathTV.EncMapInt64Float32V(v, fastpathCheckNilTrue, e) + case *map[int64]float32: + fastpathTV.EncMapInt64Float32V(*v, fastpathCheckNilTrue, e) + + case map[int64]float64: + fastpathTV.EncMapInt64Float64V(v, fastpathCheckNilTrue, e) + case *map[int64]float64: + fastpathTV.EncMapInt64Float64V(*v, fastpathCheckNilTrue, e) + + case map[int64]bool: + fastpathTV.EncMapInt64BoolV(v, fastpathCheckNilTrue, e) + case *map[int64]bool: + fastpathTV.EncMapInt64BoolV(*v, fastpathCheckNilTrue, e) + + case []bool: + fastpathTV.EncSliceBoolV(v, fastpathCheckNilTrue, e) + case *[]bool: + fastpathTV.EncSliceBoolV(*v, fastpathCheckNilTrue, e) + + case map[bool]interface{}: + fastpathTV.EncMapBoolIntfV(v, fastpathCheckNilTrue, e) + case *map[bool]interface{}: + fastpathTV.EncMapBoolIntfV(*v, fastpathCheckNilTrue, e) + + case map[bool]string: + fastpathTV.EncMapBoolStringV(v, fastpathCheckNilTrue, e) + case *map[bool]string: + fastpathTV.EncMapBoolStringV(*v, fastpathCheckNilTrue, e) + + case map[bool]uint: + fastpathTV.EncMapBoolUintV(v, fastpathCheckNilTrue, e) + case *map[bool]uint: + fastpathTV.EncMapBoolUintV(*v, fastpathCheckNilTrue, e) + + case map[bool]uint8: + fastpathTV.EncMapBoolUint8V(v, fastpathCheckNilTrue, e) + case *map[bool]uint8: + fastpathTV.EncMapBoolUint8V(*v, fastpathCheckNilTrue, e) + + case map[bool]uint16: + fastpathTV.EncMapBoolUint16V(v, fastpathCheckNilTrue, e) + case *map[bool]uint16: + fastpathTV.EncMapBoolUint16V(*v, fastpathCheckNilTrue, e) + + case map[bool]uint32: + fastpathTV.EncMapBoolUint32V(v, fastpathCheckNilTrue, e) + case *map[bool]uint32: + fastpathTV.EncMapBoolUint32V(*v, fastpathCheckNilTrue, e) + + case map[bool]uint64: + fastpathTV.EncMapBoolUint64V(v, fastpathCheckNilTrue, e) + case *map[bool]uint64: + fastpathTV.EncMapBoolUint64V(*v, fastpathCheckNilTrue, e) + + case map[bool]int: + fastpathTV.EncMapBoolIntV(v, fastpathCheckNilTrue, e) + case *map[bool]int: + fastpathTV.EncMapBoolIntV(*v, fastpathCheckNilTrue, e) + + case map[bool]int8: + fastpathTV.EncMapBoolInt8V(v, fastpathCheckNilTrue, e) + case *map[bool]int8: + fastpathTV.EncMapBoolInt8V(*v, fastpathCheckNilTrue, e) + + case map[bool]int16: + fastpathTV.EncMapBoolInt16V(v, fastpathCheckNilTrue, e) + case *map[bool]int16: + fastpathTV.EncMapBoolInt16V(*v, fastpathCheckNilTrue, e) + + case map[bool]int32: + fastpathTV.EncMapBoolInt32V(v, fastpathCheckNilTrue, e) + case *map[bool]int32: + fastpathTV.EncMapBoolInt32V(*v, fastpathCheckNilTrue, e) + + case map[bool]int64: + fastpathTV.EncMapBoolInt64V(v, fastpathCheckNilTrue, e) + case *map[bool]int64: + fastpathTV.EncMapBoolInt64V(*v, fastpathCheckNilTrue, e) + + case map[bool]float32: + fastpathTV.EncMapBoolFloat32V(v, fastpathCheckNilTrue, e) + case *map[bool]float32: + fastpathTV.EncMapBoolFloat32V(*v, fastpathCheckNilTrue, e) + + case map[bool]float64: + fastpathTV.EncMapBoolFloat64V(v, fastpathCheckNilTrue, e) + case *map[bool]float64: + fastpathTV.EncMapBoolFloat64V(*v, fastpathCheckNilTrue, e) + + case map[bool]bool: + fastpathTV.EncMapBoolBoolV(v, fastpathCheckNilTrue, e) + case *map[bool]bool: + fastpathTV.EncMapBoolBoolV(*v, fastpathCheckNilTrue, e) + + default: + return false + } + return true +} + +func fastpathEncodeTypeSwitchSlice(iv interface{}, e *Encoder) bool { + switch v := iv.(type) { + + case []interface{}: + fastpathTV.EncSliceIntfV(v, fastpathCheckNilTrue, e) + case *[]interface{}: + fastpathTV.EncSliceIntfV(*v, fastpathCheckNilTrue, e) + + case []string: + fastpathTV.EncSliceStringV(v, fastpathCheckNilTrue, e) + case *[]string: + fastpathTV.EncSliceStringV(*v, fastpathCheckNilTrue, e) + + case []float32: + fastpathTV.EncSliceFloat32V(v, fastpathCheckNilTrue, e) + case *[]float32: + fastpathTV.EncSliceFloat32V(*v, fastpathCheckNilTrue, e) + + case []float64: + fastpathTV.EncSliceFloat64V(v, fastpathCheckNilTrue, e) + case *[]float64: + fastpathTV.EncSliceFloat64V(*v, fastpathCheckNilTrue, e) + + case []uint: + fastpathTV.EncSliceUintV(v, fastpathCheckNilTrue, e) + case *[]uint: + fastpathTV.EncSliceUintV(*v, fastpathCheckNilTrue, e) + + case []uint16: + fastpathTV.EncSliceUint16V(v, fastpathCheckNilTrue, e) + case *[]uint16: + fastpathTV.EncSliceUint16V(*v, fastpathCheckNilTrue, e) + + case []uint32: + fastpathTV.EncSliceUint32V(v, fastpathCheckNilTrue, e) + case *[]uint32: + fastpathTV.EncSliceUint32V(*v, fastpathCheckNilTrue, e) + + case []uint64: + fastpathTV.EncSliceUint64V(v, fastpathCheckNilTrue, e) + case *[]uint64: + fastpathTV.EncSliceUint64V(*v, fastpathCheckNilTrue, e) + + case []int: + fastpathTV.EncSliceIntV(v, fastpathCheckNilTrue, e) + case *[]int: + fastpathTV.EncSliceIntV(*v, fastpathCheckNilTrue, e) + + case []int8: + fastpathTV.EncSliceInt8V(v, fastpathCheckNilTrue, e) + case *[]int8: + fastpathTV.EncSliceInt8V(*v, fastpathCheckNilTrue, e) + + case []int16: + fastpathTV.EncSliceInt16V(v, fastpathCheckNilTrue, e) + case *[]int16: + fastpathTV.EncSliceInt16V(*v, fastpathCheckNilTrue, e) + + case []int32: + fastpathTV.EncSliceInt32V(v, fastpathCheckNilTrue, e) + case *[]int32: + fastpathTV.EncSliceInt32V(*v, fastpathCheckNilTrue, e) + + case []int64: + fastpathTV.EncSliceInt64V(v, fastpathCheckNilTrue, e) + case *[]int64: + fastpathTV.EncSliceInt64V(*v, fastpathCheckNilTrue, e) + + case []bool: + fastpathTV.EncSliceBoolV(v, fastpathCheckNilTrue, e) + case *[]bool: + fastpathTV.EncSliceBoolV(*v, fastpathCheckNilTrue, e) + + default: + return false + } + return true +} + +func fastpathEncodeTypeSwitchMap(iv interface{}, e *Encoder) bool { + switch v := iv.(type) { + + case map[interface{}]interface{}: + fastpathTV.EncMapIntfIntfV(v, fastpathCheckNilTrue, e) + case *map[interface{}]interface{}: + fastpathTV.EncMapIntfIntfV(*v, fastpathCheckNilTrue, e) + + case map[interface{}]string: + fastpathTV.EncMapIntfStringV(v, fastpathCheckNilTrue, e) + case *map[interface{}]string: + fastpathTV.EncMapIntfStringV(*v, fastpathCheckNilTrue, e) + + case map[interface{}]uint: + fastpathTV.EncMapIntfUintV(v, fastpathCheckNilTrue, e) + case *map[interface{}]uint: + fastpathTV.EncMapIntfUintV(*v, fastpathCheckNilTrue, e) + + case map[interface{}]uint8: + fastpathTV.EncMapIntfUint8V(v, fastpathCheckNilTrue, e) + case *map[interface{}]uint8: + fastpathTV.EncMapIntfUint8V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]uint16: + fastpathTV.EncMapIntfUint16V(v, fastpathCheckNilTrue, e) + case *map[interface{}]uint16: + fastpathTV.EncMapIntfUint16V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]uint32: + fastpathTV.EncMapIntfUint32V(v, fastpathCheckNilTrue, e) + case *map[interface{}]uint32: + fastpathTV.EncMapIntfUint32V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]uint64: + fastpathTV.EncMapIntfUint64V(v, fastpathCheckNilTrue, e) + case *map[interface{}]uint64: + fastpathTV.EncMapIntfUint64V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]int: + fastpathTV.EncMapIntfIntV(v, fastpathCheckNilTrue, e) + case *map[interface{}]int: + fastpathTV.EncMapIntfIntV(*v, fastpathCheckNilTrue, e) + + case map[interface{}]int8: + fastpathTV.EncMapIntfInt8V(v, fastpathCheckNilTrue, e) + case *map[interface{}]int8: + fastpathTV.EncMapIntfInt8V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]int16: + fastpathTV.EncMapIntfInt16V(v, fastpathCheckNilTrue, e) + case *map[interface{}]int16: + fastpathTV.EncMapIntfInt16V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]int32: + fastpathTV.EncMapIntfInt32V(v, fastpathCheckNilTrue, e) + case *map[interface{}]int32: + fastpathTV.EncMapIntfInt32V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]int64: + fastpathTV.EncMapIntfInt64V(v, fastpathCheckNilTrue, e) + case *map[interface{}]int64: + fastpathTV.EncMapIntfInt64V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]float32: + fastpathTV.EncMapIntfFloat32V(v, fastpathCheckNilTrue, e) + case *map[interface{}]float32: + fastpathTV.EncMapIntfFloat32V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]float64: + fastpathTV.EncMapIntfFloat64V(v, fastpathCheckNilTrue, e) + case *map[interface{}]float64: + fastpathTV.EncMapIntfFloat64V(*v, fastpathCheckNilTrue, e) + + case map[interface{}]bool: + fastpathTV.EncMapIntfBoolV(v, fastpathCheckNilTrue, e) + case *map[interface{}]bool: + fastpathTV.EncMapIntfBoolV(*v, fastpathCheckNilTrue, e) + + case map[string]interface{}: + fastpathTV.EncMapStringIntfV(v, fastpathCheckNilTrue, e) + case *map[string]interface{}: + fastpathTV.EncMapStringIntfV(*v, fastpathCheckNilTrue, e) + + case map[string]string: + fastpathTV.EncMapStringStringV(v, fastpathCheckNilTrue, e) + case *map[string]string: + fastpathTV.EncMapStringStringV(*v, fastpathCheckNilTrue, e) + + case map[string]uint: + fastpathTV.EncMapStringUintV(v, fastpathCheckNilTrue, e) + case *map[string]uint: + fastpathTV.EncMapStringUintV(*v, fastpathCheckNilTrue, e) + + case map[string]uint8: + fastpathTV.EncMapStringUint8V(v, fastpathCheckNilTrue, e) + case *map[string]uint8: + fastpathTV.EncMapStringUint8V(*v, fastpathCheckNilTrue, e) + + case map[string]uint16: + fastpathTV.EncMapStringUint16V(v, fastpathCheckNilTrue, e) + case *map[string]uint16: + fastpathTV.EncMapStringUint16V(*v, fastpathCheckNilTrue, e) + + case map[string]uint32: + fastpathTV.EncMapStringUint32V(v, fastpathCheckNilTrue, e) + case *map[string]uint32: + fastpathTV.EncMapStringUint32V(*v, fastpathCheckNilTrue, e) + + case map[string]uint64: + fastpathTV.EncMapStringUint64V(v, fastpathCheckNilTrue, e) + case *map[string]uint64: + fastpathTV.EncMapStringUint64V(*v, fastpathCheckNilTrue, e) + + case map[string]int: + fastpathTV.EncMapStringIntV(v, fastpathCheckNilTrue, e) + case *map[string]int: + fastpathTV.EncMapStringIntV(*v, fastpathCheckNilTrue, e) + + case map[string]int8: + fastpathTV.EncMapStringInt8V(v, fastpathCheckNilTrue, e) + case *map[string]int8: + fastpathTV.EncMapStringInt8V(*v, fastpathCheckNilTrue, e) + + case map[string]int16: + fastpathTV.EncMapStringInt16V(v, fastpathCheckNilTrue, e) + case *map[string]int16: + fastpathTV.EncMapStringInt16V(*v, fastpathCheckNilTrue, e) + + case map[string]int32: + fastpathTV.EncMapStringInt32V(v, fastpathCheckNilTrue, e) + case *map[string]int32: + fastpathTV.EncMapStringInt32V(*v, fastpathCheckNilTrue, e) + + case map[string]int64: + fastpathTV.EncMapStringInt64V(v, fastpathCheckNilTrue, e) + case *map[string]int64: + fastpathTV.EncMapStringInt64V(*v, fastpathCheckNilTrue, e) + + case map[string]float32: + fastpathTV.EncMapStringFloat32V(v, fastpathCheckNilTrue, e) + case *map[string]float32: + fastpathTV.EncMapStringFloat32V(*v, fastpathCheckNilTrue, e) + + case map[string]float64: + fastpathTV.EncMapStringFloat64V(v, fastpathCheckNilTrue, e) + case *map[string]float64: + fastpathTV.EncMapStringFloat64V(*v, fastpathCheckNilTrue, e) + + case map[string]bool: + fastpathTV.EncMapStringBoolV(v, fastpathCheckNilTrue, e) + case *map[string]bool: + fastpathTV.EncMapStringBoolV(*v, fastpathCheckNilTrue, e) + + case map[float32]interface{}: + fastpathTV.EncMapFloat32IntfV(v, fastpathCheckNilTrue, e) + case *map[float32]interface{}: + fastpathTV.EncMapFloat32IntfV(*v, fastpathCheckNilTrue, e) + + case map[float32]string: + fastpathTV.EncMapFloat32StringV(v, fastpathCheckNilTrue, e) + case *map[float32]string: + fastpathTV.EncMapFloat32StringV(*v, fastpathCheckNilTrue, e) + + case map[float32]uint: + fastpathTV.EncMapFloat32UintV(v, fastpathCheckNilTrue, e) + case *map[float32]uint: + fastpathTV.EncMapFloat32UintV(*v, fastpathCheckNilTrue, e) + + case map[float32]uint8: + fastpathTV.EncMapFloat32Uint8V(v, fastpathCheckNilTrue, e) + case *map[float32]uint8: + fastpathTV.EncMapFloat32Uint8V(*v, fastpathCheckNilTrue, e) + + case map[float32]uint16: + fastpathTV.EncMapFloat32Uint16V(v, fastpathCheckNilTrue, e) + case *map[float32]uint16: + fastpathTV.EncMapFloat32Uint16V(*v, fastpathCheckNilTrue, e) + + case map[float32]uint32: + fastpathTV.EncMapFloat32Uint32V(v, fastpathCheckNilTrue, e) + case *map[float32]uint32: + fastpathTV.EncMapFloat32Uint32V(*v, fastpathCheckNilTrue, e) + + case map[float32]uint64: + fastpathTV.EncMapFloat32Uint64V(v, fastpathCheckNilTrue, e) + case *map[float32]uint64: + fastpathTV.EncMapFloat32Uint64V(*v, fastpathCheckNilTrue, e) + + case map[float32]int: + fastpathTV.EncMapFloat32IntV(v, fastpathCheckNilTrue, e) + case *map[float32]int: + fastpathTV.EncMapFloat32IntV(*v, fastpathCheckNilTrue, e) + + case map[float32]int8: + fastpathTV.EncMapFloat32Int8V(v, fastpathCheckNilTrue, e) + case *map[float32]int8: + fastpathTV.EncMapFloat32Int8V(*v, fastpathCheckNilTrue, e) + + case map[float32]int16: + fastpathTV.EncMapFloat32Int16V(v, fastpathCheckNilTrue, e) + case *map[float32]int16: + fastpathTV.EncMapFloat32Int16V(*v, fastpathCheckNilTrue, e) + + case map[float32]int32: + fastpathTV.EncMapFloat32Int32V(v, fastpathCheckNilTrue, e) + case *map[float32]int32: + fastpathTV.EncMapFloat32Int32V(*v, fastpathCheckNilTrue, e) + + case map[float32]int64: + fastpathTV.EncMapFloat32Int64V(v, fastpathCheckNilTrue, e) + case *map[float32]int64: + fastpathTV.EncMapFloat32Int64V(*v, fastpathCheckNilTrue, e) + + case map[float32]float32: + fastpathTV.EncMapFloat32Float32V(v, fastpathCheckNilTrue, e) + case *map[float32]float32: + fastpathTV.EncMapFloat32Float32V(*v, fastpathCheckNilTrue, e) + + case map[float32]float64: + fastpathTV.EncMapFloat32Float64V(v, fastpathCheckNilTrue, e) + case *map[float32]float64: + fastpathTV.EncMapFloat32Float64V(*v, fastpathCheckNilTrue, e) + + case map[float32]bool: + fastpathTV.EncMapFloat32BoolV(v, fastpathCheckNilTrue, e) + case *map[float32]bool: + fastpathTV.EncMapFloat32BoolV(*v, fastpathCheckNilTrue, e) + + case map[float64]interface{}: + fastpathTV.EncMapFloat64IntfV(v, fastpathCheckNilTrue, e) + case *map[float64]interface{}: + fastpathTV.EncMapFloat64IntfV(*v, fastpathCheckNilTrue, e) + + case map[float64]string: + fastpathTV.EncMapFloat64StringV(v, fastpathCheckNilTrue, e) + case *map[float64]string: + fastpathTV.EncMapFloat64StringV(*v, fastpathCheckNilTrue, e) + + case map[float64]uint: + fastpathTV.EncMapFloat64UintV(v, fastpathCheckNilTrue, e) + case *map[float64]uint: + fastpathTV.EncMapFloat64UintV(*v, fastpathCheckNilTrue, e) + + case map[float64]uint8: + fastpathTV.EncMapFloat64Uint8V(v, fastpathCheckNilTrue, e) + case *map[float64]uint8: + fastpathTV.EncMapFloat64Uint8V(*v, fastpathCheckNilTrue, e) + + case map[float64]uint16: + fastpathTV.EncMapFloat64Uint16V(v, fastpathCheckNilTrue, e) + case *map[float64]uint16: + fastpathTV.EncMapFloat64Uint16V(*v, fastpathCheckNilTrue, e) + + case map[float64]uint32: + fastpathTV.EncMapFloat64Uint32V(v, fastpathCheckNilTrue, e) + case *map[float64]uint32: + fastpathTV.EncMapFloat64Uint32V(*v, fastpathCheckNilTrue, e) + + case map[float64]uint64: + fastpathTV.EncMapFloat64Uint64V(v, fastpathCheckNilTrue, e) + case *map[float64]uint64: + fastpathTV.EncMapFloat64Uint64V(*v, fastpathCheckNilTrue, e) + + case map[float64]int: + fastpathTV.EncMapFloat64IntV(v, fastpathCheckNilTrue, e) + case *map[float64]int: + fastpathTV.EncMapFloat64IntV(*v, fastpathCheckNilTrue, e) + + case map[float64]int8: + fastpathTV.EncMapFloat64Int8V(v, fastpathCheckNilTrue, e) + case *map[float64]int8: + fastpathTV.EncMapFloat64Int8V(*v, fastpathCheckNilTrue, e) + + case map[float64]int16: + fastpathTV.EncMapFloat64Int16V(v, fastpathCheckNilTrue, e) + case *map[float64]int16: + fastpathTV.EncMapFloat64Int16V(*v, fastpathCheckNilTrue, e) + + case map[float64]int32: + fastpathTV.EncMapFloat64Int32V(v, fastpathCheckNilTrue, e) + case *map[float64]int32: + fastpathTV.EncMapFloat64Int32V(*v, fastpathCheckNilTrue, e) + + case map[float64]int64: + fastpathTV.EncMapFloat64Int64V(v, fastpathCheckNilTrue, e) + case *map[float64]int64: + fastpathTV.EncMapFloat64Int64V(*v, fastpathCheckNilTrue, e) + + case map[float64]float32: + fastpathTV.EncMapFloat64Float32V(v, fastpathCheckNilTrue, e) + case *map[float64]float32: + fastpathTV.EncMapFloat64Float32V(*v, fastpathCheckNilTrue, e) + + case map[float64]float64: + fastpathTV.EncMapFloat64Float64V(v, fastpathCheckNilTrue, e) + case *map[float64]float64: + fastpathTV.EncMapFloat64Float64V(*v, fastpathCheckNilTrue, e) + + case map[float64]bool: + fastpathTV.EncMapFloat64BoolV(v, fastpathCheckNilTrue, e) + case *map[float64]bool: + fastpathTV.EncMapFloat64BoolV(*v, fastpathCheckNilTrue, e) + + case map[uint]interface{}: + fastpathTV.EncMapUintIntfV(v, fastpathCheckNilTrue, e) + case *map[uint]interface{}: + fastpathTV.EncMapUintIntfV(*v, fastpathCheckNilTrue, e) + + case map[uint]string: + fastpathTV.EncMapUintStringV(v, fastpathCheckNilTrue, e) + case *map[uint]string: + fastpathTV.EncMapUintStringV(*v, fastpathCheckNilTrue, e) + + case map[uint]uint: + fastpathTV.EncMapUintUintV(v, fastpathCheckNilTrue, e) + case *map[uint]uint: + fastpathTV.EncMapUintUintV(*v, fastpathCheckNilTrue, e) + + case map[uint]uint8: + fastpathTV.EncMapUintUint8V(v, fastpathCheckNilTrue, e) + case *map[uint]uint8: + fastpathTV.EncMapUintUint8V(*v, fastpathCheckNilTrue, e) + + case map[uint]uint16: + fastpathTV.EncMapUintUint16V(v, fastpathCheckNilTrue, e) + case *map[uint]uint16: + fastpathTV.EncMapUintUint16V(*v, fastpathCheckNilTrue, e) + + case map[uint]uint32: + fastpathTV.EncMapUintUint32V(v, fastpathCheckNilTrue, e) + case *map[uint]uint32: + fastpathTV.EncMapUintUint32V(*v, fastpathCheckNilTrue, e) + + case map[uint]uint64: + fastpathTV.EncMapUintUint64V(v, fastpathCheckNilTrue, e) + case *map[uint]uint64: + fastpathTV.EncMapUintUint64V(*v, fastpathCheckNilTrue, e) + + case map[uint]int: + fastpathTV.EncMapUintIntV(v, fastpathCheckNilTrue, e) + case *map[uint]int: + fastpathTV.EncMapUintIntV(*v, fastpathCheckNilTrue, e) + + case map[uint]int8: + fastpathTV.EncMapUintInt8V(v, fastpathCheckNilTrue, e) + case *map[uint]int8: + fastpathTV.EncMapUintInt8V(*v, fastpathCheckNilTrue, e) + + case map[uint]int16: + fastpathTV.EncMapUintInt16V(v, fastpathCheckNilTrue, e) + case *map[uint]int16: + fastpathTV.EncMapUintInt16V(*v, fastpathCheckNilTrue, e) + + case map[uint]int32: + fastpathTV.EncMapUintInt32V(v, fastpathCheckNilTrue, e) + case *map[uint]int32: + fastpathTV.EncMapUintInt32V(*v, fastpathCheckNilTrue, e) + + case map[uint]int64: + fastpathTV.EncMapUintInt64V(v, fastpathCheckNilTrue, e) + case *map[uint]int64: + fastpathTV.EncMapUintInt64V(*v, fastpathCheckNilTrue, e) + + case map[uint]float32: + fastpathTV.EncMapUintFloat32V(v, fastpathCheckNilTrue, e) + case *map[uint]float32: + fastpathTV.EncMapUintFloat32V(*v, fastpathCheckNilTrue, e) + + case map[uint]float64: + fastpathTV.EncMapUintFloat64V(v, fastpathCheckNilTrue, e) + case *map[uint]float64: + fastpathTV.EncMapUintFloat64V(*v, fastpathCheckNilTrue, e) + + case map[uint]bool: + fastpathTV.EncMapUintBoolV(v, fastpathCheckNilTrue, e) + case *map[uint]bool: + fastpathTV.EncMapUintBoolV(*v, fastpathCheckNilTrue, e) + + case map[uint8]interface{}: + fastpathTV.EncMapUint8IntfV(v, fastpathCheckNilTrue, e) + case *map[uint8]interface{}: + fastpathTV.EncMapUint8IntfV(*v, fastpathCheckNilTrue, e) + + case map[uint8]string: + fastpathTV.EncMapUint8StringV(v, fastpathCheckNilTrue, e) + case *map[uint8]string: + fastpathTV.EncMapUint8StringV(*v, fastpathCheckNilTrue, e) + + case map[uint8]uint: + fastpathTV.EncMapUint8UintV(v, fastpathCheckNilTrue, e) + case *map[uint8]uint: + fastpathTV.EncMapUint8UintV(*v, fastpathCheckNilTrue, e) + + case map[uint8]uint8: + fastpathTV.EncMapUint8Uint8V(v, fastpathCheckNilTrue, e) + case *map[uint8]uint8: + fastpathTV.EncMapUint8Uint8V(*v, fastpathCheckNilTrue, e) + + case map[uint8]uint16: + fastpathTV.EncMapUint8Uint16V(v, fastpathCheckNilTrue, e) + case *map[uint8]uint16: + fastpathTV.EncMapUint8Uint16V(*v, fastpathCheckNilTrue, e) + + case map[uint8]uint32: + fastpathTV.EncMapUint8Uint32V(v, fastpathCheckNilTrue, e) + case *map[uint8]uint32: + fastpathTV.EncMapUint8Uint32V(*v, fastpathCheckNilTrue, e) + + case map[uint8]uint64: + fastpathTV.EncMapUint8Uint64V(v, fastpathCheckNilTrue, e) + case *map[uint8]uint64: + fastpathTV.EncMapUint8Uint64V(*v, fastpathCheckNilTrue, e) + + case map[uint8]int: + fastpathTV.EncMapUint8IntV(v, fastpathCheckNilTrue, e) + case *map[uint8]int: + fastpathTV.EncMapUint8IntV(*v, fastpathCheckNilTrue, e) + + case map[uint8]int8: + fastpathTV.EncMapUint8Int8V(v, fastpathCheckNilTrue, e) + case *map[uint8]int8: + fastpathTV.EncMapUint8Int8V(*v, fastpathCheckNilTrue, e) + + case map[uint8]int16: + fastpathTV.EncMapUint8Int16V(v, fastpathCheckNilTrue, e) + case *map[uint8]int16: + fastpathTV.EncMapUint8Int16V(*v, fastpathCheckNilTrue, e) + + case map[uint8]int32: + fastpathTV.EncMapUint8Int32V(v, fastpathCheckNilTrue, e) + case *map[uint8]int32: + fastpathTV.EncMapUint8Int32V(*v, fastpathCheckNilTrue, e) + + case map[uint8]int64: + fastpathTV.EncMapUint8Int64V(v, fastpathCheckNilTrue, e) + case *map[uint8]int64: + fastpathTV.EncMapUint8Int64V(*v, fastpathCheckNilTrue, e) + + case map[uint8]float32: + fastpathTV.EncMapUint8Float32V(v, fastpathCheckNilTrue, e) + case *map[uint8]float32: + fastpathTV.EncMapUint8Float32V(*v, fastpathCheckNilTrue, e) + + case map[uint8]float64: + fastpathTV.EncMapUint8Float64V(v, fastpathCheckNilTrue, e) + case *map[uint8]float64: + fastpathTV.EncMapUint8Float64V(*v, fastpathCheckNilTrue, e) + + case map[uint8]bool: + fastpathTV.EncMapUint8BoolV(v, fastpathCheckNilTrue, e) + case *map[uint8]bool: + fastpathTV.EncMapUint8BoolV(*v, fastpathCheckNilTrue, e) + + case map[uint16]interface{}: + fastpathTV.EncMapUint16IntfV(v, fastpathCheckNilTrue, e) + case *map[uint16]interface{}: + fastpathTV.EncMapUint16IntfV(*v, fastpathCheckNilTrue, e) + + case map[uint16]string: + fastpathTV.EncMapUint16StringV(v, fastpathCheckNilTrue, e) + case *map[uint16]string: + fastpathTV.EncMapUint16StringV(*v, fastpathCheckNilTrue, e) + + case map[uint16]uint: + fastpathTV.EncMapUint16UintV(v, fastpathCheckNilTrue, e) + case *map[uint16]uint: + fastpathTV.EncMapUint16UintV(*v, fastpathCheckNilTrue, e) + + case map[uint16]uint8: + fastpathTV.EncMapUint16Uint8V(v, fastpathCheckNilTrue, e) + case *map[uint16]uint8: + fastpathTV.EncMapUint16Uint8V(*v, fastpathCheckNilTrue, e) + + case map[uint16]uint16: + fastpathTV.EncMapUint16Uint16V(v, fastpathCheckNilTrue, e) + case *map[uint16]uint16: + fastpathTV.EncMapUint16Uint16V(*v, fastpathCheckNilTrue, e) + + case map[uint16]uint32: + fastpathTV.EncMapUint16Uint32V(v, fastpathCheckNilTrue, e) + case *map[uint16]uint32: + fastpathTV.EncMapUint16Uint32V(*v, fastpathCheckNilTrue, e) + + case map[uint16]uint64: + fastpathTV.EncMapUint16Uint64V(v, fastpathCheckNilTrue, e) + case *map[uint16]uint64: + fastpathTV.EncMapUint16Uint64V(*v, fastpathCheckNilTrue, e) + + case map[uint16]int: + fastpathTV.EncMapUint16IntV(v, fastpathCheckNilTrue, e) + case *map[uint16]int: + fastpathTV.EncMapUint16IntV(*v, fastpathCheckNilTrue, e) + + case map[uint16]int8: + fastpathTV.EncMapUint16Int8V(v, fastpathCheckNilTrue, e) + case *map[uint16]int8: + fastpathTV.EncMapUint16Int8V(*v, fastpathCheckNilTrue, e) + + case map[uint16]int16: + fastpathTV.EncMapUint16Int16V(v, fastpathCheckNilTrue, e) + case *map[uint16]int16: + fastpathTV.EncMapUint16Int16V(*v, fastpathCheckNilTrue, e) + + case map[uint16]int32: + fastpathTV.EncMapUint16Int32V(v, fastpathCheckNilTrue, e) + case *map[uint16]int32: + fastpathTV.EncMapUint16Int32V(*v, fastpathCheckNilTrue, e) + + case map[uint16]int64: + fastpathTV.EncMapUint16Int64V(v, fastpathCheckNilTrue, e) + case *map[uint16]int64: + fastpathTV.EncMapUint16Int64V(*v, fastpathCheckNilTrue, e) + + case map[uint16]float32: + fastpathTV.EncMapUint16Float32V(v, fastpathCheckNilTrue, e) + case *map[uint16]float32: + fastpathTV.EncMapUint16Float32V(*v, fastpathCheckNilTrue, e) + + case map[uint16]float64: + fastpathTV.EncMapUint16Float64V(v, fastpathCheckNilTrue, e) + case *map[uint16]float64: + fastpathTV.EncMapUint16Float64V(*v, fastpathCheckNilTrue, e) + + case map[uint16]bool: + fastpathTV.EncMapUint16BoolV(v, fastpathCheckNilTrue, e) + case *map[uint16]bool: + fastpathTV.EncMapUint16BoolV(*v, fastpathCheckNilTrue, e) + + case map[uint32]interface{}: + fastpathTV.EncMapUint32IntfV(v, fastpathCheckNilTrue, e) + case *map[uint32]interface{}: + fastpathTV.EncMapUint32IntfV(*v, fastpathCheckNilTrue, e) + + case map[uint32]string: + fastpathTV.EncMapUint32StringV(v, fastpathCheckNilTrue, e) + case *map[uint32]string: + fastpathTV.EncMapUint32StringV(*v, fastpathCheckNilTrue, e) + + case map[uint32]uint: + fastpathTV.EncMapUint32UintV(v, fastpathCheckNilTrue, e) + case *map[uint32]uint: + fastpathTV.EncMapUint32UintV(*v, fastpathCheckNilTrue, e) + + case map[uint32]uint8: + fastpathTV.EncMapUint32Uint8V(v, fastpathCheckNilTrue, e) + case *map[uint32]uint8: + fastpathTV.EncMapUint32Uint8V(*v, fastpathCheckNilTrue, e) + + case map[uint32]uint16: + fastpathTV.EncMapUint32Uint16V(v, fastpathCheckNilTrue, e) + case *map[uint32]uint16: + fastpathTV.EncMapUint32Uint16V(*v, fastpathCheckNilTrue, e) + + case map[uint32]uint32: + fastpathTV.EncMapUint32Uint32V(v, fastpathCheckNilTrue, e) + case *map[uint32]uint32: + fastpathTV.EncMapUint32Uint32V(*v, fastpathCheckNilTrue, e) + + case map[uint32]uint64: + fastpathTV.EncMapUint32Uint64V(v, fastpathCheckNilTrue, e) + case *map[uint32]uint64: + fastpathTV.EncMapUint32Uint64V(*v, fastpathCheckNilTrue, e) + + case map[uint32]int: + fastpathTV.EncMapUint32IntV(v, fastpathCheckNilTrue, e) + case *map[uint32]int: + fastpathTV.EncMapUint32IntV(*v, fastpathCheckNilTrue, e) + + case map[uint32]int8: + fastpathTV.EncMapUint32Int8V(v, fastpathCheckNilTrue, e) + case *map[uint32]int8: + fastpathTV.EncMapUint32Int8V(*v, fastpathCheckNilTrue, e) + + case map[uint32]int16: + fastpathTV.EncMapUint32Int16V(v, fastpathCheckNilTrue, e) + case *map[uint32]int16: + fastpathTV.EncMapUint32Int16V(*v, fastpathCheckNilTrue, e) + + case map[uint32]int32: + fastpathTV.EncMapUint32Int32V(v, fastpathCheckNilTrue, e) + case *map[uint32]int32: + fastpathTV.EncMapUint32Int32V(*v, fastpathCheckNilTrue, e) + + case map[uint32]int64: + fastpathTV.EncMapUint32Int64V(v, fastpathCheckNilTrue, e) + case *map[uint32]int64: + fastpathTV.EncMapUint32Int64V(*v, fastpathCheckNilTrue, e) + + case map[uint32]float32: + fastpathTV.EncMapUint32Float32V(v, fastpathCheckNilTrue, e) + case *map[uint32]float32: + fastpathTV.EncMapUint32Float32V(*v, fastpathCheckNilTrue, e) + + case map[uint32]float64: + fastpathTV.EncMapUint32Float64V(v, fastpathCheckNilTrue, e) + case *map[uint32]float64: + fastpathTV.EncMapUint32Float64V(*v, fastpathCheckNilTrue, e) + + case map[uint32]bool: + fastpathTV.EncMapUint32BoolV(v, fastpathCheckNilTrue, e) + case *map[uint32]bool: + fastpathTV.EncMapUint32BoolV(*v, fastpathCheckNilTrue, e) + + case map[uint64]interface{}: + fastpathTV.EncMapUint64IntfV(v, fastpathCheckNilTrue, e) + case *map[uint64]interface{}: + fastpathTV.EncMapUint64IntfV(*v, fastpathCheckNilTrue, e) + + case map[uint64]string: + fastpathTV.EncMapUint64StringV(v, fastpathCheckNilTrue, e) + case *map[uint64]string: + fastpathTV.EncMapUint64StringV(*v, fastpathCheckNilTrue, e) + + case map[uint64]uint: + fastpathTV.EncMapUint64UintV(v, fastpathCheckNilTrue, e) + case *map[uint64]uint: + fastpathTV.EncMapUint64UintV(*v, fastpathCheckNilTrue, e) + + case map[uint64]uint8: + fastpathTV.EncMapUint64Uint8V(v, fastpathCheckNilTrue, e) + case *map[uint64]uint8: + fastpathTV.EncMapUint64Uint8V(*v, fastpathCheckNilTrue, e) + + case map[uint64]uint16: + fastpathTV.EncMapUint64Uint16V(v, fastpathCheckNilTrue, e) + case *map[uint64]uint16: + fastpathTV.EncMapUint64Uint16V(*v, fastpathCheckNilTrue, e) + + case map[uint64]uint32: + fastpathTV.EncMapUint64Uint32V(v, fastpathCheckNilTrue, e) + case *map[uint64]uint32: + fastpathTV.EncMapUint64Uint32V(*v, fastpathCheckNilTrue, e) + + case map[uint64]uint64: + fastpathTV.EncMapUint64Uint64V(v, fastpathCheckNilTrue, e) + case *map[uint64]uint64: + fastpathTV.EncMapUint64Uint64V(*v, fastpathCheckNilTrue, e) + + case map[uint64]int: + fastpathTV.EncMapUint64IntV(v, fastpathCheckNilTrue, e) + case *map[uint64]int: + fastpathTV.EncMapUint64IntV(*v, fastpathCheckNilTrue, e) + + case map[uint64]int8: + fastpathTV.EncMapUint64Int8V(v, fastpathCheckNilTrue, e) + case *map[uint64]int8: + fastpathTV.EncMapUint64Int8V(*v, fastpathCheckNilTrue, e) + + case map[uint64]int16: + fastpathTV.EncMapUint64Int16V(v, fastpathCheckNilTrue, e) + case *map[uint64]int16: + fastpathTV.EncMapUint64Int16V(*v, fastpathCheckNilTrue, e) + + case map[uint64]int32: + fastpathTV.EncMapUint64Int32V(v, fastpathCheckNilTrue, e) + case *map[uint64]int32: + fastpathTV.EncMapUint64Int32V(*v, fastpathCheckNilTrue, e) + + case map[uint64]int64: + fastpathTV.EncMapUint64Int64V(v, fastpathCheckNilTrue, e) + case *map[uint64]int64: + fastpathTV.EncMapUint64Int64V(*v, fastpathCheckNilTrue, e) + + case map[uint64]float32: + fastpathTV.EncMapUint64Float32V(v, fastpathCheckNilTrue, e) + case *map[uint64]float32: + fastpathTV.EncMapUint64Float32V(*v, fastpathCheckNilTrue, e) + + case map[uint64]float64: + fastpathTV.EncMapUint64Float64V(v, fastpathCheckNilTrue, e) + case *map[uint64]float64: + fastpathTV.EncMapUint64Float64V(*v, fastpathCheckNilTrue, e) + + case map[uint64]bool: + fastpathTV.EncMapUint64BoolV(v, fastpathCheckNilTrue, e) + case *map[uint64]bool: + fastpathTV.EncMapUint64BoolV(*v, fastpathCheckNilTrue, e) + + case map[int]interface{}: + fastpathTV.EncMapIntIntfV(v, fastpathCheckNilTrue, e) + case *map[int]interface{}: + fastpathTV.EncMapIntIntfV(*v, fastpathCheckNilTrue, e) + + case map[int]string: + fastpathTV.EncMapIntStringV(v, fastpathCheckNilTrue, e) + case *map[int]string: + fastpathTV.EncMapIntStringV(*v, fastpathCheckNilTrue, e) + + case map[int]uint: + fastpathTV.EncMapIntUintV(v, fastpathCheckNilTrue, e) + case *map[int]uint: + fastpathTV.EncMapIntUintV(*v, fastpathCheckNilTrue, e) + + case map[int]uint8: + fastpathTV.EncMapIntUint8V(v, fastpathCheckNilTrue, e) + case *map[int]uint8: + fastpathTV.EncMapIntUint8V(*v, fastpathCheckNilTrue, e) + + case map[int]uint16: + fastpathTV.EncMapIntUint16V(v, fastpathCheckNilTrue, e) + case *map[int]uint16: + fastpathTV.EncMapIntUint16V(*v, fastpathCheckNilTrue, e) + + case map[int]uint32: + fastpathTV.EncMapIntUint32V(v, fastpathCheckNilTrue, e) + case *map[int]uint32: + fastpathTV.EncMapIntUint32V(*v, fastpathCheckNilTrue, e) + + case map[int]uint64: + fastpathTV.EncMapIntUint64V(v, fastpathCheckNilTrue, e) + case *map[int]uint64: + fastpathTV.EncMapIntUint64V(*v, fastpathCheckNilTrue, e) + + case map[int]int: + fastpathTV.EncMapIntIntV(v, fastpathCheckNilTrue, e) + case *map[int]int: + fastpathTV.EncMapIntIntV(*v, fastpathCheckNilTrue, e) + + case map[int]int8: + fastpathTV.EncMapIntInt8V(v, fastpathCheckNilTrue, e) + case *map[int]int8: + fastpathTV.EncMapIntInt8V(*v, fastpathCheckNilTrue, e) + + case map[int]int16: + fastpathTV.EncMapIntInt16V(v, fastpathCheckNilTrue, e) + case *map[int]int16: + fastpathTV.EncMapIntInt16V(*v, fastpathCheckNilTrue, e) + + case map[int]int32: + fastpathTV.EncMapIntInt32V(v, fastpathCheckNilTrue, e) + case *map[int]int32: + fastpathTV.EncMapIntInt32V(*v, fastpathCheckNilTrue, e) + + case map[int]int64: + fastpathTV.EncMapIntInt64V(v, fastpathCheckNilTrue, e) + case *map[int]int64: + fastpathTV.EncMapIntInt64V(*v, fastpathCheckNilTrue, e) + + case map[int]float32: + fastpathTV.EncMapIntFloat32V(v, fastpathCheckNilTrue, e) + case *map[int]float32: + fastpathTV.EncMapIntFloat32V(*v, fastpathCheckNilTrue, e) + + case map[int]float64: + fastpathTV.EncMapIntFloat64V(v, fastpathCheckNilTrue, e) + case *map[int]float64: + fastpathTV.EncMapIntFloat64V(*v, fastpathCheckNilTrue, e) + + case map[int]bool: + fastpathTV.EncMapIntBoolV(v, fastpathCheckNilTrue, e) + case *map[int]bool: + fastpathTV.EncMapIntBoolV(*v, fastpathCheckNilTrue, e) + + case map[int8]interface{}: + fastpathTV.EncMapInt8IntfV(v, fastpathCheckNilTrue, e) + case *map[int8]interface{}: + fastpathTV.EncMapInt8IntfV(*v, fastpathCheckNilTrue, e) + + case map[int8]string: + fastpathTV.EncMapInt8StringV(v, fastpathCheckNilTrue, e) + case *map[int8]string: + fastpathTV.EncMapInt8StringV(*v, fastpathCheckNilTrue, e) + + case map[int8]uint: + fastpathTV.EncMapInt8UintV(v, fastpathCheckNilTrue, e) + case *map[int8]uint: + fastpathTV.EncMapInt8UintV(*v, fastpathCheckNilTrue, e) + + case map[int8]uint8: + fastpathTV.EncMapInt8Uint8V(v, fastpathCheckNilTrue, e) + case *map[int8]uint8: + fastpathTV.EncMapInt8Uint8V(*v, fastpathCheckNilTrue, e) + + case map[int8]uint16: + fastpathTV.EncMapInt8Uint16V(v, fastpathCheckNilTrue, e) + case *map[int8]uint16: + fastpathTV.EncMapInt8Uint16V(*v, fastpathCheckNilTrue, e) + + case map[int8]uint32: + fastpathTV.EncMapInt8Uint32V(v, fastpathCheckNilTrue, e) + case *map[int8]uint32: + fastpathTV.EncMapInt8Uint32V(*v, fastpathCheckNilTrue, e) + + case map[int8]uint64: + fastpathTV.EncMapInt8Uint64V(v, fastpathCheckNilTrue, e) + case *map[int8]uint64: + fastpathTV.EncMapInt8Uint64V(*v, fastpathCheckNilTrue, e) + + case map[int8]int: + fastpathTV.EncMapInt8IntV(v, fastpathCheckNilTrue, e) + case *map[int8]int: + fastpathTV.EncMapInt8IntV(*v, fastpathCheckNilTrue, e) + + case map[int8]int8: + fastpathTV.EncMapInt8Int8V(v, fastpathCheckNilTrue, e) + case *map[int8]int8: + fastpathTV.EncMapInt8Int8V(*v, fastpathCheckNilTrue, e) + + case map[int8]int16: + fastpathTV.EncMapInt8Int16V(v, fastpathCheckNilTrue, e) + case *map[int8]int16: + fastpathTV.EncMapInt8Int16V(*v, fastpathCheckNilTrue, e) + + case map[int8]int32: + fastpathTV.EncMapInt8Int32V(v, fastpathCheckNilTrue, e) + case *map[int8]int32: + fastpathTV.EncMapInt8Int32V(*v, fastpathCheckNilTrue, e) + + case map[int8]int64: + fastpathTV.EncMapInt8Int64V(v, fastpathCheckNilTrue, e) + case *map[int8]int64: + fastpathTV.EncMapInt8Int64V(*v, fastpathCheckNilTrue, e) + + case map[int8]float32: + fastpathTV.EncMapInt8Float32V(v, fastpathCheckNilTrue, e) + case *map[int8]float32: + fastpathTV.EncMapInt8Float32V(*v, fastpathCheckNilTrue, e) + + case map[int8]float64: + fastpathTV.EncMapInt8Float64V(v, fastpathCheckNilTrue, e) + case *map[int8]float64: + fastpathTV.EncMapInt8Float64V(*v, fastpathCheckNilTrue, e) + + case map[int8]bool: + fastpathTV.EncMapInt8BoolV(v, fastpathCheckNilTrue, e) + case *map[int8]bool: + fastpathTV.EncMapInt8BoolV(*v, fastpathCheckNilTrue, e) + + case map[int16]interface{}: + fastpathTV.EncMapInt16IntfV(v, fastpathCheckNilTrue, e) + case *map[int16]interface{}: + fastpathTV.EncMapInt16IntfV(*v, fastpathCheckNilTrue, e) + + case map[int16]string: + fastpathTV.EncMapInt16StringV(v, fastpathCheckNilTrue, e) + case *map[int16]string: + fastpathTV.EncMapInt16StringV(*v, fastpathCheckNilTrue, e) + + case map[int16]uint: + fastpathTV.EncMapInt16UintV(v, fastpathCheckNilTrue, e) + case *map[int16]uint: + fastpathTV.EncMapInt16UintV(*v, fastpathCheckNilTrue, e) + + case map[int16]uint8: + fastpathTV.EncMapInt16Uint8V(v, fastpathCheckNilTrue, e) + case *map[int16]uint8: + fastpathTV.EncMapInt16Uint8V(*v, fastpathCheckNilTrue, e) + + case map[int16]uint16: + fastpathTV.EncMapInt16Uint16V(v, fastpathCheckNilTrue, e) + case *map[int16]uint16: + fastpathTV.EncMapInt16Uint16V(*v, fastpathCheckNilTrue, e) + + case map[int16]uint32: + fastpathTV.EncMapInt16Uint32V(v, fastpathCheckNilTrue, e) + case *map[int16]uint32: + fastpathTV.EncMapInt16Uint32V(*v, fastpathCheckNilTrue, e) + + case map[int16]uint64: + fastpathTV.EncMapInt16Uint64V(v, fastpathCheckNilTrue, e) + case *map[int16]uint64: + fastpathTV.EncMapInt16Uint64V(*v, fastpathCheckNilTrue, e) + + case map[int16]int: + fastpathTV.EncMapInt16IntV(v, fastpathCheckNilTrue, e) + case *map[int16]int: + fastpathTV.EncMapInt16IntV(*v, fastpathCheckNilTrue, e) + + case map[int16]int8: + fastpathTV.EncMapInt16Int8V(v, fastpathCheckNilTrue, e) + case *map[int16]int8: + fastpathTV.EncMapInt16Int8V(*v, fastpathCheckNilTrue, e) + + case map[int16]int16: + fastpathTV.EncMapInt16Int16V(v, fastpathCheckNilTrue, e) + case *map[int16]int16: + fastpathTV.EncMapInt16Int16V(*v, fastpathCheckNilTrue, e) + + case map[int16]int32: + fastpathTV.EncMapInt16Int32V(v, fastpathCheckNilTrue, e) + case *map[int16]int32: + fastpathTV.EncMapInt16Int32V(*v, fastpathCheckNilTrue, e) + + case map[int16]int64: + fastpathTV.EncMapInt16Int64V(v, fastpathCheckNilTrue, e) + case *map[int16]int64: + fastpathTV.EncMapInt16Int64V(*v, fastpathCheckNilTrue, e) + + case map[int16]float32: + fastpathTV.EncMapInt16Float32V(v, fastpathCheckNilTrue, e) + case *map[int16]float32: + fastpathTV.EncMapInt16Float32V(*v, fastpathCheckNilTrue, e) + + case map[int16]float64: + fastpathTV.EncMapInt16Float64V(v, fastpathCheckNilTrue, e) + case *map[int16]float64: + fastpathTV.EncMapInt16Float64V(*v, fastpathCheckNilTrue, e) + + case map[int16]bool: + fastpathTV.EncMapInt16BoolV(v, fastpathCheckNilTrue, e) + case *map[int16]bool: + fastpathTV.EncMapInt16BoolV(*v, fastpathCheckNilTrue, e) + + case map[int32]interface{}: + fastpathTV.EncMapInt32IntfV(v, fastpathCheckNilTrue, e) + case *map[int32]interface{}: + fastpathTV.EncMapInt32IntfV(*v, fastpathCheckNilTrue, e) + + case map[int32]string: + fastpathTV.EncMapInt32StringV(v, fastpathCheckNilTrue, e) + case *map[int32]string: + fastpathTV.EncMapInt32StringV(*v, fastpathCheckNilTrue, e) + + case map[int32]uint: + fastpathTV.EncMapInt32UintV(v, fastpathCheckNilTrue, e) + case *map[int32]uint: + fastpathTV.EncMapInt32UintV(*v, fastpathCheckNilTrue, e) + + case map[int32]uint8: + fastpathTV.EncMapInt32Uint8V(v, fastpathCheckNilTrue, e) + case *map[int32]uint8: + fastpathTV.EncMapInt32Uint8V(*v, fastpathCheckNilTrue, e) + + case map[int32]uint16: + fastpathTV.EncMapInt32Uint16V(v, fastpathCheckNilTrue, e) + case *map[int32]uint16: + fastpathTV.EncMapInt32Uint16V(*v, fastpathCheckNilTrue, e) + + case map[int32]uint32: + fastpathTV.EncMapInt32Uint32V(v, fastpathCheckNilTrue, e) + case *map[int32]uint32: + fastpathTV.EncMapInt32Uint32V(*v, fastpathCheckNilTrue, e) + + case map[int32]uint64: + fastpathTV.EncMapInt32Uint64V(v, fastpathCheckNilTrue, e) + case *map[int32]uint64: + fastpathTV.EncMapInt32Uint64V(*v, fastpathCheckNilTrue, e) + + case map[int32]int: + fastpathTV.EncMapInt32IntV(v, fastpathCheckNilTrue, e) + case *map[int32]int: + fastpathTV.EncMapInt32IntV(*v, fastpathCheckNilTrue, e) + + case map[int32]int8: + fastpathTV.EncMapInt32Int8V(v, fastpathCheckNilTrue, e) + case *map[int32]int8: + fastpathTV.EncMapInt32Int8V(*v, fastpathCheckNilTrue, e) + + case map[int32]int16: + fastpathTV.EncMapInt32Int16V(v, fastpathCheckNilTrue, e) + case *map[int32]int16: + fastpathTV.EncMapInt32Int16V(*v, fastpathCheckNilTrue, e) + + case map[int32]int32: + fastpathTV.EncMapInt32Int32V(v, fastpathCheckNilTrue, e) + case *map[int32]int32: + fastpathTV.EncMapInt32Int32V(*v, fastpathCheckNilTrue, e) + + case map[int32]int64: + fastpathTV.EncMapInt32Int64V(v, fastpathCheckNilTrue, e) + case *map[int32]int64: + fastpathTV.EncMapInt32Int64V(*v, fastpathCheckNilTrue, e) + + case map[int32]float32: + fastpathTV.EncMapInt32Float32V(v, fastpathCheckNilTrue, e) + case *map[int32]float32: + fastpathTV.EncMapInt32Float32V(*v, fastpathCheckNilTrue, e) + + case map[int32]float64: + fastpathTV.EncMapInt32Float64V(v, fastpathCheckNilTrue, e) + case *map[int32]float64: + fastpathTV.EncMapInt32Float64V(*v, fastpathCheckNilTrue, e) + + case map[int32]bool: + fastpathTV.EncMapInt32BoolV(v, fastpathCheckNilTrue, e) + case *map[int32]bool: + fastpathTV.EncMapInt32BoolV(*v, fastpathCheckNilTrue, e) + + case map[int64]interface{}: + fastpathTV.EncMapInt64IntfV(v, fastpathCheckNilTrue, e) + case *map[int64]interface{}: + fastpathTV.EncMapInt64IntfV(*v, fastpathCheckNilTrue, e) + + case map[int64]string: + fastpathTV.EncMapInt64StringV(v, fastpathCheckNilTrue, e) + case *map[int64]string: + fastpathTV.EncMapInt64StringV(*v, fastpathCheckNilTrue, e) + + case map[int64]uint: + fastpathTV.EncMapInt64UintV(v, fastpathCheckNilTrue, e) + case *map[int64]uint: + fastpathTV.EncMapInt64UintV(*v, fastpathCheckNilTrue, e) + + case map[int64]uint8: + fastpathTV.EncMapInt64Uint8V(v, fastpathCheckNilTrue, e) + case *map[int64]uint8: + fastpathTV.EncMapInt64Uint8V(*v, fastpathCheckNilTrue, e) + + case map[int64]uint16: + fastpathTV.EncMapInt64Uint16V(v, fastpathCheckNilTrue, e) + case *map[int64]uint16: + fastpathTV.EncMapInt64Uint16V(*v, fastpathCheckNilTrue, e) + + case map[int64]uint32: + fastpathTV.EncMapInt64Uint32V(v, fastpathCheckNilTrue, e) + case *map[int64]uint32: + fastpathTV.EncMapInt64Uint32V(*v, fastpathCheckNilTrue, e) + + case map[int64]uint64: + fastpathTV.EncMapInt64Uint64V(v, fastpathCheckNilTrue, e) + case *map[int64]uint64: + fastpathTV.EncMapInt64Uint64V(*v, fastpathCheckNilTrue, e) + + case map[int64]int: + fastpathTV.EncMapInt64IntV(v, fastpathCheckNilTrue, e) + case *map[int64]int: + fastpathTV.EncMapInt64IntV(*v, fastpathCheckNilTrue, e) + + case map[int64]int8: + fastpathTV.EncMapInt64Int8V(v, fastpathCheckNilTrue, e) + case *map[int64]int8: + fastpathTV.EncMapInt64Int8V(*v, fastpathCheckNilTrue, e) + + case map[int64]int16: + fastpathTV.EncMapInt64Int16V(v, fastpathCheckNilTrue, e) + case *map[int64]int16: + fastpathTV.EncMapInt64Int16V(*v, fastpathCheckNilTrue, e) + + case map[int64]int32: + fastpathTV.EncMapInt64Int32V(v, fastpathCheckNilTrue, e) + case *map[int64]int32: + fastpathTV.EncMapInt64Int32V(*v, fastpathCheckNilTrue, e) + + case map[int64]int64: + fastpathTV.EncMapInt64Int64V(v, fastpathCheckNilTrue, e) + case *map[int64]int64: + fastpathTV.EncMapInt64Int64V(*v, fastpathCheckNilTrue, e) + + case map[int64]float32: + fastpathTV.EncMapInt64Float32V(v, fastpathCheckNilTrue, e) + case *map[int64]float32: + fastpathTV.EncMapInt64Float32V(*v, fastpathCheckNilTrue, e) + + case map[int64]float64: + fastpathTV.EncMapInt64Float64V(v, fastpathCheckNilTrue, e) + case *map[int64]float64: + fastpathTV.EncMapInt64Float64V(*v, fastpathCheckNilTrue, e) + + case map[int64]bool: + fastpathTV.EncMapInt64BoolV(v, fastpathCheckNilTrue, e) + case *map[int64]bool: + fastpathTV.EncMapInt64BoolV(*v, fastpathCheckNilTrue, e) + + case map[bool]interface{}: + fastpathTV.EncMapBoolIntfV(v, fastpathCheckNilTrue, e) + case *map[bool]interface{}: + fastpathTV.EncMapBoolIntfV(*v, fastpathCheckNilTrue, e) + + case map[bool]string: + fastpathTV.EncMapBoolStringV(v, fastpathCheckNilTrue, e) + case *map[bool]string: + fastpathTV.EncMapBoolStringV(*v, fastpathCheckNilTrue, e) + + case map[bool]uint: + fastpathTV.EncMapBoolUintV(v, fastpathCheckNilTrue, e) + case *map[bool]uint: + fastpathTV.EncMapBoolUintV(*v, fastpathCheckNilTrue, e) + + case map[bool]uint8: + fastpathTV.EncMapBoolUint8V(v, fastpathCheckNilTrue, e) + case *map[bool]uint8: + fastpathTV.EncMapBoolUint8V(*v, fastpathCheckNilTrue, e) + + case map[bool]uint16: + fastpathTV.EncMapBoolUint16V(v, fastpathCheckNilTrue, e) + case *map[bool]uint16: + fastpathTV.EncMapBoolUint16V(*v, fastpathCheckNilTrue, e) + + case map[bool]uint32: + fastpathTV.EncMapBoolUint32V(v, fastpathCheckNilTrue, e) + case *map[bool]uint32: + fastpathTV.EncMapBoolUint32V(*v, fastpathCheckNilTrue, e) + + case map[bool]uint64: + fastpathTV.EncMapBoolUint64V(v, fastpathCheckNilTrue, e) + case *map[bool]uint64: + fastpathTV.EncMapBoolUint64V(*v, fastpathCheckNilTrue, e) + + case map[bool]int: + fastpathTV.EncMapBoolIntV(v, fastpathCheckNilTrue, e) + case *map[bool]int: + fastpathTV.EncMapBoolIntV(*v, fastpathCheckNilTrue, e) + + case map[bool]int8: + fastpathTV.EncMapBoolInt8V(v, fastpathCheckNilTrue, e) + case *map[bool]int8: + fastpathTV.EncMapBoolInt8V(*v, fastpathCheckNilTrue, e) + + case map[bool]int16: + fastpathTV.EncMapBoolInt16V(v, fastpathCheckNilTrue, e) + case *map[bool]int16: + fastpathTV.EncMapBoolInt16V(*v, fastpathCheckNilTrue, e) + + case map[bool]int32: + fastpathTV.EncMapBoolInt32V(v, fastpathCheckNilTrue, e) + case *map[bool]int32: + fastpathTV.EncMapBoolInt32V(*v, fastpathCheckNilTrue, e) + + case map[bool]int64: + fastpathTV.EncMapBoolInt64V(v, fastpathCheckNilTrue, e) + case *map[bool]int64: + fastpathTV.EncMapBoolInt64V(*v, fastpathCheckNilTrue, e) + + case map[bool]float32: + fastpathTV.EncMapBoolFloat32V(v, fastpathCheckNilTrue, e) + case *map[bool]float32: + fastpathTV.EncMapBoolFloat32V(*v, fastpathCheckNilTrue, e) + + case map[bool]float64: + fastpathTV.EncMapBoolFloat64V(v, fastpathCheckNilTrue, e) + case *map[bool]float64: + fastpathTV.EncMapBoolFloat64V(*v, fastpathCheckNilTrue, e) + + case map[bool]bool: + fastpathTV.EncMapBoolBoolV(v, fastpathCheckNilTrue, e) + case *map[bool]bool: + fastpathTV.EncMapBoolBoolV(*v, fastpathCheckNilTrue, e) + + default: + return false + } + return true +} + +// -- -- fast path functions + +func (f encFnInfo) fastpathEncSliceIntfR(rv reflect.Value) { + fastpathTV.EncSliceIntfV(rv.Interface().([]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceIntfV(v []interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + e.encode(v2) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + e.encode(v2) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceStringR(rv reflect.Value) { + fastpathTV.EncSliceStringV(rv.Interface().([]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceStringV(v []string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeString(c_UTF8, v2) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeString(c_UTF8, v2) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceFloat32R(rv reflect.Value) { + fastpathTV.EncSliceFloat32V(rv.Interface().([]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceFloat32V(v []float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeFloat32(v2) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeFloat32(v2) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceFloat64R(rv reflect.Value) { + fastpathTV.EncSliceFloat64V(rv.Interface().([]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceFloat64V(v []float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeFloat64(v2) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeFloat64(v2) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceUintR(rv reflect.Value) { + fastpathTV.EncSliceUintV(rv.Interface().([]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceUintV(v []uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeUint(uint64(v2)) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeUint(uint64(v2)) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceUint16R(rv reflect.Value) { + fastpathTV.EncSliceUint16V(rv.Interface().([]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceUint16V(v []uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeUint(uint64(v2)) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeUint(uint64(v2)) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceUint32R(rv reflect.Value) { + fastpathTV.EncSliceUint32V(rv.Interface().([]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceUint32V(v []uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeUint(uint64(v2)) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeUint(uint64(v2)) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceUint64R(rv reflect.Value) { + fastpathTV.EncSliceUint64V(rv.Interface().([]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceUint64V(v []uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeUint(uint64(v2)) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeUint(uint64(v2)) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceIntR(rv reflect.Value) { + fastpathTV.EncSliceIntV(rv.Interface().([]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceIntV(v []int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeInt(int64(v2)) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeInt(int64(v2)) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceInt8R(rv reflect.Value) { + fastpathTV.EncSliceInt8V(rv.Interface().([]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceInt8V(v []int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeInt(int64(v2)) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeInt(int64(v2)) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceInt16R(rv reflect.Value) { + fastpathTV.EncSliceInt16V(rv.Interface().([]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceInt16V(v []int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeInt(int64(v2)) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeInt(int64(v2)) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceInt32R(rv reflect.Value) { + fastpathTV.EncSliceInt32V(rv.Interface().([]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceInt32V(v []int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeInt(int64(v2)) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeInt(int64(v2)) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceInt64R(rv reflect.Value) { + fastpathTV.EncSliceInt64V(rv.Interface().([]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceInt64V(v []int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeInt(int64(v2)) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeInt(int64(v2)) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncSliceBoolR(rv reflect.Value) { + fastpathTV.EncSliceBoolV(rv.Interface().([]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncSliceBoolV(v []bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + ee.EncodeBool(v2) + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + ee.EncodeBool(v2) + } + ee.EncodeArrayEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfIntfR(rv reflect.Value) { + fastpathTV.EncMapIntfIntfV(rv.Interface().(map[interface{}]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfIntfV(v map[interface{}]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfStringR(rv reflect.Value) { + fastpathTV.EncMapIntfStringV(rv.Interface().(map[interface{}]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfStringV(v map[interface{}]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfUintR(rv reflect.Value) { + fastpathTV.EncMapIntfUintV(rv.Interface().(map[interface{}]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfUintV(v map[interface{}]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfUint8R(rv reflect.Value) { + fastpathTV.EncMapIntfUint8V(rv.Interface().(map[interface{}]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfUint8V(v map[interface{}]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfUint16R(rv reflect.Value) { + fastpathTV.EncMapIntfUint16V(rv.Interface().(map[interface{}]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfUint16V(v map[interface{}]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfUint32R(rv reflect.Value) { + fastpathTV.EncMapIntfUint32V(rv.Interface().(map[interface{}]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfUint32V(v map[interface{}]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfUint64R(rv reflect.Value) { + fastpathTV.EncMapIntfUint64V(rv.Interface().(map[interface{}]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfUint64V(v map[interface{}]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfIntR(rv reflect.Value) { + fastpathTV.EncMapIntfIntV(rv.Interface().(map[interface{}]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfIntV(v map[interface{}]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfInt8R(rv reflect.Value) { + fastpathTV.EncMapIntfInt8V(rv.Interface().(map[interface{}]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfInt8V(v map[interface{}]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfInt16R(rv reflect.Value) { + fastpathTV.EncMapIntfInt16V(rv.Interface().(map[interface{}]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfInt16V(v map[interface{}]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfInt32R(rv reflect.Value) { + fastpathTV.EncMapIntfInt32V(rv.Interface().(map[interface{}]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfInt32V(v map[interface{}]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfInt64R(rv reflect.Value) { + fastpathTV.EncMapIntfInt64V(rv.Interface().(map[interface{}]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfInt64V(v map[interface{}]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfFloat32R(rv reflect.Value) { + fastpathTV.EncMapIntfFloat32V(rv.Interface().(map[interface{}]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfFloat32V(v map[interface{}]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfFloat64R(rv reflect.Value) { + fastpathTV.EncMapIntfFloat64V(rv.Interface().(map[interface{}]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfFloat64V(v map[interface{}]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntfBoolR(rv reflect.Value) { + fastpathTV.EncMapIntfBoolV(rv.Interface().(map[interface{}]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntfBoolV(v map[interface{}]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + e.encode(k2) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + e.encode(k2) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringIntfR(rv reflect.Value) { + fastpathTV.EncMapStringIntfV(rv.Interface().(map[string]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringIntfV(v map[string]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringStringR(rv reflect.Value) { + fastpathTV.EncMapStringStringV(rv.Interface().(map[string]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringStringV(v map[string]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringUintR(rv reflect.Value) { + fastpathTV.EncMapStringUintV(rv.Interface().(map[string]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringUintV(v map[string]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringUint8R(rv reflect.Value) { + fastpathTV.EncMapStringUint8V(rv.Interface().(map[string]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringUint8V(v map[string]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringUint16R(rv reflect.Value) { + fastpathTV.EncMapStringUint16V(rv.Interface().(map[string]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringUint16V(v map[string]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringUint32R(rv reflect.Value) { + fastpathTV.EncMapStringUint32V(rv.Interface().(map[string]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringUint32V(v map[string]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringUint64R(rv reflect.Value) { + fastpathTV.EncMapStringUint64V(rv.Interface().(map[string]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringUint64V(v map[string]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringIntR(rv reflect.Value) { + fastpathTV.EncMapStringIntV(rv.Interface().(map[string]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringIntV(v map[string]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringInt8R(rv reflect.Value) { + fastpathTV.EncMapStringInt8V(rv.Interface().(map[string]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringInt8V(v map[string]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringInt16R(rv reflect.Value) { + fastpathTV.EncMapStringInt16V(rv.Interface().(map[string]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringInt16V(v map[string]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringInt32R(rv reflect.Value) { + fastpathTV.EncMapStringInt32V(rv.Interface().(map[string]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringInt32V(v map[string]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringInt64R(rv reflect.Value) { + fastpathTV.EncMapStringInt64V(rv.Interface().(map[string]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringInt64V(v map[string]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringFloat32R(rv reflect.Value) { + fastpathTV.EncMapStringFloat32V(rv.Interface().(map[string]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringFloat32V(v map[string]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringFloat64R(rv reflect.Value) { + fastpathTV.EncMapStringFloat64V(rv.Interface().(map[string]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringFloat64V(v map[string]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapStringBoolR(rv reflect.Value) { + fastpathTV.EncMapStringBoolV(rv.Interface().(map[string]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapStringBoolV(v map[string]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0 + if e.be { + for k2, v2 := range v { + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + } + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32IntfR(rv reflect.Value) { + fastpathTV.EncMapFloat32IntfV(rv.Interface().(map[float32]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32IntfV(v map[float32]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32StringR(rv reflect.Value) { + fastpathTV.EncMapFloat32StringV(rv.Interface().(map[float32]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32StringV(v map[float32]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32UintR(rv reflect.Value) { + fastpathTV.EncMapFloat32UintV(rv.Interface().(map[float32]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32UintV(v map[float32]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32Uint8R(rv reflect.Value) { + fastpathTV.EncMapFloat32Uint8V(rv.Interface().(map[float32]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32Uint8V(v map[float32]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32Uint16R(rv reflect.Value) { + fastpathTV.EncMapFloat32Uint16V(rv.Interface().(map[float32]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32Uint16V(v map[float32]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32Uint32R(rv reflect.Value) { + fastpathTV.EncMapFloat32Uint32V(rv.Interface().(map[float32]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32Uint32V(v map[float32]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32Uint64R(rv reflect.Value) { + fastpathTV.EncMapFloat32Uint64V(rv.Interface().(map[float32]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32Uint64V(v map[float32]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32IntR(rv reflect.Value) { + fastpathTV.EncMapFloat32IntV(rv.Interface().(map[float32]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32IntV(v map[float32]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32Int8R(rv reflect.Value) { + fastpathTV.EncMapFloat32Int8V(rv.Interface().(map[float32]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32Int8V(v map[float32]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32Int16R(rv reflect.Value) { + fastpathTV.EncMapFloat32Int16V(rv.Interface().(map[float32]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32Int16V(v map[float32]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32Int32R(rv reflect.Value) { + fastpathTV.EncMapFloat32Int32V(rv.Interface().(map[float32]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32Int32V(v map[float32]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32Int64R(rv reflect.Value) { + fastpathTV.EncMapFloat32Int64V(rv.Interface().(map[float32]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32Int64V(v map[float32]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32Float32R(rv reflect.Value) { + fastpathTV.EncMapFloat32Float32V(rv.Interface().(map[float32]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32Float32V(v map[float32]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32Float64R(rv reflect.Value) { + fastpathTV.EncMapFloat32Float64V(rv.Interface().(map[float32]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32Float64V(v map[float32]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat32BoolR(rv reflect.Value) { + fastpathTV.EncMapFloat32BoolV(rv.Interface().(map[float32]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat32BoolV(v map[float32]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat32(k2) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat32(k2) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64IntfR(rv reflect.Value) { + fastpathTV.EncMapFloat64IntfV(rv.Interface().(map[float64]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64IntfV(v map[float64]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64StringR(rv reflect.Value) { + fastpathTV.EncMapFloat64StringV(rv.Interface().(map[float64]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64StringV(v map[float64]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64UintR(rv reflect.Value) { + fastpathTV.EncMapFloat64UintV(rv.Interface().(map[float64]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64UintV(v map[float64]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64Uint8R(rv reflect.Value) { + fastpathTV.EncMapFloat64Uint8V(rv.Interface().(map[float64]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64Uint8V(v map[float64]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64Uint16R(rv reflect.Value) { + fastpathTV.EncMapFloat64Uint16V(rv.Interface().(map[float64]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64Uint16V(v map[float64]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64Uint32R(rv reflect.Value) { + fastpathTV.EncMapFloat64Uint32V(rv.Interface().(map[float64]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64Uint32V(v map[float64]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64Uint64R(rv reflect.Value) { + fastpathTV.EncMapFloat64Uint64V(rv.Interface().(map[float64]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64Uint64V(v map[float64]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64IntR(rv reflect.Value) { + fastpathTV.EncMapFloat64IntV(rv.Interface().(map[float64]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64IntV(v map[float64]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64Int8R(rv reflect.Value) { + fastpathTV.EncMapFloat64Int8V(rv.Interface().(map[float64]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64Int8V(v map[float64]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64Int16R(rv reflect.Value) { + fastpathTV.EncMapFloat64Int16V(rv.Interface().(map[float64]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64Int16V(v map[float64]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64Int32R(rv reflect.Value) { + fastpathTV.EncMapFloat64Int32V(rv.Interface().(map[float64]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64Int32V(v map[float64]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64Int64R(rv reflect.Value) { + fastpathTV.EncMapFloat64Int64V(rv.Interface().(map[float64]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64Int64V(v map[float64]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64Float32R(rv reflect.Value) { + fastpathTV.EncMapFloat64Float32V(rv.Interface().(map[float64]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64Float32V(v map[float64]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64Float64R(rv reflect.Value) { + fastpathTV.EncMapFloat64Float64V(rv.Interface().(map[float64]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64Float64V(v map[float64]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapFloat64BoolR(rv reflect.Value) { + fastpathTV.EncMapFloat64BoolV(rv.Interface().(map[float64]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapFloat64BoolV(v map[float64]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeFloat64(k2) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeFloat64(k2) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintIntfR(rv reflect.Value) { + fastpathTV.EncMapUintIntfV(rv.Interface().(map[uint]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintIntfV(v map[uint]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintStringR(rv reflect.Value) { + fastpathTV.EncMapUintStringV(rv.Interface().(map[uint]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintStringV(v map[uint]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintUintR(rv reflect.Value) { + fastpathTV.EncMapUintUintV(rv.Interface().(map[uint]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintUintV(v map[uint]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintUint8R(rv reflect.Value) { + fastpathTV.EncMapUintUint8V(rv.Interface().(map[uint]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintUint8V(v map[uint]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintUint16R(rv reflect.Value) { + fastpathTV.EncMapUintUint16V(rv.Interface().(map[uint]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintUint16V(v map[uint]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintUint32R(rv reflect.Value) { + fastpathTV.EncMapUintUint32V(rv.Interface().(map[uint]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintUint32V(v map[uint]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintUint64R(rv reflect.Value) { + fastpathTV.EncMapUintUint64V(rv.Interface().(map[uint]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintUint64V(v map[uint]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintIntR(rv reflect.Value) { + fastpathTV.EncMapUintIntV(rv.Interface().(map[uint]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintIntV(v map[uint]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintInt8R(rv reflect.Value) { + fastpathTV.EncMapUintInt8V(rv.Interface().(map[uint]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintInt8V(v map[uint]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintInt16R(rv reflect.Value) { + fastpathTV.EncMapUintInt16V(rv.Interface().(map[uint]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintInt16V(v map[uint]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintInt32R(rv reflect.Value) { + fastpathTV.EncMapUintInt32V(rv.Interface().(map[uint]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintInt32V(v map[uint]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintInt64R(rv reflect.Value) { + fastpathTV.EncMapUintInt64V(rv.Interface().(map[uint]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintInt64V(v map[uint]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintFloat32R(rv reflect.Value) { + fastpathTV.EncMapUintFloat32V(rv.Interface().(map[uint]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintFloat32V(v map[uint]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintFloat64R(rv reflect.Value) { + fastpathTV.EncMapUintFloat64V(rv.Interface().(map[uint]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintFloat64V(v map[uint]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUintBoolR(rv reflect.Value) { + fastpathTV.EncMapUintBoolV(rv.Interface().(map[uint]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUintBoolV(v map[uint]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8IntfR(rv reflect.Value) { + fastpathTV.EncMapUint8IntfV(rv.Interface().(map[uint8]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8IntfV(v map[uint8]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8StringR(rv reflect.Value) { + fastpathTV.EncMapUint8StringV(rv.Interface().(map[uint8]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8StringV(v map[uint8]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8UintR(rv reflect.Value) { + fastpathTV.EncMapUint8UintV(rv.Interface().(map[uint8]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8UintV(v map[uint8]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8Uint8R(rv reflect.Value) { + fastpathTV.EncMapUint8Uint8V(rv.Interface().(map[uint8]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8Uint8V(v map[uint8]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8Uint16R(rv reflect.Value) { + fastpathTV.EncMapUint8Uint16V(rv.Interface().(map[uint8]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8Uint16V(v map[uint8]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8Uint32R(rv reflect.Value) { + fastpathTV.EncMapUint8Uint32V(rv.Interface().(map[uint8]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8Uint32V(v map[uint8]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8Uint64R(rv reflect.Value) { + fastpathTV.EncMapUint8Uint64V(rv.Interface().(map[uint8]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8Uint64V(v map[uint8]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8IntR(rv reflect.Value) { + fastpathTV.EncMapUint8IntV(rv.Interface().(map[uint8]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8IntV(v map[uint8]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8Int8R(rv reflect.Value) { + fastpathTV.EncMapUint8Int8V(rv.Interface().(map[uint8]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8Int8V(v map[uint8]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8Int16R(rv reflect.Value) { + fastpathTV.EncMapUint8Int16V(rv.Interface().(map[uint8]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8Int16V(v map[uint8]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8Int32R(rv reflect.Value) { + fastpathTV.EncMapUint8Int32V(rv.Interface().(map[uint8]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8Int32V(v map[uint8]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8Int64R(rv reflect.Value) { + fastpathTV.EncMapUint8Int64V(rv.Interface().(map[uint8]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8Int64V(v map[uint8]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8Float32R(rv reflect.Value) { + fastpathTV.EncMapUint8Float32V(rv.Interface().(map[uint8]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8Float32V(v map[uint8]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8Float64R(rv reflect.Value) { + fastpathTV.EncMapUint8Float64V(rv.Interface().(map[uint8]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8Float64V(v map[uint8]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint8BoolR(rv reflect.Value) { + fastpathTV.EncMapUint8BoolV(rv.Interface().(map[uint8]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint8BoolV(v map[uint8]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16IntfR(rv reflect.Value) { + fastpathTV.EncMapUint16IntfV(rv.Interface().(map[uint16]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16IntfV(v map[uint16]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16StringR(rv reflect.Value) { + fastpathTV.EncMapUint16StringV(rv.Interface().(map[uint16]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16StringV(v map[uint16]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16UintR(rv reflect.Value) { + fastpathTV.EncMapUint16UintV(rv.Interface().(map[uint16]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16UintV(v map[uint16]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16Uint8R(rv reflect.Value) { + fastpathTV.EncMapUint16Uint8V(rv.Interface().(map[uint16]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16Uint8V(v map[uint16]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16Uint16R(rv reflect.Value) { + fastpathTV.EncMapUint16Uint16V(rv.Interface().(map[uint16]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16Uint16V(v map[uint16]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16Uint32R(rv reflect.Value) { + fastpathTV.EncMapUint16Uint32V(rv.Interface().(map[uint16]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16Uint32V(v map[uint16]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16Uint64R(rv reflect.Value) { + fastpathTV.EncMapUint16Uint64V(rv.Interface().(map[uint16]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16Uint64V(v map[uint16]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16IntR(rv reflect.Value) { + fastpathTV.EncMapUint16IntV(rv.Interface().(map[uint16]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16IntV(v map[uint16]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16Int8R(rv reflect.Value) { + fastpathTV.EncMapUint16Int8V(rv.Interface().(map[uint16]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16Int8V(v map[uint16]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16Int16R(rv reflect.Value) { + fastpathTV.EncMapUint16Int16V(rv.Interface().(map[uint16]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16Int16V(v map[uint16]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16Int32R(rv reflect.Value) { + fastpathTV.EncMapUint16Int32V(rv.Interface().(map[uint16]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16Int32V(v map[uint16]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16Int64R(rv reflect.Value) { + fastpathTV.EncMapUint16Int64V(rv.Interface().(map[uint16]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16Int64V(v map[uint16]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16Float32R(rv reflect.Value) { + fastpathTV.EncMapUint16Float32V(rv.Interface().(map[uint16]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16Float32V(v map[uint16]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16Float64R(rv reflect.Value) { + fastpathTV.EncMapUint16Float64V(rv.Interface().(map[uint16]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16Float64V(v map[uint16]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint16BoolR(rv reflect.Value) { + fastpathTV.EncMapUint16BoolV(rv.Interface().(map[uint16]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint16BoolV(v map[uint16]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32IntfR(rv reflect.Value) { + fastpathTV.EncMapUint32IntfV(rv.Interface().(map[uint32]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32IntfV(v map[uint32]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32StringR(rv reflect.Value) { + fastpathTV.EncMapUint32StringV(rv.Interface().(map[uint32]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32StringV(v map[uint32]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32UintR(rv reflect.Value) { + fastpathTV.EncMapUint32UintV(rv.Interface().(map[uint32]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32UintV(v map[uint32]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32Uint8R(rv reflect.Value) { + fastpathTV.EncMapUint32Uint8V(rv.Interface().(map[uint32]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32Uint8V(v map[uint32]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32Uint16R(rv reflect.Value) { + fastpathTV.EncMapUint32Uint16V(rv.Interface().(map[uint32]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32Uint16V(v map[uint32]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32Uint32R(rv reflect.Value) { + fastpathTV.EncMapUint32Uint32V(rv.Interface().(map[uint32]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32Uint32V(v map[uint32]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32Uint64R(rv reflect.Value) { + fastpathTV.EncMapUint32Uint64V(rv.Interface().(map[uint32]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32Uint64V(v map[uint32]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32IntR(rv reflect.Value) { + fastpathTV.EncMapUint32IntV(rv.Interface().(map[uint32]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32IntV(v map[uint32]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32Int8R(rv reflect.Value) { + fastpathTV.EncMapUint32Int8V(rv.Interface().(map[uint32]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32Int8V(v map[uint32]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32Int16R(rv reflect.Value) { + fastpathTV.EncMapUint32Int16V(rv.Interface().(map[uint32]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32Int16V(v map[uint32]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32Int32R(rv reflect.Value) { + fastpathTV.EncMapUint32Int32V(rv.Interface().(map[uint32]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32Int32V(v map[uint32]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32Int64R(rv reflect.Value) { + fastpathTV.EncMapUint32Int64V(rv.Interface().(map[uint32]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32Int64V(v map[uint32]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32Float32R(rv reflect.Value) { + fastpathTV.EncMapUint32Float32V(rv.Interface().(map[uint32]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32Float32V(v map[uint32]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32Float64R(rv reflect.Value) { + fastpathTV.EncMapUint32Float64V(rv.Interface().(map[uint32]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32Float64V(v map[uint32]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint32BoolR(rv reflect.Value) { + fastpathTV.EncMapUint32BoolV(rv.Interface().(map[uint32]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint32BoolV(v map[uint32]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64IntfR(rv reflect.Value) { + fastpathTV.EncMapUint64IntfV(rv.Interface().(map[uint64]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64IntfV(v map[uint64]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64StringR(rv reflect.Value) { + fastpathTV.EncMapUint64StringV(rv.Interface().(map[uint64]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64StringV(v map[uint64]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64UintR(rv reflect.Value) { + fastpathTV.EncMapUint64UintV(rv.Interface().(map[uint64]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64UintV(v map[uint64]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64Uint8R(rv reflect.Value) { + fastpathTV.EncMapUint64Uint8V(rv.Interface().(map[uint64]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64Uint8V(v map[uint64]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64Uint16R(rv reflect.Value) { + fastpathTV.EncMapUint64Uint16V(rv.Interface().(map[uint64]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64Uint16V(v map[uint64]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64Uint32R(rv reflect.Value) { + fastpathTV.EncMapUint64Uint32V(rv.Interface().(map[uint64]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64Uint32V(v map[uint64]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64Uint64R(rv reflect.Value) { + fastpathTV.EncMapUint64Uint64V(rv.Interface().(map[uint64]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64Uint64V(v map[uint64]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64IntR(rv reflect.Value) { + fastpathTV.EncMapUint64IntV(rv.Interface().(map[uint64]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64IntV(v map[uint64]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64Int8R(rv reflect.Value) { + fastpathTV.EncMapUint64Int8V(rv.Interface().(map[uint64]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64Int8V(v map[uint64]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64Int16R(rv reflect.Value) { + fastpathTV.EncMapUint64Int16V(rv.Interface().(map[uint64]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64Int16V(v map[uint64]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64Int32R(rv reflect.Value) { + fastpathTV.EncMapUint64Int32V(rv.Interface().(map[uint64]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64Int32V(v map[uint64]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64Int64R(rv reflect.Value) { + fastpathTV.EncMapUint64Int64V(rv.Interface().(map[uint64]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64Int64V(v map[uint64]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64Float32R(rv reflect.Value) { + fastpathTV.EncMapUint64Float32V(rv.Interface().(map[uint64]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64Float32V(v map[uint64]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64Float64R(rv reflect.Value) { + fastpathTV.EncMapUint64Float64V(rv.Interface().(map[uint64]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64Float64V(v map[uint64]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapUint64BoolR(rv reflect.Value) { + fastpathTV.EncMapUint64BoolV(rv.Interface().(map[uint64]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapUint64BoolV(v map[uint64]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeUint(uint64(k2)) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeUint(uint64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntIntfR(rv reflect.Value) { + fastpathTV.EncMapIntIntfV(rv.Interface().(map[int]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntIntfV(v map[int]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntStringR(rv reflect.Value) { + fastpathTV.EncMapIntStringV(rv.Interface().(map[int]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntStringV(v map[int]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntUintR(rv reflect.Value) { + fastpathTV.EncMapIntUintV(rv.Interface().(map[int]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntUintV(v map[int]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntUint8R(rv reflect.Value) { + fastpathTV.EncMapIntUint8V(rv.Interface().(map[int]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntUint8V(v map[int]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntUint16R(rv reflect.Value) { + fastpathTV.EncMapIntUint16V(rv.Interface().(map[int]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntUint16V(v map[int]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntUint32R(rv reflect.Value) { + fastpathTV.EncMapIntUint32V(rv.Interface().(map[int]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntUint32V(v map[int]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntUint64R(rv reflect.Value) { + fastpathTV.EncMapIntUint64V(rv.Interface().(map[int]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntUint64V(v map[int]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntIntR(rv reflect.Value) { + fastpathTV.EncMapIntIntV(rv.Interface().(map[int]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntIntV(v map[int]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntInt8R(rv reflect.Value) { + fastpathTV.EncMapIntInt8V(rv.Interface().(map[int]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntInt8V(v map[int]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntInt16R(rv reflect.Value) { + fastpathTV.EncMapIntInt16V(rv.Interface().(map[int]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntInt16V(v map[int]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntInt32R(rv reflect.Value) { + fastpathTV.EncMapIntInt32V(rv.Interface().(map[int]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntInt32V(v map[int]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntInt64R(rv reflect.Value) { + fastpathTV.EncMapIntInt64V(rv.Interface().(map[int]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntInt64V(v map[int]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntFloat32R(rv reflect.Value) { + fastpathTV.EncMapIntFloat32V(rv.Interface().(map[int]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntFloat32V(v map[int]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntFloat64R(rv reflect.Value) { + fastpathTV.EncMapIntFloat64V(rv.Interface().(map[int]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntFloat64V(v map[int]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapIntBoolR(rv reflect.Value) { + fastpathTV.EncMapIntBoolV(rv.Interface().(map[int]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapIntBoolV(v map[int]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8IntfR(rv reflect.Value) { + fastpathTV.EncMapInt8IntfV(rv.Interface().(map[int8]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8IntfV(v map[int8]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8StringR(rv reflect.Value) { + fastpathTV.EncMapInt8StringV(rv.Interface().(map[int8]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8StringV(v map[int8]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8UintR(rv reflect.Value) { + fastpathTV.EncMapInt8UintV(rv.Interface().(map[int8]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8UintV(v map[int8]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8Uint8R(rv reflect.Value) { + fastpathTV.EncMapInt8Uint8V(rv.Interface().(map[int8]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8Uint8V(v map[int8]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8Uint16R(rv reflect.Value) { + fastpathTV.EncMapInt8Uint16V(rv.Interface().(map[int8]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8Uint16V(v map[int8]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8Uint32R(rv reflect.Value) { + fastpathTV.EncMapInt8Uint32V(rv.Interface().(map[int8]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8Uint32V(v map[int8]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8Uint64R(rv reflect.Value) { + fastpathTV.EncMapInt8Uint64V(rv.Interface().(map[int8]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8Uint64V(v map[int8]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8IntR(rv reflect.Value) { + fastpathTV.EncMapInt8IntV(rv.Interface().(map[int8]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8IntV(v map[int8]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8Int8R(rv reflect.Value) { + fastpathTV.EncMapInt8Int8V(rv.Interface().(map[int8]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8Int8V(v map[int8]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8Int16R(rv reflect.Value) { + fastpathTV.EncMapInt8Int16V(rv.Interface().(map[int8]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8Int16V(v map[int8]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8Int32R(rv reflect.Value) { + fastpathTV.EncMapInt8Int32V(rv.Interface().(map[int8]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8Int32V(v map[int8]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8Int64R(rv reflect.Value) { + fastpathTV.EncMapInt8Int64V(rv.Interface().(map[int8]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8Int64V(v map[int8]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8Float32R(rv reflect.Value) { + fastpathTV.EncMapInt8Float32V(rv.Interface().(map[int8]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8Float32V(v map[int8]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8Float64R(rv reflect.Value) { + fastpathTV.EncMapInt8Float64V(rv.Interface().(map[int8]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8Float64V(v map[int8]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt8BoolR(rv reflect.Value) { + fastpathTV.EncMapInt8BoolV(rv.Interface().(map[int8]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt8BoolV(v map[int8]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16IntfR(rv reflect.Value) { + fastpathTV.EncMapInt16IntfV(rv.Interface().(map[int16]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16IntfV(v map[int16]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16StringR(rv reflect.Value) { + fastpathTV.EncMapInt16StringV(rv.Interface().(map[int16]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16StringV(v map[int16]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16UintR(rv reflect.Value) { + fastpathTV.EncMapInt16UintV(rv.Interface().(map[int16]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16UintV(v map[int16]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16Uint8R(rv reflect.Value) { + fastpathTV.EncMapInt16Uint8V(rv.Interface().(map[int16]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16Uint8V(v map[int16]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16Uint16R(rv reflect.Value) { + fastpathTV.EncMapInt16Uint16V(rv.Interface().(map[int16]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16Uint16V(v map[int16]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16Uint32R(rv reflect.Value) { + fastpathTV.EncMapInt16Uint32V(rv.Interface().(map[int16]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16Uint32V(v map[int16]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16Uint64R(rv reflect.Value) { + fastpathTV.EncMapInt16Uint64V(rv.Interface().(map[int16]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16Uint64V(v map[int16]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16IntR(rv reflect.Value) { + fastpathTV.EncMapInt16IntV(rv.Interface().(map[int16]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16IntV(v map[int16]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16Int8R(rv reflect.Value) { + fastpathTV.EncMapInt16Int8V(rv.Interface().(map[int16]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16Int8V(v map[int16]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16Int16R(rv reflect.Value) { + fastpathTV.EncMapInt16Int16V(rv.Interface().(map[int16]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16Int16V(v map[int16]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16Int32R(rv reflect.Value) { + fastpathTV.EncMapInt16Int32V(rv.Interface().(map[int16]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16Int32V(v map[int16]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16Int64R(rv reflect.Value) { + fastpathTV.EncMapInt16Int64V(rv.Interface().(map[int16]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16Int64V(v map[int16]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16Float32R(rv reflect.Value) { + fastpathTV.EncMapInt16Float32V(rv.Interface().(map[int16]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16Float32V(v map[int16]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16Float64R(rv reflect.Value) { + fastpathTV.EncMapInt16Float64V(rv.Interface().(map[int16]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16Float64V(v map[int16]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt16BoolR(rv reflect.Value) { + fastpathTV.EncMapInt16BoolV(rv.Interface().(map[int16]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt16BoolV(v map[int16]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32IntfR(rv reflect.Value) { + fastpathTV.EncMapInt32IntfV(rv.Interface().(map[int32]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32IntfV(v map[int32]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32StringR(rv reflect.Value) { + fastpathTV.EncMapInt32StringV(rv.Interface().(map[int32]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32StringV(v map[int32]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32UintR(rv reflect.Value) { + fastpathTV.EncMapInt32UintV(rv.Interface().(map[int32]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32UintV(v map[int32]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32Uint8R(rv reflect.Value) { + fastpathTV.EncMapInt32Uint8V(rv.Interface().(map[int32]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32Uint8V(v map[int32]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32Uint16R(rv reflect.Value) { + fastpathTV.EncMapInt32Uint16V(rv.Interface().(map[int32]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32Uint16V(v map[int32]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32Uint32R(rv reflect.Value) { + fastpathTV.EncMapInt32Uint32V(rv.Interface().(map[int32]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32Uint32V(v map[int32]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32Uint64R(rv reflect.Value) { + fastpathTV.EncMapInt32Uint64V(rv.Interface().(map[int32]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32Uint64V(v map[int32]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32IntR(rv reflect.Value) { + fastpathTV.EncMapInt32IntV(rv.Interface().(map[int32]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32IntV(v map[int32]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32Int8R(rv reflect.Value) { + fastpathTV.EncMapInt32Int8V(rv.Interface().(map[int32]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32Int8V(v map[int32]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32Int16R(rv reflect.Value) { + fastpathTV.EncMapInt32Int16V(rv.Interface().(map[int32]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32Int16V(v map[int32]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32Int32R(rv reflect.Value) { + fastpathTV.EncMapInt32Int32V(rv.Interface().(map[int32]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32Int32V(v map[int32]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32Int64R(rv reflect.Value) { + fastpathTV.EncMapInt32Int64V(rv.Interface().(map[int32]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32Int64V(v map[int32]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32Float32R(rv reflect.Value) { + fastpathTV.EncMapInt32Float32V(rv.Interface().(map[int32]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32Float32V(v map[int32]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32Float64R(rv reflect.Value) { + fastpathTV.EncMapInt32Float64V(rv.Interface().(map[int32]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32Float64V(v map[int32]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt32BoolR(rv reflect.Value) { + fastpathTV.EncMapInt32BoolV(rv.Interface().(map[int32]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt32BoolV(v map[int32]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64IntfR(rv reflect.Value) { + fastpathTV.EncMapInt64IntfV(rv.Interface().(map[int64]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64IntfV(v map[int64]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64StringR(rv reflect.Value) { + fastpathTV.EncMapInt64StringV(rv.Interface().(map[int64]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64StringV(v map[int64]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64UintR(rv reflect.Value) { + fastpathTV.EncMapInt64UintV(rv.Interface().(map[int64]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64UintV(v map[int64]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64Uint8R(rv reflect.Value) { + fastpathTV.EncMapInt64Uint8V(rv.Interface().(map[int64]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64Uint8V(v map[int64]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64Uint16R(rv reflect.Value) { + fastpathTV.EncMapInt64Uint16V(rv.Interface().(map[int64]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64Uint16V(v map[int64]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64Uint32R(rv reflect.Value) { + fastpathTV.EncMapInt64Uint32V(rv.Interface().(map[int64]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64Uint32V(v map[int64]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64Uint64R(rv reflect.Value) { + fastpathTV.EncMapInt64Uint64V(rv.Interface().(map[int64]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64Uint64V(v map[int64]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64IntR(rv reflect.Value) { + fastpathTV.EncMapInt64IntV(rv.Interface().(map[int64]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64IntV(v map[int64]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64Int8R(rv reflect.Value) { + fastpathTV.EncMapInt64Int8V(rv.Interface().(map[int64]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64Int8V(v map[int64]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64Int16R(rv reflect.Value) { + fastpathTV.EncMapInt64Int16V(rv.Interface().(map[int64]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64Int16V(v map[int64]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64Int32R(rv reflect.Value) { + fastpathTV.EncMapInt64Int32V(rv.Interface().(map[int64]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64Int32V(v map[int64]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64Int64R(rv reflect.Value) { + fastpathTV.EncMapInt64Int64V(rv.Interface().(map[int64]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64Int64V(v map[int64]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64Float32R(rv reflect.Value) { + fastpathTV.EncMapInt64Float32V(rv.Interface().(map[int64]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64Float32V(v map[int64]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64Float64R(rv reflect.Value) { + fastpathTV.EncMapInt64Float64V(rv.Interface().(map[int64]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64Float64V(v map[int64]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapInt64BoolR(rv reflect.Value) { + fastpathTV.EncMapInt64BoolV(rv.Interface().(map[int64]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapInt64BoolV(v map[int64]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeInt(int64(k2)) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeInt(int64(k2)) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolIntfR(rv reflect.Value) { + fastpathTV.EncMapBoolIntfV(rv.Interface().(map[bool]interface{}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolIntfV(v map[bool]interface{}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + e.encode(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + e.encode(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolStringR(rv reflect.Value) { + fastpathTV.EncMapBoolStringV(rv.Interface().(map[bool]string), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolStringV(v map[bool]string, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeString(c_UTF8, v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeString(c_UTF8, v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolUintR(rv reflect.Value) { + fastpathTV.EncMapBoolUintV(rv.Interface().(map[bool]uint), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolUintV(v map[bool]uint, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolUint8R(rv reflect.Value) { + fastpathTV.EncMapBoolUint8V(rv.Interface().(map[bool]uint8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolUint8V(v map[bool]uint8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolUint16R(rv reflect.Value) { + fastpathTV.EncMapBoolUint16V(rv.Interface().(map[bool]uint16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolUint16V(v map[bool]uint16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolUint32R(rv reflect.Value) { + fastpathTV.EncMapBoolUint32V(rv.Interface().(map[bool]uint32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolUint32V(v map[bool]uint32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolUint64R(rv reflect.Value) { + fastpathTV.EncMapBoolUint64V(rv.Interface().(map[bool]uint64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolUint64V(v map[bool]uint64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeUint(uint64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeUint(uint64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolIntR(rv reflect.Value) { + fastpathTV.EncMapBoolIntV(rv.Interface().(map[bool]int), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolIntV(v map[bool]int, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolInt8R(rv reflect.Value) { + fastpathTV.EncMapBoolInt8V(rv.Interface().(map[bool]int8), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolInt8V(v map[bool]int8, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolInt16R(rv reflect.Value) { + fastpathTV.EncMapBoolInt16V(rv.Interface().(map[bool]int16), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolInt16V(v map[bool]int16, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolInt32R(rv reflect.Value) { + fastpathTV.EncMapBoolInt32V(rv.Interface().(map[bool]int32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolInt32V(v map[bool]int32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolInt64R(rv reflect.Value) { + fastpathTV.EncMapBoolInt64V(rv.Interface().(map[bool]int64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolInt64V(v map[bool]int64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeInt(int64(v2)) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeInt(int64(v2)) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolFloat32R(rv reflect.Value) { + fastpathTV.EncMapBoolFloat32V(rv.Interface().(map[bool]float32), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolFloat32V(v map[bool]float32, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeFloat32(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeFloat32(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolFloat64R(rv reflect.Value) { + fastpathTV.EncMapBoolFloat64V(rv.Interface().(map[bool]float64), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolFloat64V(v map[bool]float64, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeFloat64(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeFloat64(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +func (f encFnInfo) fastpathEncMapBoolBoolR(rv reflect.Value) { + fastpathTV.EncMapBoolBoolV(rv.Interface().(map[bool]bool), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) EncMapBoolBoolV(v map[bool]bool, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + + if e.be { + for k2, v2 := range v { + ee.EncodeBool(k2) + ee.EncodeBool(v2) + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + ee.EncodeBool(k2) + ee.EncodeMapKVSeparator() + ee.EncodeBool(v2) + j++ + } + ee.EncodeMapEnd() + } +} + +// -- decode + +// -- -- fast path type switch +func fastpathDecodeTypeSwitch(iv interface{}, d *Decoder) bool { + switch v := iv.(type) { + + case []interface{}: + fastpathTV.DecSliceIntfV(v, fastpathCheckNilFalse, false, d) + case *[]interface{}: + v2, changed2 := fastpathTV.DecSliceIntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]interface{}: + fastpathTV.DecMapIntfIntfV(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]interface{}: + v2, changed2 := fastpathTV.DecMapIntfIntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]string: + fastpathTV.DecMapIntfStringV(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]string: + v2, changed2 := fastpathTV.DecMapIntfStringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]uint: + fastpathTV.DecMapIntfUintV(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]uint: + v2, changed2 := fastpathTV.DecMapIntfUintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]uint8: + fastpathTV.DecMapIntfUint8V(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]uint8: + v2, changed2 := fastpathTV.DecMapIntfUint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]uint16: + fastpathTV.DecMapIntfUint16V(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]uint16: + v2, changed2 := fastpathTV.DecMapIntfUint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]uint32: + fastpathTV.DecMapIntfUint32V(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]uint32: + v2, changed2 := fastpathTV.DecMapIntfUint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]uint64: + fastpathTV.DecMapIntfUint64V(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]uint64: + v2, changed2 := fastpathTV.DecMapIntfUint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]int: + fastpathTV.DecMapIntfIntV(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]int: + v2, changed2 := fastpathTV.DecMapIntfIntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]int8: + fastpathTV.DecMapIntfInt8V(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]int8: + v2, changed2 := fastpathTV.DecMapIntfInt8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]int16: + fastpathTV.DecMapIntfInt16V(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]int16: + v2, changed2 := fastpathTV.DecMapIntfInt16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]int32: + fastpathTV.DecMapIntfInt32V(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]int32: + v2, changed2 := fastpathTV.DecMapIntfInt32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]int64: + fastpathTV.DecMapIntfInt64V(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]int64: + v2, changed2 := fastpathTV.DecMapIntfInt64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]float32: + fastpathTV.DecMapIntfFloat32V(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]float32: + v2, changed2 := fastpathTV.DecMapIntfFloat32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]float64: + fastpathTV.DecMapIntfFloat64V(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]float64: + v2, changed2 := fastpathTV.DecMapIntfFloat64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[interface{}]bool: + fastpathTV.DecMapIntfBoolV(v, fastpathCheckNilFalse, false, d) + case *map[interface{}]bool: + v2, changed2 := fastpathTV.DecMapIntfBoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []string: + fastpathTV.DecSliceStringV(v, fastpathCheckNilFalse, false, d) + case *[]string: + v2, changed2 := fastpathTV.DecSliceStringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]interface{}: + fastpathTV.DecMapStringIntfV(v, fastpathCheckNilFalse, false, d) + case *map[string]interface{}: + v2, changed2 := fastpathTV.DecMapStringIntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]string: + fastpathTV.DecMapStringStringV(v, fastpathCheckNilFalse, false, d) + case *map[string]string: + v2, changed2 := fastpathTV.DecMapStringStringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]uint: + fastpathTV.DecMapStringUintV(v, fastpathCheckNilFalse, false, d) + case *map[string]uint: + v2, changed2 := fastpathTV.DecMapStringUintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]uint8: + fastpathTV.DecMapStringUint8V(v, fastpathCheckNilFalse, false, d) + case *map[string]uint8: + v2, changed2 := fastpathTV.DecMapStringUint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]uint16: + fastpathTV.DecMapStringUint16V(v, fastpathCheckNilFalse, false, d) + case *map[string]uint16: + v2, changed2 := fastpathTV.DecMapStringUint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]uint32: + fastpathTV.DecMapStringUint32V(v, fastpathCheckNilFalse, false, d) + case *map[string]uint32: + v2, changed2 := fastpathTV.DecMapStringUint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]uint64: + fastpathTV.DecMapStringUint64V(v, fastpathCheckNilFalse, false, d) + case *map[string]uint64: + v2, changed2 := fastpathTV.DecMapStringUint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]int: + fastpathTV.DecMapStringIntV(v, fastpathCheckNilFalse, false, d) + case *map[string]int: + v2, changed2 := fastpathTV.DecMapStringIntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]int8: + fastpathTV.DecMapStringInt8V(v, fastpathCheckNilFalse, false, d) + case *map[string]int8: + v2, changed2 := fastpathTV.DecMapStringInt8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]int16: + fastpathTV.DecMapStringInt16V(v, fastpathCheckNilFalse, false, d) + case *map[string]int16: + v2, changed2 := fastpathTV.DecMapStringInt16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]int32: + fastpathTV.DecMapStringInt32V(v, fastpathCheckNilFalse, false, d) + case *map[string]int32: + v2, changed2 := fastpathTV.DecMapStringInt32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]int64: + fastpathTV.DecMapStringInt64V(v, fastpathCheckNilFalse, false, d) + case *map[string]int64: + v2, changed2 := fastpathTV.DecMapStringInt64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]float32: + fastpathTV.DecMapStringFloat32V(v, fastpathCheckNilFalse, false, d) + case *map[string]float32: + v2, changed2 := fastpathTV.DecMapStringFloat32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]float64: + fastpathTV.DecMapStringFloat64V(v, fastpathCheckNilFalse, false, d) + case *map[string]float64: + v2, changed2 := fastpathTV.DecMapStringFloat64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[string]bool: + fastpathTV.DecMapStringBoolV(v, fastpathCheckNilFalse, false, d) + case *map[string]bool: + v2, changed2 := fastpathTV.DecMapStringBoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []float32: + fastpathTV.DecSliceFloat32V(v, fastpathCheckNilFalse, false, d) + case *[]float32: + v2, changed2 := fastpathTV.DecSliceFloat32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]interface{}: + fastpathTV.DecMapFloat32IntfV(v, fastpathCheckNilFalse, false, d) + case *map[float32]interface{}: + v2, changed2 := fastpathTV.DecMapFloat32IntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]string: + fastpathTV.DecMapFloat32StringV(v, fastpathCheckNilFalse, false, d) + case *map[float32]string: + v2, changed2 := fastpathTV.DecMapFloat32StringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]uint: + fastpathTV.DecMapFloat32UintV(v, fastpathCheckNilFalse, false, d) + case *map[float32]uint: + v2, changed2 := fastpathTV.DecMapFloat32UintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]uint8: + fastpathTV.DecMapFloat32Uint8V(v, fastpathCheckNilFalse, false, d) + case *map[float32]uint8: + v2, changed2 := fastpathTV.DecMapFloat32Uint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]uint16: + fastpathTV.DecMapFloat32Uint16V(v, fastpathCheckNilFalse, false, d) + case *map[float32]uint16: + v2, changed2 := fastpathTV.DecMapFloat32Uint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]uint32: + fastpathTV.DecMapFloat32Uint32V(v, fastpathCheckNilFalse, false, d) + case *map[float32]uint32: + v2, changed2 := fastpathTV.DecMapFloat32Uint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]uint64: + fastpathTV.DecMapFloat32Uint64V(v, fastpathCheckNilFalse, false, d) + case *map[float32]uint64: + v2, changed2 := fastpathTV.DecMapFloat32Uint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]int: + fastpathTV.DecMapFloat32IntV(v, fastpathCheckNilFalse, false, d) + case *map[float32]int: + v2, changed2 := fastpathTV.DecMapFloat32IntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]int8: + fastpathTV.DecMapFloat32Int8V(v, fastpathCheckNilFalse, false, d) + case *map[float32]int8: + v2, changed2 := fastpathTV.DecMapFloat32Int8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]int16: + fastpathTV.DecMapFloat32Int16V(v, fastpathCheckNilFalse, false, d) + case *map[float32]int16: + v2, changed2 := fastpathTV.DecMapFloat32Int16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]int32: + fastpathTV.DecMapFloat32Int32V(v, fastpathCheckNilFalse, false, d) + case *map[float32]int32: + v2, changed2 := fastpathTV.DecMapFloat32Int32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]int64: + fastpathTV.DecMapFloat32Int64V(v, fastpathCheckNilFalse, false, d) + case *map[float32]int64: + v2, changed2 := fastpathTV.DecMapFloat32Int64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]float32: + fastpathTV.DecMapFloat32Float32V(v, fastpathCheckNilFalse, false, d) + case *map[float32]float32: + v2, changed2 := fastpathTV.DecMapFloat32Float32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]float64: + fastpathTV.DecMapFloat32Float64V(v, fastpathCheckNilFalse, false, d) + case *map[float32]float64: + v2, changed2 := fastpathTV.DecMapFloat32Float64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float32]bool: + fastpathTV.DecMapFloat32BoolV(v, fastpathCheckNilFalse, false, d) + case *map[float32]bool: + v2, changed2 := fastpathTV.DecMapFloat32BoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []float64: + fastpathTV.DecSliceFloat64V(v, fastpathCheckNilFalse, false, d) + case *[]float64: + v2, changed2 := fastpathTV.DecSliceFloat64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]interface{}: + fastpathTV.DecMapFloat64IntfV(v, fastpathCheckNilFalse, false, d) + case *map[float64]interface{}: + v2, changed2 := fastpathTV.DecMapFloat64IntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]string: + fastpathTV.DecMapFloat64StringV(v, fastpathCheckNilFalse, false, d) + case *map[float64]string: + v2, changed2 := fastpathTV.DecMapFloat64StringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]uint: + fastpathTV.DecMapFloat64UintV(v, fastpathCheckNilFalse, false, d) + case *map[float64]uint: + v2, changed2 := fastpathTV.DecMapFloat64UintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]uint8: + fastpathTV.DecMapFloat64Uint8V(v, fastpathCheckNilFalse, false, d) + case *map[float64]uint8: + v2, changed2 := fastpathTV.DecMapFloat64Uint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]uint16: + fastpathTV.DecMapFloat64Uint16V(v, fastpathCheckNilFalse, false, d) + case *map[float64]uint16: + v2, changed2 := fastpathTV.DecMapFloat64Uint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]uint32: + fastpathTV.DecMapFloat64Uint32V(v, fastpathCheckNilFalse, false, d) + case *map[float64]uint32: + v2, changed2 := fastpathTV.DecMapFloat64Uint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]uint64: + fastpathTV.DecMapFloat64Uint64V(v, fastpathCheckNilFalse, false, d) + case *map[float64]uint64: + v2, changed2 := fastpathTV.DecMapFloat64Uint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]int: + fastpathTV.DecMapFloat64IntV(v, fastpathCheckNilFalse, false, d) + case *map[float64]int: + v2, changed2 := fastpathTV.DecMapFloat64IntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]int8: + fastpathTV.DecMapFloat64Int8V(v, fastpathCheckNilFalse, false, d) + case *map[float64]int8: + v2, changed2 := fastpathTV.DecMapFloat64Int8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]int16: + fastpathTV.DecMapFloat64Int16V(v, fastpathCheckNilFalse, false, d) + case *map[float64]int16: + v2, changed2 := fastpathTV.DecMapFloat64Int16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]int32: + fastpathTV.DecMapFloat64Int32V(v, fastpathCheckNilFalse, false, d) + case *map[float64]int32: + v2, changed2 := fastpathTV.DecMapFloat64Int32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]int64: + fastpathTV.DecMapFloat64Int64V(v, fastpathCheckNilFalse, false, d) + case *map[float64]int64: + v2, changed2 := fastpathTV.DecMapFloat64Int64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]float32: + fastpathTV.DecMapFloat64Float32V(v, fastpathCheckNilFalse, false, d) + case *map[float64]float32: + v2, changed2 := fastpathTV.DecMapFloat64Float32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]float64: + fastpathTV.DecMapFloat64Float64V(v, fastpathCheckNilFalse, false, d) + case *map[float64]float64: + v2, changed2 := fastpathTV.DecMapFloat64Float64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[float64]bool: + fastpathTV.DecMapFloat64BoolV(v, fastpathCheckNilFalse, false, d) + case *map[float64]bool: + v2, changed2 := fastpathTV.DecMapFloat64BoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []uint: + fastpathTV.DecSliceUintV(v, fastpathCheckNilFalse, false, d) + case *[]uint: + v2, changed2 := fastpathTV.DecSliceUintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]interface{}: + fastpathTV.DecMapUintIntfV(v, fastpathCheckNilFalse, false, d) + case *map[uint]interface{}: + v2, changed2 := fastpathTV.DecMapUintIntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]string: + fastpathTV.DecMapUintStringV(v, fastpathCheckNilFalse, false, d) + case *map[uint]string: + v2, changed2 := fastpathTV.DecMapUintStringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]uint: + fastpathTV.DecMapUintUintV(v, fastpathCheckNilFalse, false, d) + case *map[uint]uint: + v2, changed2 := fastpathTV.DecMapUintUintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]uint8: + fastpathTV.DecMapUintUint8V(v, fastpathCheckNilFalse, false, d) + case *map[uint]uint8: + v2, changed2 := fastpathTV.DecMapUintUint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]uint16: + fastpathTV.DecMapUintUint16V(v, fastpathCheckNilFalse, false, d) + case *map[uint]uint16: + v2, changed2 := fastpathTV.DecMapUintUint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]uint32: + fastpathTV.DecMapUintUint32V(v, fastpathCheckNilFalse, false, d) + case *map[uint]uint32: + v2, changed2 := fastpathTV.DecMapUintUint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]uint64: + fastpathTV.DecMapUintUint64V(v, fastpathCheckNilFalse, false, d) + case *map[uint]uint64: + v2, changed2 := fastpathTV.DecMapUintUint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]int: + fastpathTV.DecMapUintIntV(v, fastpathCheckNilFalse, false, d) + case *map[uint]int: + v2, changed2 := fastpathTV.DecMapUintIntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]int8: + fastpathTV.DecMapUintInt8V(v, fastpathCheckNilFalse, false, d) + case *map[uint]int8: + v2, changed2 := fastpathTV.DecMapUintInt8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]int16: + fastpathTV.DecMapUintInt16V(v, fastpathCheckNilFalse, false, d) + case *map[uint]int16: + v2, changed2 := fastpathTV.DecMapUintInt16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]int32: + fastpathTV.DecMapUintInt32V(v, fastpathCheckNilFalse, false, d) + case *map[uint]int32: + v2, changed2 := fastpathTV.DecMapUintInt32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]int64: + fastpathTV.DecMapUintInt64V(v, fastpathCheckNilFalse, false, d) + case *map[uint]int64: + v2, changed2 := fastpathTV.DecMapUintInt64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]float32: + fastpathTV.DecMapUintFloat32V(v, fastpathCheckNilFalse, false, d) + case *map[uint]float32: + v2, changed2 := fastpathTV.DecMapUintFloat32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]float64: + fastpathTV.DecMapUintFloat64V(v, fastpathCheckNilFalse, false, d) + case *map[uint]float64: + v2, changed2 := fastpathTV.DecMapUintFloat64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint]bool: + fastpathTV.DecMapUintBoolV(v, fastpathCheckNilFalse, false, d) + case *map[uint]bool: + v2, changed2 := fastpathTV.DecMapUintBoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]interface{}: + fastpathTV.DecMapUint8IntfV(v, fastpathCheckNilFalse, false, d) + case *map[uint8]interface{}: + v2, changed2 := fastpathTV.DecMapUint8IntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]string: + fastpathTV.DecMapUint8StringV(v, fastpathCheckNilFalse, false, d) + case *map[uint8]string: + v2, changed2 := fastpathTV.DecMapUint8StringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]uint: + fastpathTV.DecMapUint8UintV(v, fastpathCheckNilFalse, false, d) + case *map[uint8]uint: + v2, changed2 := fastpathTV.DecMapUint8UintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]uint8: + fastpathTV.DecMapUint8Uint8V(v, fastpathCheckNilFalse, false, d) + case *map[uint8]uint8: + v2, changed2 := fastpathTV.DecMapUint8Uint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]uint16: + fastpathTV.DecMapUint8Uint16V(v, fastpathCheckNilFalse, false, d) + case *map[uint8]uint16: + v2, changed2 := fastpathTV.DecMapUint8Uint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]uint32: + fastpathTV.DecMapUint8Uint32V(v, fastpathCheckNilFalse, false, d) + case *map[uint8]uint32: + v2, changed2 := fastpathTV.DecMapUint8Uint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]uint64: + fastpathTV.DecMapUint8Uint64V(v, fastpathCheckNilFalse, false, d) + case *map[uint8]uint64: + v2, changed2 := fastpathTV.DecMapUint8Uint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]int: + fastpathTV.DecMapUint8IntV(v, fastpathCheckNilFalse, false, d) + case *map[uint8]int: + v2, changed2 := fastpathTV.DecMapUint8IntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]int8: + fastpathTV.DecMapUint8Int8V(v, fastpathCheckNilFalse, false, d) + case *map[uint8]int8: + v2, changed2 := fastpathTV.DecMapUint8Int8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]int16: + fastpathTV.DecMapUint8Int16V(v, fastpathCheckNilFalse, false, d) + case *map[uint8]int16: + v2, changed2 := fastpathTV.DecMapUint8Int16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]int32: + fastpathTV.DecMapUint8Int32V(v, fastpathCheckNilFalse, false, d) + case *map[uint8]int32: + v2, changed2 := fastpathTV.DecMapUint8Int32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]int64: + fastpathTV.DecMapUint8Int64V(v, fastpathCheckNilFalse, false, d) + case *map[uint8]int64: + v2, changed2 := fastpathTV.DecMapUint8Int64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]float32: + fastpathTV.DecMapUint8Float32V(v, fastpathCheckNilFalse, false, d) + case *map[uint8]float32: + v2, changed2 := fastpathTV.DecMapUint8Float32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]float64: + fastpathTV.DecMapUint8Float64V(v, fastpathCheckNilFalse, false, d) + case *map[uint8]float64: + v2, changed2 := fastpathTV.DecMapUint8Float64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint8]bool: + fastpathTV.DecMapUint8BoolV(v, fastpathCheckNilFalse, false, d) + case *map[uint8]bool: + v2, changed2 := fastpathTV.DecMapUint8BoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []uint16: + fastpathTV.DecSliceUint16V(v, fastpathCheckNilFalse, false, d) + case *[]uint16: + v2, changed2 := fastpathTV.DecSliceUint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]interface{}: + fastpathTV.DecMapUint16IntfV(v, fastpathCheckNilFalse, false, d) + case *map[uint16]interface{}: + v2, changed2 := fastpathTV.DecMapUint16IntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]string: + fastpathTV.DecMapUint16StringV(v, fastpathCheckNilFalse, false, d) + case *map[uint16]string: + v2, changed2 := fastpathTV.DecMapUint16StringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]uint: + fastpathTV.DecMapUint16UintV(v, fastpathCheckNilFalse, false, d) + case *map[uint16]uint: + v2, changed2 := fastpathTV.DecMapUint16UintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]uint8: + fastpathTV.DecMapUint16Uint8V(v, fastpathCheckNilFalse, false, d) + case *map[uint16]uint8: + v2, changed2 := fastpathTV.DecMapUint16Uint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]uint16: + fastpathTV.DecMapUint16Uint16V(v, fastpathCheckNilFalse, false, d) + case *map[uint16]uint16: + v2, changed2 := fastpathTV.DecMapUint16Uint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]uint32: + fastpathTV.DecMapUint16Uint32V(v, fastpathCheckNilFalse, false, d) + case *map[uint16]uint32: + v2, changed2 := fastpathTV.DecMapUint16Uint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]uint64: + fastpathTV.DecMapUint16Uint64V(v, fastpathCheckNilFalse, false, d) + case *map[uint16]uint64: + v2, changed2 := fastpathTV.DecMapUint16Uint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]int: + fastpathTV.DecMapUint16IntV(v, fastpathCheckNilFalse, false, d) + case *map[uint16]int: + v2, changed2 := fastpathTV.DecMapUint16IntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]int8: + fastpathTV.DecMapUint16Int8V(v, fastpathCheckNilFalse, false, d) + case *map[uint16]int8: + v2, changed2 := fastpathTV.DecMapUint16Int8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]int16: + fastpathTV.DecMapUint16Int16V(v, fastpathCheckNilFalse, false, d) + case *map[uint16]int16: + v2, changed2 := fastpathTV.DecMapUint16Int16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]int32: + fastpathTV.DecMapUint16Int32V(v, fastpathCheckNilFalse, false, d) + case *map[uint16]int32: + v2, changed2 := fastpathTV.DecMapUint16Int32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]int64: + fastpathTV.DecMapUint16Int64V(v, fastpathCheckNilFalse, false, d) + case *map[uint16]int64: + v2, changed2 := fastpathTV.DecMapUint16Int64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]float32: + fastpathTV.DecMapUint16Float32V(v, fastpathCheckNilFalse, false, d) + case *map[uint16]float32: + v2, changed2 := fastpathTV.DecMapUint16Float32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]float64: + fastpathTV.DecMapUint16Float64V(v, fastpathCheckNilFalse, false, d) + case *map[uint16]float64: + v2, changed2 := fastpathTV.DecMapUint16Float64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint16]bool: + fastpathTV.DecMapUint16BoolV(v, fastpathCheckNilFalse, false, d) + case *map[uint16]bool: + v2, changed2 := fastpathTV.DecMapUint16BoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []uint32: + fastpathTV.DecSliceUint32V(v, fastpathCheckNilFalse, false, d) + case *[]uint32: + v2, changed2 := fastpathTV.DecSliceUint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]interface{}: + fastpathTV.DecMapUint32IntfV(v, fastpathCheckNilFalse, false, d) + case *map[uint32]interface{}: + v2, changed2 := fastpathTV.DecMapUint32IntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]string: + fastpathTV.DecMapUint32StringV(v, fastpathCheckNilFalse, false, d) + case *map[uint32]string: + v2, changed2 := fastpathTV.DecMapUint32StringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]uint: + fastpathTV.DecMapUint32UintV(v, fastpathCheckNilFalse, false, d) + case *map[uint32]uint: + v2, changed2 := fastpathTV.DecMapUint32UintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]uint8: + fastpathTV.DecMapUint32Uint8V(v, fastpathCheckNilFalse, false, d) + case *map[uint32]uint8: + v2, changed2 := fastpathTV.DecMapUint32Uint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]uint16: + fastpathTV.DecMapUint32Uint16V(v, fastpathCheckNilFalse, false, d) + case *map[uint32]uint16: + v2, changed2 := fastpathTV.DecMapUint32Uint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]uint32: + fastpathTV.DecMapUint32Uint32V(v, fastpathCheckNilFalse, false, d) + case *map[uint32]uint32: + v2, changed2 := fastpathTV.DecMapUint32Uint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]uint64: + fastpathTV.DecMapUint32Uint64V(v, fastpathCheckNilFalse, false, d) + case *map[uint32]uint64: + v2, changed2 := fastpathTV.DecMapUint32Uint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]int: + fastpathTV.DecMapUint32IntV(v, fastpathCheckNilFalse, false, d) + case *map[uint32]int: + v2, changed2 := fastpathTV.DecMapUint32IntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]int8: + fastpathTV.DecMapUint32Int8V(v, fastpathCheckNilFalse, false, d) + case *map[uint32]int8: + v2, changed2 := fastpathTV.DecMapUint32Int8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]int16: + fastpathTV.DecMapUint32Int16V(v, fastpathCheckNilFalse, false, d) + case *map[uint32]int16: + v2, changed2 := fastpathTV.DecMapUint32Int16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]int32: + fastpathTV.DecMapUint32Int32V(v, fastpathCheckNilFalse, false, d) + case *map[uint32]int32: + v2, changed2 := fastpathTV.DecMapUint32Int32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]int64: + fastpathTV.DecMapUint32Int64V(v, fastpathCheckNilFalse, false, d) + case *map[uint32]int64: + v2, changed2 := fastpathTV.DecMapUint32Int64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]float32: + fastpathTV.DecMapUint32Float32V(v, fastpathCheckNilFalse, false, d) + case *map[uint32]float32: + v2, changed2 := fastpathTV.DecMapUint32Float32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]float64: + fastpathTV.DecMapUint32Float64V(v, fastpathCheckNilFalse, false, d) + case *map[uint32]float64: + v2, changed2 := fastpathTV.DecMapUint32Float64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint32]bool: + fastpathTV.DecMapUint32BoolV(v, fastpathCheckNilFalse, false, d) + case *map[uint32]bool: + v2, changed2 := fastpathTV.DecMapUint32BoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []uint64: + fastpathTV.DecSliceUint64V(v, fastpathCheckNilFalse, false, d) + case *[]uint64: + v2, changed2 := fastpathTV.DecSliceUint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]interface{}: + fastpathTV.DecMapUint64IntfV(v, fastpathCheckNilFalse, false, d) + case *map[uint64]interface{}: + v2, changed2 := fastpathTV.DecMapUint64IntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]string: + fastpathTV.DecMapUint64StringV(v, fastpathCheckNilFalse, false, d) + case *map[uint64]string: + v2, changed2 := fastpathTV.DecMapUint64StringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]uint: + fastpathTV.DecMapUint64UintV(v, fastpathCheckNilFalse, false, d) + case *map[uint64]uint: + v2, changed2 := fastpathTV.DecMapUint64UintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]uint8: + fastpathTV.DecMapUint64Uint8V(v, fastpathCheckNilFalse, false, d) + case *map[uint64]uint8: + v2, changed2 := fastpathTV.DecMapUint64Uint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]uint16: + fastpathTV.DecMapUint64Uint16V(v, fastpathCheckNilFalse, false, d) + case *map[uint64]uint16: + v2, changed2 := fastpathTV.DecMapUint64Uint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]uint32: + fastpathTV.DecMapUint64Uint32V(v, fastpathCheckNilFalse, false, d) + case *map[uint64]uint32: + v2, changed2 := fastpathTV.DecMapUint64Uint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]uint64: + fastpathTV.DecMapUint64Uint64V(v, fastpathCheckNilFalse, false, d) + case *map[uint64]uint64: + v2, changed2 := fastpathTV.DecMapUint64Uint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]int: + fastpathTV.DecMapUint64IntV(v, fastpathCheckNilFalse, false, d) + case *map[uint64]int: + v2, changed2 := fastpathTV.DecMapUint64IntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]int8: + fastpathTV.DecMapUint64Int8V(v, fastpathCheckNilFalse, false, d) + case *map[uint64]int8: + v2, changed2 := fastpathTV.DecMapUint64Int8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]int16: + fastpathTV.DecMapUint64Int16V(v, fastpathCheckNilFalse, false, d) + case *map[uint64]int16: + v2, changed2 := fastpathTV.DecMapUint64Int16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]int32: + fastpathTV.DecMapUint64Int32V(v, fastpathCheckNilFalse, false, d) + case *map[uint64]int32: + v2, changed2 := fastpathTV.DecMapUint64Int32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]int64: + fastpathTV.DecMapUint64Int64V(v, fastpathCheckNilFalse, false, d) + case *map[uint64]int64: + v2, changed2 := fastpathTV.DecMapUint64Int64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]float32: + fastpathTV.DecMapUint64Float32V(v, fastpathCheckNilFalse, false, d) + case *map[uint64]float32: + v2, changed2 := fastpathTV.DecMapUint64Float32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]float64: + fastpathTV.DecMapUint64Float64V(v, fastpathCheckNilFalse, false, d) + case *map[uint64]float64: + v2, changed2 := fastpathTV.DecMapUint64Float64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[uint64]bool: + fastpathTV.DecMapUint64BoolV(v, fastpathCheckNilFalse, false, d) + case *map[uint64]bool: + v2, changed2 := fastpathTV.DecMapUint64BoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []int: + fastpathTV.DecSliceIntV(v, fastpathCheckNilFalse, false, d) + case *[]int: + v2, changed2 := fastpathTV.DecSliceIntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]interface{}: + fastpathTV.DecMapIntIntfV(v, fastpathCheckNilFalse, false, d) + case *map[int]interface{}: + v2, changed2 := fastpathTV.DecMapIntIntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]string: + fastpathTV.DecMapIntStringV(v, fastpathCheckNilFalse, false, d) + case *map[int]string: + v2, changed2 := fastpathTV.DecMapIntStringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]uint: + fastpathTV.DecMapIntUintV(v, fastpathCheckNilFalse, false, d) + case *map[int]uint: + v2, changed2 := fastpathTV.DecMapIntUintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]uint8: + fastpathTV.DecMapIntUint8V(v, fastpathCheckNilFalse, false, d) + case *map[int]uint8: + v2, changed2 := fastpathTV.DecMapIntUint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]uint16: + fastpathTV.DecMapIntUint16V(v, fastpathCheckNilFalse, false, d) + case *map[int]uint16: + v2, changed2 := fastpathTV.DecMapIntUint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]uint32: + fastpathTV.DecMapIntUint32V(v, fastpathCheckNilFalse, false, d) + case *map[int]uint32: + v2, changed2 := fastpathTV.DecMapIntUint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]uint64: + fastpathTV.DecMapIntUint64V(v, fastpathCheckNilFalse, false, d) + case *map[int]uint64: + v2, changed2 := fastpathTV.DecMapIntUint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]int: + fastpathTV.DecMapIntIntV(v, fastpathCheckNilFalse, false, d) + case *map[int]int: + v2, changed2 := fastpathTV.DecMapIntIntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]int8: + fastpathTV.DecMapIntInt8V(v, fastpathCheckNilFalse, false, d) + case *map[int]int8: + v2, changed2 := fastpathTV.DecMapIntInt8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]int16: + fastpathTV.DecMapIntInt16V(v, fastpathCheckNilFalse, false, d) + case *map[int]int16: + v2, changed2 := fastpathTV.DecMapIntInt16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]int32: + fastpathTV.DecMapIntInt32V(v, fastpathCheckNilFalse, false, d) + case *map[int]int32: + v2, changed2 := fastpathTV.DecMapIntInt32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]int64: + fastpathTV.DecMapIntInt64V(v, fastpathCheckNilFalse, false, d) + case *map[int]int64: + v2, changed2 := fastpathTV.DecMapIntInt64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]float32: + fastpathTV.DecMapIntFloat32V(v, fastpathCheckNilFalse, false, d) + case *map[int]float32: + v2, changed2 := fastpathTV.DecMapIntFloat32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]float64: + fastpathTV.DecMapIntFloat64V(v, fastpathCheckNilFalse, false, d) + case *map[int]float64: + v2, changed2 := fastpathTV.DecMapIntFloat64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int]bool: + fastpathTV.DecMapIntBoolV(v, fastpathCheckNilFalse, false, d) + case *map[int]bool: + v2, changed2 := fastpathTV.DecMapIntBoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []int8: + fastpathTV.DecSliceInt8V(v, fastpathCheckNilFalse, false, d) + case *[]int8: + v2, changed2 := fastpathTV.DecSliceInt8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]interface{}: + fastpathTV.DecMapInt8IntfV(v, fastpathCheckNilFalse, false, d) + case *map[int8]interface{}: + v2, changed2 := fastpathTV.DecMapInt8IntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]string: + fastpathTV.DecMapInt8StringV(v, fastpathCheckNilFalse, false, d) + case *map[int8]string: + v2, changed2 := fastpathTV.DecMapInt8StringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]uint: + fastpathTV.DecMapInt8UintV(v, fastpathCheckNilFalse, false, d) + case *map[int8]uint: + v2, changed2 := fastpathTV.DecMapInt8UintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]uint8: + fastpathTV.DecMapInt8Uint8V(v, fastpathCheckNilFalse, false, d) + case *map[int8]uint8: + v2, changed2 := fastpathTV.DecMapInt8Uint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]uint16: + fastpathTV.DecMapInt8Uint16V(v, fastpathCheckNilFalse, false, d) + case *map[int8]uint16: + v2, changed2 := fastpathTV.DecMapInt8Uint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]uint32: + fastpathTV.DecMapInt8Uint32V(v, fastpathCheckNilFalse, false, d) + case *map[int8]uint32: + v2, changed2 := fastpathTV.DecMapInt8Uint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]uint64: + fastpathTV.DecMapInt8Uint64V(v, fastpathCheckNilFalse, false, d) + case *map[int8]uint64: + v2, changed2 := fastpathTV.DecMapInt8Uint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]int: + fastpathTV.DecMapInt8IntV(v, fastpathCheckNilFalse, false, d) + case *map[int8]int: + v2, changed2 := fastpathTV.DecMapInt8IntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]int8: + fastpathTV.DecMapInt8Int8V(v, fastpathCheckNilFalse, false, d) + case *map[int8]int8: + v2, changed2 := fastpathTV.DecMapInt8Int8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]int16: + fastpathTV.DecMapInt8Int16V(v, fastpathCheckNilFalse, false, d) + case *map[int8]int16: + v2, changed2 := fastpathTV.DecMapInt8Int16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]int32: + fastpathTV.DecMapInt8Int32V(v, fastpathCheckNilFalse, false, d) + case *map[int8]int32: + v2, changed2 := fastpathTV.DecMapInt8Int32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]int64: + fastpathTV.DecMapInt8Int64V(v, fastpathCheckNilFalse, false, d) + case *map[int8]int64: + v2, changed2 := fastpathTV.DecMapInt8Int64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]float32: + fastpathTV.DecMapInt8Float32V(v, fastpathCheckNilFalse, false, d) + case *map[int8]float32: + v2, changed2 := fastpathTV.DecMapInt8Float32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]float64: + fastpathTV.DecMapInt8Float64V(v, fastpathCheckNilFalse, false, d) + case *map[int8]float64: + v2, changed2 := fastpathTV.DecMapInt8Float64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int8]bool: + fastpathTV.DecMapInt8BoolV(v, fastpathCheckNilFalse, false, d) + case *map[int8]bool: + v2, changed2 := fastpathTV.DecMapInt8BoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []int16: + fastpathTV.DecSliceInt16V(v, fastpathCheckNilFalse, false, d) + case *[]int16: + v2, changed2 := fastpathTV.DecSliceInt16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]interface{}: + fastpathTV.DecMapInt16IntfV(v, fastpathCheckNilFalse, false, d) + case *map[int16]interface{}: + v2, changed2 := fastpathTV.DecMapInt16IntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]string: + fastpathTV.DecMapInt16StringV(v, fastpathCheckNilFalse, false, d) + case *map[int16]string: + v2, changed2 := fastpathTV.DecMapInt16StringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]uint: + fastpathTV.DecMapInt16UintV(v, fastpathCheckNilFalse, false, d) + case *map[int16]uint: + v2, changed2 := fastpathTV.DecMapInt16UintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]uint8: + fastpathTV.DecMapInt16Uint8V(v, fastpathCheckNilFalse, false, d) + case *map[int16]uint8: + v2, changed2 := fastpathTV.DecMapInt16Uint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]uint16: + fastpathTV.DecMapInt16Uint16V(v, fastpathCheckNilFalse, false, d) + case *map[int16]uint16: + v2, changed2 := fastpathTV.DecMapInt16Uint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]uint32: + fastpathTV.DecMapInt16Uint32V(v, fastpathCheckNilFalse, false, d) + case *map[int16]uint32: + v2, changed2 := fastpathTV.DecMapInt16Uint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]uint64: + fastpathTV.DecMapInt16Uint64V(v, fastpathCheckNilFalse, false, d) + case *map[int16]uint64: + v2, changed2 := fastpathTV.DecMapInt16Uint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]int: + fastpathTV.DecMapInt16IntV(v, fastpathCheckNilFalse, false, d) + case *map[int16]int: + v2, changed2 := fastpathTV.DecMapInt16IntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]int8: + fastpathTV.DecMapInt16Int8V(v, fastpathCheckNilFalse, false, d) + case *map[int16]int8: + v2, changed2 := fastpathTV.DecMapInt16Int8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]int16: + fastpathTV.DecMapInt16Int16V(v, fastpathCheckNilFalse, false, d) + case *map[int16]int16: + v2, changed2 := fastpathTV.DecMapInt16Int16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]int32: + fastpathTV.DecMapInt16Int32V(v, fastpathCheckNilFalse, false, d) + case *map[int16]int32: + v2, changed2 := fastpathTV.DecMapInt16Int32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]int64: + fastpathTV.DecMapInt16Int64V(v, fastpathCheckNilFalse, false, d) + case *map[int16]int64: + v2, changed2 := fastpathTV.DecMapInt16Int64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]float32: + fastpathTV.DecMapInt16Float32V(v, fastpathCheckNilFalse, false, d) + case *map[int16]float32: + v2, changed2 := fastpathTV.DecMapInt16Float32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]float64: + fastpathTV.DecMapInt16Float64V(v, fastpathCheckNilFalse, false, d) + case *map[int16]float64: + v2, changed2 := fastpathTV.DecMapInt16Float64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int16]bool: + fastpathTV.DecMapInt16BoolV(v, fastpathCheckNilFalse, false, d) + case *map[int16]bool: + v2, changed2 := fastpathTV.DecMapInt16BoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []int32: + fastpathTV.DecSliceInt32V(v, fastpathCheckNilFalse, false, d) + case *[]int32: + v2, changed2 := fastpathTV.DecSliceInt32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]interface{}: + fastpathTV.DecMapInt32IntfV(v, fastpathCheckNilFalse, false, d) + case *map[int32]interface{}: + v2, changed2 := fastpathTV.DecMapInt32IntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]string: + fastpathTV.DecMapInt32StringV(v, fastpathCheckNilFalse, false, d) + case *map[int32]string: + v2, changed2 := fastpathTV.DecMapInt32StringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]uint: + fastpathTV.DecMapInt32UintV(v, fastpathCheckNilFalse, false, d) + case *map[int32]uint: + v2, changed2 := fastpathTV.DecMapInt32UintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]uint8: + fastpathTV.DecMapInt32Uint8V(v, fastpathCheckNilFalse, false, d) + case *map[int32]uint8: + v2, changed2 := fastpathTV.DecMapInt32Uint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]uint16: + fastpathTV.DecMapInt32Uint16V(v, fastpathCheckNilFalse, false, d) + case *map[int32]uint16: + v2, changed2 := fastpathTV.DecMapInt32Uint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]uint32: + fastpathTV.DecMapInt32Uint32V(v, fastpathCheckNilFalse, false, d) + case *map[int32]uint32: + v2, changed2 := fastpathTV.DecMapInt32Uint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]uint64: + fastpathTV.DecMapInt32Uint64V(v, fastpathCheckNilFalse, false, d) + case *map[int32]uint64: + v2, changed2 := fastpathTV.DecMapInt32Uint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]int: + fastpathTV.DecMapInt32IntV(v, fastpathCheckNilFalse, false, d) + case *map[int32]int: + v2, changed2 := fastpathTV.DecMapInt32IntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]int8: + fastpathTV.DecMapInt32Int8V(v, fastpathCheckNilFalse, false, d) + case *map[int32]int8: + v2, changed2 := fastpathTV.DecMapInt32Int8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]int16: + fastpathTV.DecMapInt32Int16V(v, fastpathCheckNilFalse, false, d) + case *map[int32]int16: + v2, changed2 := fastpathTV.DecMapInt32Int16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]int32: + fastpathTV.DecMapInt32Int32V(v, fastpathCheckNilFalse, false, d) + case *map[int32]int32: + v2, changed2 := fastpathTV.DecMapInt32Int32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]int64: + fastpathTV.DecMapInt32Int64V(v, fastpathCheckNilFalse, false, d) + case *map[int32]int64: + v2, changed2 := fastpathTV.DecMapInt32Int64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]float32: + fastpathTV.DecMapInt32Float32V(v, fastpathCheckNilFalse, false, d) + case *map[int32]float32: + v2, changed2 := fastpathTV.DecMapInt32Float32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]float64: + fastpathTV.DecMapInt32Float64V(v, fastpathCheckNilFalse, false, d) + case *map[int32]float64: + v2, changed2 := fastpathTV.DecMapInt32Float64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int32]bool: + fastpathTV.DecMapInt32BoolV(v, fastpathCheckNilFalse, false, d) + case *map[int32]bool: + v2, changed2 := fastpathTV.DecMapInt32BoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []int64: + fastpathTV.DecSliceInt64V(v, fastpathCheckNilFalse, false, d) + case *[]int64: + v2, changed2 := fastpathTV.DecSliceInt64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]interface{}: + fastpathTV.DecMapInt64IntfV(v, fastpathCheckNilFalse, false, d) + case *map[int64]interface{}: + v2, changed2 := fastpathTV.DecMapInt64IntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]string: + fastpathTV.DecMapInt64StringV(v, fastpathCheckNilFalse, false, d) + case *map[int64]string: + v2, changed2 := fastpathTV.DecMapInt64StringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]uint: + fastpathTV.DecMapInt64UintV(v, fastpathCheckNilFalse, false, d) + case *map[int64]uint: + v2, changed2 := fastpathTV.DecMapInt64UintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]uint8: + fastpathTV.DecMapInt64Uint8V(v, fastpathCheckNilFalse, false, d) + case *map[int64]uint8: + v2, changed2 := fastpathTV.DecMapInt64Uint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]uint16: + fastpathTV.DecMapInt64Uint16V(v, fastpathCheckNilFalse, false, d) + case *map[int64]uint16: + v2, changed2 := fastpathTV.DecMapInt64Uint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]uint32: + fastpathTV.DecMapInt64Uint32V(v, fastpathCheckNilFalse, false, d) + case *map[int64]uint32: + v2, changed2 := fastpathTV.DecMapInt64Uint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]uint64: + fastpathTV.DecMapInt64Uint64V(v, fastpathCheckNilFalse, false, d) + case *map[int64]uint64: + v2, changed2 := fastpathTV.DecMapInt64Uint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]int: + fastpathTV.DecMapInt64IntV(v, fastpathCheckNilFalse, false, d) + case *map[int64]int: + v2, changed2 := fastpathTV.DecMapInt64IntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]int8: + fastpathTV.DecMapInt64Int8V(v, fastpathCheckNilFalse, false, d) + case *map[int64]int8: + v2, changed2 := fastpathTV.DecMapInt64Int8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]int16: + fastpathTV.DecMapInt64Int16V(v, fastpathCheckNilFalse, false, d) + case *map[int64]int16: + v2, changed2 := fastpathTV.DecMapInt64Int16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]int32: + fastpathTV.DecMapInt64Int32V(v, fastpathCheckNilFalse, false, d) + case *map[int64]int32: + v2, changed2 := fastpathTV.DecMapInt64Int32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]int64: + fastpathTV.DecMapInt64Int64V(v, fastpathCheckNilFalse, false, d) + case *map[int64]int64: + v2, changed2 := fastpathTV.DecMapInt64Int64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]float32: + fastpathTV.DecMapInt64Float32V(v, fastpathCheckNilFalse, false, d) + case *map[int64]float32: + v2, changed2 := fastpathTV.DecMapInt64Float32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]float64: + fastpathTV.DecMapInt64Float64V(v, fastpathCheckNilFalse, false, d) + case *map[int64]float64: + v2, changed2 := fastpathTV.DecMapInt64Float64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[int64]bool: + fastpathTV.DecMapInt64BoolV(v, fastpathCheckNilFalse, false, d) + case *map[int64]bool: + v2, changed2 := fastpathTV.DecMapInt64BoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case []bool: + fastpathTV.DecSliceBoolV(v, fastpathCheckNilFalse, false, d) + case *[]bool: + v2, changed2 := fastpathTV.DecSliceBoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]interface{}: + fastpathTV.DecMapBoolIntfV(v, fastpathCheckNilFalse, false, d) + case *map[bool]interface{}: + v2, changed2 := fastpathTV.DecMapBoolIntfV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]string: + fastpathTV.DecMapBoolStringV(v, fastpathCheckNilFalse, false, d) + case *map[bool]string: + v2, changed2 := fastpathTV.DecMapBoolStringV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]uint: + fastpathTV.DecMapBoolUintV(v, fastpathCheckNilFalse, false, d) + case *map[bool]uint: + v2, changed2 := fastpathTV.DecMapBoolUintV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]uint8: + fastpathTV.DecMapBoolUint8V(v, fastpathCheckNilFalse, false, d) + case *map[bool]uint8: + v2, changed2 := fastpathTV.DecMapBoolUint8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]uint16: + fastpathTV.DecMapBoolUint16V(v, fastpathCheckNilFalse, false, d) + case *map[bool]uint16: + v2, changed2 := fastpathTV.DecMapBoolUint16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]uint32: + fastpathTV.DecMapBoolUint32V(v, fastpathCheckNilFalse, false, d) + case *map[bool]uint32: + v2, changed2 := fastpathTV.DecMapBoolUint32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]uint64: + fastpathTV.DecMapBoolUint64V(v, fastpathCheckNilFalse, false, d) + case *map[bool]uint64: + v2, changed2 := fastpathTV.DecMapBoolUint64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]int: + fastpathTV.DecMapBoolIntV(v, fastpathCheckNilFalse, false, d) + case *map[bool]int: + v2, changed2 := fastpathTV.DecMapBoolIntV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]int8: + fastpathTV.DecMapBoolInt8V(v, fastpathCheckNilFalse, false, d) + case *map[bool]int8: + v2, changed2 := fastpathTV.DecMapBoolInt8V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]int16: + fastpathTV.DecMapBoolInt16V(v, fastpathCheckNilFalse, false, d) + case *map[bool]int16: + v2, changed2 := fastpathTV.DecMapBoolInt16V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]int32: + fastpathTV.DecMapBoolInt32V(v, fastpathCheckNilFalse, false, d) + case *map[bool]int32: + v2, changed2 := fastpathTV.DecMapBoolInt32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]int64: + fastpathTV.DecMapBoolInt64V(v, fastpathCheckNilFalse, false, d) + case *map[bool]int64: + v2, changed2 := fastpathTV.DecMapBoolInt64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]float32: + fastpathTV.DecMapBoolFloat32V(v, fastpathCheckNilFalse, false, d) + case *map[bool]float32: + v2, changed2 := fastpathTV.DecMapBoolFloat32V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]float64: + fastpathTV.DecMapBoolFloat64V(v, fastpathCheckNilFalse, false, d) + case *map[bool]float64: + v2, changed2 := fastpathTV.DecMapBoolFloat64V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + case map[bool]bool: + fastpathTV.DecMapBoolBoolV(v, fastpathCheckNilFalse, false, d) + case *map[bool]bool: + v2, changed2 := fastpathTV.DecMapBoolBoolV(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } + + default: + return false + } + return true +} + +// -- -- fast path functions + +func (f decFnInfo) fastpathDecSliceIntfR(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]interface{}) + v, changed := fastpathTV.DecSliceIntfV(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]interface{}) + fastpathTV.DecSliceIntfV(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceIntfX(vp *[]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecSliceIntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceIntfV(v []interface{}, checkNil bool, canChange bool, + d *Decoder) (_ []interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []interface{}{} + } else { + v = make([]interface{}, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]interface{}, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + d.decode(&v[j]) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, nil) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + d.decode(&v[j]) + + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceStringR(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]string) + v, changed := fastpathTV.DecSliceStringV(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]string) + fastpathTV.DecSliceStringV(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceStringX(vp *[]string, checkNil bool, d *Decoder) { + v, changed := f.DecSliceStringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceStringV(v []string, checkNil bool, canChange bool, + d *Decoder) (_ []string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []string{} + } else { + v = make([]string, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]string, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = dd.DecodeString() + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, "") + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = dd.DecodeString() + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceFloat32R(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]float32) + v, changed := fastpathTV.DecSliceFloat32V(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]float32) + fastpathTV.DecSliceFloat32V(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceFloat32X(vp *[]float32, checkNil bool, d *Decoder) { + v, changed := f.DecSliceFloat32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceFloat32V(v []float32, checkNil bool, canChange bool, + d *Decoder) (_ []float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []float32{} + } else { + v = make([]float32, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]float32, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = float32(dd.DecodeFloat(true)) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, 0) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = float32(dd.DecodeFloat(true)) + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceFloat64R(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]float64) + v, changed := fastpathTV.DecSliceFloat64V(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]float64) + fastpathTV.DecSliceFloat64V(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceFloat64X(vp *[]float64, checkNil bool, d *Decoder) { + v, changed := f.DecSliceFloat64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceFloat64V(v []float64, checkNil bool, canChange bool, + d *Decoder) (_ []float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []float64{} + } else { + v = make([]float64, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]float64, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = dd.DecodeFloat(false) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, 0) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = dd.DecodeFloat(false) + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceUintR(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]uint) + v, changed := fastpathTV.DecSliceUintV(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]uint) + fastpathTV.DecSliceUintV(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceUintX(vp *[]uint, checkNil bool, d *Decoder) { + v, changed := f.DecSliceUintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceUintV(v []uint, checkNil bool, canChange bool, + d *Decoder) (_ []uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []uint{} + } else { + v = make([]uint, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]uint, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = uint(dd.DecodeUint(uintBitsize)) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, 0) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = uint(dd.DecodeUint(uintBitsize)) + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceUint16R(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]uint16) + v, changed := fastpathTV.DecSliceUint16V(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]uint16) + fastpathTV.DecSliceUint16V(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceUint16X(vp *[]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecSliceUint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceUint16V(v []uint16, checkNil bool, canChange bool, + d *Decoder) (_ []uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []uint16{} + } else { + v = make([]uint16, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]uint16, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = uint16(dd.DecodeUint(16)) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, 0) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = uint16(dd.DecodeUint(16)) + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceUint32R(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]uint32) + v, changed := fastpathTV.DecSliceUint32V(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]uint32) + fastpathTV.DecSliceUint32V(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceUint32X(vp *[]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecSliceUint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceUint32V(v []uint32, checkNil bool, canChange bool, + d *Decoder) (_ []uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []uint32{} + } else { + v = make([]uint32, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]uint32, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = uint32(dd.DecodeUint(32)) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, 0) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = uint32(dd.DecodeUint(32)) + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceUint64R(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]uint64) + v, changed := fastpathTV.DecSliceUint64V(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]uint64) + fastpathTV.DecSliceUint64V(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceUint64X(vp *[]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecSliceUint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceUint64V(v []uint64, checkNil bool, canChange bool, + d *Decoder) (_ []uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []uint64{} + } else { + v = make([]uint64, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]uint64, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = dd.DecodeUint(64) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, 0) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = dd.DecodeUint(64) + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceIntR(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]int) + v, changed := fastpathTV.DecSliceIntV(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]int) + fastpathTV.DecSliceIntV(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceIntX(vp *[]int, checkNil bool, d *Decoder) { + v, changed := f.DecSliceIntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceIntV(v []int, checkNil bool, canChange bool, + d *Decoder) (_ []int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []int{} + } else { + v = make([]int, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]int, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = int(dd.DecodeInt(intBitsize)) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, 0) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = int(dd.DecodeInt(intBitsize)) + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceInt8R(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]int8) + v, changed := fastpathTV.DecSliceInt8V(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]int8) + fastpathTV.DecSliceInt8V(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceInt8X(vp *[]int8, checkNil bool, d *Decoder) { + v, changed := f.DecSliceInt8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceInt8V(v []int8, checkNil bool, canChange bool, + d *Decoder) (_ []int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []int8{} + } else { + v = make([]int8, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]int8, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = int8(dd.DecodeInt(8)) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, 0) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = int8(dd.DecodeInt(8)) + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceInt16R(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]int16) + v, changed := fastpathTV.DecSliceInt16V(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]int16) + fastpathTV.DecSliceInt16V(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceInt16X(vp *[]int16, checkNil bool, d *Decoder) { + v, changed := f.DecSliceInt16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceInt16V(v []int16, checkNil bool, canChange bool, + d *Decoder) (_ []int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []int16{} + } else { + v = make([]int16, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]int16, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = int16(dd.DecodeInt(16)) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, 0) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = int16(dd.DecodeInt(16)) + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceInt32R(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]int32) + v, changed := fastpathTV.DecSliceInt32V(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]int32) + fastpathTV.DecSliceInt32V(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceInt32X(vp *[]int32, checkNil bool, d *Decoder) { + v, changed := f.DecSliceInt32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceInt32V(v []int32, checkNil bool, canChange bool, + d *Decoder) (_ []int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []int32{} + } else { + v = make([]int32, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]int32, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = int32(dd.DecodeInt(32)) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, 0) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = int32(dd.DecodeInt(32)) + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceInt64R(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]int64) + v, changed := fastpathTV.DecSliceInt64V(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]int64) + fastpathTV.DecSliceInt64V(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceInt64X(vp *[]int64, checkNil bool, d *Decoder) { + v, changed := f.DecSliceInt64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceInt64V(v []int64, checkNil bool, canChange bool, + d *Decoder) (_ []int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []int64{} + } else { + v = make([]int64, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]int64, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = dd.DecodeInt(64) + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, 0) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = dd.DecodeInt(64) + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecSliceBoolR(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]bool) + v, changed := fastpathTV.DecSliceBoolV(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]bool) + fastpathTV.DecSliceBoolV(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) DecSliceBoolX(vp *[]bool, checkNil bool, d *Decoder) { + v, changed := f.DecSliceBoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecSliceBoolV(v []bool, checkNil bool, canChange bool, + d *Decoder) (_ []bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []bool{} + } else { + v = make([]bool, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + } + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]bool, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + v[j] = dd.DecodeBool() + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, false) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + v[j] = dd.DecodeBool() + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfIntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]interface{}) + v, changed := fastpathTV.DecMapIntfIntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]interface{}) + fastpathTV.DecMapIntfIntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfIntfX(vp *map[interface{}]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfIntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfIntfV(v map[interface{}]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]interface{}, containerLen) + } else { + v = make(map[interface{}]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfStringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]string) + v, changed := fastpathTV.DecMapIntfStringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]string) + fastpathTV.DecMapIntfStringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfStringX(vp *map[interface{}]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfStringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfStringV(v map[interface{}]string, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]string, containerLen) + } else { + v = make(map[interface{}]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfUintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]uint) + v, changed := fastpathTV.DecMapIntfUintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]uint) + fastpathTV.DecMapIntfUintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfUintX(vp *map[interface{}]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfUintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfUintV(v map[interface{}]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]uint, containerLen) + } else { + v = make(map[interface{}]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfUint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]uint8) + v, changed := fastpathTV.DecMapIntfUint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]uint8) + fastpathTV.DecMapIntfUint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfUint8X(vp *map[interface{}]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfUint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfUint8V(v map[interface{}]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]uint8, containerLen) + } else { + v = make(map[interface{}]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfUint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]uint16) + v, changed := fastpathTV.DecMapIntfUint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]uint16) + fastpathTV.DecMapIntfUint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfUint16X(vp *map[interface{}]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfUint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfUint16V(v map[interface{}]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]uint16, containerLen) + } else { + v = make(map[interface{}]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfUint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]uint32) + v, changed := fastpathTV.DecMapIntfUint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]uint32) + fastpathTV.DecMapIntfUint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfUint32X(vp *map[interface{}]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfUint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfUint32V(v map[interface{}]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]uint32, containerLen) + } else { + v = make(map[interface{}]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfUint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]uint64) + v, changed := fastpathTV.DecMapIntfUint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]uint64) + fastpathTV.DecMapIntfUint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfUint64X(vp *map[interface{}]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfUint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfUint64V(v map[interface{}]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]uint64, containerLen) + } else { + v = make(map[interface{}]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfIntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]int) + v, changed := fastpathTV.DecMapIntfIntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]int) + fastpathTV.DecMapIntfIntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfIntX(vp *map[interface{}]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfIntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfIntV(v map[interface{}]int, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]int, containerLen) + } else { + v = make(map[interface{}]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfInt8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]int8) + v, changed := fastpathTV.DecMapIntfInt8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]int8) + fastpathTV.DecMapIntfInt8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfInt8X(vp *map[interface{}]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfInt8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfInt8V(v map[interface{}]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]int8, containerLen) + } else { + v = make(map[interface{}]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfInt16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]int16) + v, changed := fastpathTV.DecMapIntfInt16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]int16) + fastpathTV.DecMapIntfInt16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfInt16X(vp *map[interface{}]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfInt16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfInt16V(v map[interface{}]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]int16, containerLen) + } else { + v = make(map[interface{}]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfInt32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]int32) + v, changed := fastpathTV.DecMapIntfInt32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]int32) + fastpathTV.DecMapIntfInt32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfInt32X(vp *map[interface{}]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfInt32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfInt32V(v map[interface{}]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]int32, containerLen) + } else { + v = make(map[interface{}]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfInt64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]int64) + v, changed := fastpathTV.DecMapIntfInt64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]int64) + fastpathTV.DecMapIntfInt64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfInt64X(vp *map[interface{}]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfInt64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfInt64V(v map[interface{}]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]int64, containerLen) + } else { + v = make(map[interface{}]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfFloat32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]float32) + v, changed := fastpathTV.DecMapIntfFloat32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]float32) + fastpathTV.DecMapIntfFloat32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfFloat32X(vp *map[interface{}]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfFloat32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfFloat32V(v map[interface{}]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]float32, containerLen) + } else { + v = make(map[interface{}]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfFloat64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]float64) + v, changed := fastpathTV.DecMapIntfFloat64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]float64) + fastpathTV.DecMapIntfFloat64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfFloat64X(vp *map[interface{}]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfFloat64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfFloat64V(v map[interface{}]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]float64, containerLen) + } else { + v = make(map[interface{}]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntfBoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[interface{}]bool) + v, changed := fastpathTV.DecMapIntfBoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[interface{}]bool) + fastpathTV.DecMapIntfBoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntfBoolX(vp *map[interface{}]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntfBoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntfBoolV(v map[interface{}]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[interface{}]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[interface{}]bool, containerLen) + } else { + v = make(map[interface{}]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + } + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringIntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]interface{}) + v, changed := fastpathTV.DecMapStringIntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]interface{}) + fastpathTV.DecMapStringIntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringIntfX(vp *map[string]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringIntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringIntfV(v map[string]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[string]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]interface{}, containerLen) + } else { + v = make(map[string]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringStringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]string) + v, changed := fastpathTV.DecMapStringStringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]string) + fastpathTV.DecMapStringStringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringStringX(vp *map[string]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringStringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringStringV(v map[string]string, checkNil bool, canChange bool, + d *Decoder) (_ map[string]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]string, containerLen) + } else { + v = make(map[string]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringUintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]uint) + v, changed := fastpathTV.DecMapStringUintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]uint) + fastpathTV.DecMapStringUintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringUintX(vp *map[string]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringUintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringUintV(v map[string]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[string]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]uint, containerLen) + } else { + v = make(map[string]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringUint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]uint8) + v, changed := fastpathTV.DecMapStringUint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]uint8) + fastpathTV.DecMapStringUint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringUint8X(vp *map[string]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringUint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringUint8V(v map[string]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[string]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]uint8, containerLen) + } else { + v = make(map[string]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringUint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]uint16) + v, changed := fastpathTV.DecMapStringUint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]uint16) + fastpathTV.DecMapStringUint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringUint16X(vp *map[string]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringUint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringUint16V(v map[string]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[string]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]uint16, containerLen) + } else { + v = make(map[string]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringUint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]uint32) + v, changed := fastpathTV.DecMapStringUint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]uint32) + fastpathTV.DecMapStringUint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringUint32X(vp *map[string]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringUint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringUint32V(v map[string]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[string]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]uint32, containerLen) + } else { + v = make(map[string]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringUint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]uint64) + v, changed := fastpathTV.DecMapStringUint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]uint64) + fastpathTV.DecMapStringUint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringUint64X(vp *map[string]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringUint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringUint64V(v map[string]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[string]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]uint64, containerLen) + } else { + v = make(map[string]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringIntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]int) + v, changed := fastpathTV.DecMapStringIntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]int) + fastpathTV.DecMapStringIntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringIntX(vp *map[string]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringIntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringIntV(v map[string]int, checkNil bool, canChange bool, + d *Decoder) (_ map[string]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]int, containerLen) + } else { + v = make(map[string]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringInt8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]int8) + v, changed := fastpathTV.DecMapStringInt8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]int8) + fastpathTV.DecMapStringInt8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringInt8X(vp *map[string]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringInt8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringInt8V(v map[string]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[string]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]int8, containerLen) + } else { + v = make(map[string]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringInt16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]int16) + v, changed := fastpathTV.DecMapStringInt16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]int16) + fastpathTV.DecMapStringInt16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringInt16X(vp *map[string]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringInt16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringInt16V(v map[string]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[string]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]int16, containerLen) + } else { + v = make(map[string]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringInt32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]int32) + v, changed := fastpathTV.DecMapStringInt32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]int32) + fastpathTV.DecMapStringInt32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringInt32X(vp *map[string]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringInt32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringInt32V(v map[string]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[string]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]int32, containerLen) + } else { + v = make(map[string]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringInt64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]int64) + v, changed := fastpathTV.DecMapStringInt64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]int64) + fastpathTV.DecMapStringInt64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringInt64X(vp *map[string]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringInt64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringInt64V(v map[string]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[string]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]int64, containerLen) + } else { + v = make(map[string]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringFloat32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]float32) + v, changed := fastpathTV.DecMapStringFloat32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]float32) + fastpathTV.DecMapStringFloat32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringFloat32X(vp *map[string]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringFloat32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringFloat32V(v map[string]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[string]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]float32, containerLen) + } else { + v = make(map[string]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringFloat64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]float64) + v, changed := fastpathTV.DecMapStringFloat64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]float64) + fastpathTV.DecMapStringFloat64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringFloat64X(vp *map[string]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringFloat64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringFloat64V(v map[string]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[string]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]float64, containerLen) + } else { + v = make(map[string]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapStringBoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[string]bool) + v, changed := fastpathTV.DecMapStringBoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[string]bool) + fastpathTV.DecMapStringBoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapStringBoolX(vp *map[string]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapStringBoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapStringBoolV(v map[string]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[string]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[string]bool, containerLen) + } else { + v = make(map[string]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeString() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeString() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32IntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]interface{}) + v, changed := fastpathTV.DecMapFloat32IntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]interface{}) + fastpathTV.DecMapFloat32IntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32IntfX(vp *map[float32]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32IntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32IntfV(v map[float32]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]interface{}, containerLen) + } else { + v = make(map[float32]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32StringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]string) + v, changed := fastpathTV.DecMapFloat32StringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]string) + fastpathTV.DecMapFloat32StringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32StringX(vp *map[float32]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32StringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32StringV(v map[float32]string, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]string, containerLen) + } else { + v = make(map[float32]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32UintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]uint) + v, changed := fastpathTV.DecMapFloat32UintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]uint) + fastpathTV.DecMapFloat32UintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32UintX(vp *map[float32]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32UintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32UintV(v map[float32]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]uint, containerLen) + } else { + v = make(map[float32]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32Uint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]uint8) + v, changed := fastpathTV.DecMapFloat32Uint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]uint8) + fastpathTV.DecMapFloat32Uint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32Uint8X(vp *map[float32]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32Uint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32Uint8V(v map[float32]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]uint8, containerLen) + } else { + v = make(map[float32]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32Uint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]uint16) + v, changed := fastpathTV.DecMapFloat32Uint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]uint16) + fastpathTV.DecMapFloat32Uint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32Uint16X(vp *map[float32]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32Uint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32Uint16V(v map[float32]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]uint16, containerLen) + } else { + v = make(map[float32]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32Uint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]uint32) + v, changed := fastpathTV.DecMapFloat32Uint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]uint32) + fastpathTV.DecMapFloat32Uint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32Uint32X(vp *map[float32]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32Uint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32Uint32V(v map[float32]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]uint32, containerLen) + } else { + v = make(map[float32]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32Uint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]uint64) + v, changed := fastpathTV.DecMapFloat32Uint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]uint64) + fastpathTV.DecMapFloat32Uint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32Uint64X(vp *map[float32]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32Uint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32Uint64V(v map[float32]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]uint64, containerLen) + } else { + v = make(map[float32]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32IntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]int) + v, changed := fastpathTV.DecMapFloat32IntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]int) + fastpathTV.DecMapFloat32IntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32IntX(vp *map[float32]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32IntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32IntV(v map[float32]int, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]int, containerLen) + } else { + v = make(map[float32]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32Int8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]int8) + v, changed := fastpathTV.DecMapFloat32Int8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]int8) + fastpathTV.DecMapFloat32Int8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32Int8X(vp *map[float32]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32Int8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32Int8V(v map[float32]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]int8, containerLen) + } else { + v = make(map[float32]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32Int16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]int16) + v, changed := fastpathTV.DecMapFloat32Int16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]int16) + fastpathTV.DecMapFloat32Int16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32Int16X(vp *map[float32]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32Int16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32Int16V(v map[float32]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]int16, containerLen) + } else { + v = make(map[float32]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32Int32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]int32) + v, changed := fastpathTV.DecMapFloat32Int32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]int32) + fastpathTV.DecMapFloat32Int32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32Int32X(vp *map[float32]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32Int32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32Int32V(v map[float32]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]int32, containerLen) + } else { + v = make(map[float32]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32Int64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]int64) + v, changed := fastpathTV.DecMapFloat32Int64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]int64) + fastpathTV.DecMapFloat32Int64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32Int64X(vp *map[float32]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32Int64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32Int64V(v map[float32]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]int64, containerLen) + } else { + v = make(map[float32]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32Float32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]float32) + v, changed := fastpathTV.DecMapFloat32Float32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]float32) + fastpathTV.DecMapFloat32Float32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32Float32X(vp *map[float32]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32Float32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32Float32V(v map[float32]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]float32, containerLen) + } else { + v = make(map[float32]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32Float64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]float64) + v, changed := fastpathTV.DecMapFloat32Float64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]float64) + fastpathTV.DecMapFloat32Float64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32Float64X(vp *map[float32]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32Float64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32Float64V(v map[float32]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]float64, containerLen) + } else { + v = make(map[float32]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat32BoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float32]bool) + v, changed := fastpathTV.DecMapFloat32BoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float32]bool) + fastpathTV.DecMapFloat32BoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat32BoolX(vp *map[float32]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat32BoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat32BoolV(v map[float32]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[float32]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float32]bool, containerLen) + } else { + v = make(map[float32]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := float32(dd.DecodeFloat(true)) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := float32(dd.DecodeFloat(true)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64IntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]interface{}) + v, changed := fastpathTV.DecMapFloat64IntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]interface{}) + fastpathTV.DecMapFloat64IntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64IntfX(vp *map[float64]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64IntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64IntfV(v map[float64]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]interface{}, containerLen) + } else { + v = make(map[float64]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64StringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]string) + v, changed := fastpathTV.DecMapFloat64StringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]string) + fastpathTV.DecMapFloat64StringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64StringX(vp *map[float64]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64StringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64StringV(v map[float64]string, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]string, containerLen) + } else { + v = make(map[float64]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64UintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]uint) + v, changed := fastpathTV.DecMapFloat64UintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]uint) + fastpathTV.DecMapFloat64UintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64UintX(vp *map[float64]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64UintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64UintV(v map[float64]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]uint, containerLen) + } else { + v = make(map[float64]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64Uint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]uint8) + v, changed := fastpathTV.DecMapFloat64Uint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]uint8) + fastpathTV.DecMapFloat64Uint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64Uint8X(vp *map[float64]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64Uint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64Uint8V(v map[float64]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]uint8, containerLen) + } else { + v = make(map[float64]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64Uint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]uint16) + v, changed := fastpathTV.DecMapFloat64Uint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]uint16) + fastpathTV.DecMapFloat64Uint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64Uint16X(vp *map[float64]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64Uint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64Uint16V(v map[float64]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]uint16, containerLen) + } else { + v = make(map[float64]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64Uint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]uint32) + v, changed := fastpathTV.DecMapFloat64Uint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]uint32) + fastpathTV.DecMapFloat64Uint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64Uint32X(vp *map[float64]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64Uint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64Uint32V(v map[float64]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]uint32, containerLen) + } else { + v = make(map[float64]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64Uint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]uint64) + v, changed := fastpathTV.DecMapFloat64Uint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]uint64) + fastpathTV.DecMapFloat64Uint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64Uint64X(vp *map[float64]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64Uint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64Uint64V(v map[float64]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]uint64, containerLen) + } else { + v = make(map[float64]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64IntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]int) + v, changed := fastpathTV.DecMapFloat64IntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]int) + fastpathTV.DecMapFloat64IntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64IntX(vp *map[float64]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64IntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64IntV(v map[float64]int, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]int, containerLen) + } else { + v = make(map[float64]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64Int8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]int8) + v, changed := fastpathTV.DecMapFloat64Int8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]int8) + fastpathTV.DecMapFloat64Int8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64Int8X(vp *map[float64]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64Int8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64Int8V(v map[float64]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]int8, containerLen) + } else { + v = make(map[float64]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64Int16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]int16) + v, changed := fastpathTV.DecMapFloat64Int16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]int16) + fastpathTV.DecMapFloat64Int16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64Int16X(vp *map[float64]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64Int16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64Int16V(v map[float64]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]int16, containerLen) + } else { + v = make(map[float64]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64Int32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]int32) + v, changed := fastpathTV.DecMapFloat64Int32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]int32) + fastpathTV.DecMapFloat64Int32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64Int32X(vp *map[float64]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64Int32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64Int32V(v map[float64]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]int32, containerLen) + } else { + v = make(map[float64]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64Int64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]int64) + v, changed := fastpathTV.DecMapFloat64Int64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]int64) + fastpathTV.DecMapFloat64Int64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64Int64X(vp *map[float64]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64Int64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64Int64V(v map[float64]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]int64, containerLen) + } else { + v = make(map[float64]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64Float32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]float32) + v, changed := fastpathTV.DecMapFloat64Float32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]float32) + fastpathTV.DecMapFloat64Float32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64Float32X(vp *map[float64]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64Float32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64Float32V(v map[float64]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]float32, containerLen) + } else { + v = make(map[float64]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64Float64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]float64) + v, changed := fastpathTV.DecMapFloat64Float64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]float64) + fastpathTV.DecMapFloat64Float64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64Float64X(vp *map[float64]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64Float64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64Float64V(v map[float64]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]float64, containerLen) + } else { + v = make(map[float64]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapFloat64BoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[float64]bool) + v, changed := fastpathTV.DecMapFloat64BoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[float64]bool) + fastpathTV.DecMapFloat64BoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapFloat64BoolX(vp *map[float64]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapFloat64BoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapFloat64BoolV(v map[float64]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[float64]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[float64]bool, containerLen) + } else { + v = make(map[float64]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeFloat(false) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeFloat(false) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintIntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]interface{}) + v, changed := fastpathTV.DecMapUintIntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]interface{}) + fastpathTV.DecMapUintIntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintIntfX(vp *map[uint]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintIntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintIntfV(v map[uint]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]interface{}, containerLen) + } else { + v = make(map[uint]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintStringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]string) + v, changed := fastpathTV.DecMapUintStringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]string) + fastpathTV.DecMapUintStringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintStringX(vp *map[uint]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintStringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintStringV(v map[uint]string, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]string, containerLen) + } else { + v = make(map[uint]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintUintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]uint) + v, changed := fastpathTV.DecMapUintUintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]uint) + fastpathTV.DecMapUintUintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintUintX(vp *map[uint]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintUintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintUintV(v map[uint]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]uint, containerLen) + } else { + v = make(map[uint]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintUint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]uint8) + v, changed := fastpathTV.DecMapUintUint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]uint8) + fastpathTV.DecMapUintUint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintUint8X(vp *map[uint]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintUint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintUint8V(v map[uint]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]uint8, containerLen) + } else { + v = make(map[uint]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintUint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]uint16) + v, changed := fastpathTV.DecMapUintUint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]uint16) + fastpathTV.DecMapUintUint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintUint16X(vp *map[uint]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintUint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintUint16V(v map[uint]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]uint16, containerLen) + } else { + v = make(map[uint]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintUint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]uint32) + v, changed := fastpathTV.DecMapUintUint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]uint32) + fastpathTV.DecMapUintUint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintUint32X(vp *map[uint]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintUint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintUint32V(v map[uint]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]uint32, containerLen) + } else { + v = make(map[uint]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintUint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]uint64) + v, changed := fastpathTV.DecMapUintUint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]uint64) + fastpathTV.DecMapUintUint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintUint64X(vp *map[uint]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintUint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintUint64V(v map[uint]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]uint64, containerLen) + } else { + v = make(map[uint]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintIntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]int) + v, changed := fastpathTV.DecMapUintIntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]int) + fastpathTV.DecMapUintIntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintIntX(vp *map[uint]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintIntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintIntV(v map[uint]int, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]int, containerLen) + } else { + v = make(map[uint]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintInt8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]int8) + v, changed := fastpathTV.DecMapUintInt8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]int8) + fastpathTV.DecMapUintInt8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintInt8X(vp *map[uint]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintInt8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintInt8V(v map[uint]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]int8, containerLen) + } else { + v = make(map[uint]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintInt16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]int16) + v, changed := fastpathTV.DecMapUintInt16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]int16) + fastpathTV.DecMapUintInt16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintInt16X(vp *map[uint]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintInt16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintInt16V(v map[uint]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]int16, containerLen) + } else { + v = make(map[uint]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintInt32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]int32) + v, changed := fastpathTV.DecMapUintInt32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]int32) + fastpathTV.DecMapUintInt32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintInt32X(vp *map[uint]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintInt32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintInt32V(v map[uint]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]int32, containerLen) + } else { + v = make(map[uint]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintInt64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]int64) + v, changed := fastpathTV.DecMapUintInt64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]int64) + fastpathTV.DecMapUintInt64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintInt64X(vp *map[uint]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintInt64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintInt64V(v map[uint]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]int64, containerLen) + } else { + v = make(map[uint]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintFloat32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]float32) + v, changed := fastpathTV.DecMapUintFloat32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]float32) + fastpathTV.DecMapUintFloat32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintFloat32X(vp *map[uint]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintFloat32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintFloat32V(v map[uint]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]float32, containerLen) + } else { + v = make(map[uint]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintFloat64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]float64) + v, changed := fastpathTV.DecMapUintFloat64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]float64) + fastpathTV.DecMapUintFloat64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintFloat64X(vp *map[uint]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintFloat64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintFloat64V(v map[uint]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]float64, containerLen) + } else { + v = make(map[uint]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUintBoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint]bool) + v, changed := fastpathTV.DecMapUintBoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint]bool) + fastpathTV.DecMapUintBoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUintBoolX(vp *map[uint]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapUintBoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUintBoolV(v map[uint]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[uint]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint]bool, containerLen) + } else { + v = make(map[uint]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint(dd.DecodeUint(uintBitsize)) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint(dd.DecodeUint(uintBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8IntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]interface{}) + v, changed := fastpathTV.DecMapUint8IntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]interface{}) + fastpathTV.DecMapUint8IntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8IntfX(vp *map[uint8]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8IntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8IntfV(v map[uint8]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]interface{}, containerLen) + } else { + v = make(map[uint8]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8StringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]string) + v, changed := fastpathTV.DecMapUint8StringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]string) + fastpathTV.DecMapUint8StringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8StringX(vp *map[uint8]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8StringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8StringV(v map[uint8]string, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]string, containerLen) + } else { + v = make(map[uint8]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8UintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]uint) + v, changed := fastpathTV.DecMapUint8UintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]uint) + fastpathTV.DecMapUint8UintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8UintX(vp *map[uint8]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8UintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8UintV(v map[uint8]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]uint, containerLen) + } else { + v = make(map[uint8]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8Uint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]uint8) + v, changed := fastpathTV.DecMapUint8Uint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]uint8) + fastpathTV.DecMapUint8Uint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8Uint8X(vp *map[uint8]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8Uint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8Uint8V(v map[uint8]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]uint8, containerLen) + } else { + v = make(map[uint8]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8Uint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]uint16) + v, changed := fastpathTV.DecMapUint8Uint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]uint16) + fastpathTV.DecMapUint8Uint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8Uint16X(vp *map[uint8]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8Uint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8Uint16V(v map[uint8]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]uint16, containerLen) + } else { + v = make(map[uint8]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8Uint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]uint32) + v, changed := fastpathTV.DecMapUint8Uint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]uint32) + fastpathTV.DecMapUint8Uint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8Uint32X(vp *map[uint8]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8Uint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8Uint32V(v map[uint8]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]uint32, containerLen) + } else { + v = make(map[uint8]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8Uint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]uint64) + v, changed := fastpathTV.DecMapUint8Uint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]uint64) + fastpathTV.DecMapUint8Uint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8Uint64X(vp *map[uint8]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8Uint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8Uint64V(v map[uint8]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]uint64, containerLen) + } else { + v = make(map[uint8]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8IntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]int) + v, changed := fastpathTV.DecMapUint8IntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]int) + fastpathTV.DecMapUint8IntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8IntX(vp *map[uint8]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8IntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8IntV(v map[uint8]int, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]int, containerLen) + } else { + v = make(map[uint8]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8Int8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]int8) + v, changed := fastpathTV.DecMapUint8Int8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]int8) + fastpathTV.DecMapUint8Int8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8Int8X(vp *map[uint8]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8Int8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8Int8V(v map[uint8]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]int8, containerLen) + } else { + v = make(map[uint8]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8Int16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]int16) + v, changed := fastpathTV.DecMapUint8Int16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]int16) + fastpathTV.DecMapUint8Int16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8Int16X(vp *map[uint8]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8Int16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8Int16V(v map[uint8]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]int16, containerLen) + } else { + v = make(map[uint8]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8Int32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]int32) + v, changed := fastpathTV.DecMapUint8Int32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]int32) + fastpathTV.DecMapUint8Int32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8Int32X(vp *map[uint8]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8Int32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8Int32V(v map[uint8]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]int32, containerLen) + } else { + v = make(map[uint8]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8Int64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]int64) + v, changed := fastpathTV.DecMapUint8Int64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]int64) + fastpathTV.DecMapUint8Int64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8Int64X(vp *map[uint8]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8Int64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8Int64V(v map[uint8]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]int64, containerLen) + } else { + v = make(map[uint8]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8Float32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]float32) + v, changed := fastpathTV.DecMapUint8Float32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]float32) + fastpathTV.DecMapUint8Float32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8Float32X(vp *map[uint8]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8Float32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8Float32V(v map[uint8]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]float32, containerLen) + } else { + v = make(map[uint8]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8Float64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]float64) + v, changed := fastpathTV.DecMapUint8Float64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]float64) + fastpathTV.DecMapUint8Float64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8Float64X(vp *map[uint8]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8Float64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8Float64V(v map[uint8]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]float64, containerLen) + } else { + v = make(map[uint8]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint8BoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint8]bool) + v, changed := fastpathTV.DecMapUint8BoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint8]bool) + fastpathTV.DecMapUint8BoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint8BoolX(vp *map[uint8]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint8BoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint8BoolV(v map[uint8]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[uint8]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint8]bool, containerLen) + } else { + v = make(map[uint8]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint8(dd.DecodeUint(8)) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint8(dd.DecodeUint(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16IntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]interface{}) + v, changed := fastpathTV.DecMapUint16IntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]interface{}) + fastpathTV.DecMapUint16IntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16IntfX(vp *map[uint16]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16IntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16IntfV(v map[uint16]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]interface{}, containerLen) + } else { + v = make(map[uint16]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16StringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]string) + v, changed := fastpathTV.DecMapUint16StringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]string) + fastpathTV.DecMapUint16StringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16StringX(vp *map[uint16]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16StringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16StringV(v map[uint16]string, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]string, containerLen) + } else { + v = make(map[uint16]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16UintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]uint) + v, changed := fastpathTV.DecMapUint16UintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]uint) + fastpathTV.DecMapUint16UintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16UintX(vp *map[uint16]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16UintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16UintV(v map[uint16]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]uint, containerLen) + } else { + v = make(map[uint16]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16Uint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]uint8) + v, changed := fastpathTV.DecMapUint16Uint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]uint8) + fastpathTV.DecMapUint16Uint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16Uint8X(vp *map[uint16]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16Uint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16Uint8V(v map[uint16]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]uint8, containerLen) + } else { + v = make(map[uint16]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16Uint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]uint16) + v, changed := fastpathTV.DecMapUint16Uint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]uint16) + fastpathTV.DecMapUint16Uint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16Uint16X(vp *map[uint16]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16Uint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16Uint16V(v map[uint16]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]uint16, containerLen) + } else { + v = make(map[uint16]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16Uint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]uint32) + v, changed := fastpathTV.DecMapUint16Uint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]uint32) + fastpathTV.DecMapUint16Uint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16Uint32X(vp *map[uint16]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16Uint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16Uint32V(v map[uint16]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]uint32, containerLen) + } else { + v = make(map[uint16]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16Uint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]uint64) + v, changed := fastpathTV.DecMapUint16Uint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]uint64) + fastpathTV.DecMapUint16Uint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16Uint64X(vp *map[uint16]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16Uint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16Uint64V(v map[uint16]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]uint64, containerLen) + } else { + v = make(map[uint16]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16IntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]int) + v, changed := fastpathTV.DecMapUint16IntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]int) + fastpathTV.DecMapUint16IntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16IntX(vp *map[uint16]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16IntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16IntV(v map[uint16]int, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]int, containerLen) + } else { + v = make(map[uint16]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16Int8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]int8) + v, changed := fastpathTV.DecMapUint16Int8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]int8) + fastpathTV.DecMapUint16Int8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16Int8X(vp *map[uint16]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16Int8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16Int8V(v map[uint16]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]int8, containerLen) + } else { + v = make(map[uint16]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16Int16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]int16) + v, changed := fastpathTV.DecMapUint16Int16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]int16) + fastpathTV.DecMapUint16Int16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16Int16X(vp *map[uint16]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16Int16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16Int16V(v map[uint16]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]int16, containerLen) + } else { + v = make(map[uint16]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16Int32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]int32) + v, changed := fastpathTV.DecMapUint16Int32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]int32) + fastpathTV.DecMapUint16Int32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16Int32X(vp *map[uint16]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16Int32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16Int32V(v map[uint16]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]int32, containerLen) + } else { + v = make(map[uint16]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16Int64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]int64) + v, changed := fastpathTV.DecMapUint16Int64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]int64) + fastpathTV.DecMapUint16Int64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16Int64X(vp *map[uint16]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16Int64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16Int64V(v map[uint16]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]int64, containerLen) + } else { + v = make(map[uint16]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16Float32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]float32) + v, changed := fastpathTV.DecMapUint16Float32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]float32) + fastpathTV.DecMapUint16Float32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16Float32X(vp *map[uint16]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16Float32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16Float32V(v map[uint16]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]float32, containerLen) + } else { + v = make(map[uint16]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16Float64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]float64) + v, changed := fastpathTV.DecMapUint16Float64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]float64) + fastpathTV.DecMapUint16Float64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16Float64X(vp *map[uint16]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16Float64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16Float64V(v map[uint16]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]float64, containerLen) + } else { + v = make(map[uint16]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint16BoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint16]bool) + v, changed := fastpathTV.DecMapUint16BoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint16]bool) + fastpathTV.DecMapUint16BoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint16BoolX(vp *map[uint16]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint16BoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint16BoolV(v map[uint16]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[uint16]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint16]bool, containerLen) + } else { + v = make(map[uint16]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint16(dd.DecodeUint(16)) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint16(dd.DecodeUint(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32IntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]interface{}) + v, changed := fastpathTV.DecMapUint32IntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]interface{}) + fastpathTV.DecMapUint32IntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32IntfX(vp *map[uint32]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32IntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32IntfV(v map[uint32]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]interface{}, containerLen) + } else { + v = make(map[uint32]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32StringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]string) + v, changed := fastpathTV.DecMapUint32StringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]string) + fastpathTV.DecMapUint32StringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32StringX(vp *map[uint32]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32StringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32StringV(v map[uint32]string, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]string, containerLen) + } else { + v = make(map[uint32]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32UintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]uint) + v, changed := fastpathTV.DecMapUint32UintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]uint) + fastpathTV.DecMapUint32UintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32UintX(vp *map[uint32]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32UintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32UintV(v map[uint32]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]uint, containerLen) + } else { + v = make(map[uint32]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32Uint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]uint8) + v, changed := fastpathTV.DecMapUint32Uint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]uint8) + fastpathTV.DecMapUint32Uint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32Uint8X(vp *map[uint32]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32Uint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32Uint8V(v map[uint32]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]uint8, containerLen) + } else { + v = make(map[uint32]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32Uint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]uint16) + v, changed := fastpathTV.DecMapUint32Uint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]uint16) + fastpathTV.DecMapUint32Uint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32Uint16X(vp *map[uint32]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32Uint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32Uint16V(v map[uint32]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]uint16, containerLen) + } else { + v = make(map[uint32]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32Uint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]uint32) + v, changed := fastpathTV.DecMapUint32Uint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]uint32) + fastpathTV.DecMapUint32Uint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32Uint32X(vp *map[uint32]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32Uint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32Uint32V(v map[uint32]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]uint32, containerLen) + } else { + v = make(map[uint32]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32Uint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]uint64) + v, changed := fastpathTV.DecMapUint32Uint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]uint64) + fastpathTV.DecMapUint32Uint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32Uint64X(vp *map[uint32]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32Uint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32Uint64V(v map[uint32]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]uint64, containerLen) + } else { + v = make(map[uint32]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32IntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]int) + v, changed := fastpathTV.DecMapUint32IntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]int) + fastpathTV.DecMapUint32IntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32IntX(vp *map[uint32]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32IntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32IntV(v map[uint32]int, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]int, containerLen) + } else { + v = make(map[uint32]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32Int8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]int8) + v, changed := fastpathTV.DecMapUint32Int8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]int8) + fastpathTV.DecMapUint32Int8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32Int8X(vp *map[uint32]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32Int8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32Int8V(v map[uint32]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]int8, containerLen) + } else { + v = make(map[uint32]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32Int16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]int16) + v, changed := fastpathTV.DecMapUint32Int16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]int16) + fastpathTV.DecMapUint32Int16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32Int16X(vp *map[uint32]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32Int16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32Int16V(v map[uint32]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]int16, containerLen) + } else { + v = make(map[uint32]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32Int32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]int32) + v, changed := fastpathTV.DecMapUint32Int32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]int32) + fastpathTV.DecMapUint32Int32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32Int32X(vp *map[uint32]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32Int32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32Int32V(v map[uint32]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]int32, containerLen) + } else { + v = make(map[uint32]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32Int64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]int64) + v, changed := fastpathTV.DecMapUint32Int64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]int64) + fastpathTV.DecMapUint32Int64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32Int64X(vp *map[uint32]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32Int64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32Int64V(v map[uint32]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]int64, containerLen) + } else { + v = make(map[uint32]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32Float32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]float32) + v, changed := fastpathTV.DecMapUint32Float32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]float32) + fastpathTV.DecMapUint32Float32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32Float32X(vp *map[uint32]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32Float32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32Float32V(v map[uint32]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]float32, containerLen) + } else { + v = make(map[uint32]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32Float64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]float64) + v, changed := fastpathTV.DecMapUint32Float64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]float64) + fastpathTV.DecMapUint32Float64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32Float64X(vp *map[uint32]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32Float64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32Float64V(v map[uint32]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]float64, containerLen) + } else { + v = make(map[uint32]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint32BoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint32]bool) + v, changed := fastpathTV.DecMapUint32BoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint32]bool) + fastpathTV.DecMapUint32BoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint32BoolX(vp *map[uint32]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint32BoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint32BoolV(v map[uint32]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[uint32]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint32]bool, containerLen) + } else { + v = make(map[uint32]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := uint32(dd.DecodeUint(32)) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := uint32(dd.DecodeUint(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64IntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]interface{}) + v, changed := fastpathTV.DecMapUint64IntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]interface{}) + fastpathTV.DecMapUint64IntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64IntfX(vp *map[uint64]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64IntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64IntfV(v map[uint64]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]interface{}, containerLen) + } else { + v = make(map[uint64]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64StringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]string) + v, changed := fastpathTV.DecMapUint64StringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]string) + fastpathTV.DecMapUint64StringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64StringX(vp *map[uint64]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64StringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64StringV(v map[uint64]string, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]string, containerLen) + } else { + v = make(map[uint64]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64UintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]uint) + v, changed := fastpathTV.DecMapUint64UintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]uint) + fastpathTV.DecMapUint64UintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64UintX(vp *map[uint64]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64UintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64UintV(v map[uint64]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]uint, containerLen) + } else { + v = make(map[uint64]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64Uint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]uint8) + v, changed := fastpathTV.DecMapUint64Uint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]uint8) + fastpathTV.DecMapUint64Uint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64Uint8X(vp *map[uint64]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64Uint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64Uint8V(v map[uint64]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]uint8, containerLen) + } else { + v = make(map[uint64]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64Uint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]uint16) + v, changed := fastpathTV.DecMapUint64Uint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]uint16) + fastpathTV.DecMapUint64Uint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64Uint16X(vp *map[uint64]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64Uint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64Uint16V(v map[uint64]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]uint16, containerLen) + } else { + v = make(map[uint64]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64Uint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]uint32) + v, changed := fastpathTV.DecMapUint64Uint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]uint32) + fastpathTV.DecMapUint64Uint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64Uint32X(vp *map[uint64]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64Uint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64Uint32V(v map[uint64]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]uint32, containerLen) + } else { + v = make(map[uint64]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64Uint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]uint64) + v, changed := fastpathTV.DecMapUint64Uint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]uint64) + fastpathTV.DecMapUint64Uint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64Uint64X(vp *map[uint64]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64Uint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64Uint64V(v map[uint64]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]uint64, containerLen) + } else { + v = make(map[uint64]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64IntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]int) + v, changed := fastpathTV.DecMapUint64IntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]int) + fastpathTV.DecMapUint64IntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64IntX(vp *map[uint64]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64IntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64IntV(v map[uint64]int, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]int, containerLen) + } else { + v = make(map[uint64]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64Int8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]int8) + v, changed := fastpathTV.DecMapUint64Int8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]int8) + fastpathTV.DecMapUint64Int8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64Int8X(vp *map[uint64]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64Int8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64Int8V(v map[uint64]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]int8, containerLen) + } else { + v = make(map[uint64]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64Int16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]int16) + v, changed := fastpathTV.DecMapUint64Int16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]int16) + fastpathTV.DecMapUint64Int16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64Int16X(vp *map[uint64]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64Int16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64Int16V(v map[uint64]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]int16, containerLen) + } else { + v = make(map[uint64]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64Int32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]int32) + v, changed := fastpathTV.DecMapUint64Int32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]int32) + fastpathTV.DecMapUint64Int32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64Int32X(vp *map[uint64]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64Int32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64Int32V(v map[uint64]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]int32, containerLen) + } else { + v = make(map[uint64]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64Int64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]int64) + v, changed := fastpathTV.DecMapUint64Int64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]int64) + fastpathTV.DecMapUint64Int64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64Int64X(vp *map[uint64]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64Int64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64Int64V(v map[uint64]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]int64, containerLen) + } else { + v = make(map[uint64]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64Float32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]float32) + v, changed := fastpathTV.DecMapUint64Float32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]float32) + fastpathTV.DecMapUint64Float32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64Float32X(vp *map[uint64]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64Float32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64Float32V(v map[uint64]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]float32, containerLen) + } else { + v = make(map[uint64]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64Float64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]float64) + v, changed := fastpathTV.DecMapUint64Float64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]float64) + fastpathTV.DecMapUint64Float64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64Float64X(vp *map[uint64]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64Float64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64Float64V(v map[uint64]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]float64, containerLen) + } else { + v = make(map[uint64]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapUint64BoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[uint64]bool) + v, changed := fastpathTV.DecMapUint64BoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[uint64]bool) + fastpathTV.DecMapUint64BoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapUint64BoolX(vp *map[uint64]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapUint64BoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapUint64BoolV(v map[uint64]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[uint64]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[uint64]bool, containerLen) + } else { + v = make(map[uint64]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeUint(64) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeUint(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntIntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]interface{}) + v, changed := fastpathTV.DecMapIntIntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]interface{}) + fastpathTV.DecMapIntIntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntIntfX(vp *map[int]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntIntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntIntfV(v map[int]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[int]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]interface{}, containerLen) + } else { + v = make(map[int]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntStringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]string) + v, changed := fastpathTV.DecMapIntStringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]string) + fastpathTV.DecMapIntStringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntStringX(vp *map[int]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntStringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntStringV(v map[int]string, checkNil bool, canChange bool, + d *Decoder) (_ map[int]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]string, containerLen) + } else { + v = make(map[int]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntUintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]uint) + v, changed := fastpathTV.DecMapIntUintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]uint) + fastpathTV.DecMapIntUintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntUintX(vp *map[int]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntUintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntUintV(v map[int]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[int]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]uint, containerLen) + } else { + v = make(map[int]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntUint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]uint8) + v, changed := fastpathTV.DecMapIntUint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]uint8) + fastpathTV.DecMapIntUint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntUint8X(vp *map[int]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntUint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntUint8V(v map[int]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[int]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]uint8, containerLen) + } else { + v = make(map[int]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntUint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]uint16) + v, changed := fastpathTV.DecMapIntUint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]uint16) + fastpathTV.DecMapIntUint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntUint16X(vp *map[int]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntUint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntUint16V(v map[int]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[int]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]uint16, containerLen) + } else { + v = make(map[int]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntUint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]uint32) + v, changed := fastpathTV.DecMapIntUint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]uint32) + fastpathTV.DecMapIntUint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntUint32X(vp *map[int]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntUint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntUint32V(v map[int]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[int]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]uint32, containerLen) + } else { + v = make(map[int]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntUint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]uint64) + v, changed := fastpathTV.DecMapIntUint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]uint64) + fastpathTV.DecMapIntUint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntUint64X(vp *map[int]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntUint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntUint64V(v map[int]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[int]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]uint64, containerLen) + } else { + v = make(map[int]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntIntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]int) + v, changed := fastpathTV.DecMapIntIntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]int) + fastpathTV.DecMapIntIntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntIntX(vp *map[int]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntIntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntIntV(v map[int]int, checkNil bool, canChange bool, + d *Decoder) (_ map[int]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]int, containerLen) + } else { + v = make(map[int]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntInt8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]int8) + v, changed := fastpathTV.DecMapIntInt8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]int8) + fastpathTV.DecMapIntInt8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntInt8X(vp *map[int]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntInt8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntInt8V(v map[int]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[int]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]int8, containerLen) + } else { + v = make(map[int]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntInt16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]int16) + v, changed := fastpathTV.DecMapIntInt16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]int16) + fastpathTV.DecMapIntInt16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntInt16X(vp *map[int]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntInt16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntInt16V(v map[int]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[int]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]int16, containerLen) + } else { + v = make(map[int]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntInt32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]int32) + v, changed := fastpathTV.DecMapIntInt32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]int32) + fastpathTV.DecMapIntInt32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntInt32X(vp *map[int]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntInt32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntInt32V(v map[int]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[int]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]int32, containerLen) + } else { + v = make(map[int]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntInt64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]int64) + v, changed := fastpathTV.DecMapIntInt64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]int64) + fastpathTV.DecMapIntInt64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntInt64X(vp *map[int]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntInt64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntInt64V(v map[int]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[int]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]int64, containerLen) + } else { + v = make(map[int]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntFloat32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]float32) + v, changed := fastpathTV.DecMapIntFloat32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]float32) + fastpathTV.DecMapIntFloat32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntFloat32X(vp *map[int]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntFloat32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntFloat32V(v map[int]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[int]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]float32, containerLen) + } else { + v = make(map[int]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntFloat64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]float64) + v, changed := fastpathTV.DecMapIntFloat64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]float64) + fastpathTV.DecMapIntFloat64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntFloat64X(vp *map[int]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntFloat64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntFloat64V(v map[int]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[int]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]float64, containerLen) + } else { + v = make(map[int]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapIntBoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int]bool) + v, changed := fastpathTV.DecMapIntBoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int]bool) + fastpathTV.DecMapIntBoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapIntBoolX(vp *map[int]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapIntBoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapIntBoolV(v map[int]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[int]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int]bool, containerLen) + } else { + v = make(map[int]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int(dd.DecodeInt(intBitsize)) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int(dd.DecodeInt(intBitsize)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8IntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]interface{}) + v, changed := fastpathTV.DecMapInt8IntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]interface{}) + fastpathTV.DecMapInt8IntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8IntfX(vp *map[int8]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8IntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8IntfV(v map[int8]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]interface{}, containerLen) + } else { + v = make(map[int8]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8StringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]string) + v, changed := fastpathTV.DecMapInt8StringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]string) + fastpathTV.DecMapInt8StringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8StringX(vp *map[int8]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8StringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8StringV(v map[int8]string, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]string, containerLen) + } else { + v = make(map[int8]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8UintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]uint) + v, changed := fastpathTV.DecMapInt8UintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]uint) + fastpathTV.DecMapInt8UintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8UintX(vp *map[int8]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8UintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8UintV(v map[int8]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]uint, containerLen) + } else { + v = make(map[int8]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8Uint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]uint8) + v, changed := fastpathTV.DecMapInt8Uint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]uint8) + fastpathTV.DecMapInt8Uint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8Uint8X(vp *map[int8]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8Uint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8Uint8V(v map[int8]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]uint8, containerLen) + } else { + v = make(map[int8]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8Uint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]uint16) + v, changed := fastpathTV.DecMapInt8Uint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]uint16) + fastpathTV.DecMapInt8Uint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8Uint16X(vp *map[int8]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8Uint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8Uint16V(v map[int8]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]uint16, containerLen) + } else { + v = make(map[int8]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8Uint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]uint32) + v, changed := fastpathTV.DecMapInt8Uint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]uint32) + fastpathTV.DecMapInt8Uint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8Uint32X(vp *map[int8]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8Uint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8Uint32V(v map[int8]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]uint32, containerLen) + } else { + v = make(map[int8]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8Uint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]uint64) + v, changed := fastpathTV.DecMapInt8Uint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]uint64) + fastpathTV.DecMapInt8Uint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8Uint64X(vp *map[int8]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8Uint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8Uint64V(v map[int8]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]uint64, containerLen) + } else { + v = make(map[int8]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8IntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]int) + v, changed := fastpathTV.DecMapInt8IntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]int) + fastpathTV.DecMapInt8IntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8IntX(vp *map[int8]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8IntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8IntV(v map[int8]int, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]int, containerLen) + } else { + v = make(map[int8]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8Int8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]int8) + v, changed := fastpathTV.DecMapInt8Int8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]int8) + fastpathTV.DecMapInt8Int8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8Int8X(vp *map[int8]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8Int8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8Int8V(v map[int8]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]int8, containerLen) + } else { + v = make(map[int8]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8Int16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]int16) + v, changed := fastpathTV.DecMapInt8Int16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]int16) + fastpathTV.DecMapInt8Int16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8Int16X(vp *map[int8]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8Int16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8Int16V(v map[int8]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]int16, containerLen) + } else { + v = make(map[int8]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8Int32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]int32) + v, changed := fastpathTV.DecMapInt8Int32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]int32) + fastpathTV.DecMapInt8Int32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8Int32X(vp *map[int8]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8Int32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8Int32V(v map[int8]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]int32, containerLen) + } else { + v = make(map[int8]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8Int64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]int64) + v, changed := fastpathTV.DecMapInt8Int64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]int64) + fastpathTV.DecMapInt8Int64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8Int64X(vp *map[int8]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8Int64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8Int64V(v map[int8]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]int64, containerLen) + } else { + v = make(map[int8]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8Float32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]float32) + v, changed := fastpathTV.DecMapInt8Float32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]float32) + fastpathTV.DecMapInt8Float32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8Float32X(vp *map[int8]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8Float32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8Float32V(v map[int8]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]float32, containerLen) + } else { + v = make(map[int8]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8Float64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]float64) + v, changed := fastpathTV.DecMapInt8Float64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]float64) + fastpathTV.DecMapInt8Float64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8Float64X(vp *map[int8]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8Float64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8Float64V(v map[int8]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]float64, containerLen) + } else { + v = make(map[int8]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt8BoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int8]bool) + v, changed := fastpathTV.DecMapInt8BoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int8]bool) + fastpathTV.DecMapInt8BoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt8BoolX(vp *map[int8]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt8BoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt8BoolV(v map[int8]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[int8]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int8]bool, containerLen) + } else { + v = make(map[int8]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int8(dd.DecodeInt(8)) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int8(dd.DecodeInt(8)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16IntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]interface{}) + v, changed := fastpathTV.DecMapInt16IntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]interface{}) + fastpathTV.DecMapInt16IntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16IntfX(vp *map[int16]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16IntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16IntfV(v map[int16]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]interface{}, containerLen) + } else { + v = make(map[int16]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16StringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]string) + v, changed := fastpathTV.DecMapInt16StringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]string) + fastpathTV.DecMapInt16StringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16StringX(vp *map[int16]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16StringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16StringV(v map[int16]string, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]string, containerLen) + } else { + v = make(map[int16]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16UintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]uint) + v, changed := fastpathTV.DecMapInt16UintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]uint) + fastpathTV.DecMapInt16UintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16UintX(vp *map[int16]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16UintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16UintV(v map[int16]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]uint, containerLen) + } else { + v = make(map[int16]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16Uint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]uint8) + v, changed := fastpathTV.DecMapInt16Uint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]uint8) + fastpathTV.DecMapInt16Uint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16Uint8X(vp *map[int16]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16Uint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16Uint8V(v map[int16]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]uint8, containerLen) + } else { + v = make(map[int16]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16Uint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]uint16) + v, changed := fastpathTV.DecMapInt16Uint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]uint16) + fastpathTV.DecMapInt16Uint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16Uint16X(vp *map[int16]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16Uint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16Uint16V(v map[int16]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]uint16, containerLen) + } else { + v = make(map[int16]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16Uint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]uint32) + v, changed := fastpathTV.DecMapInt16Uint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]uint32) + fastpathTV.DecMapInt16Uint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16Uint32X(vp *map[int16]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16Uint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16Uint32V(v map[int16]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]uint32, containerLen) + } else { + v = make(map[int16]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16Uint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]uint64) + v, changed := fastpathTV.DecMapInt16Uint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]uint64) + fastpathTV.DecMapInt16Uint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16Uint64X(vp *map[int16]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16Uint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16Uint64V(v map[int16]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]uint64, containerLen) + } else { + v = make(map[int16]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16IntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]int) + v, changed := fastpathTV.DecMapInt16IntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]int) + fastpathTV.DecMapInt16IntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16IntX(vp *map[int16]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16IntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16IntV(v map[int16]int, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]int, containerLen) + } else { + v = make(map[int16]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16Int8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]int8) + v, changed := fastpathTV.DecMapInt16Int8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]int8) + fastpathTV.DecMapInt16Int8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16Int8X(vp *map[int16]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16Int8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16Int8V(v map[int16]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]int8, containerLen) + } else { + v = make(map[int16]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16Int16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]int16) + v, changed := fastpathTV.DecMapInt16Int16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]int16) + fastpathTV.DecMapInt16Int16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16Int16X(vp *map[int16]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16Int16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16Int16V(v map[int16]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]int16, containerLen) + } else { + v = make(map[int16]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16Int32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]int32) + v, changed := fastpathTV.DecMapInt16Int32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]int32) + fastpathTV.DecMapInt16Int32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16Int32X(vp *map[int16]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16Int32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16Int32V(v map[int16]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]int32, containerLen) + } else { + v = make(map[int16]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16Int64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]int64) + v, changed := fastpathTV.DecMapInt16Int64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]int64) + fastpathTV.DecMapInt16Int64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16Int64X(vp *map[int16]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16Int64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16Int64V(v map[int16]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]int64, containerLen) + } else { + v = make(map[int16]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16Float32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]float32) + v, changed := fastpathTV.DecMapInt16Float32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]float32) + fastpathTV.DecMapInt16Float32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16Float32X(vp *map[int16]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16Float32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16Float32V(v map[int16]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]float32, containerLen) + } else { + v = make(map[int16]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16Float64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]float64) + v, changed := fastpathTV.DecMapInt16Float64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]float64) + fastpathTV.DecMapInt16Float64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16Float64X(vp *map[int16]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16Float64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16Float64V(v map[int16]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]float64, containerLen) + } else { + v = make(map[int16]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt16BoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int16]bool) + v, changed := fastpathTV.DecMapInt16BoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int16]bool) + fastpathTV.DecMapInt16BoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt16BoolX(vp *map[int16]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt16BoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt16BoolV(v map[int16]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[int16]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int16]bool, containerLen) + } else { + v = make(map[int16]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int16(dd.DecodeInt(16)) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int16(dd.DecodeInt(16)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32IntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]interface{}) + v, changed := fastpathTV.DecMapInt32IntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]interface{}) + fastpathTV.DecMapInt32IntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32IntfX(vp *map[int32]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32IntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32IntfV(v map[int32]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]interface{}, containerLen) + } else { + v = make(map[int32]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32StringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]string) + v, changed := fastpathTV.DecMapInt32StringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]string) + fastpathTV.DecMapInt32StringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32StringX(vp *map[int32]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32StringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32StringV(v map[int32]string, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]string, containerLen) + } else { + v = make(map[int32]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32UintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]uint) + v, changed := fastpathTV.DecMapInt32UintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]uint) + fastpathTV.DecMapInt32UintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32UintX(vp *map[int32]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32UintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32UintV(v map[int32]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]uint, containerLen) + } else { + v = make(map[int32]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32Uint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]uint8) + v, changed := fastpathTV.DecMapInt32Uint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]uint8) + fastpathTV.DecMapInt32Uint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32Uint8X(vp *map[int32]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32Uint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32Uint8V(v map[int32]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]uint8, containerLen) + } else { + v = make(map[int32]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32Uint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]uint16) + v, changed := fastpathTV.DecMapInt32Uint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]uint16) + fastpathTV.DecMapInt32Uint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32Uint16X(vp *map[int32]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32Uint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32Uint16V(v map[int32]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]uint16, containerLen) + } else { + v = make(map[int32]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32Uint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]uint32) + v, changed := fastpathTV.DecMapInt32Uint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]uint32) + fastpathTV.DecMapInt32Uint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32Uint32X(vp *map[int32]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32Uint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32Uint32V(v map[int32]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]uint32, containerLen) + } else { + v = make(map[int32]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32Uint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]uint64) + v, changed := fastpathTV.DecMapInt32Uint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]uint64) + fastpathTV.DecMapInt32Uint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32Uint64X(vp *map[int32]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32Uint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32Uint64V(v map[int32]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]uint64, containerLen) + } else { + v = make(map[int32]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32IntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]int) + v, changed := fastpathTV.DecMapInt32IntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]int) + fastpathTV.DecMapInt32IntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32IntX(vp *map[int32]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32IntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32IntV(v map[int32]int, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]int, containerLen) + } else { + v = make(map[int32]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32Int8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]int8) + v, changed := fastpathTV.DecMapInt32Int8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]int8) + fastpathTV.DecMapInt32Int8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32Int8X(vp *map[int32]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32Int8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32Int8V(v map[int32]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]int8, containerLen) + } else { + v = make(map[int32]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32Int16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]int16) + v, changed := fastpathTV.DecMapInt32Int16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]int16) + fastpathTV.DecMapInt32Int16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32Int16X(vp *map[int32]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32Int16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32Int16V(v map[int32]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]int16, containerLen) + } else { + v = make(map[int32]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32Int32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]int32) + v, changed := fastpathTV.DecMapInt32Int32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]int32) + fastpathTV.DecMapInt32Int32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32Int32X(vp *map[int32]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32Int32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32Int32V(v map[int32]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]int32, containerLen) + } else { + v = make(map[int32]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32Int64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]int64) + v, changed := fastpathTV.DecMapInt32Int64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]int64) + fastpathTV.DecMapInt32Int64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32Int64X(vp *map[int32]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32Int64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32Int64V(v map[int32]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]int64, containerLen) + } else { + v = make(map[int32]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32Float32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]float32) + v, changed := fastpathTV.DecMapInt32Float32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]float32) + fastpathTV.DecMapInt32Float32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32Float32X(vp *map[int32]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32Float32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32Float32V(v map[int32]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]float32, containerLen) + } else { + v = make(map[int32]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32Float64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]float64) + v, changed := fastpathTV.DecMapInt32Float64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]float64) + fastpathTV.DecMapInt32Float64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32Float64X(vp *map[int32]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32Float64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32Float64V(v map[int32]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]float64, containerLen) + } else { + v = make(map[int32]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt32BoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int32]bool) + v, changed := fastpathTV.DecMapInt32BoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int32]bool) + fastpathTV.DecMapInt32BoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt32BoolX(vp *map[int32]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt32BoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt32BoolV(v map[int32]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[int32]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int32]bool, containerLen) + } else { + v = make(map[int32]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := int32(dd.DecodeInt(32)) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := int32(dd.DecodeInt(32)) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64IntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]interface{}) + v, changed := fastpathTV.DecMapInt64IntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]interface{}) + fastpathTV.DecMapInt64IntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64IntfX(vp *map[int64]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64IntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64IntfV(v map[int64]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]interface{}, containerLen) + } else { + v = make(map[int64]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64StringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]string) + v, changed := fastpathTV.DecMapInt64StringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]string) + fastpathTV.DecMapInt64StringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64StringX(vp *map[int64]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64StringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64StringV(v map[int64]string, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]string, containerLen) + } else { + v = make(map[int64]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64UintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]uint) + v, changed := fastpathTV.DecMapInt64UintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]uint) + fastpathTV.DecMapInt64UintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64UintX(vp *map[int64]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64UintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64UintV(v map[int64]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]uint, containerLen) + } else { + v = make(map[int64]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64Uint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]uint8) + v, changed := fastpathTV.DecMapInt64Uint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]uint8) + fastpathTV.DecMapInt64Uint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64Uint8X(vp *map[int64]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64Uint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64Uint8V(v map[int64]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]uint8, containerLen) + } else { + v = make(map[int64]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64Uint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]uint16) + v, changed := fastpathTV.DecMapInt64Uint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]uint16) + fastpathTV.DecMapInt64Uint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64Uint16X(vp *map[int64]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64Uint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64Uint16V(v map[int64]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]uint16, containerLen) + } else { + v = make(map[int64]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64Uint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]uint32) + v, changed := fastpathTV.DecMapInt64Uint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]uint32) + fastpathTV.DecMapInt64Uint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64Uint32X(vp *map[int64]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64Uint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64Uint32V(v map[int64]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]uint32, containerLen) + } else { + v = make(map[int64]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64Uint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]uint64) + v, changed := fastpathTV.DecMapInt64Uint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]uint64) + fastpathTV.DecMapInt64Uint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64Uint64X(vp *map[int64]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64Uint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64Uint64V(v map[int64]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]uint64, containerLen) + } else { + v = make(map[int64]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64IntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]int) + v, changed := fastpathTV.DecMapInt64IntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]int) + fastpathTV.DecMapInt64IntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64IntX(vp *map[int64]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64IntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64IntV(v map[int64]int, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]int, containerLen) + } else { + v = make(map[int64]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64Int8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]int8) + v, changed := fastpathTV.DecMapInt64Int8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]int8) + fastpathTV.DecMapInt64Int8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64Int8X(vp *map[int64]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64Int8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64Int8V(v map[int64]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]int8, containerLen) + } else { + v = make(map[int64]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64Int16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]int16) + v, changed := fastpathTV.DecMapInt64Int16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]int16) + fastpathTV.DecMapInt64Int16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64Int16X(vp *map[int64]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64Int16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64Int16V(v map[int64]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]int16, containerLen) + } else { + v = make(map[int64]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64Int32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]int32) + v, changed := fastpathTV.DecMapInt64Int32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]int32) + fastpathTV.DecMapInt64Int32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64Int32X(vp *map[int64]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64Int32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64Int32V(v map[int64]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]int32, containerLen) + } else { + v = make(map[int64]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64Int64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]int64) + v, changed := fastpathTV.DecMapInt64Int64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]int64) + fastpathTV.DecMapInt64Int64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64Int64X(vp *map[int64]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64Int64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64Int64V(v map[int64]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]int64, containerLen) + } else { + v = make(map[int64]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64Float32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]float32) + v, changed := fastpathTV.DecMapInt64Float32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]float32) + fastpathTV.DecMapInt64Float32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64Float32X(vp *map[int64]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64Float32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64Float32V(v map[int64]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]float32, containerLen) + } else { + v = make(map[int64]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64Float64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]float64) + v, changed := fastpathTV.DecMapInt64Float64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]float64) + fastpathTV.DecMapInt64Float64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64Float64X(vp *map[int64]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64Float64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64Float64V(v map[int64]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]float64, containerLen) + } else { + v = make(map[int64]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapInt64BoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[int64]bool) + v, changed := fastpathTV.DecMapInt64BoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[int64]bool) + fastpathTV.DecMapInt64BoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapInt64BoolX(vp *map[int64]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapInt64BoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapInt64BoolV(v map[int64]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[int64]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[int64]bool, containerLen) + } else { + v = make(map[int64]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeInt(64) + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeInt(64) + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolIntfR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]interface{}) + v, changed := fastpathTV.DecMapBoolIntfV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]interface{}) + fastpathTV.DecMapBoolIntfV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolIntfX(vp *map[bool]interface{}, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolIntfV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolIntfV(v map[bool]interface{}, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]interface{}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]interface{}, containerLen) + } else { + v = make(map[bool]interface{}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + d.decode(&mv) + + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolStringR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]string) + v, changed := fastpathTV.DecMapBoolStringV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]string) + fastpathTV.DecMapBoolStringV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolStringX(vp *map[bool]string, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolStringV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolStringV(v map[bool]string, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]string, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]string, containerLen) + } else { + v = make(map[bool]string) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeString() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolUintR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]uint) + v, changed := fastpathTV.DecMapBoolUintV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]uint) + fastpathTV.DecMapBoolUintV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolUintX(vp *map[bool]uint, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolUintV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolUintV(v map[bool]uint, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]uint, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]uint, containerLen) + } else { + v = make(map[bool]uint) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint(dd.DecodeUint(uintBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolUint8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]uint8) + v, changed := fastpathTV.DecMapBoolUint8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]uint8) + fastpathTV.DecMapBoolUint8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolUint8X(vp *map[bool]uint8, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolUint8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolUint8V(v map[bool]uint8, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]uint8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]uint8, containerLen) + } else { + v = make(map[bool]uint8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint8(dd.DecodeUint(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolUint16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]uint16) + v, changed := fastpathTV.DecMapBoolUint16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]uint16) + fastpathTV.DecMapBoolUint16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolUint16X(vp *map[bool]uint16, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolUint16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolUint16V(v map[bool]uint16, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]uint16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]uint16, containerLen) + } else { + v = make(map[bool]uint16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint16(dd.DecodeUint(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolUint32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]uint32) + v, changed := fastpathTV.DecMapBoolUint32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]uint32) + fastpathTV.DecMapBoolUint32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolUint32X(vp *map[bool]uint32, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolUint32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolUint32V(v map[bool]uint32, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]uint32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]uint32, containerLen) + } else { + v = make(map[bool]uint32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = uint32(dd.DecodeUint(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolUint64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]uint64) + v, changed := fastpathTV.DecMapBoolUint64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]uint64) + fastpathTV.DecMapBoolUint64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolUint64X(vp *map[bool]uint64, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolUint64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolUint64V(v map[bool]uint64, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]uint64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]uint64, containerLen) + } else { + v = make(map[bool]uint64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeUint(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolIntR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]int) + v, changed := fastpathTV.DecMapBoolIntV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]int) + fastpathTV.DecMapBoolIntV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolIntX(vp *map[bool]int, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolIntV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolIntV(v map[bool]int, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]int, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]int, containerLen) + } else { + v = make(map[bool]int) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int(dd.DecodeInt(intBitsize)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolInt8R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]int8) + v, changed := fastpathTV.DecMapBoolInt8V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]int8) + fastpathTV.DecMapBoolInt8V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolInt8X(vp *map[bool]int8, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolInt8V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolInt8V(v map[bool]int8, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]int8, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]int8, containerLen) + } else { + v = make(map[bool]int8) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int8(dd.DecodeInt(8)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolInt16R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]int16) + v, changed := fastpathTV.DecMapBoolInt16V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]int16) + fastpathTV.DecMapBoolInt16V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolInt16X(vp *map[bool]int16, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolInt16V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolInt16V(v map[bool]int16, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]int16, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]int16, containerLen) + } else { + v = make(map[bool]int16) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int16(dd.DecodeInt(16)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolInt32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]int32) + v, changed := fastpathTV.DecMapBoolInt32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]int32) + fastpathTV.DecMapBoolInt32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolInt32X(vp *map[bool]int32, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolInt32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolInt32V(v map[bool]int32, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]int32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]int32, containerLen) + } else { + v = make(map[bool]int32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = int32(dd.DecodeInt(32)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolInt64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]int64) + v, changed := fastpathTV.DecMapBoolInt64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]int64) + fastpathTV.DecMapBoolInt64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolInt64X(vp *map[bool]int64, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolInt64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolInt64V(v map[bool]int64, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]int64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]int64, containerLen) + } else { + v = make(map[bool]int64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeInt(64) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolFloat32R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]float32) + v, changed := fastpathTV.DecMapBoolFloat32V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]float32) + fastpathTV.DecMapBoolFloat32V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolFloat32X(vp *map[bool]float32, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolFloat32V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolFloat32V(v map[bool]float32, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]float32, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]float32, containerLen) + } else { + v = make(map[bool]float32) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = float32(dd.DecodeFloat(true)) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolFloat64R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]float64) + v, changed := fastpathTV.DecMapBoolFloat64V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]float64) + fastpathTV.DecMapBoolFloat64V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolFloat64X(vp *map[bool]float64, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolFloat64V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolFloat64V(v map[bool]float64, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]float64, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]float64, containerLen) + } else { + v = make(map[bool]float64) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeFloat(false) + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +func (f decFnInfo) fastpathDecMapBoolBoolR(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[bool]bool) + v, changed := fastpathTV.DecMapBoolBoolV(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[bool]bool) + fastpathTV.DecMapBoolBoolV(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) DecMapBoolBoolX(vp *map[bool]bool, checkNil bool, d *Decoder) { + v, changed := f.DecMapBoolBoolV(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) DecMapBoolBoolV(v map[bool]bool, checkNil bool, canChange bool, + d *Decoder) (_ map[bool]bool, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[bool]bool, containerLen) + } else { + v = make(map[bool]bool) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + mk := dd.DecodeBool() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + mk := dd.DecodeBool() + dd.ReadMapKVSeparator() + mv := v[mk] + mv = dd.DecodeBool() + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/fast-path.go.tmpl b/Godeps/_workspace/src/github.com/ugorji/go/codec/fast-path.go.tmpl new file mode 100644 index 0000000000..19138c87ab --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/fast-path.go.tmpl @@ -0,0 +1,442 @@ +// //+build ignore + +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +// ************************************************************ +// DO NOT EDIT. +// THIS FILE IS AUTO-GENERATED from fast-path.go.tmpl +// ************************************************************ + +package codec + +// Fast path functions try to create a fast path encode or decode implementation +// for common maps and slices. +// +// We define the functions and register then in this single file +// so as not to pollute the encode.go and decode.go, and create a dependency in there. +// This file can be omitted without causing a build failure. +// +// The advantage of fast paths is: +// - Many calls bypass reflection altogether +// +// Currently support +// - slice of all builtin types, +// - map of all builtin types to string or interface value +// - symetrical maps of all builtin types (e.g. str-str, uint8-uint8) +// This should provide adequate "typical" implementations. +// +// Note that fast track decode functions must handle values for which an address cannot be obtained. +// For example: +// m2 := map[string]int{} +// p2 := []interface{}{m2} +// // decoding into p2 will bomb if fast track functions do not treat like unaddressable. +// + +import ( + "reflect" + "sort" +) + +const fastpathCheckNilFalse = false // for reflect +const fastpathCheckNilTrue = true // for type switch + +type fastpathT struct {} + +var fastpathTV fastpathT + +type fastpathE struct { + rtid uintptr + rt reflect.Type + encfn func(encFnInfo, reflect.Value) + decfn func(decFnInfo, reflect.Value) +} + +type fastpathA [{{ .FastpathLen }}]fastpathE + +func (x *fastpathA) index(rtid uintptr) int { + // use binary search to grab the index (adapted from sort/search.go) + h, i, j := 0, 0, {{ .FastpathLen }} // len(x) + for i < j { + h = i + (j-i)/2 + if x[h].rtid < rtid { + i = h + 1 + } else { + j = h + } + } + if i < {{ .FastpathLen }} && x[i].rtid == rtid { + return i + } + return -1 +} + +type fastpathAslice []fastpathE + +func (x fastpathAslice) Len() int { return len(x) } +func (x fastpathAslice) Less(i, j int) bool { return x[i].rtid < x[j].rtid } +func (x fastpathAslice) Swap(i, j int) { x[i], x[j] = x[j], x[i] } + +var fastpathAV fastpathA + +// due to possible initialization loop error, make fastpath in an init() +func init() { + if !fastpathEnabled { + return + } + i := 0 + fn := func(v interface{}, fe func(encFnInfo, reflect.Value), fd func(decFnInfo, reflect.Value)) (f fastpathE) { + xrt := reflect.TypeOf(v) + xptr := reflect.ValueOf(xrt).Pointer() + fastpathAV[i] = fastpathE{xptr, xrt, fe, fd} + i++ + return + } + + {{range .Values}}{{if not .Primitive}}{{if .Slice }} + fn([]{{ .Elem }}(nil), (encFnInfo).{{ .MethodNamePfx "fastpathEnc" false }}R, (decFnInfo).{{ .MethodNamePfx "fastpathDec" false }}R){{end}}{{end}}{{end}} + + {{range .Values}}{{if not .Primitive}}{{if not .Slice }} + fn(map[{{ .MapKey }}]{{ .Elem }}(nil), (encFnInfo).{{ .MethodNamePfx "fastpathEnc" false }}R, (decFnInfo).{{ .MethodNamePfx "fastpathDec" false }}R){{end}}{{end}}{{end}} + + sort.Sort(fastpathAslice(fastpathAV[:])) +} + +// -- encode + +// -- -- fast path type switch +func fastpathEncodeTypeSwitch(iv interface{}, e *Encoder) bool { + switch v := iv.(type) { +{{range .Values}}{{if not .Primitive}}{{if .Slice }} + case []{{ .Elem }}:{{else}} + case map[{{ .MapKey }}]{{ .Elem }}:{{end}} + fastpathTV.{{ .MethodNamePfx "Enc" false }}V(v, fastpathCheckNilTrue, e){{if .Slice }} + case *[]{{ .Elem }}:{{else}} + case *map[{{ .MapKey }}]{{ .Elem }}:{{end}} + fastpathTV.{{ .MethodNamePfx "Enc" false }}V(*v, fastpathCheckNilTrue, e) +{{end}}{{end}} + default: + return false + } + return true +} + +func fastpathEncodeTypeSwitchSlice(iv interface{}, e *Encoder) bool { + switch v := iv.(type) { +{{range .Values}}{{if not .Primitive}}{{if .Slice }} + case []{{ .Elem }}: + fastpathTV.{{ .MethodNamePfx "Enc" false }}V(v, fastpathCheckNilTrue, e) + case *[]{{ .Elem }}: + fastpathTV.{{ .MethodNamePfx "Enc" false }}V(*v, fastpathCheckNilTrue, e) +{{end}}{{end}}{{end}} + default: + return false + } + return true +} + +func fastpathEncodeTypeSwitchMap(iv interface{}, e *Encoder) bool { + switch v := iv.(type) { +{{range .Values}}{{if not .Primitive}}{{if not .Slice }} + case map[{{ .MapKey }}]{{ .Elem }}: + fastpathTV.{{ .MethodNamePfx "Enc" false }}V(v, fastpathCheckNilTrue, e) + case *map[{{ .MapKey }}]{{ .Elem }}: + fastpathTV.{{ .MethodNamePfx "Enc" false }}V(*v, fastpathCheckNilTrue, e) +{{end}}{{end}}{{end}} + default: + return false + } + return true +} + +// -- -- fast path functions +{{range .Values}}{{if not .Primitive}}{{if .Slice }} + +func (f encFnInfo) {{ .MethodNamePfx "fastpathEnc" false }}R(rv reflect.Value) { + fastpathTV.{{ .MethodNamePfx "Enc" false }}V(rv.Interface().([]{{ .Elem }}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) {{ .MethodNamePfx "Enc" false }}V(v []{{ .Elem }}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeArrayStart(len(v)) + if e.be { + for _, v2 := range v { + {{ encmd .Elem "v2"}} + } + } else { + for j, v2 := range v { + if j > 0 { + ee.EncodeArrayEntrySeparator() + } + {{ encmd .Elem "v2"}} + } + ee.EncodeArrayEnd() + } +} + +{{end}}{{end}}{{end}} + +{{range .Values}}{{if not .Primitive}}{{if not .Slice }} + +func (f encFnInfo) {{ .MethodNamePfx "fastpathEnc" false }}R(rv reflect.Value) { + fastpathTV.{{ .MethodNamePfx "Enc" false }}V(rv.Interface().(map[{{ .MapKey }}]{{ .Elem }}), fastpathCheckNilFalse, f.e) +} +func (_ fastpathT) {{ .MethodNamePfx "Enc" false }}V(v map[{{ .MapKey }}]{{ .Elem }}, checkNil bool, e *Encoder) { + ee := e.e + if checkNil && v == nil { + ee.EncodeNil() + return + } + ee.EncodeMapStart(len(v)) + {{if eq .MapKey "string"}}asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0{{end}} + if e.be { + for k2, v2 := range v { + {{if eq .MapKey "string"}}if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + }{{else}}{{ encmd .MapKey "k2"}}{{end}} + {{ encmd .Elem "v2"}} + } + } else { + j := 0 + for k2, v2 := range v { + if j > 0 { + ee.EncodeMapEntrySeparator() + } + {{if eq .MapKey "string"}}if asSymbols { + ee.EncodeSymbol(k2) + } else { + ee.EncodeString(c_UTF8, k2) + }{{else}}{{ encmd .MapKey "k2"}}{{end}} + ee.EncodeMapKVSeparator() + {{ encmd .Elem "v2"}} + j++ + } + ee.EncodeMapEnd() + } +} + +{{end}}{{end}}{{end}} + +// -- decode + +// -- -- fast path type switch +func fastpathDecodeTypeSwitch(iv interface{}, d *Decoder) bool { + switch v := iv.(type) { +{{range .Values}}{{if not .Primitive}}{{if .Slice }} + case []{{ .Elem }}:{{else}} + case map[{{ .MapKey }}]{{ .Elem }}:{{end}} + fastpathTV.{{ .MethodNamePfx "Dec" false }}V(v, fastpathCheckNilFalse, false, d){{if .Slice }} + case *[]{{ .Elem }}:{{else}} + case *map[{{ .MapKey }}]{{ .Elem }}:{{end}} + v2, changed2 := fastpathTV.{{ .MethodNamePfx "Dec" false }}V(*v, fastpathCheckNilFalse, true, d) + if changed2 { + *v = v2 + } +{{end}}{{end}} + default: + return false + } + return true +} + +// -- -- fast path functions +{{range .Values}}{{if not .Primitive}}{{if .Slice }} +{{/* +Slices can change if they +- did not come from an array +- are addressable (from a ptr) +- are settable (e.g. contained in an interface{}) +*/}} +func (f decFnInfo) {{ .MethodNamePfx "fastpathDec" false }}R(rv reflect.Value) { + array := f.seq == seqTypeArray + if !array && rv.CanAddr() { // CanSet => CanAddr + Exported + vp := rv.Addr().Interface().(*[]{{ .Elem }}) + v, changed := fastpathTV.{{ .MethodNamePfx "Dec" false }}V(*vp, fastpathCheckNilFalse, !array, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().([]{{ .Elem }}) + fastpathTV.{{ .MethodNamePfx "Dec" false }}V(v, fastpathCheckNilFalse, false, f.d) + } +} + +func (f fastpathT) {{ .MethodNamePfx "Dec" false }}X(vp *[]{{ .Elem }}, checkNil bool, d *Decoder) { + v, changed := f.{{ .MethodNamePfx "Dec" false }}V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) {{ .MethodNamePfx "Dec" false }}V(v []{{ .Elem }}, checkNil bool, canChange bool, + d *Decoder) (_ []{{ .Elem }}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + slh, containerLenS := d.decSliceHelperStart() + if canChange && v == nil { + if containerLenS <= 0 { + v = []{{ .Elem }}{} + } else { + v = make([]{{ .Elem }}, containerLenS, containerLenS) + } + changed = true + } + if containerLenS == 0 { + if canChange && len(v) != 0 { + v = v[:0] + changed = true + }{{/* + // slh.End() // dd.ReadArrayEnd() + */}} + return v, changed + } + + // for j := 0; j < containerLenS; j++ { + if containerLenS > 0 { + decLen := containerLenS + if containerLenS > cap(v) { + if canChange { + s := make([]{{ .Elem }}, containerLenS, containerLenS) + // copy(s, v[:cap(v)]) + v = s + changed = true + } else { + d.arrayCannotExpand(len(v), containerLenS) + decLen = len(v) + } + } else if containerLenS != len(v) { + v = v[:containerLenS] + changed = true + } + // all checks done. cannot go past len. + j := 0 + for ; j < decLen; j++ { + {{ if eq .Elem "interface{}" }}d.decode(&v[j]){{ else }}v[j] = {{ decmd .Elem }}{{ end }} + } + if !canChange { + for ; j < containerLenS; j++ { + d.swallow() + } + } + } else { + j := 0 + for ; !dd.CheckBreak(); j++ { + if j >= len(v) { + if canChange { + v = append(v, {{ zerocmd .Elem }}) + changed = true + } else { + d.arrayCannotExpand(len(v), j+1) + } + } + if j > 0 { + slh.Sep(j) + } + if j < len(v) { // all checks done. cannot go past len. + {{ if eq .Elem "interface{}" }}d.decode(&v[j]) + {{ else }}v[j] = {{ decmd .Elem }}{{ end }} + } else { + d.swallow() + } + } + slh.End() + } + return v, changed +} + +{{end}}{{end}}{{end}} + + +{{range .Values}}{{if not .Primitive}}{{if not .Slice }} +{{/* +Maps can change if they are +- addressable (from a ptr) +- settable (e.g. contained in an interface{}) +*/}} +func (f decFnInfo) {{ .MethodNamePfx "fastpathDec" false }}R(rv reflect.Value) { + if rv.CanAddr() { + vp := rv.Addr().Interface().(*map[{{ .MapKey }}]{{ .Elem }}) + v, changed := fastpathTV.{{ .MethodNamePfx "Dec" false }}V(*vp, fastpathCheckNilFalse, true, f.d) + if changed { + *vp = v + } + } else { + v := rv.Interface().(map[{{ .MapKey }}]{{ .Elem }}) + fastpathTV.{{ .MethodNamePfx "Dec" false }}V(v, fastpathCheckNilFalse, false, f.d) + } +} +func (f fastpathT) {{ .MethodNamePfx "Dec" false }}X(vp *map[{{ .MapKey }}]{{ .Elem }}, checkNil bool, d *Decoder) { + v, changed := f.{{ .MethodNamePfx "Dec" false }}V(*vp, checkNil, true, d) + if changed { + *vp = v + } +} +func (_ fastpathT) {{ .MethodNamePfx "Dec" false }}V(v map[{{ .MapKey }}]{{ .Elem }}, checkNil bool, canChange bool, + d *Decoder) (_ map[{{ .MapKey }}]{{ .Elem }}, changed bool) { + dd := d.d + // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() + if checkNil && dd.TryDecodeAsNil() { + if v != nil { + changed = true + } + return nil, changed + } + + containerLen := dd.ReadMapStart() + if canChange && v == nil { + if containerLen > 0 { + v = make(map[{{ .MapKey }}]{{ .Elem }}, containerLen) + } else { + v = make(map[{{ .MapKey }}]{{ .Elem }}) // supports indefinite-length, etc + } + changed = true + } + if containerLen > 0 { + for j := 0; j < containerLen; j++ { + {{ if eq .MapKey "interface{}" }}var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + }{{ else }}mk := {{ decmd .MapKey }}{{ end }} + mv := v[mk] + {{ if eq .Elem "interface{}" }}d.decode(&mv) + {{ else }}mv = {{ decmd .Elem }}{{ end }} + if v != nil { + v[mk] = mv + } + } + } else if containerLen < 0 { + for j := 0; !dd.CheckBreak(); j++ { + if j > 0 { + dd.ReadMapEntrySeparator() + } + {{ if eq .MapKey "interface{}" }}var mk interface{} + d.decode(&mk) + if bv, bok := mk.([]byte); bok { + mk = string(bv) // maps cannot have []byte as key. switch to string. + }{{ else }}mk := {{ decmd .MapKey }}{{ end }} + dd.ReadMapKVSeparator() + mv := v[mk] + {{ if eq .Elem "interface{}" }}d.decode(&mv) + {{ else }}mv = {{ decmd .Elem }}{{ end }} + if v != nil { + v[mk] = mv + } + } + dd.ReadMapEnd() + } + return v, changed +} + +{{end}}{{end}}{{end}} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-dec-array.go.tmpl b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-dec-array.go.tmpl new file mode 100644 index 0000000000..ffb2cc4f24 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-dec-array.go.tmpl @@ -0,0 +1,77 @@ +{{var "v"}} := *{{ .Varname }} +{{var "h"}}, {{var "l"}} := z.DecSliceHelperStart() + +var {{var "c"}} bool +{{ if not isArray }}if {{var "v"}} == nil { + if {{var "l"}} <= 0 { + {{var "v"}} = make({{ .CTyp }}, 0) + } else { + {{var "v"}} = make({{ .CTyp }}, {{var "l"}}) + } + {{var "c"}} = true +} +{{ end }} +if {{var "l"}} == 0 { {{ if isSlice }} + if len({{var "v"}}) != 0 { + {{var "v"}} = {{var "v"}}[:0] + {{var "c"}} = true + } {{ end }} +} else if {{var "l"}} > 0 { + {{ if isChan }} + for {{var "r"}} := 0; {{var "r"}} < {{var "l"}}; {{var "r"}}++ { + var {{var "t"}} {{ .Typ }} + {{ $x := printf "%st%s" .TempVar .Rand }}{{ decLineVar $x }} + {{var "v"}} <- {{var "t"}} + {{ else }} + {{var "n"}} := {{var "l"}} + if {{var "l"}} > cap({{var "v"}}) { + {{ if isArray }}r.ReadArrayCannotExpand(len({{var "v"}}), {{var "l"}}) + {{var "n"}} = len({{var "v"}}) + {{ else }}{{ if .Immutable }} + {{var "v2"}} := {{var "v"}} + {{var "v"}} = make([]{{ .Typ }}, {{var "l"}}, {{var "l"}}) + if len({{var "v"}}) > 0 { + copy({{var "v"}}, {{var "v2"}}[:cap({{var "v2"}})]) + } + {{ else }}{{var "v"}} = make([]{{ .Typ }}, {{var "l"}}, {{var "l"}}) + {{ end }}{{var "c"}} = true + {{ end }} + } else if {{var "l"}} != len({{var "v"}}) { + {{var "v"}} = {{var "v"}}[:{{var "l"}}] + {{var "c"}} = true + } + {{var "j"}} := 0 + for ; {{var "j"}} < {{var "n"}} ; {{var "j"}}++ { + {{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }} + } {{ if isArray }} + for ; {{var "j"}} < {{var "l"}} ; {{var "j"}}++ { + z.DecSwallow() + }{{ end }} + {{ end }}{{/* closing if not chan */}} +} else { + for {{var "j"}} := 0; !r.CheckBreak(); {{var "j"}}++ { + if {{var "j"}} >= len({{var "v"}}) { + {{ if isArray }}r.ReadArrayCannotExpand(len({{var "v"}}), {{var "j"}}+1) + {{ else if isSlice}}{{var "v"}} = append({{var "v"}}, {{zero}})// var {{var "z"}} {{ .Typ }} + {{var "c"}} = true {{ end }} + } + if {{var "j"}} > 0 { + {{var "h"}}.Sep({{var "j"}}) + } + {{ if isChan}} + var {{var "t"}} {{ .Typ }} + {{ $x := printf "%st%s" .TempVar .Rand }}{{ decLineVar $x }} + {{var "v"}} <- {{var "t"}} + {{ else }} + if {{var "j"}} < len({{var "v"}}) { + {{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }} + } else { + z.DecSwallow() + } + {{ end }} + } + {{var "h"}}.End() +} +if {{var "c"}} { + *{{ .Varname }} = {{var "v"}} +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-dec-map.go.tmpl b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-dec-map.go.tmpl new file mode 100644 index 0000000000..9f8dafa548 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-dec-map.go.tmpl @@ -0,0 +1,46 @@ +{{var "v"}} := *{{ .Varname }} +{{var "l"}} := r.ReadMapStart() +if {{var "v"}} == nil { + if {{var "l"}} > 0 { + {{var "v"}} = make(map[{{ .KTyp }}]{{ .Typ }}, {{var "l"}}) + } else { + {{var "v"}} = make(map[{{ .KTyp }}]{{ .Typ }}) // supports indefinite-length, etc + } + *{{ .Varname }} = {{var "v"}} +} +if {{var "l"}} > 0 { +for {{var "j"}} := 0; {{var "j"}} < {{var "l"}}; {{var "j"}}++ { + var {{var "mk"}} {{ .KTyp }} + {{ $x := printf "%vmk%v" .TempVar .Rand }}{{ decLineVarK $x }} +{{ if eq .KTyp "interface{}" }}// special case if a byte array. + if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} { + {{var "mk"}} = string({{var "bv"}}) + } +{{ end }} + {{var "mv"}} := {{var "v"}}[{{var "mk"}}] + {{ $x := printf "%vmv%v" .TempVar .Rand }}{{ decLineVar $x }} + if {{var "v"}} != nil { + {{var "v"}}[{{var "mk"}}] = {{var "mv"}} + } +} +} else if {{var "l"}} < 0 { +for {{var "j"}} := 0; !r.CheckBreak(); {{var "j"}}++ { + if {{var "j"}} > 0 { + r.ReadMapEntrySeparator() + } + var {{var "mk"}} {{ .KTyp }} + {{ $x := printf "%vmk%v" .TempVar .Rand }}{{ decLineVarK $x }} +{{ if eq .KTyp "interface{}" }}// special case if a byte array. + if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} { + {{var "mk"}} = string({{var "bv"}}) + } +{{ end }} + r.ReadMapKVSeparator() + {{var "mv"}} := {{var "v"}}[{{var "mk"}}] + {{ $x := printf "%vmv%v" .TempVar .Rand }}{{ decLineVar $x }} + if {{var "v"}} != nil { + {{var "v"}}[{{var "mk"}}] = {{var "mv"}} + } +} +r.ReadMapEnd() +} // else len==0: TODO: Should we clear map entries? diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-helper.generated.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-helper.generated.go new file mode 100644 index 0000000000..1811a4877c --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-helper.generated.go @@ -0,0 +1,102 @@ +// //+build ignore + +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +// ************************************************************ +// DO NOT EDIT. +// THIS FILE IS AUTO-GENERATED from gen-helper.go.tmpl +// ************************************************************ + +package codec + +// This file is used to generate helper code for codecgen. +// The values here i.e. genHelper(En|De)coder are not to be used directly by +// library users. They WILL change continously and without notice. +// +// To help enforce this, we create an unexported type with exported members. +// The only way to get the type is via the one exported type that we control (somewhat). +// +// When static codecs are created for types, they will use this value +// to perform encoding or decoding of primitives or known slice or map types. + +// GenHelperEncoder is exported so that it can be used externally by codecgen. +// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE. +func GenHelperEncoder(e *Encoder) (genHelperEncoder, encDriver) { + return genHelperEncoder{e: e}, e.e +} + +// GenHelperDecoder is exported so that it can be used externally by codecgen. +// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE. +func GenHelperDecoder(d *Decoder) (genHelperDecoder, decDriver) { + return genHelperDecoder{d: d}, d.d +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +type genHelperEncoder struct { + e *Encoder + F fastpathT +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +type genHelperDecoder struct { + d *Decoder + F fastpathT +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncBasicHandle() *BasicHandle { + return f.e.h +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncBinary() bool { + return f.e.be // f.e.hh.isBinaryEncoding() +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncFallback(iv interface{}) { + // println(">>>>>>>>> EncFallback") + f.e.encodeI(iv, false, false) +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecBasicHandle() *BasicHandle { + return f.d.h +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecBinary() bool { + return f.d.be // f.d.hh.isBinaryEncoding() +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecSwallow() { + f.d.swallow() +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecScratchBuffer() []byte { + return f.d.b[:] +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) { + // println(">>>>>>>>> DecFallback") + f.d.decodeI(iv, chkPtr, false, false, false) +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) { + return f.d.decSliceHelperStart() +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) { + f.d.structFieldNotFound(index, name) +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) { + f.d.arrayCannotExpand(sliceLen, streamLen) +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-helper.go.tmpl b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-helper.go.tmpl new file mode 100644 index 0000000000..50c029975f --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen-helper.go.tmpl @@ -0,0 +1,250 @@ +// //+build ignore + +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +// ************************************************************ +// DO NOT EDIT. +// THIS FILE IS AUTO-GENERATED from gen-helper.go.tmpl +// ************************************************************ + +package codec + +// This file is used to generate helper code for codecgen. +// The values here i.e. genHelper(En|De)coder are not to be used directly by +// library users. They WILL change continously and without notice. +// +// To help enforce this, we create an unexported type with exported members. +// The only way to get the type is via the one exported type that we control (somewhat). +// +// When static codecs are created for types, they will use this value +// to perform encoding or decoding of primitives or known slice or map types. + +// GenHelperEncoder is exported so that it can be used externally by codecgen. +// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE. +func GenHelperEncoder(e *Encoder) (genHelperEncoder, encDriver) { + return genHelperEncoder{e:e}, e.e +} + +// GenHelperDecoder is exported so that it can be used externally by codecgen. +// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE. +func GenHelperDecoder(d *Decoder) (genHelperDecoder, decDriver) { + return genHelperDecoder{d:d}, d.d +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +type genHelperEncoder struct { + e *Encoder + F fastpathT +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +type genHelperDecoder struct { + d *Decoder + F fastpathT +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncBasicHandle() *BasicHandle { + return f.e.h +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncBinary() bool { + return f.e.be // f.e.hh.isBinaryEncoding() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncFallback(iv interface{}) { + // println(">>>>>>>>> EncFallback") + f.e.encodeI(iv, false, false) +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecBasicHandle() *BasicHandle { + return f.d.h +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecBinary() bool { + return f.d.be // f.d.hh.isBinaryEncoding() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecSwallow() { + f.d.swallow() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecScratchBuffer() []byte { + return f.d.b[:] +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) { + // println(">>>>>>>>> DecFallback") + f.d.decodeI(iv, chkPtr, false, false, false) +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) { + return f.d.decSliceHelperStart() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) { + f.d.structFieldNotFound(index, name) +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) { + f.d.arrayCannotExpand(sliceLen, streamLen) +} + + +{{/* + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncDriver() encDriver { + return f.e.e +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecDriver() decDriver { + return f.d.d +} + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncNil() { + f.e.e.EncodeNil() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncBytes(v []byte) { + f.e.e.EncodeStringBytes(c_RAW, v) +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncArrayStart(length int) { + f.e.e.EncodeArrayStart(length) +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncArrayEnd() { + f.e.e.EncodeArrayEnd() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncArrayEntrySeparator() { + f.e.e.EncodeArrayEntrySeparator() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncMapStart(length int) { + f.e.e.EncodeMapStart(length) +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncMapEnd() { + f.e.e.EncodeMapEnd() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncMapEntrySeparator() { + f.e.e.EncodeMapEntrySeparator() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) EncMapKVSeparator() { + f.e.e.EncodeMapKVSeparator() +} + +// --------- + +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecBytes(v *[]byte) { + *v = f.d.d.DecodeBytes(*v) +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecTryNil() bool { + return f.d.d.TryDecodeAsNil() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecContainerIsNil() (b bool) { + return f.d.d.IsContainerType(valueTypeNil) +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecContainerIsMap() (b bool) { + return f.d.d.IsContainerType(valueTypeMap) +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecContainerIsArray() (b bool) { + return f.d.d.IsContainerType(valueTypeArray) +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecCheckBreak() bool { + return f.d.d.CheckBreak() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecMapStart() int { + return f.d.d.ReadMapStart() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecArrayStart() int { + return f.d.d.ReadArrayStart() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecMapEnd() { + f.d.d.ReadMapEnd() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecArrayEnd() { + f.d.d.ReadArrayEnd() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecArrayEntrySeparator() { + f.d.d.ReadArrayEntrySeparator() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecMapEntrySeparator() { + f.d.d.ReadMapEntrySeparator() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) DecMapKVSeparator() { + f.d.d.ReadMapKVSeparator() +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) ReadStringAsBytes(bs []byte) []byte { + return f.d.d.DecodeStringAsBytes(bs) +} + + +// -- encode calls (primitives) +{{range .Values}}{{if .Primitive }}{{if ne .Primitive "interface{}" }} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) {{ .MethodNamePfx "Enc" true }}(v {{ .Primitive }}) { + ee := f.e.e + {{ encmd .Primitive "v" }} +} +{{ end }}{{ end }}{{ end }} + +// -- decode calls (primitives) +{{range .Values}}{{if .Primitive }}{{if ne .Primitive "interface{}" }} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) {{ .MethodNamePfx "Dec" true }}(vp *{{ .Primitive }}) { + dd := f.d.d + *vp = {{ decmd .Primitive }} +} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperDecoder) {{ .MethodNamePfx "Read" true }}() (v {{ .Primitive }}) { + dd := f.d.d + v = {{ decmd .Primitive }} + return +} +{{ end }}{{ end }}{{ end }} + + +// -- encode calls (slices/maps) +{{range .Values}}{{if not .Primitive }}{{if .Slice }} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) {{ .MethodNamePfx "Enc" false }}(v []{{ .Elem }}) { {{ else }} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +func (f genHelperEncoder) {{ .MethodNamePfx "Enc" false }}(v map[{{ .MapKey }}]{{ .Elem }}) { {{end}} + f.F.{{ .MethodNamePfx "Enc" false }}V(v, false, f.e) +} +{{ end }}{{ end }} + +// -- decode calls (slices/maps) +{{range .Values}}{{if not .Primitive }} +// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* +{{if .Slice }}func (f genHelperDecoder) {{ .MethodNamePfx "Dec" false }}(vp *[]{{ .Elem }}) { +{{else}}func (f genHelperDecoder) {{ .MethodNamePfx "Dec" false }}(vp *map[{{ .MapKey }}]{{ .Elem }}) { {{end}} + v, changed := f.F.{{ .MethodNamePfx "Dec" false }}V(*vp, false, true, f.d) + if changed { + *vp = v + } +} +{{ end }}{{ end }} +*/}} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/gen.generated.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen.generated.go new file mode 100644 index 0000000000..f035401d80 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen.generated.go @@ -0,0 +1,136 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +// DO NOT EDIT. THIS FILE IS AUTO-GENERATED FROM gen-dec-(map|array).go.tmpl + +const genDecMapTmpl = ` +{{var "v"}} := *{{ .Varname }} +{{var "l"}} := r.ReadMapStart() +if {{var "v"}} == nil { + if {{var "l"}} > 0 { + {{var "v"}} = make(map[{{ .KTyp }}]{{ .Typ }}, {{var "l"}}) + } else { + {{var "v"}} = make(map[{{ .KTyp }}]{{ .Typ }}) // supports indefinite-length, etc + } + *{{ .Varname }} = {{var "v"}} +} +if {{var "l"}} > 0 { +for {{var "j"}} := 0; {{var "j"}} < {{var "l"}}; {{var "j"}}++ { + var {{var "mk"}} {{ .KTyp }} + {{ $x := printf "%vmk%v" .TempVar .Rand }}{{ decLineVarK $x }} +{{ if eq .KTyp "interface{}" }}// special case if a byte array. + if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} { + {{var "mk"}} = string({{var "bv"}}) + } +{{ end }} + {{var "mv"}} := {{var "v"}}[{{var "mk"}}] + {{ $x := printf "%vmv%v" .TempVar .Rand }}{{ decLineVar $x }} + if {{var "v"}} != nil { + {{var "v"}}[{{var "mk"}}] = {{var "mv"}} + } +} +} else if {{var "l"}} < 0 { +for {{var "j"}} := 0; !r.CheckBreak(); {{var "j"}}++ { + if {{var "j"}} > 0 { + r.ReadMapEntrySeparator() + } + var {{var "mk"}} {{ .KTyp }} + {{ $x := printf "%vmk%v" .TempVar .Rand }}{{ decLineVarK $x }} +{{ if eq .KTyp "interface{}" }}// special case if a byte array. + if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} { + {{var "mk"}} = string({{var "bv"}}) + } +{{ end }} + r.ReadMapKVSeparator() + {{var "mv"}} := {{var "v"}}[{{var "mk"}}] + {{ $x := printf "%vmv%v" .TempVar .Rand }}{{ decLineVar $x }} + if {{var "v"}} != nil { + {{var "v"}}[{{var "mk"}}] = {{var "mv"}} + } +} +r.ReadMapEnd() +} // else len==0: TODO: Should we clear map entries? +` + +const genDecListTmpl = ` +{{var "v"}} := *{{ .Varname }} +{{var "h"}}, {{var "l"}} := z.DecSliceHelperStart() + +var {{var "c"}} bool +{{ if not isArray }}if {{var "v"}} == nil { + if {{var "l"}} <= 0 { + {{var "v"}} = make({{ .CTyp }}, 0) + } else { + {{var "v"}} = make({{ .CTyp }}, {{var "l"}}) + } + {{var "c"}} = true +} +{{ end }} +if {{var "l"}} == 0 { {{ if isSlice }} + if len({{var "v"}}) != 0 { + {{var "v"}} = {{var "v"}}[:0] + {{var "c"}} = true + } {{ end }} +} else if {{var "l"}} > 0 { + {{ if isChan }} + for {{var "r"}} := 0; {{var "r"}} < {{var "l"}}; {{var "r"}}++ { + var {{var "t"}} {{ .Typ }} + {{ $x := printf "%st%s" .TempVar .Rand }}{{ decLineVar $x }} + {{var "v"}} <- {{var "t"}} + {{ else }} + {{var "n"}} := {{var "l"}} + if {{var "l"}} > cap({{var "v"}}) { + {{ if isArray }}r.ReadArrayCannotExpand(len({{var "v"}}), {{var "l"}}) + {{var "n"}} = len({{var "v"}}) + {{ else }}{{ if .Immutable }} + {{var "v2"}} := {{var "v"}} + {{var "v"}} = make([]{{ .Typ }}, {{var "l"}}, {{var "l"}}) + if len({{var "v"}}) > 0 { + copy({{var "v"}}, {{var "v2"}}[:cap({{var "v2"}})]) + } + {{ else }}{{var "v"}} = make([]{{ .Typ }}, {{var "l"}}, {{var "l"}}) + {{ end }}{{var "c"}} = true + {{ end }} + } else if {{var "l"}} != len({{var "v"}}) { + {{var "v"}} = {{var "v"}}[:{{var "l"}}] + {{var "c"}} = true + } + {{var "j"}} := 0 + for ; {{var "j"}} < {{var "n"}} ; {{var "j"}}++ { + {{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }} + } {{ if isArray }} + for ; {{var "j"}} < {{var "l"}} ; {{var "j"}}++ { + z.DecSwallow() + }{{ end }} + {{ end }}{{/* closing if not chan */}} +} else { + for {{var "j"}} := 0; !r.CheckBreak(); {{var "j"}}++ { + if {{var "j"}} >= len({{var "v"}}) { + {{ if isArray }}r.ReadArrayCannotExpand(len({{var "v"}}), {{var "j"}}+1) + {{ else if isSlice}}{{var "v"}} = append({{var "v"}}, {{zero}})// var {{var "z"}} {{ .Typ }} + {{var "c"}} = true {{ end }} + } + if {{var "j"}} > 0 { + {{var "h"}}.Sep({{var "j"}}) + } + {{ if isChan}} + var {{var "t"}} {{ .Typ }} + {{ $x := printf "%st%s" .TempVar .Rand }}{{ decLineVar $x }} + {{var "v"}} <- {{var "t"}} + {{ else }} + if {{var "j"}} < len({{var "v"}}) { + {{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }} + } else { + z.DecSwallow() + } + {{ end }} + } + {{var "h"}}.End() +} +if {{var "c"}} { + *{{ .Varname }} = {{var "v"}} +} +` + diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/gen.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen.go new file mode 100644 index 0000000000..618eb5740c --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/gen.go @@ -0,0 +1,1709 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +import ( + "bytes" + "encoding/base64" + "errors" + "fmt" + "go/format" + "io" + "io/ioutil" + "math/rand" + "reflect" + "regexp" + "strconv" + "strings" + "sync" + "text/template" + "time" +) + +// --------------------------------------------------- +// codecgen only works in the following: +// - extensions are not supported. Do not make a type a Selfer and an extension. +// - Selfer takes precedence. +// Any type that implements it knows how to encode/decode itself statically. +// Extensions are only known at runtime. +// codecgen only looks at the Kind of the type. +// +// - the following types are supported: +// array: [n]T +// slice: []T +// map: map[K]V +// primitive: [u]int[n], float(32|64), bool, string +// struct +// +// --------------------------------------------------- +// Note that a Selfer cannot call (e|d).(En|De)code on itself, +// as this will cause a circular reference, as (En|De)code will call Selfer methods. +// Any type that implements Selfer must implement completely and not fallback to (En|De)code. +// +// In addition, code in this file manages the generation of fast-path implementations of +// encode/decode of slices/maps of primitive keys/values. +// +// Users MUST re-generate their implementations whenever the code shape changes. +// The generated code will panic if it was generated with a version older than the supporting library. +// --------------------------------------------------- +// +// codec framework is very feature rich. +// When encoding or decoding into an interface, it depends on the runtime type of the interface. +// The type of the interface may be a named type, an extension, etc. +// Consequently, we fallback to runtime codec for encoding/decoding interfaces. +// In addition, we fallback for any value which cannot be guaranteed at runtime. +// This allows us support ANY value, including any named types, specifically those which +// do not implement our interfaces (e.g. Selfer). +// +// This explains some slowness compared to other code generation codecs (e.g. msgp). +// This reduction in speed is only seen when your refers to interfaces, +// e.g. type T struct { A interface{}; B []interface{}; C map[string]interface{} } +// +// codecgen will panic if the file was generated with an old version of the library in use. +// +// Note: +// It was a concious decision to have gen.go always explicitly call EncodeNil or TryDecodeAsNil. +// This way, there isn't a function call overhead just to see that we should not enter a block of code. + +const GenVersion = 2 // increment this value each time codecgen changes fundamentally. + +const ( + genCodecPkg = "codec1978" + genTempVarPfx = "yy" + + // ignore canBeNil parameter, and always set to true. + // This is because nil can appear anywhere, so we should always check. + genAnythingCanBeNil = true + + // if genUseOneFunctionForDecStructMap, make a single codecDecodeSelferFromMap function; + // else make codecDecodeSelferFromMap{LenPrefix,CheckBreak} so that conditionals + // are not executed a lot. + // + // From testing, it didn't make much difference in runtime, so keep as true (one function only) + genUseOneFunctionForDecStructMap = true +) + +var ( + genAllTypesSamePkgErr = errors.New("All types must be in the same package") + genExpectArrayOrMapErr = errors.New("unexpected type. Expecting array/map/slice") + genBase64enc = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789__") + genQNameRegex = regexp.MustCompile(`[A-Za-z_.]+`) +) + +// genRunner holds some state used during a Gen run. +type genRunner struct { + w io.Writer // output + c uint64 // ctr used for generating varsfx + t []reflect.Type // list of types to run selfer on + + tc reflect.Type // currently running selfer on this type + te map[uintptr]bool // types for which the encoder has been created + td map[uintptr]bool // types for which the decoder has been created + cp string // codec import path + im map[string]reflect.Type // imports to add + is map[reflect.Type]struct{} // types seen during import search + bp string // base PkgPath, for which we are generating for + + cpfx string // codec package prefix + unsafe bool // is unsafe to be used in generated code? + + ts map[reflect.Type]struct{} // types for which enc/dec must be generated + xs string // top level variable/constant suffix + hn string // fn helper type name + + rr *rand.Rand // random generator for file-specific types +} + +// Gen will write a complete go file containing Selfer implementations for each +// type passed. All the types must be in the same package. +func Gen(w io.Writer, buildTags, pkgName string, useUnsafe bool, typ ...reflect.Type) { + if len(typ) == 0 { + return + } + x := genRunner{ + unsafe: useUnsafe, + w: w, + t: typ, + te: make(map[uintptr]bool), + td: make(map[uintptr]bool), + im: make(map[string]reflect.Type), + is: make(map[reflect.Type]struct{}), + ts: make(map[reflect.Type]struct{}), + bp: typ[0].PkgPath(), + rr: rand.New(rand.NewSource(time.Now().UnixNano())), + } + + // gather imports first: + x.cp = reflect.TypeOf(x).PkgPath() + for _, t := range typ { + // fmt.Printf("###########: PkgPath: '%v', Name: '%s'\n", t.PkgPath(), t.Name()) + if t.PkgPath() != x.bp { + panic(genAllTypesSamePkgErr) + } + x.genRefPkgs(t) + } + if buildTags != "" { + x.line("//+build " + buildTags) + x.line("") + } + x.line(` + +// ************************************************************ +// DO NOT EDIT. +// THIS FILE IS AUTO-GENERATED BY codecgen. +// ************************************************************ + +`) + x.line("package " + pkgName) + x.line("") + x.line("import (") + if x.cp != x.bp { + x.cpfx = genCodecPkg + "." + x.linef("%s \"%s\"", genCodecPkg, x.cp) + } + for k, _ := range x.im { + x.line("\"" + k + "\"") + } + // add required packages + for _, k := range [...]string{"reflect", "unsafe", "runtime", "fmt", "errors"} { + if _, ok := x.im[k]; !ok { + if k == "unsafe" && !x.unsafe { + continue + } + x.line("\"" + k + "\"") + } + } + x.line(")") + x.line("") + + x.xs = strconv.FormatInt(x.rr.Int63n(9999), 10) + + x.line("const (") + x.linef("codecSelferC_UTF8%s = %v", x.xs, int64(c_UTF8)) + x.linef("codecSelferC_RAW%s = %v", x.xs, int64(c_RAW)) + x.linef("codecSelverValueTypeArray%s = %v", x.xs, int64(valueTypeArray)) + x.linef("codecSelverValueTypeMap%s = %v", x.xs, int64(valueTypeMap)) + x.line(")") + x.line("var (") + x.line("codecSelferBitsize" + x.xs + " = uint8(reflect.TypeOf(uint(0)).Bits())") + x.line("codecSelferOnlyMapOrArrayEncodeToStructErr" + x.xs + " = errors.New(`only encoded map or array can be decoded into a struct`)") + x.line(")") + x.line("") + + if x.unsafe { + x.line("type codecSelferUnsafeString" + x.xs + " struct { Data uintptr; Len int}") + x.line("") + } + x.hn = "codecSelfer" + x.xs + x.line("type " + x.hn + " struct{}") + x.line("") + + x.line("func init() {") + x.linef("if %sGenVersion != %v {", x.cpfx, GenVersion) + x.line("_, file, _, _ := runtime.Caller(0)") + x.line(`err := fmt.Errorf("codecgen version mismatch: current: %v, need %v. Re-generate file: %v", `) + x.linef(`%v, %sGenVersion, file)`, GenVersion, x.cpfx) + x.line("panic(err)") + // x.linef(`panic(fmt.Errorf("Re-run codecgen due to version mismatch: `+ + // `current: %%v, need %%v, file: %%v", %v, %sGenVersion, file))`, GenVersion, x.cpfx) + x.linef("}") + x.line("if false { // reference the types, but skip this branch at build/run time") + var n int + for _, t := range x.im { + x.linef("var v%v %s", n, t.String()) + n++ + } + if x.unsafe { + x.linef("var v%v unsafe.Pointer", n) + n++ + } + if n > 0 { + x.out("_") + for i := 1; i < n; i++ { + x.out(", _") + } + x.out(" = v0") + for i := 1; i < n; i++ { + x.outf(", v%v", i) + } + } + x.line("} ") // close if false + x.line("}") // close init + x.line("") + + // generate rest of type info + for _, t := range typ { + x.tc = t + x.selfer(true) + x.selfer(false) + } + + for t, _ := range x.ts { + rtid := reflect.ValueOf(t).Pointer() + // generate enc functions for all these slice/map types. + x.linef("func (x %s) enc%s(v %s, e *%sEncoder) {", x.hn, x.genMethodNameT(t), x.genTypeName(t), x.cpfx) + x.genRequiredMethodVars(true) + switch t.Kind() { + case reflect.Array, reflect.Slice, reflect.Chan: + x.encListFallback("v", rtid, t) + case reflect.Map: + x.encMapFallback("v", rtid, t) + default: + panic(genExpectArrayOrMapErr) + } + x.line("}") + x.line("") + + // generate dec functions for all these slice/map types. + x.linef("func (x %s) dec%s(v *%s, d *%sDecoder) {", x.hn, x.genMethodNameT(t), x.genTypeName(t), x.cpfx) + x.genRequiredMethodVars(false) + switch t.Kind() { + case reflect.Array, reflect.Slice, reflect.Chan: + x.decListFallback("v", rtid, t) + case reflect.Map: + x.decMapFallback("v", rtid, t) + default: + panic(genExpectArrayOrMapErr) + } + x.line("}") + x.line("") + } + + x.line("") +} + +func (x *genRunner) genRequiredMethodVars(encode bool) { + x.line("var h " + x.hn) + if encode { + x.line("z, r := " + x.cpfx + "GenHelperEncoder(e)") + } else { + x.line("z, r := " + x.cpfx + "GenHelperDecoder(d)") + } + x.line("_, _, _ = h, z, r") +} + +func (x *genRunner) genRefPkgs(t reflect.Type) { + if _, ok := x.is[t]; ok { + return + } + // fmt.Printf(">>>>>>: PkgPath: '%v', Name: '%s'\n", t.PkgPath(), t.Name()) + x.is[t] = struct{}{} + tpkg, tname := t.PkgPath(), t.Name() + if tpkg != "" && tpkg != x.bp && tpkg != x.cp && tname != "" && tname[0] >= 'A' && tname[0] <= 'Z' { + x.im[tpkg] = t + } + switch t.Kind() { + case reflect.Array, reflect.Slice, reflect.Ptr, reflect.Chan: + x.genRefPkgs(t.Elem()) + case reflect.Map: + x.genRefPkgs(t.Elem()) + x.genRefPkgs(t.Key()) + case reflect.Struct: + for i := 0; i < t.NumField(); i++ { + if fname := t.Field(i).Name; fname != "" && fname[0] >= 'A' && fname[0] <= 'Z' { + x.genRefPkgs(t.Field(i).Type) + } + } + } +} + +func (x *genRunner) line(s string) { + x.out(s) + if len(s) == 0 || s[len(s)-1] != '\n' { + x.out("\n") + } +} + +func (x *genRunner) varsfx() string { + x.c++ + return strconv.FormatUint(x.c, 10) +} + +func (x *genRunner) out(s string) { + if _, err := io.WriteString(x.w, s); err != nil { + panic(err) + } +} + +func (x *genRunner) linef(s string, params ...interface{}) { + x.line(fmt.Sprintf(s, params...)) +} + +func (x *genRunner) outf(s string, params ...interface{}) { + x.out(fmt.Sprintf(s, params...)) +} + +func (x *genRunner) genTypeName(t reflect.Type) (n string) { + return genTypeName(t, x.tc) +} + +func (x *genRunner) genMethodNameT(t reflect.Type) (s string) { + return genMethodNameT(t, x.tc) +} + +func (x *genRunner) selfer(encode bool) { + t := x.tc + t0 := t + // always make decode use a pointer receiver, + // and structs always use a ptr receiver (encode|decode) + isptr := !encode || t.Kind() == reflect.Struct + fnSigPfx := "func (x " + if isptr { + fnSigPfx += "*" + } + fnSigPfx += x.genTypeName(t) + + x.out(fnSigPfx) + if isptr { + t = reflect.PtrTo(t) + } + if encode { + x.line(") CodecEncodeSelf(e *" + x.cpfx + "Encoder) {") + x.genRequiredMethodVars(true) + // x.enc("x", t) + x.encVar("x", t) + } else { + x.line(") CodecDecodeSelf(d *" + x.cpfx + "Decoder) {") + x.genRequiredMethodVars(false) + // do not use decVar, as there is no need to check TryDecodeAsNil + // or way to elegantly handle that, and also setting it to a + // non-nil value doesn't affect the pointer passed. + // x.decVar("x", t, false) + x.dec("x", t0) + } + x.line("}") + x.line("") + + if encode || t0.Kind() != reflect.Struct { + return + } + + // write is containerMap + if genUseOneFunctionForDecStructMap { + x.out(fnSigPfx) + x.line(") codecDecodeSelfFromMap(l int, d *" + x.cpfx + "Decoder) {") + x.genRequiredMethodVars(false) + x.decStructMap("x", "l", reflect.ValueOf(t0).Pointer(), t0, 0) + x.line("}") + x.line("") + } else { + x.out(fnSigPfx) + x.line(") codecDecodeSelfFromMapLenPrefix(l int, d *" + x.cpfx + "Decoder) {") + x.genRequiredMethodVars(false) + x.decStructMap("x", "l", reflect.ValueOf(t0).Pointer(), t0, 1) + x.line("}") + x.line("") + + x.out(fnSigPfx) + x.line(") codecDecodeSelfFromMapCheckBreak(l int, d *" + x.cpfx + "Decoder) {") + x.genRequiredMethodVars(false) + x.decStructMap("x", "l", reflect.ValueOf(t0).Pointer(), t0, 2) + x.line("}") + x.line("") + } + + // write containerArray + x.out(fnSigPfx) + x.line(") codecDecodeSelfFromArray(l int, d *" + x.cpfx + "Decoder) {") + x.genRequiredMethodVars(false) + x.decStructArray("x", "l", "return", reflect.ValueOf(t0).Pointer(), t0) + x.line("}") + x.line("") + +} + +func (x *genRunner) xtraSM(varname string, encode bool, t reflect.Type) { + if encode { + x.linef("h.enc%s(%s(%s), e)", x.genMethodNameT(t), x.genTypeName(t), varname) + // x.line("h.enc" + x.genMethodNameT(t) + "(" + x.genTypeName(t) + "(" + varname + "), e)") + } else { + x.linef("h.dec%s((*%s)(%s), d)", x.genMethodNameT(t), x.genTypeName(t), varname) + // x.line("h.dec" + x.genMethodNameT(t) + "((*" + x.genTypeName(t) + ")(" + varname + "), d)") + } + x.ts[t] = struct{}{} +} + +func (x *genRunner) encVar(varname string, t reflect.Type) { + var checkNil bool + switch t.Kind() { + case reflect.Ptr, reflect.Interface, reflect.Slice, reflect.Map, reflect.Chan: + checkNil = true + } + if checkNil { + x.linef("if %s == nil { r.EncodeNil() } else { ", varname) + } + switch t.Kind() { + case reflect.Ptr: + if t.Elem().Kind() == reflect.Struct { + x.enc(varname, genNonPtr(t)) + } else { + i := x.varsfx() + x.line(genTempVarPfx + i + " := *" + varname) + x.enc(genTempVarPfx+i, genNonPtr(t)) + } + default: + x.enc(varname, genNonPtr(t)) + } + + if checkNil { + x.line("}") + } + +} + +func (x *genRunner) enc(varname string, t reflect.Type) { + // varName here must be to a pointer to a struct, or to a value directly. + rtid := reflect.ValueOf(t).Pointer() + // We call CodecEncodeSelf if one of the following are honored: + // - the type already implements Selfer, call that + // - the type has a Selfer implementation just created, use that + // - the type is in the list of the ones we will generate for, but it is not currently being generated + if t.Implements(selferTyp) { + x.line(varname + ".CodecEncodeSelf(e)") + return + } + if t.Kind() == reflect.Struct && reflect.PtrTo(t).Implements(selferTyp) { + x.line(varname + ".CodecEncodeSelf(e)") + return + } + if _, ok := x.te[rtid]; ok { + x.line(varname + ".CodecEncodeSelf(e)") + return + } + + inlist := false + for _, t0 := range x.t { + if t == t0 { + inlist = true + if t != x.tc { + x.line(varname + ".CodecEncodeSelf(e)") + return + } + break + } + } + var rtidAdded bool + if t == x.tc { + x.te[rtid] = true + rtidAdded = true + } + + switch t.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + x.line("r.EncodeInt(int64(" + varname + "))") + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + x.line("r.EncodeUint(uint64(" + varname + "))") + case reflect.Float32: + x.line("r.EncodeFloat32(float32(" + varname + "))") + case reflect.Float64: + x.line("r.EncodeFloat64(float64(" + varname + "))") + case reflect.Bool: + x.line("r.EncodeBool(bool(" + varname + "))") + case reflect.String: + x.line("r.EncodeString(codecSelferC_UTF8" + x.xs + ", string(" + varname + "))") + case reflect.Array, reflect.Chan: + x.xtraSM(varname, true, t) + // x.encListFallback(varname, rtid, t) + case reflect.Slice: + // if nil, call dedicated function + // if a []uint8, call dedicated function + // if a known fastpath slice, call dedicated function + // else write encode function in-line. + // - if elements are primitives or Selfers, call dedicated function on each member. + // - else call Encoder.encode(XXX) on it. + if rtid == uint8SliceTypId { + x.line("r.EncodeStringBytes(codecSelferC_RAW" + x.xs + ", []byte(" + varname + "))") + } else if fastpathAV.index(rtid) != -1 { + g := genV{Slice: true, Elem: x.genTypeName(t.Elem())} + x.line("z.F." + g.MethodNamePfx("Enc", false) + "V(" + varname + ", false, e)") + } else { + x.xtraSM(varname, true, t) + // x.encListFallback(varname, rtid, t) + } + case reflect.Map: + // if nil, call dedicated function + // if a known fastpath map, call dedicated function + // else write encode function in-line. + // - if elements are primitives or Selfers, call dedicated function on each member. + // - else call Encoder.encode(XXX) on it. + // x.line("if " + varname + " == nil { \nr.EncodeNil()\n } else { ") + if fastpathAV.index(rtid) != -1 { + g := genV{Slice: false, + Elem: x.genTypeName(t.Elem()), + MapKey: x.genTypeName(t.Key())} + x.line("z.F." + g.MethodNamePfx("Enc", false) + "V(" + varname + ", false, e)") + } else { + x.xtraSM(varname, true, t) + // x.encMapFallback(varname, rtid, t) + } + case reflect.Struct: + if !inlist { + delete(x.te, rtid) + x.line("z.EncFallback(" + varname + ")") + break + } + x.encStruct(varname, rtid, t) + default: + if rtidAdded { + delete(x.te, rtid) + } + x.line("z.EncFallback(" + varname + ")") + } +} + +func (x *genRunner) encZero(t reflect.Type) { + switch t.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + x.line("r.EncodeInt(0)") + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + x.line("r.EncodeUint(0)") + case reflect.Float32: + x.line("r.EncodeFloat32(0)") + case reflect.Float64: + x.line("r.EncodeFloat64(0)") + case reflect.Bool: + x.line("r.EncodeBool(false)") + case reflect.String: + x.line("r.EncodeString(codecSelferC_UTF8" + x.xs + `, "")`) + default: + x.line("r.EncodeNil()") + } +} + +func (x *genRunner) encStruct(varname string, rtid uintptr, t reflect.Type) { + // Use knowledge from structfieldinfo (mbs, encodable fields. Ignore omitempty. ) + // replicate code in kStruct i.e. for each field, deref type to non-pointer, and call x.enc on it + + // if t === type currently running selfer on, do for all + ti := getTypeInfo(rtid, t) + i := x.varsfx() + sepVarname := genTempVarPfx + "sep" + i + firstVarname := genTempVarPfx + "first" + i + numfieldsvar := genTempVarPfx + "q" + i + ti2arrayvar := genTempVarPfx + "r" + i + struct2arrvar := genTempVarPfx + "2arr" + i + + x.line(sepVarname + " := !z.EncBinary()") + x.linef("%s := z.EncBasicHandle().StructToArray", struct2arrvar) + x.line("var " + firstVarname + " bool") + tisfi := ti.sfip // always use sequence from file. decStruct expects same thing. + // due to omitEmpty, we need to calculate the + // number of non-empty things we write out first. + // This is required as we need to pre-determine the size of the container, + // to support length-prefixing. + x.linef("var %s [%v]bool", numfieldsvar, len(tisfi)) + x.linef("_, _, _, _ = %s, %s, %s, %s", sepVarname, firstVarname, numfieldsvar, struct2arrvar) + x.linef("const %s bool = %v", ti2arrayvar, ti.toArray) + nn := 0 + for j, si := range tisfi { + if !si.omitEmpty { + nn++ + continue + } + var t2 reflect.StructField + var omitline string + if si.i != -1 { + t2 = t.Field(int(si.i)) + } else { + t2typ := t + varname3 := varname + for _, ix := range si.is { + for t2typ.Kind() == reflect.Ptr { + t2typ = t2typ.Elem() + } + t2 = t2typ.Field(ix) + t2typ = t2.Type + varname3 = varname3 + "." + t2.Name + if t2typ.Kind() == reflect.Ptr { + omitline += varname3 + " != nil && " + } + } + } + // never check omitEmpty on a struct type, as it may contain uncomparable map/slice/etc. + // also, for maps/slices/arrays, check if len ! 0 (not if == zero value) + switch t2.Type.Kind() { + case reflect.Struct: + omitline += " true" + case reflect.Map, reflect.Slice, reflect.Array, reflect.Chan: + omitline += "len(" + varname + "." + t2.Name + ") != 0" + default: + omitline += varname + "." + t2.Name + " != " + genZeroValueR(t2.Type, x.tc) + } + x.linef("%s[%v] = %s", numfieldsvar, j, omitline) + } + x.linef("if %s || %s {", ti2arrayvar, struct2arrvar) // if ti.toArray { + x.line("r.EncodeArrayStart(" + strconv.FormatInt(int64(len(tisfi)), 10) + ")") + x.linef("} else {") // if not ti.toArray + x.linef("var %snn%s int = %v", genTempVarPfx, i, nn) + x.linef("for _, b := range %s { if b { %snn%s++ } }", numfieldsvar, genTempVarPfx, i) + x.linef("r.EncodeMapStart(%snn%s)", genTempVarPfx, i) + // x.line("r.EncodeMapStart(" + strconv.FormatInt(int64(len(tisfi)), 10) + ")") + x.line("}") // close if not StructToArray + + for j, si := range tisfi { + i := x.varsfx() + isNilVarName := genTempVarPfx + "n" + i + var labelUsed bool + var t2 reflect.StructField + if si.i != -1 { + t2 = t.Field(int(si.i)) + } else { + t2typ := t + varname3 := varname + for _, ix := range si.is { + // fmt.Printf("%%%% %v, ix: %v\n", t2typ, ix) + for t2typ.Kind() == reflect.Ptr { + t2typ = t2typ.Elem() + } + t2 = t2typ.Field(ix) + t2typ = t2.Type + varname3 = varname3 + "." + t2.Name + if t2typ.Kind() == reflect.Ptr { + if !labelUsed { + x.line("var " + isNilVarName + " bool") + } + x.line("if " + varname3 + " == nil { " + isNilVarName + " = true ") + x.line("goto LABEL" + i) + x.line("}") + labelUsed = true + // "varname3 = new(" + x.genTypeName(t3.Elem()) + ") }") + } + } + // t2 = t.FieldByIndex(si.is) + } + if labelUsed { + x.line("LABEL" + i + ":") + } + // if the type of the field is a Selfer, or one of the ones + + x.linef("if %s || %s {", ti2arrayvar, struct2arrvar) // if ti.toArray + if j > 0 { + x.line("if " + sepVarname + " {") + x.line("r.EncodeArrayEntrySeparator()") + x.line("}") + } + if labelUsed { + x.line("if " + isNilVarName + " { r.EncodeNil() } else { ") + } + if si.omitEmpty { + x.linef("if %s[%v] {", numfieldsvar, j) + // omitEmptyVarNameX := genTempVarPfx + "ov" + i + // x.line("var " + omitEmptyVarNameX + " " + x.genTypeName(t2.Type)) + // x.encVar(omitEmptyVarNameX, t2.Type) + } + x.encVar(varname+"."+t2.Name, t2.Type) + if si.omitEmpty { + x.linef("} else {") + x.encZero(t2.Type) + x.linef("}") + } + if labelUsed { + x.line("}") + } + x.linef("} else {") // if not ti.toArray + // omitEmptyVar := genTempVarPfx + "x" + i + t2.Name + // x.line("const " + omitEmptyVar + " bool = " + strconv.FormatBool(si.omitEmpty)) + // doOmitEmpty := si.omitEmpty && t2.Type.Kind() != reflect.Struct + if si.omitEmpty { + x.linef("if %s[%v] {", numfieldsvar, j) + // x.linef(`println("Encoding field: %v")`, j) + // x.out("if ") + // if labelUsed { + // x.out("!" + isNilVarName + " && ") + // } + // x.line(varname + "." + t2.Name + " != " + genZeroValueR(t2.Type, x.tc) + " {") + } + if j == 0 { + x.linef("%s = true", firstVarname) + } else { + x.linef("if %s { r.EncodeMapEntrySeparator() } else { %s = true }", firstVarname, firstVarname) + } + + // x.line("r.EncodeString(codecSelferC_UTF8" + x.xs + ", string(\"" + t2.Name + "\"))") + x.line("r.EncodeString(codecSelferC_UTF8" + x.xs + ", string(\"" + si.encName + "\"))") + x.line("if " + sepVarname + " {") + x.line("r.EncodeMapKVSeparator()") + x.line("}") + if labelUsed { + x.line("if " + isNilVarName + " { r.EncodeNil() } else { ") + x.encVar(varname+"."+t2.Name, t2.Type) + x.line("}") + } else { + x.encVar(varname+"."+t2.Name, t2.Type) + } + if si.omitEmpty { + x.line("}") + } + x.linef("} ") // end if/else ti.toArray + } + x.line("if " + sepVarname + " {") + x.linef("if %s || %s {", ti2arrayvar, struct2arrvar) // if ti.toArray { + x.line("r.EncodeArrayEnd()") + x.linef("} else {") // if not ti.toArray + x.line("r.EncodeMapEnd()") + x.linef("} ") // end if/else ti.toArray + x.line("}") +} + +func (x *genRunner) encListFallback(varname string, rtid uintptr, t reflect.Type) { + i := x.varsfx() + g := genTempVarPfx + x.line("r.EncodeArrayStart(len(" + varname + "))") + x.line(genTempVarPfx + "s" + i + " := !z.EncBinary()") + x.line("if " + genTempVarPfx + "s" + i + " {") + if t.Kind() == reflect.Chan { + x.linef("for %si%s, %si2%s := 0, len(%s); %si%s < %si2%s; %si%s++ {", g, i, g, i, varname, g, i, g, i, g, i) + x.linef("%sv%s := <-%s", g, i, varname) + } else { + x.linef("for %si%s, %sv%s := range %s {", genTempVarPfx, i, genTempVarPfx, i, varname) + } + x.linef("if %si%s > 0 { r.EncodeArrayEntrySeparator() }", genTempVarPfx, i) + x.encVar(genTempVarPfx+"v"+i, t.Elem()) + x.line("}") + x.line("r.EncodeArrayEnd()") + x.line("} else {") + if t.Kind() == reflect.Chan { + x.linef("for %si%s, %si2%s := 0, len(%s); %si%s < %si2%s; %si%s++ {", g, i, g, i, varname, g, i, g, i, g, i) + x.linef("%sv%s := <-%s", g, i, varname) + } else { + x.line("for _, " + genTempVarPfx + "v" + i + " := range " + varname + " {") + } + x.encVar(genTempVarPfx+"v"+i, t.Elem()) + x.line("}") + x.line("}") +} + +func (x *genRunner) encMapFallback(varname string, rtid uintptr, t reflect.Type) { + i := x.varsfx() + x.line("r.EncodeMapStart(len(" + varname + "))") + x.line(genTempVarPfx + "s" + i + " := !z.EncBinary()") + + x.line(genTempVarPfx + "j" + i + " := 0") + + x.line("if " + genTempVarPfx + "s" + i + " {") + + x.line("for " + genTempVarPfx + "k" + i + ", " + + genTempVarPfx + "v" + i + " := range " + varname + " {") + x.line("if " + genTempVarPfx + "j" + i + " > 0 { r.EncodeMapEntrySeparator() }") + x.encVar(genTempVarPfx+"k"+i, t.Key()) + x.line("r.EncodeMapKVSeparator()") + x.encVar(genTempVarPfx+"v"+i, t.Elem()) + x.line(genTempVarPfx + "j" + i + "++") + x.line("}") + x.line("r.EncodeMapEnd()") + + x.line("} else {") + x.linef("for %sk%s, %sv%s := range %s {", genTempVarPfx, i, genTempVarPfx, i, varname) + x.encVar(genTempVarPfx+"k"+i, t.Key()) + x.encVar(genTempVarPfx+"v"+i, t.Elem()) + x.line("}") + + x.line("}") +} + +func (x *genRunner) decVar(varname string, t reflect.Type, canBeNil bool) { + // We only encode as nil if a nillable value. + // This removes some of the wasted checks for TryDecodeAsNil. + // We need to think about this more, to see what happens if omitempty, etc + // cause a nil value to be stored when something is expected. + // This could happen when decoding from a struct encoded as an array. + // For that, decVar should be called with canNil=true, to force true as its value. + i := x.varsfx() + if !canBeNil { + canBeNil = genAnythingCanBeNil || !genIsImmutable(t) + } + if canBeNil { + x.line("if r.TryDecodeAsNil() {") + if t.Kind() == reflect.Ptr { + x.line("if " + varname + " != nil { ") + // x.line("var " + genTempVarPfx + i + " " + x.genTypeName(t.Elem())) + // x.line("*" + varname + " = " + genTempVarPfx + i) + + // if varname is a field of a struct (has a dot in it), + // then just set it to nil + if strings.IndexByte(varname, '.') != -1 { + x.line(varname + " = nil") + } else { + x.line("*" + varname + " = " + genZeroValueR(t.Elem(), x.tc)) + } + // x.line("*" + varname + " = nil") + x.line("}") + + } else { + // x.line("var " + genTempVarPfx + i + " " + x.genTypeName(t)) + // x.line(varname + " = " + genTempVarPfx + i) + x.line(varname + " = " + genZeroValueR(t, x.tc)) + } + x.line("} else {") + } else { + x.line("// cannot be nil") + } + if t.Kind() != reflect.Ptr { + if x.decTryAssignPrimitive(varname, t) { + x.line(genTempVarPfx + "v" + i + " := &" + varname) + x.dec(genTempVarPfx+"v"+i, t) + } + } else { + x.linef("if %s == nil { %s = new(%s) }", varname, varname, x.genTypeName(t.Elem())) + // Ensure we set underlying ptr to a non-nil value (so we can deref to it later). + // There's a chance of a **T in here which is nil. + var ptrPfx string + for t = t.Elem(); t.Kind() == reflect.Ptr; t = t.Elem() { + ptrPfx += "*" + x.linef("if %s%s == nil { %s%s = new(%s)}", + ptrPfx, varname, ptrPfx, varname, x.genTypeName(t)) + } + // if varname has [ in it, then create temp variable for this ptr thingie + if strings.Index(varname, "[") >= 0 { + varname2 := genTempVarPfx + "w" + i + x.line(varname2 + " := " + varname) + varname = varname2 + } + + if ptrPfx == "" { + x.dec(varname, t) + } else { + x.line(genTempVarPfx + "z" + i + " := " + ptrPfx + varname) + x.dec(genTempVarPfx+"z"+i, t) + } + + } + + if canBeNil { + x.line("} ") + } +} + +func (x *genRunner) dec(varname string, t reflect.Type) { + // assumptions: + // - the varname is to a pointer already. No need to take address of it + + rtid := reflect.ValueOf(t).Pointer() + if t.Implements(selferTyp) || (t.Kind() == reflect.Struct && + reflect.PtrTo(t).Implements(selferTyp)) { + x.line(varname + ".CodecDecodeSelf(d)") + return + } + if _, ok := x.td[rtid]; ok { + x.line(varname + ".CodecDecodeSelf(d)") + return + } + + inlist := false + for _, t0 := range x.t { + if t == t0 { + inlist = true + if t != x.tc { + x.line(varname + ".CodecDecodeSelf(d)") + return + } + break + } + } + var rtidAdded bool + if t == x.tc { + x.td[rtid] = true + rtidAdded = true + } + + // Since these are pointers, we cannot share, and have to use them one by one + switch t.Kind() { + case reflect.Int: + x.line("*((*int)(" + varname + ")) = int(r.DecodeInt(codecSelferBitsize" + x.xs + "))") + // x.line("z.DecInt((*int)(" + varname + "))") + case reflect.Int8: + x.line("*((*int8)(" + varname + ")) = int8(r.DecodeInt(8))") + // x.line("z.DecInt8((*int8)(" + varname + "))") + case reflect.Int16: + x.line("*((*int16)(" + varname + ")) = int16(r.DecodeInt(16))") + // x.line("z.DecInt16((*int16)(" + varname + "))") + case reflect.Int32: + x.line("*((*int32)(" + varname + ")) = int32(r.DecodeInt(32))") + // x.line("z.DecInt32((*int32)(" + varname + "))") + case reflect.Int64: + x.line("*((*int64)(" + varname + ")) = int64(r.DecodeInt(64))") + // x.line("z.DecInt64((*int64)(" + varname + "))") + + case reflect.Uint: + x.line("*((*uint)(" + varname + ")) = uint(r.DecodeUint(codecSelferBitsize" + x.xs + "))") + // x.line("z.DecUint((*uint)(" + varname + "))") + case reflect.Uint8: + x.line("*((*uint8)(" + varname + ")) = uint8(r.DecodeUint(8))") + // x.line("z.DecUint8((*uint8)(" + varname + "))") + case reflect.Uint16: + x.line("*((*uint16)(" + varname + ")) = uint16(r.DecodeUint(16))") + //x.line("z.DecUint16((*uint16)(" + varname + "))") + case reflect.Uint32: + x.line("*((*uint32)(" + varname + ")) = uint32(r.DecodeUint(32))") + //x.line("z.DecUint32((*uint32)(" + varname + "))") + case reflect.Uint64: + x.line("*((*uint64)(" + varname + ")) = uint64(r.DecodeUint(64))") + //x.line("z.DecUint64((*uint64)(" + varname + "))") + + case reflect.Float32: + x.line("*((*float32)(" + varname + ")) = float32(r.DecodeFloat(true))") + //x.line("z.DecFloat32((*float32)(" + varname + "))") + case reflect.Float64: + x.line("*((*float64)(" + varname + ")) = float64(r.DecodeFloat(false))") + // x.line("z.DecFloat64((*float64)(" + varname + "))") + + case reflect.Bool: + x.line("*((*bool)(" + varname + ")) = r.DecodeBool()") + // x.line("z.DecBool((*bool)(" + varname + "))") + case reflect.String: + x.line("*((*string)(" + varname + ")) = r.DecodeString()") + // x.line("z.DecString((*string)(" + varname + "))") + case reflect.Array, reflect.Chan: + x.xtraSM(varname, false, t) + // x.decListFallback(varname, rtid, true, t) + case reflect.Slice: + // if a []uint8, call dedicated function + // if a known fastpath slice, call dedicated function + // else write encode function in-line. + // - if elements are primitives or Selfers, call dedicated function on each member. + // - else call Encoder.encode(XXX) on it. + if rtid == uint8SliceTypId { + x.line("*" + varname + " = r.DecodeBytes(*(*[]byte)(" + varname + "), false, false)") + } else if fastpathAV.index(rtid) != -1 { + g := genV{Slice: true, Elem: x.genTypeName(t.Elem())} + x.line("z.F." + g.MethodNamePfx("Dec", false) + "X(" + varname + ", false, d)") + // x.line("z." + g.MethodNamePfx("Dec", false) + "(" + varname + ")") + // x.line(g.FastpathName(false) + "(" + varname + ", d)") + } else { + x.xtraSM(varname, false, t) + // x.decListFallback(varname, rtid, false, t) + } + case reflect.Map: + // if a known fastpath map, call dedicated function + // else write encode function in-line. + // - if elements are primitives or Selfers, call dedicated function on each member. + // - else call Encoder.encode(XXX) on it. + if fastpathAV.index(rtid) != -1 { + g := genV{Slice: false, Elem: x.genTypeName(t.Elem()), MapKey: x.genTypeName(t.Key())} + x.line("z.F." + g.MethodNamePfx("Dec", false) + "X(" + varname + ", false, d)") + // x.line("z." + g.MethodNamePfx("Dec", false) + "(" + varname + ")") + // x.line(g.FastpathName(false) + "(" + varname + ", d)") + } else { + x.xtraSM(varname, false, t) + // x.decMapFallback(varname, rtid, t) + } + case reflect.Struct: + if inlist { + x.decStruct(varname, rtid, t) + } else { + // delete(x.td, rtid) + x.line("z.DecFallback(" + varname + ", false)") + } + default: + if rtidAdded { + delete(x.te, rtid) + } + x.line("z.DecFallback(" + varname + ", true)") + } +} + +func (x *genRunner) decTryAssignPrimitive(varname string, t reflect.Type) (tryAsPtr bool) { + // We have to use the actual type name when doing a direct assignment. + // We don't have the luxury of casting the pointer to the underlying type. + // + // Consequently, in the situation of a + // type Message int32 + // var x Message + // var i int32 = 32 + // x = i // this will bomb + // x = Message(i) // this will work + // *((*int32)(&x)) = i // this will work + // + // Consequently, we replace: + // case reflect.Uint32: x.line(varname + " = uint32(r.DecodeUint(32))") + // with: + // case reflect.Uint32: x.line(varname + " = " + genTypeNamePrimitiveKind(t, x.tc) + "(r.DecodeUint(32))") + + xfn := func(t reflect.Type) string { + return genTypeNamePrimitiveKind(t, x.tc) + } + switch t.Kind() { + case reflect.Int: + x.linef("%s = %s(r.DecodeInt(codecSelferBitsize%s))", varname, xfn(t), x.xs) + case reflect.Int8: + x.linef("%s = %s(r.DecodeInt(8))", varname, xfn(t)) + case reflect.Int16: + x.linef("%s = %s(r.DecodeInt(16))", varname, xfn(t)) + case reflect.Int32: + x.linef("%s = %s(r.DecodeInt(32))", varname, xfn(t)) + case reflect.Int64: + x.linef("%s = %s(r.DecodeInt(64))", varname, xfn(t)) + + case reflect.Uint: + x.linef("%s = %s(r.DecodeUint(codecSelferBitsize%s))", varname, xfn(t), x.xs) + case reflect.Uint8: + x.linef("%s = %s(r.DecodeUint(8))", varname, xfn(t)) + case reflect.Uint16: + x.linef("%s = %s(r.DecodeUint(16))", varname, xfn(t)) + case reflect.Uint32: + x.linef("%s = %s(r.DecodeUint(32))", varname, xfn(t)) + case reflect.Uint64: + x.linef("%s = %s(r.DecodeUint(64))", varname, xfn(t)) + + case reflect.Float32: + x.linef("%s = %s(r.DecodeFloat(true))", varname, xfn(t)) + case reflect.Float64: + x.linef("%s = %s(r.DecodeFloat(false))", varname, xfn(t)) + + case reflect.Bool: + x.linef("%s = %s(r.DecodeBool())", varname, xfn(t)) + case reflect.String: + x.linef("%s = %s(r.DecodeString())", varname, xfn(t)) + default: + tryAsPtr = true + } + return +} + +func (x *genRunner) decListFallback(varname string, rtid uintptr, t reflect.Type) { + type tstruc struct { + TempVar string + Rand string + Varname string + CTyp string + Typ string + Immutable bool + } + telem := t.Elem() + ts := tstruc{genTempVarPfx, x.varsfx(), varname, x.genTypeName(t), x.genTypeName(telem), genIsImmutable(telem)} + + funcs := make(template.FuncMap) + funcs["decLineVar"] = func(varname string) string { + x.decVar(varname, telem, false) + return "" + } + funcs["decLine"] = func(pfx string) string { + x.decVar(ts.TempVar+pfx+ts.Rand, reflect.PtrTo(telem), false) + return "" + } + funcs["var"] = func(s string) string { + return ts.TempVar + s + ts.Rand + } + funcs["zero"] = func() string { + return genZeroValueR(telem, x.tc) + } + funcs["isArray"] = func() bool { + return t.Kind() == reflect.Array + } + funcs["isSlice"] = func() bool { + return t.Kind() == reflect.Slice + } + funcs["isChan"] = func() bool { + return t.Kind() == reflect.Chan + } + tm, err := template.New("").Funcs(funcs).Parse(genDecListTmpl) + if err != nil { + panic(err) + } + if err = tm.Execute(x.w, &ts); err != nil { + panic(err) + } +} + +func (x *genRunner) decMapFallback(varname string, rtid uintptr, t reflect.Type) { + type tstruc struct { + TempVar string + Rand string + Varname string + KTyp string + Typ string + } + telem := t.Elem() + tkey := t.Key() + ts := tstruc{genTempVarPfx, x.varsfx(), varname, x.genTypeName(tkey), x.genTypeName(telem)} + funcs := make(template.FuncMap) + funcs["decLineVarK"] = func(varname string) string { + x.decVar(varname, tkey, false) + return "" + } + funcs["decLineVar"] = func(varname string) string { + x.decVar(varname, telem, false) + return "" + } + funcs["decLineK"] = func(pfx string) string { + x.decVar(ts.TempVar+pfx+ts.Rand, reflect.PtrTo(tkey), false) + return "" + } + funcs["decLine"] = func(pfx string) string { + x.decVar(ts.TempVar+pfx+ts.Rand, reflect.PtrTo(telem), false) + return "" + } + funcs["var"] = func(s string) string { + return ts.TempVar + s + ts.Rand + } + + tm, err := template.New("").Funcs(funcs).Parse(genDecMapTmpl) + if err != nil { + panic(err) + } + if err = tm.Execute(x.w, &ts); err != nil { + panic(err) + } +} + +func (x *genRunner) decStructMapSwitch(kName string, varname string, rtid uintptr, t reflect.Type) { + ti := getTypeInfo(rtid, t) + tisfi := ti.sfip // always use sequence from file. decStruct expects same thing. + x.line("switch (" + kName + ") {") + for _, si := range tisfi { + x.line("case \"" + si.encName + "\":") + var t2 reflect.StructField + if si.i != -1 { + t2 = t.Field(int(si.i)) + } else { + // t2 = t.FieldByIndex(si.is) + t2typ := t + varname3 := varname + for _, ix := range si.is { + for t2typ.Kind() == reflect.Ptr { + t2typ = t2typ.Elem() + } + t2 = t2typ.Field(ix) + t2typ = t2.Type + varname3 = varname3 + "." + t2.Name + if t2typ.Kind() == reflect.Ptr { + x.line("if " + varname3 + " == nil {" + + varname3 + " = new(" + x.genTypeName(t2typ.Elem()) + ") }") + } + } + } + x.decVar(varname+"."+t2.Name, t2.Type, false) + } + x.line("default:") + // pass the slice here, so that the string will not escape, and maybe save allocation + x.line("z.DecStructFieldNotFound(-1, " + kName + ")") + // x.line("z.DecStructFieldNotFoundB(" + kName + "Slc)") + x.line("} // end switch " + kName) +} + +func (x *genRunner) decStructMap(varname, lenvarname string, rtid uintptr, t reflect.Type, style uint8) { + tpfx := genTempVarPfx + i := x.varsfx() + kName := tpfx + "s" + i + + // We thought to use ReadStringAsBytes, as go compiler might optimize the copy out. + // However, using that was more expensive, as it seems that the switch expression + // is evaluated each time. + // + // We could depend on decodeString using a temporary/shared buffer internally. + // However, this model of creating a byte array, and using explicitly is faster, + // and allows optional use of unsafe []byte->string conversion without alloc. + + // Also, ensure that the slice array doesn't escape. + // That will help escape analysis prevent allocation when it gets better. + + // x.line("var " + kName + "Arr = [32]byte{} // default string to decode into") + // x.line("var " + kName + "Slc = " + kName + "Arr[:] // default slice to decode into") + // use the scratch buffer to avoid allocation (most field names are < 32). + + x.line("var " + kName + "Slc = z.DecScratchBuffer() // default slice to decode into") + + // x.line("var " + kName + " string // default string to decode into") + // x.line("_ = " + kName) + x.line("_ = " + kName + "Slc") + // x.linef("var %sb%s bool", tpfx, i) // break + switch style { + case 1: + x.linef("for %sj%s := 0; %sj%s < %s; %sj%s++ {", tpfx, i, tpfx, i, lenvarname, tpfx, i) + case 2: + x.linef("for %sj%s := 0; !r.CheckBreak(); %sj%s++ {", tpfx, i, tpfx, i) + x.linef("if %sj%s > 0 { r.ReadMapEntrySeparator() }", tpfx, i) + default: // 0, otherwise. + x.linef("var %shl%s bool = %s >= 0", tpfx, i, lenvarname) // has length + x.linef("for %sj%s := 0; ; %sj%s++ {", tpfx, i, tpfx, i) + x.linef("if %shl%s { if %sj%s >= %s { break }", tpfx, i, tpfx, i, lenvarname) + x.linef("} else { if r.CheckBreak() { break }; if %sj%s > 0 { r.ReadMapEntrySeparator() } }", + tpfx, i) + } + // x.line(kName + " = z.ReadStringAsBytes(" + kName + ")") + // x.line(kName + " = z.ReadString()") + x.line(kName + "Slc = r.DecodeBytes(" + kName + "Slc, true, true)") + // let string be scoped to this loop alone, so it doesn't escape. + // x.line(kName + " := " + x.cpfx + "GenBytesToStringRO(" + kName + "Slc)") + if x.unsafe { + x.line(kName + "SlcHdr := codecSelferUnsafeString" + x.xs + "{uintptr(unsafe.Pointer(&" + + kName + "Slc[0])), len(" + kName + "Slc)}") + x.line(kName + " := *(*string)(unsafe.Pointer(&" + kName + "SlcHdr))") + } else { + x.line(kName + " := string(" + kName + "Slc)") + } + switch style { + case 1: + case 2: + x.line("r.ReadMapKVSeparator()") + default: + x.linef("if !%shl%s { r.ReadMapKVSeparator() }", tpfx, i) + } + x.decStructMapSwitch(kName, varname, rtid, t) + + x.line("} // end for " + tpfx + "j" + i) + switch style { + case 1: + case 2: + x.line("r.ReadMapEnd()") + default: + x.linef("if !%shl%s { r.ReadMapEnd() }", tpfx, i) + } +} + +func (x *genRunner) decStructArray(varname, lenvarname, breakString string, rtid uintptr, t reflect.Type) { + tpfx := genTempVarPfx + i := x.varsfx() + ti := getTypeInfo(rtid, t) + tisfi := ti.sfip // always use sequence from file. decStruct expects same thing. + x.linef("var %sj%s int", tpfx, i) + x.linef("var %sb%s bool", tpfx, i) // break + // x.linef("var %sl%s := r.ReadArrayStart()", tpfx, i) + x.linef("var %shl%s bool = %s >= 0", tpfx, i, lenvarname) // has length + for j, si := range tisfi { + var t2 reflect.StructField + if si.i != -1 { + t2 = t.Field(int(si.i)) + } else { + t2 = t.FieldByIndex(si.is) + } + + x.linef("%sj%s++; if %shl%s { %sb%s = %sj%s > %s } else { %sb%s = r.CheckBreak() }", + tpfx, i, tpfx, i, tpfx, i, + tpfx, i, lenvarname, tpfx, i) + // x.line("if " + tpfx + "j" + i + "++; " + tpfx + "j" + + // i + " <= " + tpfx + "l" + i + " {") + x.linef("if %sb%s { r.ReadArrayEnd(); %s }", tpfx, i, breakString) + if j > 0 { + x.line("r.ReadArrayEntrySeparator()") + } + x.decVar(varname+"."+t2.Name, t2.Type, true) + // x.line("} // end if " + tpfx + "j" + i + " <= " + tpfx + "l" + i) + } + // read remaining values and throw away. + x.line("for {") + x.linef("%sj%s++; if %shl%s { %sb%s = %sj%s > %s } else { %sb%s = r.CheckBreak() }", + tpfx, i, tpfx, i, tpfx, i, + tpfx, i, lenvarname, tpfx, i) + x.linef("if %sb%s { break }", tpfx, i) + x.linef("if %sj%s > 1 { r.ReadArrayEntrySeparator() }", tpfx, i) + x.linef(`z.DecStructFieldNotFound(%sj%s - 1, "")`, tpfx, i) + x.line("}") + x.line("r.ReadArrayEnd()") +} + +func (x *genRunner) decStruct(varname string, rtid uintptr, t reflect.Type) { + // if container is map + // x.line("if z.DecContainerIsMap() { ") + i := x.varsfx() + x.line("if r.IsContainerType(codecSelverValueTypeMap" + x.xs + ") {") + x.line(genTempVarPfx + "l" + i + " := r.ReadMapStart()") + x.linef("if %sl%s == 0 {", genTempVarPfx, i) + x.line("r.ReadMapEnd()") + if genUseOneFunctionForDecStructMap { + x.line("} else { ") + x.linef("x.codecDecodeSelfFromMap(%sl%s, d)", genTempVarPfx, i) + } else { + x.line("} else if " + genTempVarPfx + "l" + i + " > 0 { ") + x.line("x.codecDecodeSelfFromMapLenPrefix(" + genTempVarPfx + "l" + i + ", d)") + x.line("} else {") + x.line("x.codecDecodeSelfFromMapCheckBreak(" + genTempVarPfx + "l" + i + ", d)") + } + x.line("}") + + // else if container is array + // x.line("} else if z.DecContainerIsArray() { ") + x.line("} else if r.IsContainerType(codecSelverValueTypeArray" + x.xs + ") {") + x.line(genTempVarPfx + "l" + i + " := r.ReadArrayStart()") + x.linef("if %sl%s == 0 {", genTempVarPfx, i) + x.line("r.ReadArrayEnd()") + x.line("} else { ") + x.linef("x.codecDecodeSelfFromArray(%sl%s, d)", genTempVarPfx, i) + x.line("}") + // else panic + x.line("} else { ") + x.line("panic(codecSelferOnlyMapOrArrayEncodeToStructErr" + x.xs + ")") + // x.line("panic(`only encoded map or array can be decoded into a struct`)") + x.line("} ") +} + +// -------- + +type genV struct { + // genV is either a primitive (Primitive != "") or a slice (Slice = true) or a map. + Slice bool + MapKey string + Elem string + Primitive string +} + +func (x *genV) MethodNamePfx(prefix string, prim bool) string { + var name []byte + if prefix != "" { + name = append(name, prefix...) + } + if prim { + name = append(name, genTitleCaseName(x.Primitive)...) + } else { + if x.Slice { + name = append(name, "Slice"...) + } else { + name = append(name, "Map"...) + name = append(name, genTitleCaseName(x.MapKey)...) + } + name = append(name, genTitleCaseName(x.Elem)...) + } + return string(name) + +} + +func genNonPtr(t reflect.Type) reflect.Type { + for t.Kind() == reflect.Ptr { + t = t.Elem() + } + return t +} + +func genTitleCaseName(s string) string { + switch s { + case "interface{}": + return "Intf" + default: + return strings.ToUpper(s[0:1]) + s[1:] + } +} + +func genTypeNamePrimitiveKind(t reflect.Type, tRef reflect.Type) (n string) { + if tRef != nil && t.PkgPath() == tRef.PkgPath() && t.Name() != "" { + return t.Name() + } else { + return t.String() // best way to get the package name inclusive + } +} + +func genTypeName(t reflect.Type, tRef reflect.Type) (n string) { + // defer func() { fmt.Printf(">>>> ####: genTypeName: t: %v, name: '%s'\n", t, n) }() + + // if the type has a PkgPath, which doesn't match the current package, + // then include it. + // We cannot depend on t.String() because it includes current package, + // or t.PkgPath because it includes full import path, + // + var ptrPfx string + for t.Kind() == reflect.Ptr { + ptrPfx += "*" + t = t.Elem() + } + if tn := t.Name(); tn != "" { + return ptrPfx + genTypeNamePrimitiveKind(t, tRef) + } + switch t.Kind() { + case reflect.Map: + return ptrPfx + "map[" + genTypeName(t.Key(), tRef) + "]" + genTypeName(t.Elem(), tRef) + case reflect.Slice: + return ptrPfx + "[]" + genTypeName(t.Elem(), tRef) + case reflect.Array: + return ptrPfx + "[" + strconv.FormatInt(int64(t.Len()), 10) + "]" + genTypeName(t.Elem(), tRef) + case reflect.Chan: + return ptrPfx + t.ChanDir().String() + " " + genTypeName(t.Elem(), tRef) + default: + if t == intfTyp { + return ptrPfx + "interface{}" + } else { + return ptrPfx + genTypeNamePrimitiveKind(t, tRef) + } + } +} + +func genMethodNameT(t reflect.Type, tRef reflect.Type) (n string) { + var ptrPfx string + for t.Kind() == reflect.Ptr { + ptrPfx += "Ptrto" + t = t.Elem() + } + if tn := t.Name(); tn != "" { + if tRef != nil && t.PkgPath() == tRef.PkgPath() { + return ptrPfx + tn + } else { + tstr := t.String() + if genQNameRegex.MatchString(tstr) { + return ptrPfx + strings.Replace(tstr, ".", "_", 1000) + } else { + return ptrPfx + genCustomTypeName(tstr) + } + } + } + switch t.Kind() { + case reflect.Map: + return ptrPfx + "Map" + genMethodNameT(t.Key(), tRef) + genMethodNameT(t.Elem(), tRef) + case reflect.Slice: + return ptrPfx + "Slice" + genMethodNameT(t.Elem(), tRef) + case reflect.Array: + return ptrPfx + "Array" + strconv.FormatInt(int64(t.Len()), 10) + genMethodNameT(t.Elem(), tRef) + case reflect.Chan: + var cx string + switch t.ChanDir() { + case reflect.SendDir: + cx = "ChanSend" + case reflect.RecvDir: + cx = "ChanRecv" + default: + cx = "Chan" + } + return ptrPfx + cx + genMethodNameT(t.Elem(), tRef) + default: + if t == intfTyp { + return ptrPfx + "Interface" + } else { + if tRef != nil && t.PkgPath() == tRef.PkgPath() { + if t.Name() != "" { + return ptrPfx + t.Name() + } else { + return ptrPfx + genCustomTypeName(t.String()) + } + } else { + // best way to get the package name inclusive + // return ptrPfx + strings.Replace(t.String(), ".", "_", 1000) + // return ptrPfx + genBase64enc.EncodeToString([]byte(t.String())) + tstr := t.String() + if t.Name() != "" && genQNameRegex.MatchString(tstr) { + return ptrPfx + strings.Replace(tstr, ".", "_", 1000) + } else { + return ptrPfx + genCustomTypeName(tstr) + } + } + } + } +} + +// genCustomNameForType base64encodes the t.String() value in such a way +// that it can be used within a function name. +func genCustomTypeName(tstr string) string { + len2 := genBase64enc.EncodedLen(len(tstr)) + bufx := make([]byte, len2) + genBase64enc.Encode(bufx, []byte(tstr)) + for i := len2 - 1; i >= 0; i-- { + if bufx[i] == '=' { + len2-- + } else { + break + } + } + return string(bufx[:len2]) +} + +func genIsImmutable(t reflect.Type) (v bool) { + return isMutableKind(t.Kind()) +} + +func genZeroValueR(t reflect.Type, tRef reflect.Type) string { + // if t is a named type, w + switch t.Kind() { + case reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func, + reflect.Slice, reflect.Map, reflect.Invalid: + return "nil" + case reflect.Bool: + return "false" + case reflect.String: + return `""` + case reflect.Struct, reflect.Array: + return genTypeName(t, tRef) + "{}" + default: // all numbers + return "0" + } +} + +type genInternal struct { + Values []genV + Unsafe bool +} + +func (x genInternal) FastpathLen() (l int) { + for _, v := range x.Values { + if v.Primitive == "" { + l++ + } + } + return +} + +func genInternalZeroValue(s string) string { + switch s { + case "interface{}": + return "nil" + case "bool": + return "false" + case "string": + return `""` + default: + return "0" + } +} + +func genInternalEncCommandAsString(s string, vname string) string { + switch s { + case "uint", "uint8", "uint16", "uint32", "uint64": + return "ee.EncodeUint(uint64(" + vname + "))" + case "int", "int8", "int16", "int32", "int64": + return "ee.EncodeInt(int64(" + vname + "))" + case "string": + return "ee.EncodeString(c_UTF8, " + vname + ")" + case "float32": + return "ee.EncodeFloat32(" + vname + ")" + case "float64": + return "ee.EncodeFloat64(" + vname + ")" + case "bool": + return "ee.EncodeBool(" + vname + ")" + case "symbol": + return "ee.EncodeSymbol(" + vname + ")" + default: + return "e.encode(" + vname + ")" + } +} + +func genInternalDecCommandAsString(s string) string { + switch s { + case "uint": + return "uint(dd.DecodeUint(uintBitsize))" + case "uint8": + return "uint8(dd.DecodeUint(8))" + case "uint16": + return "uint16(dd.DecodeUint(16))" + case "uint32": + return "uint32(dd.DecodeUint(32))" + case "uint64": + return "dd.DecodeUint(64)" + case "int": + return "int(dd.DecodeInt(intBitsize))" + case "int8": + return "int8(dd.DecodeInt(8))" + case "int16": + return "int16(dd.DecodeInt(16))" + case "int32": + return "int32(dd.DecodeInt(32))" + case "int64": + return "dd.DecodeInt(64)" + + case "string": + return "dd.DecodeString()" + case "float32": + return "float32(dd.DecodeFloat(true))" + case "float64": + return "dd.DecodeFloat(false)" + case "bool": + return "dd.DecodeBool()" + default: + panic(errors.New("unknown type for decode: " + s)) + } + +} + +// var genInternalMu sync.Mutex +var genInternalV genInternal +var genInternalTmplFuncs template.FuncMap +var genInternalOnce sync.Once + +func genInternalInit() { + types := [...]string{ + "interface{}", + "string", + "float32", + "float64", + "uint", + "uint8", + "uint16", + "uint32", + "uint64", + "int", + "int8", + "int16", + "int32", + "int64", + "bool", + } + // keep as slice, so it is in specific iteration order. + // Initial order was uint64, string, interface{}, int, int64 + mapvaltypes := [...]string{ + "interface{}", + "string", + "uint", + "uint8", + "uint16", + "uint32", + "uint64", + "int", + "int8", + "int16", + "int32", + "int64", + "float32", + "float64", + "bool", + } + mapvaltypes2 := make(map[string]bool) + for _, s := range mapvaltypes { + mapvaltypes2[s] = true + } + var gt genInternal + + // For each slice or map type, there must be a (symetrical) Encode and Decode fast-path function + for _, s := range types { + gt.Values = append(gt.Values, genV{false, "", "", s}) + if s != "uint8" { // do not generate fast path for slice of bytes. Treat specially already. + gt.Values = append(gt.Values, genV{true, "", s, ""}) + } + if !mapvaltypes2[s] { + gt.Values = append(gt.Values, genV{false, s, s, ""}) + } + for _, ms := range mapvaltypes { + gt.Values = append(gt.Values, genV{false, s, ms, ""}) + } + } + + funcs := make(template.FuncMap) + // funcs["haspfx"] = strings.HasPrefix + funcs["encmd"] = genInternalEncCommandAsString + funcs["decmd"] = genInternalDecCommandAsString + funcs["zerocmd"] = genInternalZeroValue + + genInternalV = gt + genInternalTmplFuncs = funcs +} + +// GenInternalGoFile is used to generate source files from templates. +// It is run by the program author alone. +// Unfortunately, it has to be exported so that it can be called from a command line tool. +// *** DO NOT USE *** +func GenInternalGoFile(r io.Reader, w io.Writer, safe bool) (err error) { + genInternalOnce.Do(genInternalInit) + + gt := genInternalV + gt.Unsafe = !safe + + t := template.New("").Funcs(genInternalTmplFuncs) + + tmplstr, err := ioutil.ReadAll(r) + if err != nil { + return + } + + if t, err = t.Parse(string(tmplstr)); err != nil { + return + } + + var out bytes.Buffer + err = t.Execute(&out, gt) + if err != nil { + return + } + + bout, err := format.Source(out.Bytes()) + if err != nil { + w.Write(out.Bytes()) // write out if error, so we can still see. + // w.Write(bout) // write out if error, as much as possible, so we can still see. + return + } + w.Write(bout) + return +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/helper.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/helper.go new file mode 100644 index 0000000000..945b4c4987 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/helper.go @@ -0,0 +1,846 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +// Contains code shared by both encode and decode. + +// Some shared ideas around encoding/decoding +// ------------------------------------------ +// +// If an interface{} is passed, we first do a type assertion to see if it is +// a primitive type or a map/slice of primitive types, and use a fastpath to handle it. +// +// If we start with a reflect.Value, we are already in reflect.Value land and +// will try to grab the function for the underlying Type and directly call that function. +// This is more performant than calling reflect.Value.Interface(). +// +// This still helps us bypass many layers of reflection, and give best performance. +// +// Containers +// ------------ +// Containers in the stream are either associative arrays (key-value pairs) or +// regular arrays (indexed by incrementing integers). +// +// Some streams support indefinite-length containers, and use a breaking +// byte-sequence to denote that the container has come to an end. +// +// Some streams also are text-based, and use explicit separators to denote the +// end/beginning of different values. +// +// During encode, we use a high-level condition to determine how to iterate through +// the container. That decision is based on whether the container is text-based (with +// separators) or binary (without separators). If binary, we do not even call the +// encoding of separators. +// +// During decode, we use a different high-level condition to determine how to iterate +// through the containers. That decision is based on whether the stream contained +// a length prefix, or if it used explicit breaks. If length-prefixed, we assume that +// it has to be binary, and we do not even try to read separators. +// +// The only codec that may suffer (slightly) is cbor, and only when decoding indefinite-length. +// It may suffer because we treat it like a text-based codec, and read separators. +// However, this read is a no-op and the cost is insignificant. +// +// Philosophy +// ------------ +// On decode, this codec will update containers appropriately: +// - If struct, update fields from stream into fields of struct. +// If field in stream not found in struct, handle appropriately (based on option). +// If a struct field has no corresponding value in the stream, leave it AS IS. +// If nil in stream, set value to nil/zero value. +// - If map, update map from stream. +// If the stream value is NIL, set the map to nil. +// - if slice, try to update up to length of array in stream. +// if container len is less than stream array length, +// and container cannot be expanded, handled (based on option). +// This means you can decode 4-element stream array into 1-element array. +// +// ------------------------------------ +// On encode, user can specify omitEmpty. This means that the value will be omitted +// if the zero value. The problem may occur during decode, where omitted values do not affect +// the value being decoded into. This means that if decoding into a struct with an +// int field with current value=5, and the field is omitted in the stream, then after +// decoding, the value will still be 5 (not 0). +// omitEmpty only works if you guarantee that you always decode into zero-values. +// +// ------------------------------------ +// We could have truncated a map to remove keys not available in the stream, +// or set values in the struct which are not in the stream to their zero values. +// We decided against it because there is no efficient way to do it. +// We may introduce it as an option later. +// However, that will require enabling it for both runtime and code generation modes. +// +// To support truncate, we need to do 2 passes over the container: +// map +// - first collect all keys (e.g. in k1) +// - for each key in stream, mark k1 that the key should not be removed +// - after updating map, do second pass and call delete for all keys in k1 which are not marked +// struct: +// - for each field, track the *typeInfo s1 +// - iterate through all s1, and for each one not marked, set value to zero +// - this involves checking the possible anonymous fields which are nil ptrs. +// too much work. +// +// ------------------------------------------ +// Error Handling is done within the library using panic. +// +// This way, the code doesn't have to keep checking if an error has happened, +// and we don't have to keep sending the error value along with each call +// or storing it in the En|Decoder and checking it constantly along the way. +// +// The disadvantage is that small functions which use panics cannot be inlined. +// The code accounts for that by only using panics behind an interface; +// since interface calls cannot be inlined, this is irrelevant. +// +// We considered storing the error is En|Decoder. +// - once it has its err field set, it cannot be used again. +// - panicing will be optional, controlled by const flag. +// - code should always check error first and return early. +// We eventually decided against it as it makes the code clumsier to always +// check for these error conditions. + +import ( + "encoding" + "encoding/binary" + "errors" + "fmt" + "math" + "reflect" + "sort" + "strings" + "sync" + "time" + "unicode" + "unicode/utf8" +) + +const ( + scratchByteArrayLen = 32 + + // Support encoding.(Binary|Text)(Unm|M)arshaler. + // This constant flag will enable or disable it. + supportMarshalInterfaces = true + + // Each Encoder or Decoder uses a cache of functions based on conditionals, + // so that the conditionals are not run every time. + // + // Either a map or a slice is used to keep track of the functions. + // The map is more natural, but has a higher cost than a slice/array. + // This flag (useMapForCodecCache) controls which is used. + // + // From benchmarks, slices with linear search perform better with < 32 entries. + // We have typically seen a high threshold of about 24 entries. + useMapForCodecCache = false + + // for debugging, set this to false, to catch panic traces. + // Note that this will always cause rpc tests to fail, since they need io.EOF sent via panic. + recoverPanicToErr = true + + // Fast path functions try to create a fast path encode or decode implementation + // for common maps and slices, by by-passing reflection altogether. + fastpathEnabled = true + + // if checkStructForEmptyValue, check structs fields to see if an empty value. + // This could be an expensive call, so possibly disable it. + checkStructForEmptyValue = false + + // if derefForIsEmptyValue, deref pointers and interfaces when checking isEmptyValue + derefForIsEmptyValue = false +) + +var oneByteArr = [1]byte{0} +var zeroByteSlice = oneByteArr[:0:0] + +type charEncoding uint8 + +const ( + c_RAW charEncoding = iota + c_UTF8 + c_UTF16LE + c_UTF16BE + c_UTF32LE + c_UTF32BE +) + +// valueType is the stream type +type valueType uint8 + +const ( + valueTypeUnset valueType = iota + valueTypeNil + valueTypeInt + valueTypeUint + valueTypeFloat + valueTypeBool + valueTypeString + valueTypeSymbol + valueTypeBytes + valueTypeMap + valueTypeArray + valueTypeTimestamp + valueTypeExt + + // valueTypeInvalid = 0xff +) + +type seqType uint8 + +const ( + _ seqType = iota + seqTypeArray + seqTypeSlice + seqTypeChan +) + +var ( + bigen = binary.BigEndian + structInfoFieldName = "_struct" + + cachedTypeInfo = make(map[uintptr]*typeInfo, 64) + cachedTypeInfoMutex sync.RWMutex + + // mapStrIntfTyp = reflect.TypeOf(map[string]interface{}(nil)) + intfSliceTyp = reflect.TypeOf([]interface{}(nil)) + intfTyp = intfSliceTyp.Elem() + + stringTyp = reflect.TypeOf("") + timeTyp = reflect.TypeOf(time.Time{}) + rawExtTyp = reflect.TypeOf(RawExt{}) + uint8SliceTyp = reflect.TypeOf([]uint8(nil)) + + mapBySliceTyp = reflect.TypeOf((*MapBySlice)(nil)).Elem() + + binaryMarshalerTyp = reflect.TypeOf((*encoding.BinaryMarshaler)(nil)).Elem() + binaryUnmarshalerTyp = reflect.TypeOf((*encoding.BinaryUnmarshaler)(nil)).Elem() + + textMarshalerTyp = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem() + textUnmarshalerTyp = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem() + + selferTyp = reflect.TypeOf((*Selfer)(nil)).Elem() + + uint8SliceTypId = reflect.ValueOf(uint8SliceTyp).Pointer() + rawExtTypId = reflect.ValueOf(rawExtTyp).Pointer() + intfTypId = reflect.ValueOf(intfTyp).Pointer() + timeTypId = reflect.ValueOf(timeTyp).Pointer() + stringTypId = reflect.ValueOf(stringTyp).Pointer() + + // mapBySliceTypId = reflect.ValueOf(mapBySliceTyp).Pointer() + + intBitsize uint8 = uint8(reflect.TypeOf(int(0)).Bits()) + uintBitsize uint8 = uint8(reflect.TypeOf(uint(0)).Bits()) + + bsAll0x00 = []byte{0, 0, 0, 0, 0, 0, 0, 0} + bsAll0xff = []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} + + chkOvf checkOverflow + + noFieldNameToStructFieldInfoErr = errors.New("no field name passed to parseStructFieldInfo") +) + +// Selfer defines methods by which a value can encode or decode itself. +// +// Any type which implements Selfer will be able to encode or decode itself. +// Consequently, during (en|de)code, this takes precedence over +// (text|binary)(M|Unm)arshal or extension support. +type Selfer interface { + CodecEncodeSelf(*Encoder) + CodecDecodeSelf(*Decoder) +} + +// MapBySlice represents a slice which should be encoded as a map in the stream. +// The slice contains a sequence of key-value pairs. +// This affords storing a map in a specific sequence in the stream. +// +// The support of MapBySlice affords the following: +// - A slice type which implements MapBySlice will be encoded as a map +// - A slice can be decoded from a map in the stream +type MapBySlice interface { + MapBySlice() +} + +// WARNING: DO NOT USE DIRECTLY. EXPORTED FOR GODOC BENEFIT. WILL BE REMOVED. +// +// BasicHandle encapsulates the common options and extension functions. +type BasicHandle struct { + extHandle + EncodeOptions + DecodeOptions +} + +func (x *BasicHandle) getBasicHandle() *BasicHandle { + return x +} + +// Handle is the interface for a specific encoding format. +// +// Typically, a Handle is pre-configured before first time use, +// and not modified while in use. Such a pre-configured Handle +// is safe for concurrent access. +type Handle interface { + getBasicHandle() *BasicHandle + newEncDriver(w *Encoder) encDriver + newDecDriver(r *Decoder) decDriver + isBinary() bool +} + +// RawExt represents raw unprocessed extension data. +// Some codecs will decode extension data as a *RawExt if there is no registered extension for the tag. +// +// Only one of Data or Value is nil. If Data is nil, then the content of the RawExt is in the Value. +type RawExt struct { + Tag uint64 + // Data is the []byte which represents the raw ext. If Data is nil, ext is exposed in Value. + // Data is used by codecs (e.g. binc, msgpack, simple) which do custom serialization of the types + Data []byte + // Value represents the extension, if Data is nil. + // Value is used by codecs (e.g. cbor) which use the format to do custom serialization of the types. + Value interface{} +} + +// Ext handles custom (de)serialization of custom types / extensions. +type Ext interface { + // WriteExt converts a value to a []byte. + // It is used by codecs (e.g. binc, msgpack, simple) which do custom serialization of the types. + WriteExt(v interface{}) []byte + + // ReadExt updates a value from a []byte. + // It is used by codecs (e.g. binc, msgpack, simple) which do custom serialization of the types. + ReadExt(dst interface{}, src []byte) + + // ConvertExt converts a value into a simpler interface for easy encoding e.g. convert time.Time to int64. + // It is used by codecs (e.g. cbor) which use the format to do custom serialization of the types. + ConvertExt(v interface{}) interface{} + + // UpdateExt updates a value from a simpler interface for easy decoding e.g. convert int64 to time.Time. + // It is used by codecs (e.g. cbor) which use the format to do custom serialization of the types. + UpdateExt(dst interface{}, src interface{}) +} + +// bytesExt is a wrapper implementation to support former AddExt exported method. +type bytesExt struct { + encFn func(reflect.Value) ([]byte, error) + decFn func(reflect.Value, []byte) error +} + +func (x bytesExt) WriteExt(v interface{}) []byte { + // fmt.Printf(">>>>>>>>>> WriteExt: %T, %v\n", v, v) + bs, err := x.encFn(reflect.ValueOf(v)) + if err != nil { + panic(err) + } + return bs +} + +func (x bytesExt) ReadExt(v interface{}, bs []byte) { + // fmt.Printf(">>>>>>>>>> ReadExt: %T, %v\n", v, v) + if err := x.decFn(reflect.ValueOf(v), bs); err != nil { + panic(err) + } +} + +func (x bytesExt) ConvertExt(v interface{}) interface{} { + return x.WriteExt(v) +} + +func (x bytesExt) UpdateExt(dest interface{}, v interface{}) { + x.ReadExt(dest, v.([]byte)) +} + +// type errorString string +// func (x errorString) Error() string { return string(x) } + +type binaryEncodingType struct{} + +func (_ binaryEncodingType) isBinary() bool { return true } + +type textEncodingType struct{} + +func (_ textEncodingType) isBinary() bool { return false } + +// noBuiltInTypes is embedded into many types which do not support builtins +// e.g. msgpack, simple, cbor. +type noBuiltInTypes struct{} + +func (_ noBuiltInTypes) IsBuiltinType(rt uintptr) bool { return false } +func (_ noBuiltInTypes) EncodeBuiltin(rt uintptr, v interface{}) {} +func (_ noBuiltInTypes) DecodeBuiltin(rt uintptr, v interface{}) {} + +type noStreamingCodec struct{} + +func (_ noStreamingCodec) CheckBreak() bool { return false } + +// bigenHelper. +// Users must already slice the x completely, because we will not reslice. +type bigenHelper struct { + x []byte // must be correctly sliced to appropriate len. slicing is a cost. + w encWriter +} + +func (z bigenHelper) writeUint16(v uint16) { + bigen.PutUint16(z.x, v) + z.w.writeb(z.x) +} + +func (z bigenHelper) writeUint32(v uint32) { + bigen.PutUint32(z.x, v) + z.w.writeb(z.x) +} + +func (z bigenHelper) writeUint64(v uint64) { + bigen.PutUint64(z.x, v) + z.w.writeb(z.x) +} + +type extTypeTagFn struct { + rtid uintptr + rt reflect.Type + tag uint64 + ext Ext +} + +type extHandle []*extTypeTagFn + +// DEPRECATED: AddExt is deprecated in favor of SetExt. It exists for compatibility only. +// +// AddExt registes an encode and decode function for a reflect.Type. +// AddExt internally calls SetExt. +// To deregister an Ext, call AddExt with nil encfn and/or nil decfn. +func (o *extHandle) AddExt( + rt reflect.Type, tag byte, + encfn func(reflect.Value) ([]byte, error), decfn func(reflect.Value, []byte) error, +) (err error) { + if encfn == nil || decfn == nil { + return o.SetExt(rt, uint64(tag), nil) + } + return o.SetExt(rt, uint64(tag), bytesExt{encfn, decfn}) +} + +// SetExt registers a tag and Ext for a reflect.Type. +// +// Note that the type must be a named type, and specifically not +// a pointer or Interface. An error is returned if that is not honored. +// +// To Deregister an ext, call SetExt with nil Ext +func (o *extHandle) SetExt(rt reflect.Type, tag uint64, ext Ext) (err error) { + // o is a pointer, because we may need to initialize it + if rt.PkgPath() == "" || rt.Kind() == reflect.Interface { + err = fmt.Errorf("codec.Handle.AddExt: Takes named type, especially not a pointer or interface: %T", + reflect.Zero(rt).Interface()) + return + } + + rtid := reflect.ValueOf(rt).Pointer() + for _, v := range *o { + if v.rtid == rtid { + v.tag, v.ext = tag, ext + return + } + } + + *o = append(*o, &extTypeTagFn{rtid, rt, tag, ext}) + return +} + +func (o extHandle) getExt(rtid uintptr) *extTypeTagFn { + for _, v := range o { + if v.rtid == rtid { + return v + } + } + return nil +} + +func (o extHandle) getExtForTag(tag uint64) *extTypeTagFn { + for _, v := range o { + if v.tag == tag { + return v + } + } + return nil +} + +type structFieldInfo struct { + encName string // encode name + + // only one of 'i' or 'is' can be set. If 'i' is -1, then 'is' has been set. + + is []int // (recursive/embedded) field index in struct + i int16 // field index in struct + omitEmpty bool + toArray bool // if field is _struct, is the toArray set? +} + +// rv returns the field of the struct. +// If anonymous, it returns an Invalid +func (si *structFieldInfo) field(v reflect.Value, update bool) (rv2 reflect.Value) { + if si.i != -1 { + v = v.Field(int(si.i)) + return v + } + // replicate FieldByIndex + for _, x := range si.is { + for v.Kind() == reflect.Ptr { + if v.IsNil() { + if !update { + return + } + v.Set(reflect.New(v.Type().Elem())) + } + v = v.Elem() + } + v = v.Field(x) + } + return v +} + +func (si *structFieldInfo) setToZeroValue(v reflect.Value) { + if si.i != -1 { + v = v.Field(int(si.i)) + v.Set(reflect.Zero(v.Type())) + // v.Set(reflect.New(v.Type()).Elem()) + // v.Set(reflect.New(v.Type())) + } else { + // replicate FieldByIndex + for _, x := range si.is { + for v.Kind() == reflect.Ptr { + if v.IsNil() { + return + } + v = v.Elem() + } + v = v.Field(x) + } + v.Set(reflect.Zero(v.Type())) + } +} + +func parseStructFieldInfo(fname string, stag string) *structFieldInfo { + if fname == "" { + panic(noFieldNameToStructFieldInfoErr) + } + si := structFieldInfo{ + encName: fname, + } + + if stag != "" { + for i, s := range strings.Split(stag, ",") { + if i == 0 { + if s != "" { + si.encName = s + } + } else { + if s == "omitempty" { + si.omitEmpty = true + } else if s == "toarray" { + si.toArray = true + } + } + } + } + // si.encNameBs = []byte(si.encName) + return &si +} + +type sfiSortedByEncName []*structFieldInfo + +func (p sfiSortedByEncName) Len() int { + return len(p) +} + +func (p sfiSortedByEncName) Less(i, j int) bool { + return p[i].encName < p[j].encName +} + +func (p sfiSortedByEncName) Swap(i, j int) { + p[i], p[j] = p[j], p[i] +} + +// typeInfo keeps information about each type referenced in the encode/decode sequence. +// +// During an encode/decode sequence, we work as below: +// - If base is a built in type, en/decode base value +// - If base is registered as an extension, en/decode base value +// - If type is binary(M/Unm)arshaler, call Binary(M/Unm)arshal method +// - If type is text(M/Unm)arshaler, call Text(M/Unm)arshal method +// - Else decode appropriately based on the reflect.Kind +type typeInfo struct { + sfi []*structFieldInfo // sorted. Used when enc/dec struct to map. + sfip []*structFieldInfo // unsorted. Used when enc/dec struct to array. + + rt reflect.Type + rtid uintptr + + // baseId gives pointer to the base reflect.Type, after deferencing + // the pointers. E.g. base type of ***time.Time is time.Time. + base reflect.Type + baseId uintptr + baseIndir int8 // number of indirections to get to base + + mbs bool // base type (T or *T) is a MapBySlice + + bm bool // base type (T or *T) is a binaryMarshaler + bunm bool // base type (T or *T) is a binaryUnmarshaler + bmIndir int8 // number of indirections to get to binaryMarshaler type + bunmIndir int8 // number of indirections to get to binaryUnmarshaler type + + tm bool // base type (T or *T) is a textMarshaler + tunm bool // base type (T or *T) is a textUnmarshaler + tmIndir int8 // number of indirections to get to textMarshaler type + tunmIndir int8 // number of indirections to get to textUnmarshaler type + + cs bool // base type (T or *T) is a Selfer + csIndir int8 // number of indirections to get to Selfer type + + toArray bool // whether this (struct) type should be encoded as an array +} + +func (ti *typeInfo) indexForEncName(name string) int { + //tisfi := ti.sfi + const binarySearchThreshold = 16 + if sfilen := len(ti.sfi); sfilen < binarySearchThreshold { + // linear search. faster than binary search in my testing up to 16-field structs. + for i, si := range ti.sfi { + if si.encName == name { + return i + } + } + } else { + // binary search. adapted from sort/search.go. + h, i, j := 0, 0, sfilen + for i < j { + h = i + (j-i)/2 + if ti.sfi[h].encName < name { + i = h + 1 + } else { + j = h + } + } + if i < sfilen && ti.sfi[i].encName == name { + return i + } + } + return -1 +} + +func getStructTag(t reflect.StructTag) (s string) { + // check for tags: codec, json, in that order. + // this allows seamless support for many configured structs. + s = t.Get("codec") + if s == "" { + s = t.Get("json") + } + return +} + +func getTypeInfo(rtid uintptr, rt reflect.Type) (pti *typeInfo) { + var ok bool + cachedTypeInfoMutex.RLock() + pti, ok = cachedTypeInfo[rtid] + cachedTypeInfoMutex.RUnlock() + if ok { + return + } + + cachedTypeInfoMutex.Lock() + defer cachedTypeInfoMutex.Unlock() + if pti, ok = cachedTypeInfo[rtid]; ok { + return + } + + ti := typeInfo{rt: rt, rtid: rtid} + pti = &ti + + var indir int8 + if ok, indir = implementsIntf(rt, binaryMarshalerTyp); ok { + ti.bm, ti.bmIndir = true, indir + } + if ok, indir = implementsIntf(rt, binaryUnmarshalerTyp); ok { + ti.bunm, ti.bunmIndir = true, indir + } + if ok, indir = implementsIntf(rt, textMarshalerTyp); ok { + ti.tm, ti.tmIndir = true, indir + } + if ok, indir = implementsIntf(rt, textUnmarshalerTyp); ok { + ti.tunm, ti.tunmIndir = true, indir + } + if ok, indir = implementsIntf(rt, selferTyp); ok { + ti.cs, ti.csIndir = true, indir + } + if ok, _ = implementsIntf(rt, mapBySliceTyp); ok { + ti.mbs = true + } + + pt := rt + var ptIndir int8 + // for ; pt.Kind() == reflect.Ptr; pt, ptIndir = pt.Elem(), ptIndir+1 { } + for pt.Kind() == reflect.Ptr { + pt = pt.Elem() + ptIndir++ + } + if ptIndir == 0 { + ti.base = rt + ti.baseId = rtid + } else { + ti.base = pt + ti.baseId = reflect.ValueOf(pt).Pointer() + ti.baseIndir = ptIndir + } + + if rt.Kind() == reflect.Struct { + var siInfo *structFieldInfo + if f, ok := rt.FieldByName(structInfoFieldName); ok { + siInfo = parseStructFieldInfo(structInfoFieldName, getStructTag(f.Tag)) + ti.toArray = siInfo.toArray + } + sfip := make([]*structFieldInfo, 0, rt.NumField()) + rgetTypeInfo(rt, nil, make(map[string]bool, 16), &sfip, siInfo) + + ti.sfip = make([]*structFieldInfo, len(sfip)) + ti.sfi = make([]*structFieldInfo, len(sfip)) + copy(ti.sfip, sfip) + sort.Sort(sfiSortedByEncName(sfip)) + copy(ti.sfi, sfip) + } + // sfi = sfip + cachedTypeInfo[rtid] = pti + return +} + +func rgetTypeInfo(rt reflect.Type, indexstack []int, fnameToHastag map[string]bool, + sfi *[]*structFieldInfo, siInfo *structFieldInfo, +) { + for j := 0; j < rt.NumField(); j++ { + f := rt.Field(j) + // func types are skipped. + if tk := f.Type.Kind(); tk == reflect.Func { + continue + } + stag := getStructTag(f.Tag) + if stag == "-" { + continue + } + if r1, _ := utf8.DecodeRuneInString(f.Name); r1 == utf8.RuneError || !unicode.IsUpper(r1) { + continue + } + // if anonymous and there is no struct tag and its a struct (or pointer to struct), inline it. + if f.Anonymous && stag == "" { + ft := f.Type + for ft.Kind() == reflect.Ptr { + ft = ft.Elem() + } + if ft.Kind() == reflect.Struct { + indexstack2 := make([]int, len(indexstack)+1, len(indexstack)+4) + copy(indexstack2, indexstack) + indexstack2[len(indexstack)] = j + // indexstack2 := append(append(make([]int, 0, len(indexstack)+4), indexstack...), j) + rgetTypeInfo(ft, indexstack2, fnameToHastag, sfi, siInfo) + continue + } + } + // do not let fields with same name in embedded structs override field at higher level. + // this must be done after anonymous check, to allow anonymous field + // still include their child fields + if _, ok := fnameToHastag[f.Name]; ok { + continue + } + si := parseStructFieldInfo(f.Name, stag) + // si.ikind = int(f.Type.Kind()) + if len(indexstack) == 0 { + si.i = int16(j) + } else { + si.i = -1 + si.is = append(append(make([]int, 0, len(indexstack)+4), indexstack...), j) + } + + if siInfo != nil { + if siInfo.omitEmpty { + si.omitEmpty = true + } + } + *sfi = append(*sfi, si) + fnameToHastag[f.Name] = stag != "" + } +} + +func panicToErr(err *error) { + if recoverPanicToErr { + if x := recover(); x != nil { + //debug.PrintStack() + panicValToErr(x, err) + } + } +} + +// func doPanic(tag string, format string, params ...interface{}) { +// params2 := make([]interface{}, len(params)+1) +// params2[0] = tag +// copy(params2[1:], params) +// panic(fmt.Errorf("%s: "+format, params2...)) +// } + +func isMutableKind(k reflect.Kind) (v bool) { + return k == reflect.Int || + k == reflect.Int8 || + k == reflect.Int16 || + k == reflect.Int32 || + k == reflect.Int64 || + k == reflect.Uint || + k == reflect.Uint8 || + k == reflect.Uint16 || + k == reflect.Uint32 || + k == reflect.Uint64 || + k == reflect.Float32 || + k == reflect.Float64 || + k == reflect.Bool || + k == reflect.String +} + +// these functions must be inlinable, and not call anybody +type checkOverflow struct{} + +func (_ checkOverflow) Float32(f float64) (overflow bool) { + if f < 0 { + f = -f + } + return math.MaxFloat32 < f && f <= math.MaxFloat64 +} + +func (_ checkOverflow) Uint(v uint64, bitsize uint8) (overflow bool) { + if bitsize == 0 || bitsize >= 64 || v == 0 { + return + } + if trunc := (v << (64 - bitsize)) >> (64 - bitsize); v != trunc { + overflow = true + } + return +} + +func (_ checkOverflow) Int(v int64, bitsize uint8) (overflow bool) { + if bitsize == 0 || bitsize >= 64 || v == 0 { + return + } + if trunc := (v << (64 - bitsize)) >> (64 - bitsize); v != trunc { + overflow = true + } + return +} + +func (_ checkOverflow) SignedInt(v uint64) (i int64, overflow bool) { + //e.g. -127 to 128 for int8 + pos := (v >> 63) == 0 + ui2 := v & 0x7fffffffffffffff + if pos { + if ui2 > math.MaxInt64 { + overflow = true + return + } + } else { + if ui2 > math.MaxInt64-1 { + overflow = true + return + } + } + i = int64(v) + return +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_internal.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_internal.go new file mode 100644 index 0000000000..7d4e9326a2 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_internal.go @@ -0,0 +1,151 @@ +// Copyright (c) 2012, 2013 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +// All non-std package dependencies live in this file, +// so porting to different environment is easy (just update functions). + +import ( + "errors" + "fmt" + "math" + "reflect" +) + +func panicValToErr(panicVal interface{}, err *error) { + if panicVal == nil { + return + } + // case nil + switch xerr := panicVal.(type) { + case error: + *err = xerr + case string: + *err = errors.New(xerr) + default: + *err = fmt.Errorf("%v", panicVal) + } + return +} + +func hIsEmptyValue(v reflect.Value, deref, checkStruct bool) bool { + switch v.Kind() { + case reflect.Invalid: + return true + case reflect.Array, reflect.Map, reflect.Slice, reflect.String: + return v.Len() == 0 + case reflect.Bool: + return !v.Bool() + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return v.Int() == 0 + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: + return v.Uint() == 0 + case reflect.Float32, reflect.Float64: + return v.Float() == 0 + case reflect.Interface, reflect.Ptr: + if deref { + if v.IsNil() { + return true + } + return hIsEmptyValue(v.Elem(), deref, checkStruct) + } else { + return v.IsNil() + } + case reflect.Struct: + if !checkStruct { + return false + } + // return true if all fields are empty. else return false. + // we cannot use equality check, because some fields may be maps/slices/etc + // and consequently the structs are not comparable. + // return v.Interface() == reflect.Zero(v.Type()).Interface() + for i, n := 0, v.NumField(); i < n; i++ { + if !hIsEmptyValue(v.Field(i), deref, checkStruct) { + return false + } + } + return true + } + return false +} + +func isEmptyValue(v reflect.Value) bool { + return hIsEmptyValue(v, derefForIsEmptyValue, checkStructForEmptyValue) +} + +func pruneSignExt(v []byte, pos bool) (n int) { + if len(v) < 2 { + } else if pos && v[0] == 0 { + for ; v[n] == 0 && n+1 < len(v) && (v[n+1]&(1<<7) == 0); n++ { + } + } else if !pos && v[0] == 0xff { + for ; v[n] == 0xff && n+1 < len(v) && (v[n+1]&(1<<7) != 0); n++ { + } + } + return +} + +func implementsIntf(typ, iTyp reflect.Type) (success bool, indir int8) { + if typ == nil { + return + } + rt := typ + // The type might be a pointer and we need to keep + // dereferencing to the base type until we find an implementation. + for { + if rt.Implements(iTyp) { + return true, indir + } + if p := rt; p.Kind() == reflect.Ptr { + indir++ + if indir >= math.MaxInt8 { // insane number of indirections + return false, 0 + } + rt = p.Elem() + continue + } + break + } + // No luck yet, but if this is a base type (non-pointer), the pointer might satisfy. + if typ.Kind() != reflect.Ptr { + // Not a pointer, but does the pointer work? + if reflect.PtrTo(typ).Implements(iTyp) { + return true, -1 + } + } + return false, 0 +} + +// validate that this function is correct ... +// culled from OGRE (Object-Oriented Graphics Rendering Engine) +// function: halfToFloatI (http://stderr.org/doc/ogre-doc/api/OgreBitwise_8h-source.html) +func halfFloatToFloatBits(yy uint16) (d uint32) { + y := uint32(yy) + s := (y >> 15) & 0x01 + e := (y >> 10) & 0x1f + m := y & 0x03ff + + if e == 0 { + if m == 0 { // plu or minus 0 + return s << 31 + } else { // Denormalized number -- renormalize it + for (m & 0x00000400) == 0 { + m <<= 1 + e -= 1 + } + e += 1 + const zz uint32 = 0x0400 + m &= ^zz + } + } else if e == 31 { + if m == 0 { // Inf + return (s << 31) | 0x7f800000 + } else { // NaN + return (s << 31) | 0x7f800000 | (m << 13) + } + } + e = e + (127 - 15) + m = m << 13 + return (s << 31) | (e << 23) | m +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_not_unsafe.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_not_unsafe.go new file mode 100644 index 0000000000..df0503880f --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_not_unsafe.go @@ -0,0 +1,20 @@ +//+build !unsafe + +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +// stringView returns a view of the []byte as a string. +// In unsafe mode, it doesn't incur allocation and copying caused by conversion. +// In regular safe mode, it is an allocation and copy. +func stringView(v []byte) string { + return string(v) +} + +// bytesView returns a view of the string as a []byte. +// In unsafe mode, it doesn't incur allocation and copying caused by conversion. +// In regular safe mode, it is an allocation and copy. +func bytesView(v string) []byte { + return []byte(v) +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_test.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_test.go new file mode 100644 index 0000000000..8ea6cc5e72 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_test.go @@ -0,0 +1,155 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +// All non-std package dependencies related to testing live in this file, +// so porting to different environment is easy (just update functions). +// +// This file sets up the variables used, including testInitFns. +// Each file should add initialization that should be performed +// after flags are parsed. +// +// init is a multi-step process: +// - setup vars (handled by init functions in each file) +// - parse flags +// - setup derived vars (handled by pre-init registered functions - registered in init function) +// - post init (handled by post-init registered functions - registered in init function) +// This way, no one has to manage carefully control the initialization +// using file names, etc. +// +// Tests which require external dependencies need the -tag=x parameter. +// They should be run as: +// go test -tags=x -run=. +// Benchmarks should also take this parameter, to include the sereal, xdr, etc. +// To run against codecgen, etc, make sure you pass extra parameters. +// Example usage: +// go test "-tags=x codecgen unsafe" -bench=. +// +// To fully test everything: +// go test -tags=x -benchtime=100ms -tv -bg -bi -brw -bu -v -run=. -bench=. + +import ( + "errors" + "flag" + "fmt" + "reflect" + "sync" + "testing" +) + +const ( + testLogToT = true + failNowOnFail = true +) + +var ( + testNoopH = NoopHandle(8) + testMsgpackH = &MsgpackHandle{} + testBincH = &BincHandle{} + testBincHNoSym = &BincHandle{} + testBincHSym = &BincHandle{} + testSimpleH = &SimpleHandle{} + testCborH = &CborHandle{} + testJsonH = &JsonHandle{} + + testPreInitFns []func() + testPostInitFns []func() + + testOnce sync.Once +) + +func init() { + testBincHSym.AsSymbols = AsSymbolAll + testBincHNoSym.AsSymbols = AsSymbolNone +} + +func testInitAll() { + flag.Parse() + for _, f := range testPreInitFns { + f() + } + for _, f := range testPostInitFns { + f() + } +} + +func logT(x interface{}, format string, args ...interface{}) { + if t, ok := x.(*testing.T); ok && t != nil && testLogToT { + if testVerbose { + t.Logf(format, args...) + } + } else if b, ok := x.(*testing.B); ok && b != nil && testLogToT { + b.Logf(format, args...) + } else { + if len(format) == 0 || format[len(format)-1] != '\n' { + format = format + "\n" + } + fmt.Printf(format, args...) + } +} + +func approxDataSize(rv reflect.Value) (sum int) { + switch rk := rv.Kind(); rk { + case reflect.Invalid: + case reflect.Ptr, reflect.Interface: + sum += int(rv.Type().Size()) + sum += approxDataSize(rv.Elem()) + case reflect.Slice: + sum += int(rv.Type().Size()) + for j := 0; j < rv.Len(); j++ { + sum += approxDataSize(rv.Index(j)) + } + case reflect.String: + sum += int(rv.Type().Size()) + sum += rv.Len() + case reflect.Map: + sum += int(rv.Type().Size()) + for _, mk := range rv.MapKeys() { + sum += approxDataSize(mk) + sum += approxDataSize(rv.MapIndex(mk)) + } + case reflect.Struct: + //struct size already includes the full data size. + //sum += int(rv.Type().Size()) + for j := 0; j < rv.NumField(); j++ { + sum += approxDataSize(rv.Field(j)) + } + default: + //pure value types + sum += int(rv.Type().Size()) + } + return +} + +// ----- functions below are used only by tests (not benchmarks) + +func checkErrT(t *testing.T, err error) { + if err != nil { + logT(t, err.Error()) + failT(t) + } +} + +func checkEqualT(t *testing.T, v1 interface{}, v2 interface{}, desc string) (err error) { + if err = deepEqual(v1, v2); err != nil { + logT(t, "Not Equal: %s: %v. v1: %v, v2: %v", desc, err, v1, v2) + failT(t) + } + return +} + +func failT(t *testing.T) { + if failNowOnFail { + t.FailNow() + } else { + t.Fail() + } +} + +func deepEqual(v1, v2 interface{}) (err error) { + if !reflect.DeepEqual(v1, v2) { + err = errors.New("Not Match") + } + return +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_unsafe.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_unsafe.go new file mode 100644 index 0000000000..3526d4452a --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/helper_unsafe.go @@ -0,0 +1,39 @@ +//+build unsafe + +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +import ( + "unsafe" +) + +// This file has unsafe variants of some helper methods. + +type unsafeString struct { + Data uintptr + Len int +} + +type unsafeBytes struct { + Data uintptr + Len int + Cap int +} + +// stringView returns a view of the []byte as a string. +// In unsafe mode, it doesn't incur allocation and copying caused by conversion. +// In regular safe mode, it is an allocation and copy. +func stringView(v []byte) string { + x := unsafeString{uintptr(unsafe.Pointer(&v[0])), len(v)} + return *(*string)(unsafe.Pointer(&x)) +} + +// bytesView returns a view of the string as a []byte. +// In unsafe mode, it doesn't incur allocation and copying caused by conversion. +// In regular safe mode, it is an allocation and copy. +func bytesView(v string) []byte { + x := unsafeBytes{uintptr(unsafe.Pointer(&v)), len(v), len(v)} + return *(*[]byte)(unsafe.Pointer(&x)) +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/json.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/json.go new file mode 100644 index 0000000000..c112a79716 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/json.go @@ -0,0 +1,924 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +// This json support uses base64 encoding for bytes, because you cannot +// store and read any arbitrary string in json (only unicode). +// +// This library specifically supports UTF-8 for encoding and decoding only. +// +// Note that the library will happily encode/decode things which are not valid +// json e.g. a map[int64]string. We do it for consistency. With valid json, +// we will encode and decode appropriately. +// Users can specify their map type if necessary to force it. +// +// Note: +// - we cannot use strconv.Quote and strconv.Unquote because json quotes/unquotes differently. +// We implement it here. +// - Also, strconv.ParseXXX for floats and integers +// - only works on strings resulting in unnecessary allocation and []byte-string conversion. +// - it does a lot of redundant checks, because json numbers are simpler that what it supports. +// - We parse numbers (floats and integers) directly here. +// We only delegate parsing floats if it is a hairy float which could cause a loss of precision. +// In that case, we delegate to strconv.ParseFloat. +// +// Note: +// - encode does not beautify. There is no whitespace when encoding. +// - rpc calls which take single integer arguments or write single numeric arguments will need care. + +import ( + "bytes" + "encoding/base64" + "fmt" + "strconv" + "unicode/utf16" + "unicode/utf8" +) + +//-------------------------------- + +var jsonLiterals = [...]byte{'t', 'r', 'u', 'e', 'f', 'a', 'l', 's', 'e', 'n', 'u', 'l', 'l'} + +var jsonFloat64Pow10 = [...]float64{ + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, + 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, + 1e20, 1e21, 1e22, +} + +var jsonUint64Pow10 = [...]uint64{ + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, + 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, +} + +const ( + // if jsonTrackSkipWhitespace, we track Whitespace and reduce the number of redundant checks. + // Make it a const flag, so that it can be elided during linking if false. + // + // It is not a clear win, because we continually set a flag behind a pointer + // and then check it each time, as opposed to just 4 conditionals on a stack variable. + jsonTrackSkipWhitespace = true + + // If !jsonValidateSymbols, decoding will be faster, by skipping some checks: + // - If we see first character of null, false or true, + // do not validate subsequent characters. + // - e.g. if we see a n, assume null and skip next 3 characters, + // and do not validate they are ull. + // P.S. Do not expect a significant decoding boost from this. + jsonValidateSymbols = true + + // if jsonTruncateMantissa, truncate mantissa if trailing 0's. + // This is important because it could allow some floats to be decoded without + // deferring to strconv.ParseFloat. + jsonTruncateMantissa = true + + // if mantissa >= jsonNumUintCutoff before multiplying by 10, this is an overflow + jsonNumUintCutoff = (1<<64-1)/uint64(10) + 1 // cutoff64(base) + + // if mantissa >= jsonNumUintMaxVal, this is an overflow + jsonNumUintMaxVal = 1<= slen { + e.bs = e.bs[:slen] + } else { + e.bs = make([]byte, slen) + } + base64.StdEncoding.Encode(e.bs, v) + e.w.writen1('"') + e.w.writeb(e.bs) + e.w.writen1('"') + } else { + // e.EncodeString(c, string(v)) + e.quoteStr(stringView(v)) + } +} + +func (e *jsonEncDriver) quoteStr(s string) { + // adapted from std pkg encoding/json + const hex = "0123456789abcdef" + w := e.w + w.writen1('"') + start := 0 + for i := 0; i < len(s); { + if b := s[i]; b < utf8.RuneSelf { + if 0x20 <= b && b != '\\' && b != '"' && b != '<' && b != '>' && b != '&' { + i++ + continue + } + if start < i { + w.writestr(s[start:i]) + } + switch b { + case '\\', '"': + w.writen2('\\', b) + case '\n': + w.writen2('\\', 'n') + case '\r': + w.writen2('\\', 'r') + case '\b': + w.writen2('\\', 'b') + case '\f': + w.writen2('\\', 'f') + case '\t': + w.writen2('\\', 't') + default: + // encode all bytes < 0x20 (except \r, \n). + // also encode < > & to prevent security holes when served to some browsers. + w.writestr(`\u00`) + w.writen2(hex[b>>4], hex[b&0xF]) + } + i++ + start = i + continue + } + c, size := utf8.DecodeRuneInString(s[i:]) + if c == utf8.RuneError && size == 1 { + if start < i { + w.writestr(s[start:i]) + } + w.writestr(`\ufffd`) + i += size + start = i + continue + } + // U+2028 is LINE SEPARATOR. U+2029 is PARAGRAPH SEPARATOR. + // Both technically valid JSON, but bomb on JSONP, so fix here. + if c == '\u2028' || c == '\u2029' { + if start < i { + w.writestr(s[start:i]) + } + w.writestr(`\u202`) + w.writen1(hex[c&0xF]) + i += size + start = i + continue + } + i += size + } + if start < len(s) { + w.writestr(s[start:]) + } + w.writen1('"') +} + +//-------------------------------- + +type jsonNum struct { + bytes []byte // may have [+-.eE0-9] + mantissa uint64 // where mantissa ends, and maybe dot begins. + exponent int16 // exponent value. + manOverflow bool + neg bool // started with -. No initial sign in the bytes above. + dot bool // has dot + explicitExponent bool // explicit exponent +} + +func (x *jsonNum) reset() { + x.bytes = x.bytes[:0] + x.manOverflow = false + x.neg = false + x.dot = false + x.explicitExponent = false + x.mantissa = 0 + x.exponent = 0 +} + +// uintExp is called only if exponent > 0. +func (x *jsonNum) uintExp() (n uint64, overflow bool) { + n = x.mantissa + e := x.exponent + if e >= int16(len(jsonUint64Pow10)) { + overflow = true + return + } + n *= jsonUint64Pow10[e] + if n < x.mantissa || n > jsonNumUintMaxVal { + overflow = true + return + } + return + // for i := int16(0); i < e; i++ { + // if n >= jsonNumUintCutoff { + // overflow = true + // return + // } + // n *= 10 + // } + // return +} + +func (x *jsonNum) floatVal() (f float64) { + // We do not want to lose precision. + // Consequently, we will delegate to strconv.ParseFloat if any of the following happen: + // - There are more digits than in math.MaxUint64: 18446744073709551615 (20 digits) + // We expect up to 99.... (19 digits) + // - The mantissa cannot fit into a 52 bits of uint64 + // - The exponent is beyond our scope ie beyong 22. + const uint64MantissaBits = 52 + const maxExponent = int16(len(jsonFloat64Pow10)) - 1 + + parseUsingStrConv := x.manOverflow || + x.exponent > maxExponent || + (x.exponent < 0 && -(x.exponent) > maxExponent) || + x.mantissa>>uint64MantissaBits != 0 + if parseUsingStrConv { + var err error + if f, err = strconv.ParseFloat(stringView(x.bytes), 64); err != nil { + panic(fmt.Errorf("parse float: %s, %v", x.bytes, err)) + return + } + if x.neg { + f = -f + } + return + } + + // all good. so handle parse here. + f = float64(x.mantissa) + // fmt.Printf(".Float: uint64 value: %v, float: %v\n", m, f) + if x.neg { + f = -f + } + if x.exponent > 0 { + f *= jsonFloat64Pow10[x.exponent] + } else if x.exponent < 0 { + f /= jsonFloat64Pow10[-x.exponent] + } + return +} + +type jsonDecDriver struct { + d *Decoder + h *JsonHandle + r decReader // *bytesDecReader decReader + ct valueType // container type. one of unset, array or map. + bstr [8]byte // scratch used for string \UXXX parsing + b [64]byte // scratch + + wsSkipped bool // whitespace skipped + + n jsonNum + noBuiltInTypes +} + +// This will skip whitespace characters and return the next byte to read. +// The next byte determines what the value will be one of. +func (d *jsonDecDriver) skipWhitespace(unread bool) (b byte) { + // as initReadNext is not called all the time, we set ct to unSet whenever + // we skipwhitespace, as this is the signal that something new is about to be read. + d.ct = valueTypeUnset + b = d.r.readn1() + if !jsonTrackSkipWhitespace || !d.wsSkipped { + for ; b == ' ' || b == '\t' || b == '\r' || b == '\n'; b = d.r.readn1() { + } + if jsonTrackSkipWhitespace { + d.wsSkipped = true + } + } + if unread { + d.r.unreadn1() + } + return b +} + +func (d *jsonDecDriver) CheckBreak() bool { + b := d.skipWhitespace(true) + return b == '}' || b == ']' +} + +func (d *jsonDecDriver) readStrIdx(fromIdx, toIdx uint8) { + bs := d.r.readx(int(toIdx - fromIdx)) + if jsonValidateSymbols { + if !bytes.Equal(bs, jsonLiterals[fromIdx:toIdx]) { + d.d.errorf("json: expecting %s: got %s", jsonLiterals[fromIdx:toIdx], bs) + return + } + } + if jsonTrackSkipWhitespace { + d.wsSkipped = false + } +} + +func (d *jsonDecDriver) TryDecodeAsNil() bool { + b := d.skipWhitespace(true) + if b == 'n' { + d.readStrIdx(9, 13) // null + d.ct = valueTypeNil + return true + } + return false +} + +func (d *jsonDecDriver) DecodeBool() bool { + b := d.skipWhitespace(false) + if b == 'f' { + d.readStrIdx(5, 9) // alse + return false + } + if b == 't' { + d.readStrIdx(1, 4) // rue + return true + } + d.d.errorf("json: decode bool: got first char %c", b) + return false // "unreachable" +} + +func (d *jsonDecDriver) ReadMapStart() int { + d.expectChar('{') + d.ct = valueTypeMap + return -1 +} + +func (d *jsonDecDriver) ReadArrayStart() int { + d.expectChar('[') + d.ct = valueTypeArray + return -1 +} +func (d *jsonDecDriver) ReadMapEnd() { + d.expectChar('}') +} +func (d *jsonDecDriver) ReadArrayEnd() { + d.expectChar(']') +} +func (d *jsonDecDriver) ReadArrayEntrySeparator() { + d.expectChar(',') +} +func (d *jsonDecDriver) ReadMapEntrySeparator() { + d.expectChar(',') +} +func (d *jsonDecDriver) ReadMapKVSeparator() { + d.expectChar(':') +} +func (d *jsonDecDriver) expectChar(c uint8) { + b := d.skipWhitespace(false) + if b != c { + d.d.errorf("json: expect char %c but got char %c", c, b) + return + } + if jsonTrackSkipWhitespace { + d.wsSkipped = false + } +} + +func (d *jsonDecDriver) IsContainerType(vt valueType) bool { + // check container type by checking the first char + if d.ct == valueTypeUnset { + b := d.skipWhitespace(true) + if b == '{' { + d.ct = valueTypeMap + } else if b == '[' { + d.ct = valueTypeArray + } else if b == 'n' { + d.ct = valueTypeNil + } else if b == '"' { + d.ct = valueTypeString + } + } + if vt == valueTypeNil || vt == valueTypeBytes || vt == valueTypeString || + vt == valueTypeArray || vt == valueTypeMap { + return d.ct == vt + } + // ugorji: made switch into conditionals, so that IsContainerType can be inlined. + // switch vt { + // case valueTypeNil, valueTypeBytes, valueTypeString, valueTypeArray, valueTypeMap: + // return d.ct == vt + // } + d.d.errorf("isContainerType: unsupported parameter: %v", vt) + return false // "unreachable" +} + +func (d *jsonDecDriver) decNum(storeBytes bool) { + // storeBytes = true // TODO: remove. + + // If it is has a . or an e|E, decode as a float; else decode as an int. + b := d.skipWhitespace(false) + if !(b == '+' || b == '-' || b == '.' || (b >= '0' && b <= '9')) { + d.d.errorf("json: decNum: got first char '%c'", b) + return + } + + const cutoff = (1<<64-1)/uint64(10) + 1 // cutoff64(base) + const jsonNumUintMaxVal = 1<= jsonNumUintCutoff { + n.manOverflow = true + break + } + v := uint64(b - '0') + n.mantissa *= 10 + if v != 0 { + n1 := n.mantissa + v + if n1 < n.mantissa || n1 > jsonNumUintMaxVal { + n.manOverflow = true // n+v overflows + break + } + n.mantissa = n1 + } + case 6: + state = 7 + fallthrough + case 7: + if !(b == '0' && e == 0) { + e = e*10 + int16(b-'0') + } + default: + break LOOP + } + default: + break LOOP + } + if storeBytes { + n.bytes = append(n.bytes, b) + } + b, eof = d.r.readn1eof() + } + + if jsonTruncateMantissa && n.mantissa != 0 { + for n.mantissa%10 == 0 { + n.mantissa /= 10 + n.exponent++ + } + } + + if e != 0 { + if eNeg { + n.exponent -= e + } else { + n.exponent += e + } + } + + // d.n = n + + if !eof { + d.r.unreadn1() + } + if jsonTrackSkipWhitespace { + d.wsSkipped = false + } + // fmt.Printf("1: n: bytes: %s, neg: %v, dot: %v, exponent: %v, mantissaEndIndex: %v\n", + // n.bytes, n.neg, n.dot, n.exponent, n.mantissaEndIndex) + return +} + +func (d *jsonDecDriver) DecodeInt(bitsize uint8) (i int64) { + d.decNum(false) + n := &d.n + if n.manOverflow { + d.d.errorf("json: overflow integer after: %v", n.mantissa) + return + } + var u uint64 + if n.exponent == 0 { + u = n.mantissa + } else if n.exponent < 0 { + d.d.errorf("json: fractional integer") + return + } else if n.exponent > 0 { + var overflow bool + if u, overflow = n.uintExp(); overflow { + d.d.errorf("json: overflow integer") + return + } + } + i = int64(u) + if n.neg { + i = -i + } + if chkOvf.Int(i, bitsize) { + d.d.errorf("json: overflow %v bits: %s", bitsize, n.bytes) + return + } + // fmt.Printf("DecodeInt: %v\n", i) + return +} + +func (d *jsonDecDriver) DecodeUint(bitsize uint8) (u uint64) { + d.decNum(false) + n := &d.n + if n.neg { + d.d.errorf("json: unsigned integer cannot be negative") + return + } + if n.manOverflow { + d.d.errorf("json: overflow integer after: %v", n.mantissa) + return + } + if n.exponent == 0 { + u = n.mantissa + } else if n.exponent < 0 { + d.d.errorf("json: fractional integer") + return + } else if n.exponent > 0 { + var overflow bool + if u, overflow = n.uintExp(); overflow { + d.d.errorf("json: overflow integer") + return + } + } + if chkOvf.Uint(u, bitsize) { + d.d.errorf("json: overflow %v bits: %s", bitsize, n.bytes) + return + } + // fmt.Printf("DecodeUint: %v\n", u) + return +} + +func (d *jsonDecDriver) DecodeFloat(chkOverflow32 bool) (f float64) { + d.decNum(true) + n := &d.n + f = n.floatVal() + if chkOverflow32 && chkOvf.Float32(f) { + d.d.errorf("json: overflow float32: %v, %s", f, n.bytes) + return + } + return +} + +func (d *jsonDecDriver) DecodeExt(rv interface{}, xtag uint64, ext Ext) (realxtag uint64) { + if ext == nil { + re := rv.(*RawExt) + re.Tag = xtag + d.d.decode(&re.Value) + } else { + var v interface{} + d.d.decode(&v) + ext.UpdateExt(rv, v) + } + return +} + +func (d *jsonDecDriver) DecodeBytes(bs []byte, isstring, zerocopy bool) (bsOut []byte) { + // zerocopy doesn't matter for json, as the bytes must be parsed. + bs0 := d.appendStringAsBytes(d.b[:0]) + if isstring { + return bs0 + } + slen := base64.StdEncoding.DecodedLen(len(bs0)) + if cap(bs) >= slen { + bsOut = bs[:slen] + } else { + bsOut = make([]byte, slen) + } + slen2, err := base64.StdEncoding.Decode(bsOut, bs0) + if err != nil { + d.d.errorf("json: error decoding base64 binary '%s': %v", bs0, err) + return nil + } + if slen != slen2 { + bsOut = bsOut[:slen2] + } + return +} + +func (d *jsonDecDriver) DecodeString() (s string) { + return string(d.appendStringAsBytes(d.b[:0])) +} + +func (d *jsonDecDriver) appendStringAsBytes(v []byte) []byte { + d.expectChar('"') + for { + c := d.r.readn1() + if c == '"' { + break + } else if c == '\\' { + c = d.r.readn1() + switch c { + case '"', '\\', '/', '\'': + v = append(v, c) + case 'b': + v = append(v, '\b') + case 'f': + v = append(v, '\f') + case 'n': + v = append(v, '\n') + case 'r': + v = append(v, '\r') + case 't': + v = append(v, '\t') + case 'u': + rr := d.jsonU4(false) + // fmt.Printf("$$$$$$$$$: is surrogate: %v\n", utf16.IsSurrogate(rr)) + if utf16.IsSurrogate(rr) { + rr = utf16.DecodeRune(rr, d.jsonU4(true)) + } + w2 := utf8.EncodeRune(d.bstr[:], rr) + v = append(v, d.bstr[:w2]...) + default: + d.d.errorf("json: unsupported escaped value: %c", c) + return nil + } + } else { + v = append(v, c) + } + } + if jsonTrackSkipWhitespace { + d.wsSkipped = false + } + return v +} + +func (d *jsonDecDriver) jsonU4(checkSlashU bool) rune { + if checkSlashU && !(d.r.readn1() == '\\' && d.r.readn1() == 'u') { + d.d.errorf(`json: unquoteStr: invalid unicode sequence. Expecting \u`) + return 0 + } + // u, _ := strconv.ParseUint(string(d.bstr[:4]), 16, 64) + var u uint32 + for i := 0; i < 4; i++ { + v := d.r.readn1() + if '0' <= v && v <= '9' { + v = v - '0' + } else if 'a' <= v && v <= 'z' { + v = v - 'a' + 10 + } else if 'A' <= v && v <= 'Z' { + v = v - 'A' + 10 + } else { + d.d.errorf(`json: unquoteStr: invalid hex char in \u unicode sequence: %q`, v) + return 0 + } + u = u*16 + uint32(v) + } + return rune(u) +} + +func (d *jsonDecDriver) DecodeNaked() (v interface{}, vt valueType, decodeFurther bool) { + n := d.skipWhitespace(true) + switch n { + case 'n': + d.readStrIdx(9, 13) // null + vt = valueTypeNil + case 'f': + d.readStrIdx(4, 9) // false + vt = valueTypeBool + v = false + case 't': + d.readStrIdx(0, 4) // true + vt = valueTypeBool + v = true + case '{': + vt = valueTypeMap + decodeFurther = true + case '[': + vt = valueTypeArray + decodeFurther = true + case '"': + vt = valueTypeString + v = d.DecodeString() + default: // number + d.decNum(true) + n := &d.n + // if the string had a any of [.eE], then decode as float. + switch { + case n.explicitExponent, n.dot, n.exponent < 0, n.manOverflow: + vt = valueTypeFloat + v = n.floatVal() + case n.exponent == 0: + u := n.mantissa + switch { + case n.neg: + vt = valueTypeInt + v = -int64(u) + case d.h.SignedInteger: + vt = valueTypeInt + v = int64(u) + default: + vt = valueTypeUint + v = u + } + default: + u, overflow := n.uintExp() + switch { + case overflow: + vt = valueTypeFloat + v = n.floatVal() + case n.neg: + vt = valueTypeInt + v = -int64(u) + case d.h.SignedInteger: + vt = valueTypeInt + v = int64(u) + default: + vt = valueTypeUint + v = u + } + } + // fmt.Printf("DecodeNaked: Number: %T, %v\n", v, v) + } + return +} + +//---------------------- + +// JsonHandle is a handle for JSON encoding format. +// +// Json is comprehensively supported: +// - decodes numbers into interface{} as int, uint or float64 +// - encodes and decodes []byte using base64 Std Encoding +// - UTF-8 support for encoding and decoding +// +// It has better performance than the json library in the standard library, +// by leveraging the performance improvements of the codec library and +// minimizing allocations. +// +// In addition, it doesn't read more bytes than necessary during a decode, which allows +// reading multiple values from a stream containing json and non-json content. +// For example, a user can read a json value, then a cbor value, then a msgpack value, +// all from the same stream in sequence. +type JsonHandle struct { + BasicHandle + textEncodingType +} + +func (h *JsonHandle) newEncDriver(e *Encoder) encDriver { + return &jsonEncDriver{e: e, w: e.w, h: h} +} + +func (h *JsonHandle) newDecDriver(d *Decoder) decDriver { + // d := jsonDecDriver{r: r.(*bytesDecReader), h: h} + hd := jsonDecDriver{d: d, r: d.r, h: h} + hd.n.bytes = d.b[:] + return &hd +} + +var jsonEncodeTerminate = []byte{' '} + +func (h *JsonHandle) rpcEncodeTerminate() []byte { + return jsonEncodeTerminate +} + +var _ decDriver = (*jsonDecDriver)(nil) +var _ encDriver = (*jsonEncDriver)(nil) diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/msgpack.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/msgpack.go new file mode 100644 index 0000000000..a5812ba145 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/msgpack.go @@ -0,0 +1,843 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +/* +MSGPACK + +Msgpack-c implementation powers the c, c++, python, ruby, etc libraries. +We need to maintain compatibility with it and how it encodes integer values +without caring about the type. + +For compatibility with behaviour of msgpack-c reference implementation: + - Go intX (>0) and uintX + IS ENCODED AS + msgpack +ve fixnum, unsigned + - Go intX (<0) + IS ENCODED AS + msgpack -ve fixnum, signed + +*/ +package codec + +import ( + "fmt" + "io" + "math" + "net/rpc" +) + +const ( + mpPosFixNumMin byte = 0x00 + mpPosFixNumMax = 0x7f + mpFixMapMin = 0x80 + mpFixMapMax = 0x8f + mpFixArrayMin = 0x90 + mpFixArrayMax = 0x9f + mpFixStrMin = 0xa0 + mpFixStrMax = 0xbf + mpNil = 0xc0 + _ = 0xc1 + mpFalse = 0xc2 + mpTrue = 0xc3 + mpFloat = 0xca + mpDouble = 0xcb + mpUint8 = 0xcc + mpUint16 = 0xcd + mpUint32 = 0xce + mpUint64 = 0xcf + mpInt8 = 0xd0 + mpInt16 = 0xd1 + mpInt32 = 0xd2 + mpInt64 = 0xd3 + + // extensions below + mpBin8 = 0xc4 + mpBin16 = 0xc5 + mpBin32 = 0xc6 + mpExt8 = 0xc7 + mpExt16 = 0xc8 + mpExt32 = 0xc9 + mpFixExt1 = 0xd4 + mpFixExt2 = 0xd5 + mpFixExt4 = 0xd6 + mpFixExt8 = 0xd7 + mpFixExt16 = 0xd8 + + mpStr8 = 0xd9 // new + mpStr16 = 0xda + mpStr32 = 0xdb + + mpArray16 = 0xdc + mpArray32 = 0xdd + + mpMap16 = 0xde + mpMap32 = 0xdf + + mpNegFixNumMin = 0xe0 + mpNegFixNumMax = 0xff +) + +// MsgpackSpecRpcMultiArgs is a special type which signifies to the MsgpackSpecRpcCodec +// that the backend RPC service takes multiple arguments, which have been arranged +// in sequence in the slice. +// +// The Codec then passes it AS-IS to the rpc service (without wrapping it in an +// array of 1 element). +type MsgpackSpecRpcMultiArgs []interface{} + +// A MsgpackContainer type specifies the different types of msgpackContainers. +type msgpackContainerType struct { + fixCutoff int + bFixMin, b8, b16, b32 byte + hasFixMin, has8, has8Always bool +} + +var ( + msgpackContainerStr = msgpackContainerType{32, mpFixStrMin, mpStr8, mpStr16, mpStr32, true, true, false} + msgpackContainerBin = msgpackContainerType{0, 0, mpBin8, mpBin16, mpBin32, false, true, true} + msgpackContainerList = msgpackContainerType{16, mpFixArrayMin, 0, mpArray16, mpArray32, true, false, false} + msgpackContainerMap = msgpackContainerType{16, mpFixMapMin, 0, mpMap16, mpMap32, true, false, false} +) + +//--------------------------------------------- + +type msgpackEncDriver struct { + e *Encoder + w encWriter + h *MsgpackHandle + noBuiltInTypes + encNoSeparator + x [8]byte +} + +func (e *msgpackEncDriver) EncodeNil() { + e.w.writen1(mpNil) +} + +func (e *msgpackEncDriver) EncodeInt(i int64) { + if i >= 0 { + e.EncodeUint(uint64(i)) + } else if i >= -32 { + e.w.writen1(byte(i)) + } else if i >= math.MinInt8 { + e.w.writen2(mpInt8, byte(i)) + } else if i >= math.MinInt16 { + e.w.writen1(mpInt16) + bigenHelper{e.x[:2], e.w}.writeUint16(uint16(i)) + } else if i >= math.MinInt32 { + e.w.writen1(mpInt32) + bigenHelper{e.x[:4], e.w}.writeUint32(uint32(i)) + } else { + e.w.writen1(mpInt64) + bigenHelper{e.x[:8], e.w}.writeUint64(uint64(i)) + } +} + +func (e *msgpackEncDriver) EncodeUint(i uint64) { + if i <= math.MaxInt8 { + e.w.writen1(byte(i)) + } else if i <= math.MaxUint8 { + e.w.writen2(mpUint8, byte(i)) + } else if i <= math.MaxUint16 { + e.w.writen1(mpUint16) + bigenHelper{e.x[:2], e.w}.writeUint16(uint16(i)) + } else if i <= math.MaxUint32 { + e.w.writen1(mpUint32) + bigenHelper{e.x[:4], e.w}.writeUint32(uint32(i)) + } else { + e.w.writen1(mpUint64) + bigenHelper{e.x[:8], e.w}.writeUint64(uint64(i)) + } +} + +func (e *msgpackEncDriver) EncodeBool(b bool) { + if b { + e.w.writen1(mpTrue) + } else { + e.w.writen1(mpFalse) + } +} + +func (e *msgpackEncDriver) EncodeFloat32(f float32) { + e.w.writen1(mpFloat) + bigenHelper{e.x[:4], e.w}.writeUint32(math.Float32bits(f)) +} + +func (e *msgpackEncDriver) EncodeFloat64(f float64) { + e.w.writen1(mpDouble) + bigenHelper{e.x[:8], e.w}.writeUint64(math.Float64bits(f)) +} + +func (e *msgpackEncDriver) EncodeExt(v interface{}, xtag uint64, ext Ext, _ *Encoder) { + bs := ext.WriteExt(v) + if bs == nil { + e.EncodeNil() + return + } + if e.h.WriteExt { + e.encodeExtPreamble(uint8(xtag), len(bs)) + e.w.writeb(bs) + } else { + e.EncodeStringBytes(c_RAW, bs) + } +} + +func (e *msgpackEncDriver) EncodeRawExt(re *RawExt, _ *Encoder) { + e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) + e.w.writeb(re.Data) +} + +func (e *msgpackEncDriver) encodeExtPreamble(xtag byte, l int) { + if l == 1 { + e.w.writen2(mpFixExt1, xtag) + } else if l == 2 { + e.w.writen2(mpFixExt2, xtag) + } else if l == 4 { + e.w.writen2(mpFixExt4, xtag) + } else if l == 8 { + e.w.writen2(mpFixExt8, xtag) + } else if l == 16 { + e.w.writen2(mpFixExt16, xtag) + } else if l < 256 { + e.w.writen2(mpExt8, byte(l)) + e.w.writen1(xtag) + } else if l < 65536 { + e.w.writen1(mpExt16) + bigenHelper{e.x[:2], e.w}.writeUint16(uint16(l)) + e.w.writen1(xtag) + } else { + e.w.writen1(mpExt32) + bigenHelper{e.x[:4], e.w}.writeUint32(uint32(l)) + e.w.writen1(xtag) + } +} + +func (e *msgpackEncDriver) EncodeArrayStart(length int) { + e.writeContainerLen(msgpackContainerList, length) +} + +func (e *msgpackEncDriver) EncodeMapStart(length int) { + e.writeContainerLen(msgpackContainerMap, length) +} + +func (e *msgpackEncDriver) EncodeString(c charEncoding, s string) { + if c == c_RAW && e.h.WriteExt { + e.writeContainerLen(msgpackContainerBin, len(s)) + } else { + e.writeContainerLen(msgpackContainerStr, len(s)) + } + if len(s) > 0 { + e.w.writestr(s) + } +} + +func (e *msgpackEncDriver) EncodeSymbol(v string) { + e.EncodeString(c_UTF8, v) +} + +func (e *msgpackEncDriver) EncodeStringBytes(c charEncoding, bs []byte) { + if c == c_RAW && e.h.WriteExt { + e.writeContainerLen(msgpackContainerBin, len(bs)) + } else { + e.writeContainerLen(msgpackContainerStr, len(bs)) + } + if len(bs) > 0 { + e.w.writeb(bs) + } +} + +func (e *msgpackEncDriver) writeContainerLen(ct msgpackContainerType, l int) { + if ct.hasFixMin && l < ct.fixCutoff { + e.w.writen1(ct.bFixMin | byte(l)) + } else if ct.has8 && l < 256 && (ct.has8Always || e.h.WriteExt) { + e.w.writen2(ct.b8, uint8(l)) + } else if l < 65536 { + e.w.writen1(ct.b16) + bigenHelper{e.x[:2], e.w}.writeUint16(uint16(l)) + } else { + e.w.writen1(ct.b32) + bigenHelper{e.x[:4], e.w}.writeUint32(uint32(l)) + } +} + +//--------------------------------------------- + +type msgpackDecDriver struct { + d *Decoder + r decReader // *Decoder decReader decReaderT + h *MsgpackHandle + b [scratchByteArrayLen]byte + bd byte + bdRead bool + br bool // bytes reader + bdType valueType + noBuiltInTypes + noStreamingCodec + decNoSeparator +} + +// Note: This returns either a primitive (int, bool, etc) for non-containers, +// or a containerType, or a specific type denoting nil or extension. +// It is called when a nil interface{} is passed, leaving it up to the DecDriver +// to introspect the stream and decide how best to decode. +// It deciphers the value by looking at the stream first. +func (d *msgpackDecDriver) DecodeNaked() (v interface{}, vt valueType, decodeFurther bool) { + if !d.bdRead { + d.readNextBd() + } + bd := d.bd + + switch bd { + case mpNil: + vt = valueTypeNil + d.bdRead = false + case mpFalse: + vt = valueTypeBool + v = false + case mpTrue: + vt = valueTypeBool + v = true + + case mpFloat: + vt = valueTypeFloat + v = float64(math.Float32frombits(bigen.Uint32(d.r.readx(4)))) + case mpDouble: + vt = valueTypeFloat + v = math.Float64frombits(bigen.Uint64(d.r.readx(8))) + + case mpUint8: + vt = valueTypeUint + v = uint64(d.r.readn1()) + case mpUint16: + vt = valueTypeUint + v = uint64(bigen.Uint16(d.r.readx(2))) + case mpUint32: + vt = valueTypeUint + v = uint64(bigen.Uint32(d.r.readx(4))) + case mpUint64: + vt = valueTypeUint + v = uint64(bigen.Uint64(d.r.readx(8))) + + case mpInt8: + vt = valueTypeInt + v = int64(int8(d.r.readn1())) + case mpInt16: + vt = valueTypeInt + v = int64(int16(bigen.Uint16(d.r.readx(2)))) + case mpInt32: + vt = valueTypeInt + v = int64(int32(bigen.Uint32(d.r.readx(4)))) + case mpInt64: + vt = valueTypeInt + v = int64(int64(bigen.Uint64(d.r.readx(8)))) + + default: + switch { + case bd >= mpPosFixNumMin && bd <= mpPosFixNumMax: + // positive fixnum (always signed) + vt = valueTypeInt + v = int64(int8(bd)) + case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax: + // negative fixnum + vt = valueTypeInt + v = int64(int8(bd)) + case bd == mpStr8, bd == mpStr16, bd == mpStr32, bd >= mpFixStrMin && bd <= mpFixStrMax: + if d.h.RawToString { + var rvm string + vt = valueTypeString + v = &rvm + } else { + var rvm = zeroByteSlice + vt = valueTypeBytes + v = &rvm + } + decodeFurther = true + case bd == mpBin8, bd == mpBin16, bd == mpBin32: + var rvm = zeroByteSlice + vt = valueTypeBytes + v = &rvm + decodeFurther = true + case bd == mpArray16, bd == mpArray32, bd >= mpFixArrayMin && bd <= mpFixArrayMax: + vt = valueTypeArray + decodeFurther = true + case bd == mpMap16, bd == mpMap32, bd >= mpFixMapMin && bd <= mpFixMapMax: + vt = valueTypeMap + decodeFurther = true + case bd >= mpFixExt1 && bd <= mpFixExt16, bd >= mpExt8 && bd <= mpExt32: + clen := d.readExtLen() + var re RawExt + re.Tag = uint64(d.r.readn1()) + re.Data = d.r.readx(clen) + v = &re + vt = valueTypeExt + default: + d.d.errorf("Nil-Deciphered DecodeValue: %s: hex: %x, dec: %d", msgBadDesc, bd, bd) + return + } + } + if !decodeFurther { + d.bdRead = false + } + if vt == valueTypeUint && d.h.SignedInteger { + d.bdType = valueTypeInt + v = int64(v.(uint64)) + } + return +} + +// int can be decoded from msgpack type: intXXX or uintXXX +func (d *msgpackDecDriver) DecodeInt(bitsize uint8) (i int64) { + if !d.bdRead { + d.readNextBd() + } + switch d.bd { + case mpUint8: + i = int64(uint64(d.r.readn1())) + case mpUint16: + i = int64(uint64(bigen.Uint16(d.r.readx(2)))) + case mpUint32: + i = int64(uint64(bigen.Uint32(d.r.readx(4)))) + case mpUint64: + i = int64(bigen.Uint64(d.r.readx(8))) + case mpInt8: + i = int64(int8(d.r.readn1())) + case mpInt16: + i = int64(int16(bigen.Uint16(d.r.readx(2)))) + case mpInt32: + i = int64(int32(bigen.Uint32(d.r.readx(4)))) + case mpInt64: + i = int64(bigen.Uint64(d.r.readx(8))) + default: + switch { + case d.bd >= mpPosFixNumMin && d.bd <= mpPosFixNumMax: + i = int64(int8(d.bd)) + case d.bd >= mpNegFixNumMin && d.bd <= mpNegFixNumMax: + i = int64(int8(d.bd)) + default: + d.d.errorf("Unhandled single-byte unsigned integer value: %s: %x", msgBadDesc, d.bd) + return + } + } + // check overflow (logic adapted from std pkg reflect/value.go OverflowUint() + if bitsize > 0 { + if trunc := (i << (64 - bitsize)) >> (64 - bitsize); i != trunc { + d.d.errorf("Overflow int value: %v", i) + return + } + } + d.bdRead = false + return +} + +// uint can be decoded from msgpack type: intXXX or uintXXX +func (d *msgpackDecDriver) DecodeUint(bitsize uint8) (ui uint64) { + if !d.bdRead { + d.readNextBd() + } + switch d.bd { + case mpUint8: + ui = uint64(d.r.readn1()) + case mpUint16: + ui = uint64(bigen.Uint16(d.r.readx(2))) + case mpUint32: + ui = uint64(bigen.Uint32(d.r.readx(4))) + case mpUint64: + ui = bigen.Uint64(d.r.readx(8)) + case mpInt8: + if i := int64(int8(d.r.readn1())); i >= 0 { + ui = uint64(i) + } else { + d.d.errorf("Assigning negative signed value: %v, to unsigned type", i) + return + } + case mpInt16: + if i := int64(int16(bigen.Uint16(d.r.readx(2)))); i >= 0 { + ui = uint64(i) + } else { + d.d.errorf("Assigning negative signed value: %v, to unsigned type", i) + return + } + case mpInt32: + if i := int64(int32(bigen.Uint32(d.r.readx(4)))); i >= 0 { + ui = uint64(i) + } else { + d.d.errorf("Assigning negative signed value: %v, to unsigned type", i) + return + } + case mpInt64: + if i := int64(bigen.Uint64(d.r.readx(8))); i >= 0 { + ui = uint64(i) + } else { + d.d.errorf("Assigning negative signed value: %v, to unsigned type", i) + return + } + default: + switch { + case d.bd >= mpPosFixNumMin && d.bd <= mpPosFixNumMax: + ui = uint64(d.bd) + case d.bd >= mpNegFixNumMin && d.bd <= mpNegFixNumMax: + d.d.errorf("Assigning negative signed value: %v, to unsigned type", int(d.bd)) + return + default: + d.d.errorf("Unhandled single-byte unsigned integer value: %s: %x", msgBadDesc, d.bd) + return + } + } + // check overflow (logic adapted from std pkg reflect/value.go OverflowUint() + if bitsize > 0 { + if trunc := (ui << (64 - bitsize)) >> (64 - bitsize); ui != trunc { + d.d.errorf("Overflow uint value: %v", ui) + return + } + } + d.bdRead = false + return +} + +// float can either be decoded from msgpack type: float, double or intX +func (d *msgpackDecDriver) DecodeFloat(chkOverflow32 bool) (f float64) { + if !d.bdRead { + d.readNextBd() + } + if d.bd == mpFloat { + f = float64(math.Float32frombits(bigen.Uint32(d.r.readx(4)))) + } else if d.bd == mpDouble { + f = math.Float64frombits(bigen.Uint64(d.r.readx(8))) + } else { + f = float64(d.DecodeInt(0)) + } + if chkOverflow32 && chkOvf.Float32(f) { + d.d.errorf("msgpack: float32 overflow: %v", f) + return + } + d.bdRead = false + return +} + +// bool can be decoded from bool, fixnum 0 or 1. +func (d *msgpackDecDriver) DecodeBool() (b bool) { + if !d.bdRead { + d.readNextBd() + } + if d.bd == mpFalse || d.bd == 0 { + // b = false + } else if d.bd == mpTrue || d.bd == 1 { + b = true + } else { + d.d.errorf("Invalid single-byte value for bool: %s: %x", msgBadDesc, d.bd) + return + } + d.bdRead = false + return +} + +func (d *msgpackDecDriver) DecodeBytes(bs []byte, isstring, zerocopy bool) (bsOut []byte) { + if !d.bdRead { + d.readNextBd() + } + var clen int + if isstring { + clen = d.readContainerLen(msgpackContainerStr) + } else { + // bytes can be decoded from msgpackContainerStr or msgpackContainerBin + if bd := d.bd; bd == mpBin8 || bd == mpBin16 || bd == mpBin32 { + clen = d.readContainerLen(msgpackContainerBin) + } else { + clen = d.readContainerLen(msgpackContainerStr) + } + } + // println("DecodeBytes: clen: ", clen) + d.bdRead = false + // bytes may be nil, so handle it. if nil, clen=-1. + if clen < 0 { + return nil + } + if zerocopy { + if d.br { + return d.r.readx(clen) + } else if len(bs) == 0 { + bs = d.b[:] + } + } + return decByteSlice(d.r, clen, bs) +} + +func (d *msgpackDecDriver) DecodeString() (s string) { + return string(d.DecodeBytes(d.b[:], true, true)) +} + +func (d *msgpackDecDriver) readNextBd() { + d.bd = d.r.readn1() + d.bdRead = true + d.bdType = valueTypeUnset +} + +func (d *msgpackDecDriver) IsContainerType(vt valueType) bool { + bd := d.bd + switch vt { + case valueTypeNil: + return bd == mpNil + case valueTypeBytes: + return bd == mpBin8 || bd == mpBin16 || bd == mpBin32 || + (!d.h.RawToString && + (bd == mpStr8 || bd == mpStr16 || bd == mpStr32 || (bd >= mpFixStrMin && bd <= mpFixStrMax))) + case valueTypeString: + return d.h.RawToString && + (bd == mpStr8 || bd == mpStr16 || bd == mpStr32 || (bd >= mpFixStrMin && bd <= mpFixStrMax)) + case valueTypeArray: + return bd == mpArray16 || bd == mpArray32 || (bd >= mpFixArrayMin && bd <= mpFixArrayMax) + case valueTypeMap: + return bd == mpMap16 || bd == mpMap32 || (bd >= mpFixMapMin && bd <= mpFixMapMax) + } + d.d.errorf("isContainerType: unsupported parameter: %v", vt) + return false // "unreachable" +} + +func (d *msgpackDecDriver) TryDecodeAsNil() (v bool) { + if !d.bdRead { + d.readNextBd() + } + if d.bd == mpNil { + d.bdRead = false + v = true + } + return +} + +func (d *msgpackDecDriver) readContainerLen(ct msgpackContainerType) (clen int) { + bd := d.bd + if bd == mpNil { + clen = -1 // to represent nil + } else if bd == ct.b8 { + clen = int(d.r.readn1()) + } else if bd == ct.b16 { + clen = int(bigen.Uint16(d.r.readx(2))) + } else if bd == ct.b32 { + clen = int(bigen.Uint32(d.r.readx(4))) + } else if (ct.bFixMin & bd) == ct.bFixMin { + clen = int(ct.bFixMin ^ bd) + } else { + d.d.errorf("readContainerLen: %s: hex: %x, dec: %d", msgBadDesc, bd, bd) + return + } + d.bdRead = false + return +} + +func (d *msgpackDecDriver) ReadMapStart() int { + return d.readContainerLen(msgpackContainerMap) +} + +func (d *msgpackDecDriver) ReadArrayStart() int { + return d.readContainerLen(msgpackContainerList) +} + +func (d *msgpackDecDriver) readExtLen() (clen int) { + switch d.bd { + case mpNil: + clen = -1 // to represent nil + case mpFixExt1: + clen = 1 + case mpFixExt2: + clen = 2 + case mpFixExt4: + clen = 4 + case mpFixExt8: + clen = 8 + case mpFixExt16: + clen = 16 + case mpExt8: + clen = int(d.r.readn1()) + case mpExt16: + clen = int(bigen.Uint16(d.r.readx(2))) + case mpExt32: + clen = int(bigen.Uint32(d.r.readx(4))) + default: + d.d.errorf("decoding ext bytes: found unexpected byte: %x", d.bd) + return + } + return +} + +func (d *msgpackDecDriver) DecodeExt(rv interface{}, xtag uint64, ext Ext) (realxtag uint64) { + if xtag > 0xff { + d.d.errorf("decodeExt: tag must be <= 0xff; got: %v", xtag) + return + } + realxtag1, xbs := d.decodeExtV(ext != nil, uint8(xtag)) + realxtag = uint64(realxtag1) + if ext == nil { + re := rv.(*RawExt) + re.Tag = realxtag + re.Data = detachZeroCopyBytes(d.br, re.Data, xbs) + } else { + ext.ReadExt(rv, xbs) + } + return +} + +func (d *msgpackDecDriver) decodeExtV(verifyTag bool, tag byte) (xtag byte, xbs []byte) { + if !d.bdRead { + d.readNextBd() + } + xbd := d.bd + if xbd == mpBin8 || xbd == mpBin16 || xbd == mpBin32 { + xbs = d.DecodeBytes(nil, false, true) + } else if xbd == mpStr8 || xbd == mpStr16 || xbd == mpStr32 || + (xbd >= mpFixStrMin && xbd <= mpFixStrMax) { + xbs = d.DecodeBytes(nil, true, true) + } else { + clen := d.readExtLen() + xtag = d.r.readn1() + if verifyTag && xtag != tag { + d.d.errorf("Wrong extension tag. Got %b. Expecting: %v", xtag, tag) + return + } + xbs = d.r.readx(clen) + } + d.bdRead = false + return +} + +//-------------------------------------------------- + +//MsgpackHandle is a Handle for the Msgpack Schema-Free Encoding Format. +type MsgpackHandle struct { + BasicHandle + binaryEncodingType + + // RawToString controls how raw bytes are decoded into a nil interface{}. + RawToString bool + + // WriteExt flag supports encoding configured extensions with extension tags. + // It also controls whether other elements of the new spec are encoded (ie Str8). + // + // With WriteExt=false, configured extensions are serialized as raw bytes + // and Str8 is not encoded. + // + // A stream can still be decoded into a typed value, provided an appropriate value + // is provided, but the type cannot be inferred from the stream. If no appropriate + // type is provided (e.g. decoding into a nil interface{}), you get back + // a []byte or string based on the setting of RawToString. + WriteExt bool +} + +func (h *MsgpackHandle) newEncDriver(e *Encoder) encDriver { + return &msgpackEncDriver{e: e, w: e.w, h: h} +} + +func (h *MsgpackHandle) newDecDriver(d *Decoder) decDriver { + return &msgpackDecDriver{d: d, r: d.r, h: h, br: d.bytes} +} + +//-------------------------------------------------- + +type msgpackSpecRpcCodec struct { + rpcCodec +} + +// /////////////// Spec RPC Codec /////////////////// +func (c *msgpackSpecRpcCodec) WriteRequest(r *rpc.Request, body interface{}) error { + // WriteRequest can write to both a Go service, and other services that do + // not abide by the 1 argument rule of a Go service. + // We discriminate based on if the body is a MsgpackSpecRpcMultiArgs + var bodyArr []interface{} + if m, ok := body.(MsgpackSpecRpcMultiArgs); ok { + bodyArr = ([]interface{})(m) + } else { + bodyArr = []interface{}{body} + } + r2 := []interface{}{0, uint32(r.Seq), r.ServiceMethod, bodyArr} + return c.write(r2, nil, false, true) +} + +func (c *msgpackSpecRpcCodec) WriteResponse(r *rpc.Response, body interface{}) error { + var moe interface{} + if r.Error != "" { + moe = r.Error + } + if moe != nil && body != nil { + body = nil + } + r2 := []interface{}{1, uint32(r.Seq), moe, body} + return c.write(r2, nil, false, true) +} + +func (c *msgpackSpecRpcCodec) ReadResponseHeader(r *rpc.Response) error { + return c.parseCustomHeader(1, &r.Seq, &r.Error) +} + +func (c *msgpackSpecRpcCodec) ReadRequestHeader(r *rpc.Request) error { + return c.parseCustomHeader(0, &r.Seq, &r.ServiceMethod) +} + +func (c *msgpackSpecRpcCodec) ReadRequestBody(body interface{}) error { + if body == nil { // read and discard + return c.read(nil) + } + bodyArr := []interface{}{body} + return c.read(&bodyArr) +} + +func (c *msgpackSpecRpcCodec) parseCustomHeader(expectTypeByte byte, msgid *uint64, methodOrError *string) (err error) { + + if c.cls { + return io.EOF + } + + // We read the response header by hand + // so that the body can be decoded on its own from the stream at a later time. + + const fia byte = 0x94 //four item array descriptor value + // Not sure why the panic of EOF is swallowed above. + // if bs1 := c.dec.r.readn1(); bs1 != fia { + // err = fmt.Errorf("Unexpected value for array descriptor: Expecting %v. Received %v", fia, bs1) + // return + // } + var b byte + b, err = c.br.ReadByte() + if err != nil { + return + } + if b != fia { + err = fmt.Errorf("Unexpected value for array descriptor: Expecting %v. Received %v", fia, b) + return + } + + if err = c.read(&b); err != nil { + return + } + if b != expectTypeByte { + err = fmt.Errorf("Unexpected byte descriptor in header. Expecting %v. Received %v", expectTypeByte, b) + return + } + if err = c.read(msgid); err != nil { + return + } + if err = c.read(methodOrError); err != nil { + return + } + return +} + +//-------------------------------------------------- + +// msgpackSpecRpc is the implementation of Rpc that uses custom communication protocol +// as defined in the msgpack spec at https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md +type msgpackSpecRpc struct{} + +// MsgpackSpecRpc implements Rpc using the communication protocol defined in +// the msgpack spec at https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md . +// Its methods (ServerCodec and ClientCodec) return values that implement RpcCodecBuffered. +var MsgpackSpecRpc msgpackSpecRpc + +func (x msgpackSpecRpc) ServerCodec(conn io.ReadWriteCloser, h Handle) rpc.ServerCodec { + return &msgpackSpecRpcCodec{newRPCCodec(conn, h)} +} + +func (x msgpackSpecRpc) ClientCodec(conn io.ReadWriteCloser, h Handle) rpc.ClientCodec { + return &msgpackSpecRpcCodec{newRPCCodec(conn, h)} +} + +var _ decDriver = (*msgpackDecDriver)(nil) +var _ encDriver = (*msgpackEncDriver)(nil) diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/noop.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/noop.go new file mode 100644 index 0000000000..76c01e4d3c --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/noop.go @@ -0,0 +1,164 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +import ( + "math/rand" + "time" +) + +// NoopHandle returns a no-op handle. It basically does nothing. +// It is only useful for benchmarking, as it gives an idea of the +// overhead from the codec framework. +// LIBRARY USERS: *** DO NOT USE *** +func NoopHandle(slen int) *noopHandle { + h := noopHandle{} + h.rand = rand.New(rand.NewSource(time.Now().UnixNano())) + h.B = make([][]byte, slen) + h.S = make([]string, slen) + for i := 0; i < len(h.S); i++ { + b := make([]byte, i+1) + for j := 0; j < len(b); j++ { + b[j] = 'a' + byte(i) + } + h.B[i] = b + h.S[i] = string(b) + } + return &h +} + +// noopHandle does nothing. +// It is used to simulate the overhead of the codec framework. +type noopHandle struct { + BasicHandle + binaryEncodingType + noopDrv // noopDrv is unexported here, so we can get a copy of it when needed. +} + +type noopDrv struct { + i int + S []string + B [][]byte + mk bool // are we about to read a map key? + ct valueType // last request for IsContainerType. + cb bool // last response for IsContainerType. + rand *rand.Rand +} + +func (h *noopDrv) r(v int) int { return h.rand.Intn(v) } +func (h *noopDrv) m(v int) int { h.i++; return h.i % v } + +func (h *noopDrv) newEncDriver(_ *Encoder) encDriver { return h } +func (h *noopDrv) newDecDriver(_ *Decoder) decDriver { return h } + +// --- encDriver + +func (h *noopDrv) EncodeBuiltin(rt uintptr, v interface{}) {} +func (h *noopDrv) EncodeNil() {} +func (h *noopDrv) EncodeInt(i int64) {} +func (h *noopDrv) EncodeUint(i uint64) {} +func (h *noopDrv) EncodeBool(b bool) {} +func (h *noopDrv) EncodeFloat32(f float32) {} +func (h *noopDrv) EncodeFloat64(f float64) {} +func (h *noopDrv) EncodeRawExt(re *RawExt, e *Encoder) {} +func (h *noopDrv) EncodeArrayStart(length int) {} +func (h *noopDrv) EncodeArrayEnd() {} +func (h *noopDrv) EncodeArrayEntrySeparator() {} +func (h *noopDrv) EncodeMapStart(length int) {} +func (h *noopDrv) EncodeMapEnd() {} +func (h *noopDrv) EncodeMapEntrySeparator() {} +func (h *noopDrv) EncodeMapKVSeparator() {} +func (h *noopDrv) EncodeString(c charEncoding, v string) {} +func (h *noopDrv) EncodeSymbol(v string) {} +func (h *noopDrv) EncodeStringBytes(c charEncoding, v []byte) {} + +func (h *noopDrv) EncodeExt(rv interface{}, xtag uint64, ext Ext, e *Encoder) {} + +// ---- decDriver +func (h *noopDrv) initReadNext() {} +func (h *noopDrv) CheckBreak() bool { return false } +func (h *noopDrv) IsBuiltinType(rt uintptr) bool { return false } +func (h *noopDrv) DecodeBuiltin(rt uintptr, v interface{}) {} +func (h *noopDrv) DecodeInt(bitsize uint8) (i int64) { return int64(h.m(15)) } +func (h *noopDrv) DecodeUint(bitsize uint8) (ui uint64) { return uint64(h.m(35)) } +func (h *noopDrv) DecodeFloat(chkOverflow32 bool) (f float64) { return float64(h.m(95)) } +func (h *noopDrv) DecodeBool() (b bool) { return h.m(2) == 0 } +func (h *noopDrv) DecodeString() (s string) { return h.S[h.m(8)] } + +// func (h *noopDrv) DecodeStringAsBytes(bs []byte) []byte { return h.DecodeBytes(bs) } + +func (h *noopDrv) DecodeBytes(bs []byte, isstring, zerocopy bool) []byte { return h.B[h.m(len(h.B))] } + +func (h *noopDrv) ReadMapEnd() { h.mk = false } +func (h *noopDrv) ReadArrayEnd() {} +func (h *noopDrv) ReadArrayEntrySeparator() {} +func (h *noopDrv) ReadMapEntrySeparator() { h.mk = true } +func (h *noopDrv) ReadMapKVSeparator() { h.mk = false } + +// toggle map/slice +func (h *noopDrv) ReadMapStart() int { h.mk = true; return h.m(10) } +func (h *noopDrv) ReadArrayStart() int { return h.m(10) } + +func (h *noopDrv) IsContainerType(vt valueType) bool { + // return h.m(2) == 0 + // handle kStruct + if h.ct == valueTypeMap && vt == valueTypeArray || h.ct == valueTypeArray && vt == valueTypeMap { + h.cb = !h.cb + h.ct = vt + return h.cb + } + // go in a loop and check it. + h.ct = vt + h.cb = h.m(7) == 0 + return h.cb +} +func (h *noopDrv) TryDecodeAsNil() bool { + if h.mk { + return false + } else { + return h.m(8) == 0 + } +} +func (h *noopDrv) DecodeExt(rv interface{}, xtag uint64, ext Ext) uint64 { + return 0 +} + +func (h *noopDrv) DecodeNaked() (v interface{}, vt valueType, decodeFurther bool) { + // use h.r (random) not h.m() because h.m() could cause the same value to be given. + var sk int + if h.mk { + // if mapkey, do not support values of nil OR bytes, array, map or rawext + sk = h.r(7) + 1 + } else { + sk = h.r(12) + } + switch sk { + case 0: + vt = valueTypeNil + case 1: + vt, v = valueTypeBool, false + case 2: + vt, v = valueTypeBool, true + case 3: + vt, v = valueTypeInt, h.DecodeInt(64) + case 4: + vt, v = valueTypeUint, h.DecodeUint(64) + case 5: + vt, v = valueTypeFloat, h.DecodeFloat(true) + case 6: + vt, v = valueTypeFloat, h.DecodeFloat(false) + case 7: + vt, v = valueTypeString, h.DecodeString() + case 8: + vt, v = valueTypeBytes, h.B[h.m(len(h.B))] + case 9: + vt, decodeFurther = valueTypeArray, true + case 10: + vt, decodeFurther = valueTypeMap, true + default: + vt, v = valueTypeExt, &RawExt{Tag: h.DecodeUint(64), Data: h.B[h.m(len(h.B))]} + } + h.ct = vt + return +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/prebuild.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/prebuild.go new file mode 100644 index 0000000000..2353263e88 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/prebuild.go @@ -0,0 +1,3 @@ +package codec + +//go:generate bash prebuild.sh diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/prebuild.sh b/Godeps/_workspace/src/github.com/ugorji/go/codec/prebuild.sh new file mode 100644 index 0000000000..a10e74bdc4 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/prebuild.sh @@ -0,0 +1,191 @@ +#!/bin/bash + +# _needgen is a helper function to tell if we need to generate files for msgp, codecgen. +_needgen() { + local a="$1" + zneedgen=0 + if [[ ! -e "$a" ]] + then + zneedgen=1 + echo 1 + return 0 + fi + for i in `ls -1 *.go.tmpl gen.go values_test.go` + do + if [[ "$a" -ot "$i" ]] + then + zneedgen=1 + echo 1 + return 0 + fi + done + echo 0 +} + +# _build generates fast-path.go and gen-helper.go. +# +# It is needed because there is some dependency between the generated code +# and the other classes. Consequently, we have to totally remove the +# generated files and put stubs in place, before calling "go run" again +# to recreate them. +_build() { + if ! [[ "${zforce}" == "1" || + "1" == $( _needgen "fast-path.generated.go" ) || + "1" == $( _needgen "gen-helper.generated.go" ) || + "1" == $( _needgen "gen.generated.go" ) || + 1 == 0 ]] + then + return 0 + fi + + # echo "Running prebuild" + if [ "${zbak}" == "1" ] + then + # echo "Backing up old generated files" + _zts=`date '+%m%d%Y_%H%M%S'` + _gg=".generated.go" + [ -e "gen-helper${_gg}" ] && mv gen-helper${_gg} gen-helper${_gg}__${_zts}.bak + [ -e "fast-path${_gg}" ] && mv fast-path${_gg} fast-path${_gg}__${_zts}.bak + # [ -e "safe${_gg}" ] && mv safe${_gg} safe${_gg}__${_zts}.bak + # [ -e "unsafe${_gg}" ] && mv unsafe${_gg} unsafe${_gg}__${_zts}.bak + else + rm -f fast-path.generated.go gen.generated.go gen-helper.generated.go *safe.generated.go *_generated_test.go *.generated_ffjson_expose.go + fi + + cat > gen.generated.go <> gen.generated.go < gen-dec-map.go.tmpl + + cat >> gen.generated.go <> gen.generated.go < gen-dec-array.go.tmpl + + cat >> gen.generated.go < fast-path.generated.go < gen-from-tmpl.generated.go < math.MaxInt64 { + // d.d.errorf("decIntAny: Integer out of range for signed int64: %v", ui) + // return + // } + return +} + +func (d *simpleDecDriver) DecodeInt(bitsize uint8) (i int64) { + ui, neg := d.decCheckInteger() + i, overflow := chkOvf.SignedInt(ui) + if overflow { + d.d.errorf("simple: overflow converting %v to signed integer", ui) + return + } + if neg { + i = -i + } + if chkOvf.Int(i, bitsize) { + d.d.errorf("simple: overflow integer: %v", i) + return + } + d.bdRead = false + return +} + +func (d *simpleDecDriver) DecodeUint(bitsize uint8) (ui uint64) { + ui, neg := d.decCheckInteger() + if neg { + d.d.errorf("Assigning negative signed value to unsigned type") + return + } + if chkOvf.Uint(ui, bitsize) { + d.d.errorf("simple: overflow integer: %v", ui) + return + } + d.bdRead = false + return +} + +func (d *simpleDecDriver) DecodeFloat(chkOverflow32 bool) (f float64) { + if !d.bdRead { + d.readNextBd() + } + if d.bd == simpleVdFloat32 { + f = float64(math.Float32frombits(bigen.Uint32(d.r.readx(4)))) + } else if d.bd == simpleVdFloat64 { + f = math.Float64frombits(bigen.Uint64(d.r.readx(8))) + } else { + if d.bd >= simpleVdPosInt && d.bd <= simpleVdNegInt+3 { + f = float64(d.DecodeInt(64)) + } else { + d.d.errorf("Float only valid from float32/64: Invalid descriptor: %v", d.bd) + return + } + } + if chkOverflow32 && chkOvf.Float32(f) { + d.d.errorf("msgpack: float32 overflow: %v", f) + return + } + d.bdRead = false + return +} + +// bool can be decoded from bool only (single byte). +func (d *simpleDecDriver) DecodeBool() (b bool) { + if !d.bdRead { + d.readNextBd() + } + if d.bd == simpleVdTrue { + b = true + } else if d.bd == simpleVdFalse { + } else { + d.d.errorf("Invalid single-byte value for bool: %s: %x", msgBadDesc, d.bd) + return + } + d.bdRead = false + return +} + +func (d *simpleDecDriver) ReadMapStart() (length int) { + d.bdRead = false + return d.decLen() +} + +func (d *simpleDecDriver) ReadArrayStart() (length int) { + d.bdRead = false + return d.decLen() +} + +func (d *simpleDecDriver) decLen() int { + switch d.bd % 8 { + case 0: + return 0 + case 1: + return int(d.r.readn1()) + case 2: + return int(bigen.Uint16(d.r.readx(2))) + case 3: + ui := uint64(bigen.Uint32(d.r.readx(4))) + if chkOvf.Uint(ui, intBitsize) { + d.d.errorf("simple: overflow integer: %v", ui) + return 0 + } + return int(ui) + case 4: + ui := bigen.Uint64(d.r.readx(8)) + if chkOvf.Uint(ui, intBitsize) { + d.d.errorf("simple: overflow integer: %v", ui) + return 0 + } + return int(ui) + } + d.d.errorf("decLen: Cannot read length: bd%8 must be in range 0..4. Got: %d", d.bd%8) + return -1 +} + +func (d *simpleDecDriver) DecodeString() (s string) { + return string(d.DecodeBytes(d.b[:], true, true)) +} + +func (d *simpleDecDriver) DecodeBytes(bs []byte, isstring, zerocopy bool) (bsOut []byte) { + if !d.bdRead { + d.readNextBd() + } + if d.bd == simpleVdNil { + d.bdRead = false + return + } + clen := d.decLen() + d.bdRead = false + if zerocopy { + if d.br { + return d.r.readx(clen) + } else if len(bs) == 0 { + bs = d.b[:] + } + } + return decByteSlice(d.r, clen, bs) +} + +func (d *simpleDecDriver) DecodeExt(rv interface{}, xtag uint64, ext Ext) (realxtag uint64) { + if xtag > 0xff { + d.d.errorf("decodeExt: tag must be <= 0xff; got: %v", xtag) + return + } + realxtag1, xbs := d.decodeExtV(ext != nil, uint8(xtag)) + realxtag = uint64(realxtag1) + if ext == nil { + re := rv.(*RawExt) + re.Tag = realxtag + re.Data = detachZeroCopyBytes(d.br, re.Data, xbs) + } else { + ext.ReadExt(rv, xbs) + } + return +} + +func (d *simpleDecDriver) decodeExtV(verifyTag bool, tag byte) (xtag byte, xbs []byte) { + if !d.bdRead { + d.readNextBd() + } + switch d.bd { + case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: + l := d.decLen() + xtag = d.r.readn1() + if verifyTag && xtag != tag { + d.d.errorf("Wrong extension tag. Got %b. Expecting: %v", xtag, tag) + return + } + xbs = d.r.readx(l) + case simpleVdByteArray, simpleVdByteArray + 1, simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: + xbs = d.DecodeBytes(nil, false, true) + default: + d.d.errorf("Invalid d.bd for extensions (Expecting extensions or byte array). Got: 0x%x", d.bd) + return + } + d.bdRead = false + return +} + +func (d *simpleDecDriver) DecodeNaked() (v interface{}, vt valueType, decodeFurther bool) { + if !d.bdRead { + d.readNextBd() + } + + switch d.bd { + case simpleVdNil: + vt = valueTypeNil + case simpleVdFalse: + vt = valueTypeBool + v = false + case simpleVdTrue: + vt = valueTypeBool + v = true + case simpleVdPosInt, simpleVdPosInt + 1, simpleVdPosInt + 2, simpleVdPosInt + 3: + if d.h.SignedInteger { + vt = valueTypeInt + v = d.DecodeInt(64) + } else { + vt = valueTypeUint + v = d.DecodeUint(64) + } + case simpleVdNegInt, simpleVdNegInt + 1, simpleVdNegInt + 2, simpleVdNegInt + 3: + vt = valueTypeInt + v = d.DecodeInt(64) + case simpleVdFloat32: + vt = valueTypeFloat + v = d.DecodeFloat(true) + case simpleVdFloat64: + vt = valueTypeFloat + v = d.DecodeFloat(false) + case simpleVdString, simpleVdString + 1, simpleVdString + 2, simpleVdString + 3, simpleVdString + 4: + vt = valueTypeString + v = d.DecodeString() + case simpleVdByteArray, simpleVdByteArray + 1, simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: + vt = valueTypeBytes + v = d.DecodeBytes(nil, false, false) + case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: + vt = valueTypeExt + l := d.decLen() + var re RawExt + re.Tag = uint64(d.r.readn1()) + re.Data = d.r.readx(l) + v = &re + case simpleVdArray, simpleVdArray + 1, simpleVdArray + 2, simpleVdArray + 3, simpleVdArray + 4: + vt = valueTypeArray + decodeFurther = true + case simpleVdMap, simpleVdMap + 1, simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4: + vt = valueTypeMap + decodeFurther = true + default: + d.d.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd) + return + } + + if !decodeFurther { + d.bdRead = false + } + return +} + +//------------------------------------ + +// SimpleHandle is a Handle for a very simple encoding format. +// +// simple is a simplistic codec similar to binc, but not as compact. +// - Encoding of a value is always preceeded by the descriptor byte (bd) +// - True, false, nil are encoded fully in 1 byte (the descriptor) +// - Integers (intXXX, uintXXX) are encoded in 1, 2, 4 or 8 bytes (plus a descriptor byte). +// There are positive (uintXXX and intXXX >= 0) and negative (intXXX < 0) integers. +// - Floats are encoded in 4 or 8 bytes (plus a descriptor byte) +// - Lenght of containers (strings, bytes, array, map, extensions) +// are encoded in 0, 1, 2, 4 or 8 bytes. +// Zero-length containers have no length encoded. +// For others, the number of bytes is given by pow(2, bd%3) +// - maps are encoded as [bd] [length] [[key][value]]... +// - arrays are encoded as [bd] [length] [value]... +// - extensions are encoded as [bd] [length] [tag] [byte]... +// - strings/bytearrays are encoded as [bd] [length] [byte]... +// +// The full spec will be published soon. +type SimpleHandle struct { + BasicHandle + binaryEncodingType +} + +func (h *SimpleHandle) newEncDriver(e *Encoder) encDriver { + return &simpleEncDriver{e: e, w: e.w, h: h} +} + +func (h *SimpleHandle) newDecDriver(d *Decoder) decDriver { + return &simpleDecDriver{d: d, r: d.r, h: h, br: d.bytes} +} + +var _ decDriver = (*simpleDecDriver)(nil) +var _ encDriver = (*simpleEncDriver)(nil) diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/test-cbor-goldens.json b/Godeps/_workspace/src/github.com/ugorji/go/codec/test-cbor-goldens.json new file mode 100644 index 0000000000..9028586711 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/test-cbor-goldens.json @@ -0,0 +1,639 @@ +[ + { + "cbor": "AA==", + "hex": "00", + "roundtrip": true, + "decoded": 0 + }, + { + "cbor": "AQ==", + "hex": "01", + "roundtrip": true, + "decoded": 1 + }, + { + "cbor": "Cg==", + "hex": "0a", + "roundtrip": true, + "decoded": 10 + }, + { + "cbor": "Fw==", + "hex": "17", + "roundtrip": true, + "decoded": 23 + }, + { + "cbor": "GBg=", + "hex": "1818", + "roundtrip": true, + "decoded": 24 + }, + { + "cbor": "GBk=", + "hex": "1819", + "roundtrip": true, + "decoded": 25 + }, + { + "cbor": "GGQ=", + "hex": "1864", + "roundtrip": true, + "decoded": 100 + }, + { + "cbor": "GQPo", + "hex": "1903e8", + "roundtrip": true, + "decoded": 1000 + }, + { + "cbor": "GgAPQkA=", + "hex": "1a000f4240", + "roundtrip": true, + "decoded": 1000000 + }, + { + "cbor": "GwAAAOjUpRAA", + "hex": "1b000000e8d4a51000", + "roundtrip": true, + "decoded": 1000000000000 + }, + { + "cbor": "G///////////", + "hex": "1bffffffffffffffff", + "roundtrip": true, + "decoded": 18446744073709551615 + }, + { + "cbor": "wkkBAAAAAAAAAAA=", + "hex": "c249010000000000000000", + "roundtrip": true, + "decoded": 18446744073709551616 + }, + { + "cbor": "O///////////", + "hex": "3bffffffffffffffff", + "roundtrip": true, + "decoded": -18446744073709551616, + "skip": true + }, + { + "cbor": "w0kBAAAAAAAAAAA=", + "hex": "c349010000000000000000", + "roundtrip": true, + "decoded": -18446744073709551617 + }, + { + "cbor": "IA==", + "hex": "20", + "roundtrip": true, + "decoded": -1 + }, + { + "cbor": "KQ==", + "hex": "29", + "roundtrip": true, + "decoded": -10 + }, + { + "cbor": "OGM=", + "hex": "3863", + "roundtrip": true, + "decoded": -100 + }, + { + "cbor": "OQPn", + "hex": "3903e7", + "roundtrip": true, + "decoded": -1000 + }, + { + "cbor": "+QAA", + "hex": "f90000", + "roundtrip": true, + "decoded": 0.0 + }, + { + "cbor": "+YAA", + "hex": "f98000", + "roundtrip": true, + "decoded": -0.0 + }, + { + "cbor": "+TwA", + "hex": "f93c00", + "roundtrip": true, + "decoded": 1.0 + }, + { + "cbor": "+z/xmZmZmZma", + "hex": "fb3ff199999999999a", + "roundtrip": true, + "decoded": 1.1 + }, + { + "cbor": "+T4A", + "hex": "f93e00", + "roundtrip": true, + "decoded": 1.5 + }, + { + "cbor": "+Xv/", + "hex": "f97bff", + "roundtrip": true, + "decoded": 65504.0 + }, + { + "cbor": "+kfDUAA=", + "hex": "fa47c35000", + "roundtrip": true, + "decoded": 100000.0 + }, + { + "cbor": "+n9///8=", + "hex": "fa7f7fffff", + "roundtrip": true, + "decoded": 3.4028234663852886e+38 + }, + { + "cbor": "+3435DyIAHWc", + "hex": "fb7e37e43c8800759c", + "roundtrip": true, + "decoded": 1.0e+300 + }, + { + "cbor": "+QAB", + "hex": "f90001", + "roundtrip": true, + "decoded": 5.960464477539063e-08 + }, + { + "cbor": "+QQA", + "hex": "f90400", + "roundtrip": true, + "decoded": 6.103515625e-05 + }, + { + "cbor": "+cQA", + "hex": "f9c400", + "roundtrip": true, + "decoded": -4.0 + }, + { + "cbor": "+8AQZmZmZmZm", + "hex": "fbc010666666666666", + "roundtrip": true, + "decoded": -4.1 + }, + { + "cbor": "+XwA", + "hex": "f97c00", + "roundtrip": true, + "diagnostic": "Infinity" + }, + { + "cbor": "+X4A", + "hex": "f97e00", + "roundtrip": true, + "diagnostic": "NaN" + }, + { + "cbor": "+fwA", + "hex": "f9fc00", + "roundtrip": true, + "diagnostic": "-Infinity" + }, + { + "cbor": "+n+AAAA=", + "hex": "fa7f800000", + "roundtrip": false, + "diagnostic": "Infinity" + }, + { + "cbor": "+n/AAAA=", + "hex": "fa7fc00000", + "roundtrip": false, + "diagnostic": "NaN" + }, + { + "cbor": "+v+AAAA=", + "hex": "faff800000", + "roundtrip": false, + "diagnostic": "-Infinity" + }, + { + "cbor": "+3/wAAAAAAAA", + "hex": "fb7ff0000000000000", + "roundtrip": false, + "diagnostic": "Infinity" + }, + { + "cbor": "+3/4AAAAAAAA", + "hex": "fb7ff8000000000000", + "roundtrip": false, + "diagnostic": "NaN" + }, + { + "cbor": "+//wAAAAAAAA", + "hex": "fbfff0000000000000", + "roundtrip": false, + "diagnostic": "-Infinity" + }, + { + "cbor": "9A==", + "hex": "f4", + "roundtrip": true, + "decoded": false + }, + { + "cbor": "9Q==", + "hex": "f5", + "roundtrip": true, + "decoded": true + }, + { + "cbor": "9g==", + "hex": "f6", + "roundtrip": true, + "decoded": null + }, + { + "cbor": "9w==", + "hex": "f7", + "roundtrip": true, + "diagnostic": "undefined" + }, + { + "cbor": "8A==", + "hex": "f0", + "roundtrip": true, + "diagnostic": "simple(16)" + }, + { + "cbor": "+Bg=", + "hex": "f818", + "roundtrip": true, + "diagnostic": "simple(24)" + }, + { + "cbor": "+P8=", + "hex": "f8ff", + "roundtrip": true, + "diagnostic": "simple(255)" + }, + { + "cbor": "wHQyMDEzLTAzLTIxVDIwOjA0OjAwWg==", + "hex": "c074323031332d30332d32315432303a30343a30305a", + "roundtrip": true, + "diagnostic": "0(\"2013-03-21T20:04:00Z\")" + }, + { + "cbor": "wRpRS2ew", + "hex": "c11a514b67b0", + "roundtrip": true, + "diagnostic": "1(1363896240)" + }, + { + "cbor": "wftB1FLZ7CAAAA==", + "hex": "c1fb41d452d9ec200000", + "roundtrip": true, + "diagnostic": "1(1363896240.5)" + }, + { + "cbor": "10QBAgME", + "hex": "d74401020304", + "roundtrip": true, + "diagnostic": "23(h'01020304')" + }, + { + "cbor": "2BhFZElFVEY=", + "hex": "d818456449455446", + "roundtrip": true, + "diagnostic": "24(h'6449455446')" + }, + { + "cbor": "2CB2aHR0cDovL3d3dy5leGFtcGxlLmNvbQ==", + "hex": "d82076687474703a2f2f7777772e6578616d706c652e636f6d", + "roundtrip": true, + "diagnostic": "32(\"http://www.example.com\")" + }, + { + "cbor": "QA==", + "hex": "40", + "roundtrip": true, + "diagnostic": "h''" + }, + { + "cbor": "RAECAwQ=", + "hex": "4401020304", + "roundtrip": true, + "diagnostic": "h'01020304'" + }, + { + "cbor": "YA==", + "hex": "60", + "roundtrip": true, + "decoded": "" + }, + { + "cbor": "YWE=", + "hex": "6161", + "roundtrip": true, + "decoded": "a" + }, + { + "cbor": "ZElFVEY=", + "hex": "6449455446", + "roundtrip": true, + "decoded": "IETF" + }, + { + "cbor": "YiJc", + "hex": "62225c", + "roundtrip": true, + "decoded": "\"\\" + }, + { + "cbor": "YsO8", + "hex": "62c3bc", + "roundtrip": true, + "decoded": "ü" + }, + { + "cbor": "Y+awtA==", + "hex": "63e6b0b4", + "roundtrip": true, + "decoded": "水" + }, + { + "cbor": "ZPCQhZE=", + "hex": "64f0908591", + "roundtrip": true, + "decoded": "𐅑" + }, + { + "cbor": "gA==", + "hex": "80", + "roundtrip": true, + "decoded": [ + + ] + }, + { + "cbor": "gwECAw==", + "hex": "83010203", + "roundtrip": true, + "decoded": [ + 1, + 2, + 3 + ] + }, + { + "cbor": "gwGCAgOCBAU=", + "hex": "8301820203820405", + "roundtrip": true, + "decoded": [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ] + }, + { + "cbor": "mBkBAgMEBQYHCAkKCwwNDg8QERITFBUWFxgYGBk=", + "hex": "98190102030405060708090a0b0c0d0e0f101112131415161718181819", + "roundtrip": true, + "decoded": [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25 + ] + }, + { + "cbor": "oA==", + "hex": "a0", + "roundtrip": true, + "decoded": { + } + }, + { + "cbor": "ogECAwQ=", + "hex": "a201020304", + "roundtrip": true, + "skip": true, + "diagnostic": "{1: 2, 3: 4}" + }, + { + "cbor": "omFhAWFiggID", + "hex": "a26161016162820203", + "roundtrip": true, + "decoded": { + "a": 1, + "b": [ + 2, + 3 + ] + } + }, + { + "cbor": "gmFhoWFiYWM=", + "hex": "826161a161626163", + "roundtrip": true, + "decoded": [ + "a", + { + "b": "c" + } + ] + }, + { + "cbor": "pWFhYUFhYmFCYWNhQ2FkYURhZWFF", + "hex": "a56161614161626142616361436164614461656145", + "roundtrip": true, + "decoded": { + "a": "A", + "b": "B", + "c": "C", + "d": "D", + "e": "E" + } + }, + { + "cbor": "X0IBAkMDBAX/", + "hex": "5f42010243030405ff", + "roundtrip": false, + "skip": true, + "diagnostic": "(_ h'0102', h'030405')" + }, + { + "cbor": "f2VzdHJlYWRtaW5n/w==", + "hex": "7f657374726561646d696e67ff", + "roundtrip": false, + "decoded": "streaming" + }, + { + "cbor": "n/8=", + "hex": "9fff", + "roundtrip": false, + "decoded": [ + + ] + }, + { + "cbor": "nwGCAgOfBAX//w==", + "hex": "9f018202039f0405ffff", + "roundtrip": false, + "decoded": [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ] + }, + { + "cbor": "nwGCAgOCBAX/", + "hex": "9f01820203820405ff", + "roundtrip": false, + "decoded": [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ] + }, + { + "cbor": "gwGCAgOfBAX/", + "hex": "83018202039f0405ff", + "roundtrip": false, + "decoded": [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ] + }, + { + "cbor": "gwGfAgP/ggQF", + "hex": "83019f0203ff820405", + "roundtrip": false, + "decoded": [ + 1, + [ + 2, + 3 + ], + [ + 4, + 5 + ] + ] + }, + { + "cbor": "nwECAwQFBgcICQoLDA0ODxAREhMUFRYXGBgYGf8=", + "hex": "9f0102030405060708090a0b0c0d0e0f101112131415161718181819ff", + "roundtrip": false, + "decoded": [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25 + ] + }, + { + "cbor": "v2FhAWFinwID//8=", + "hex": "bf61610161629f0203ffff", + "roundtrip": false, + "decoded": { + "a": 1, + "b": [ + 2, + 3 + ] + } + }, + { + "cbor": "gmFhv2FiYWP/", + "hex": "826161bf61626163ff", + "roundtrip": false, + "decoded": [ + "a", + { + "b": "c" + } + ] + }, + { + "cbor": "v2NGdW71Y0FtdCH/", + "hex": "bf6346756ef563416d7421ff", + "roundtrip": false, + "decoded": { + "Fun": true, + "Amt": -2 + } + } +] diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/test.py b/Godeps/_workspace/src/github.com/ugorji/go/codec/test.py new file mode 100644 index 0000000000..7b75e8cc0f --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/test.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python + +# This will create golden files in a directory passed to it. +# A Test calls this internally to create the golden files +# So it can process them (so we don't have to checkin the files). + +# Ensure msgpack-python and cbor are installed first, using: +# pip install --user msgpack-python +# pip install --user cbor + +import cbor, msgpack, msgpackrpc, sys, os, threading + +def get_test_data_list(): + # get list with all primitive types, and a combo type + l0 = [ + -8, + -1616, + -32323232, + -6464646464646464, + 192, + 1616, + 32323232, + 6464646464646464, + 192, + -3232.0, + -6464646464.0, + 3232.0, + 6464646464.0, + False, + True, + None, + u"someday", + u"", + u"bytestring", + 1328176922000002000, + -2206187877999998000, + 270, + -2013855847999995777, + #-6795364578871345152, + ] + l1 = [ + { "true": True, + "false": False }, + { "true": "True", + "false": False, + "uint16(1616)": 1616 }, + { "list": [1616, 32323232, True, -3232.0, {"TRUE":True, "FALSE":False}, [True, False] ], + "int32":32323232, "bool": True, + "LONG STRING": "123456789012345678901234567890123456789012345678901234567890", + "SHORT STRING": "1234567890" }, + { True: "true", 8: False, "false": 0 } + ] + + l = [] + l.extend(l0) + l.append(l0) + l.extend(l1) + return l + +def build_test_data(destdir): + l = get_test_data_list() + for i in range(len(l)): + # packer = msgpack.Packer() + serialized = msgpack.dumps(l[i]) + f = open(os.path.join(destdir, str(i) + '.msgpack.golden'), 'wb') + f.write(serialized) + f.close() + serialized = cbor.dumps(l[i]) + f = open(os.path.join(destdir, str(i) + '.cbor.golden'), 'wb') + f.write(serialized) + f.close() + +def doRpcServer(port, stopTimeSec): + class EchoHandler(object): + def Echo123(self, msg1, msg2, msg3): + return ("1:%s 2:%s 3:%s" % (msg1, msg2, msg3)) + def EchoStruct(self, msg): + return ("%s" % msg) + + addr = msgpackrpc.Address('localhost', port) + server = msgpackrpc.Server(EchoHandler()) + server.listen(addr) + # run thread to stop it after stopTimeSec seconds if > 0 + if stopTimeSec > 0: + def myStopRpcServer(): + server.stop() + t = threading.Timer(stopTimeSec, myStopRpcServer) + t.start() + server.start() + +def doRpcClientToPythonSvc(port): + address = msgpackrpc.Address('localhost', port) + client = msgpackrpc.Client(address, unpack_encoding='utf-8') + print client.call("Echo123", "A1", "B2", "C3") + print client.call("EchoStruct", {"A" :"Aa", "B":"Bb", "C":"Cc"}) + +def doRpcClientToGoSvc(port): + # print ">>>> port: ", port, " <<<<<" + address = msgpackrpc.Address('localhost', port) + client = msgpackrpc.Client(address, unpack_encoding='utf-8') + print client.call("TestRpcInt.Echo123", ["A1", "B2", "C3"]) + print client.call("TestRpcInt.EchoStruct", {"A" :"Aa", "B":"Bb", "C":"Cc"}) + +def doMain(args): + if len(args) == 2 and args[0] == "testdata": + build_test_data(args[1]) + elif len(args) == 3 and args[0] == "rpc-server": + doRpcServer(int(args[1]), int(args[2])) + elif len(args) == 2 and args[0] == "rpc-client-python-service": + doRpcClientToPythonSvc(int(args[1])) + elif len(args) == 2 and args[0] == "rpc-client-go-service": + doRpcClientToGoSvc(int(args[1])) + else: + print("Usage: test.py " + + "[testdata|rpc-server|rpc-client-python-service|rpc-client-go-service] ...") + +if __name__ == "__main__": + doMain(sys.argv[1:]) + diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/time.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/time.go new file mode 100644 index 0000000000..a6344ed779 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/time.go @@ -0,0 +1,193 @@ +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +import ( + "time" +) + +var ( + timeDigits = [...]byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} +) + +// EncodeTime encodes a time.Time as a []byte, including +// information on the instant in time and UTC offset. +// +// Format Description +// +// A timestamp is composed of 3 components: +// +// - secs: signed integer representing seconds since unix epoch +// - nsces: unsigned integer representing fractional seconds as a +// nanosecond offset within secs, in the range 0 <= nsecs < 1e9 +// - tz: signed integer representing timezone offset in minutes east of UTC, +// and a dst (daylight savings time) flag +// +// When encoding a timestamp, the first byte is the descriptor, which +// defines which components are encoded and how many bytes are used to +// encode secs and nsecs components. *If secs/nsecs is 0 or tz is UTC, it +// is not encoded in the byte array explicitly*. +// +// Descriptor 8 bits are of the form `A B C DDD EE`: +// A: Is secs component encoded? 1 = true +// B: Is nsecs component encoded? 1 = true +// C: Is tz component encoded? 1 = true +// DDD: Number of extra bytes for secs (range 0-7). +// If A = 1, secs encoded in DDD+1 bytes. +// If A = 0, secs is not encoded, and is assumed to be 0. +// If A = 1, then we need at least 1 byte to encode secs. +// DDD says the number of extra bytes beyond that 1. +// E.g. if DDD=0, then secs is represented in 1 byte. +// if DDD=2, then secs is represented in 3 bytes. +// EE: Number of extra bytes for nsecs (range 0-3). +// If B = 1, nsecs encoded in EE+1 bytes (similar to secs/DDD above) +// +// Following the descriptor bytes, subsequent bytes are: +// +// secs component encoded in `DDD + 1` bytes (if A == 1) +// nsecs component encoded in `EE + 1` bytes (if B == 1) +// tz component encoded in 2 bytes (if C == 1) +// +// secs and nsecs components are integers encoded in a BigEndian +// 2-complement encoding format. +// +// tz component is encoded as 2 bytes (16 bits). Most significant bit 15 to +// Least significant bit 0 are described below: +// +// Timezone offset has a range of -12:00 to +14:00 (ie -720 to +840 minutes). +// Bit 15 = have\_dst: set to 1 if we set the dst flag. +// Bit 14 = dst\_on: set to 1 if dst is in effect at the time, or 0 if not. +// Bits 13..0 = timezone offset in minutes. It is a signed integer in Big Endian format. +// +func encodeTime(t time.Time) []byte { + //t := rv.Interface().(time.Time) + tsecs, tnsecs := t.Unix(), t.Nanosecond() + var ( + bd byte + btmp [8]byte + bs [16]byte + i int = 1 + ) + l := t.Location() + if l == time.UTC { + l = nil + } + if tsecs != 0 { + bd = bd | 0x80 + bigen.PutUint64(btmp[:], uint64(tsecs)) + f := pruneSignExt(btmp[:], tsecs >= 0) + bd = bd | (byte(7-f) << 2) + copy(bs[i:], btmp[f:]) + i = i + (8 - f) + } + if tnsecs != 0 { + bd = bd | 0x40 + bigen.PutUint32(btmp[:4], uint32(tnsecs)) + f := pruneSignExt(btmp[:4], true) + bd = bd | byte(3-f) + copy(bs[i:], btmp[f:4]) + i = i + (4 - f) + } + if l != nil { + bd = bd | 0x20 + // Note that Go Libs do not give access to dst flag. + _, zoneOffset := t.Zone() + //zoneName, zoneOffset := t.Zone() + zoneOffset /= 60 + z := uint16(zoneOffset) + bigen.PutUint16(btmp[:2], z) + // clear dst flags + bs[i] = btmp[0] & 0x3f + bs[i+1] = btmp[1] + i = i + 2 + } + bs[0] = bd + return bs[0:i] +} + +// DecodeTime decodes a []byte into a time.Time. +func decodeTime(bs []byte) (tt time.Time, err error) { + bd := bs[0] + var ( + tsec int64 + tnsec uint32 + tz uint16 + i byte = 1 + i2 byte + n byte + ) + if bd&(1<<7) != 0 { + var btmp [8]byte + n = ((bd >> 2) & 0x7) + 1 + i2 = i + n + copy(btmp[8-n:], bs[i:i2]) + //if first bit of bs[i] is set, then fill btmp[0..8-n] with 0xff (ie sign extend it) + if bs[i]&(1<<7) != 0 { + copy(btmp[0:8-n], bsAll0xff) + //for j,k := byte(0), 8-n; j < k; j++ { btmp[j] = 0xff } + } + i = i2 + tsec = int64(bigen.Uint64(btmp[:])) + } + if bd&(1<<6) != 0 { + var btmp [4]byte + n = (bd & 0x3) + 1 + i2 = i + n + copy(btmp[4-n:], bs[i:i2]) + i = i2 + tnsec = bigen.Uint32(btmp[:]) + } + if bd&(1<<5) == 0 { + tt = time.Unix(tsec, int64(tnsec)).UTC() + return + } + // In stdlib time.Parse, when a date is parsed without a zone name, it uses "" as zone name. + // However, we need name here, so it can be shown when time is printed. + // Zone name is in form: UTC-08:00. + // Note that Go Libs do not give access to dst flag, so we ignore dst bits + + i2 = i + 2 + tz = bigen.Uint16(bs[i:i2]) + i = i2 + // sign extend sign bit into top 2 MSB (which were dst bits): + if tz&(1<<13) == 0 { // positive + tz = tz & 0x3fff //clear 2 MSBs: dst bits + } else { // negative + tz = tz | 0xc000 //set 2 MSBs: dst bits + //tzname[3] = '-' (TODO: verify. this works here) + } + tzint := int16(tz) + if tzint == 0 { + tt = time.Unix(tsec, int64(tnsec)).UTC() + } else { + // For Go Time, do not use a descriptive timezone. + // It's unnecessary, and makes it harder to do a reflect.DeepEqual. + // The Offset already tells what the offset should be, if not on UTC and unknown zone name. + // var zoneName = timeLocUTCName(tzint) + tt = time.Unix(tsec, int64(tnsec)).In(time.FixedZone("", int(tzint)*60)) + } + return +} + +func timeLocUTCName(tzint int16) string { + if tzint == 0 { + return "UTC" + } + var tzname = []byte("UTC+00:00") + //tzname := fmt.Sprintf("UTC%s%02d:%02d", tzsign, tz/60, tz%60) //perf issue using Sprintf. inline below. + //tzhr, tzmin := tz/60, tz%60 //faster if u convert to int first + var tzhr, tzmin int16 + if tzint < 0 { + tzname[3] = '-' // (TODO: verify. this works here) + tzhr, tzmin = -tzint/60, (-tzint)%60 + } else { + tzhr, tzmin = tzint/60, tzint%60 + } + tzname[4] = timeDigits[tzhr/10] + tzname[5] = timeDigits[tzhr%10] + tzname[7] = timeDigits[tzmin/10] + tzname[8] = timeDigits[tzmin%10] + return string(tzname) + //return time.FixedZone(string(tzname), int(tzint)*60) +} diff --git a/Godeps/_workspace/src/github.com/ugorji/go/codec/values_test.go b/Godeps/_workspace/src/github.com/ugorji/go/codec/values_test.go new file mode 100644 index 0000000000..a3d1f399b3 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ugorji/go/codec/values_test.go @@ -0,0 +1,198 @@ +// // +build testing + +// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. +// Use of this source code is governed by a BSD-style license found in the LICENSE file. + +package codec + +// This file contains values used by tests and benchmarks. +// JSON/BSON do not like maps with keys that are not strings, +// so we only use maps with string keys here. + +import ( + "math" + "time" +) + +var testStrucTime = time.Date(2012, 2, 2, 2, 2, 2, 2000, time.UTC).UTC() + +type AnonInTestStruc struct { + AS string + AI64 int64 + AI16 int16 + AUi64 uint64 + ASslice []string + AI64slice []int64 + AF64slice []float64 + // AMI32U32 map[int32]uint32 + // AMU32F64 map[uint32]float64 // json/bson do not like it + AMSU16 map[string]uint16 +} + +type AnonInTestStrucIntf struct { + Islice []interface{} + Ms map[string]interface{} + Nintf interface{} //don't set this, so we can test for nil + T time.Time +} + +type TestStruc struct { + _struct struct{} `codec:",omitempty"` //set omitempty for every field + + S string + I64 int64 + I16 int16 + Ui64 uint64 + Ui8 uint8 + B bool + By uint8 // byte: msgp doesn't like byte + + Sslice []string + I64slice []int64 + I16slice []int16 + Ui64slice []uint64 + Ui8slice []uint8 + Bslice []bool + Byslice []byte + + Iptrslice []*int64 + + AnonInTestStruc + + //M map[interface{}]interface{} `json:"-",bson:"-"` + Msi64 map[string]int64 + + // make this a ptr, so that it could be set or not. + // for comparison (e.g. with msgp), give it a struct tag (so it is not inlined), + // make this one omitempty (so it is included if nil). + *AnonInTestStrucIntf `codec:",omitempty"` + + Nmap map[string]bool //don't set this, so we can test for nil + Nslice []byte //don't set this, so we can test for nil + Nint64 *int64 //don't set this, so we can test for nil + Mtsptr map[string]*TestStruc + Mts map[string]TestStruc + Its []*TestStruc + Nteststruc *TestStruc +} + +// small struct for testing that codecgen works for unexported types +type tLowerFirstLetter struct { + I int + u uint64 + S string + b []byte +} + +func newTestStruc(depth int, bench bool, useInterface, useStringKeyOnly bool) (ts *TestStruc) { + var i64a, i64b, i64c, i64d int64 = 64, 6464, 646464, 64646464 + + ts = &TestStruc{ + S: "some string", + I64: math.MaxInt64 * 2 / 3, // 64, + I16: 1616, + Ui64: uint64(int64(math.MaxInt64 * 2 / 3)), // 64, //don't use MaxUint64, as bson can't write it + Ui8: 160, + B: true, + By: 5, + + Sslice: []string{"one", "two", "three"}, + I64slice: []int64{1111, 2222, 3333}, + I16slice: []int16{44, 55, 66}, + Ui64slice: []uint64{12121212, 34343434, 56565656}, + Ui8slice: []uint8{210, 211, 212}, + Bslice: []bool{true, false, true, false}, + Byslice: []byte{13, 14, 15}, + + Msi64: map[string]int64{ + "one": 1, + "two": 2, + }, + AnonInTestStruc: AnonInTestStruc{ + // There's more leeway in altering this. + AS: "A-String", + AI64: -64646464, + AI16: 1616, + AUi64: 64646464, + // (U+1D11E)G-clef character may be represented in json as "\uD834\uDD1E". + // single reverse solidus character may be represented in json as "\u005C". + // include these in ASslice below. + ASslice: []string{"Aone", "Atwo", "Athree", + "Afour.reverse_solidus.\u005c", "Afive.Gclef.\U0001d11E"}, + AI64slice: []int64{1, -22, 333, -4444, 55555, -666666}, + AMSU16: map[string]uint16{"1": 1, "22": 2, "333": 3, "4444": 4}, + AF64slice: []float64{11.11e-11, 22.22E+22, 33.33E-33, 44.44e+44, 555.55E-6, 666.66E6}, + }, + } + if useInterface { + ts.AnonInTestStrucIntf = &AnonInTestStrucIntf{ + Islice: []interface{}{"true", true, "no", false, uint64(288), float64(0.4)}, + Ms: map[string]interface{}{ + "true": "true", + "int64(9)": false, + }, + T: testStrucTime, + } + } + + //For benchmarks, some things will not work. + if !bench { + //json and bson require string keys in maps + //ts.M = map[interface{}]interface{}{ + // true: "true", + // int8(9): false, + //} + //gob cannot encode nil in element in array (encodeArray: nil element) + ts.Iptrslice = []*int64{nil, &i64a, nil, &i64b, nil, &i64c, nil, &i64d, nil} + // ts.Iptrslice = nil + } + if !useStringKeyOnly { + // ts.AnonInTestStruc.AMU32F64 = map[uint32]float64{1: 1, 2: 2, 3: 3} // Json/Bson barf + } + if depth > 0 { + depth-- + if ts.Mtsptr == nil { + ts.Mtsptr = make(map[string]*TestStruc) + } + if ts.Mts == nil { + ts.Mts = make(map[string]TestStruc) + } + ts.Mtsptr["0"] = newTestStruc(depth, bench, useInterface, useStringKeyOnly) + ts.Mts["0"] = *(ts.Mtsptr["0"]) + ts.Its = append(ts.Its, ts.Mtsptr["0"]) + } + return +} + +// Some other types + +type Sstring string +type Bbool bool +type Sstructsmall struct { + A int +} + +type Sstructbig struct { + A int + B bool + c string + // Sval Sstruct + Ssmallptr *Sstructsmall + Ssmall *Sstructsmall + Sptr *Sstructbig +} + +type SstructbigMapBySlice struct { + _struct struct{} `codec:",toarray"` + A int + B bool + c string + // Sval Sstruct + Ssmallptr *Sstructsmall + Ssmall *Sstructsmall + Sptr *Sstructbig +} + +type Sinterface interface { + Noop() +} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/.travis.yml b/Godeps/_workspace/src/github.com/vanackere/ldap/.travis.yml deleted file mode 100644 index 8d7d11f325..0000000000 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: go -go: - - 1.2 - - 1.3 - - tip -install: - - go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v - - go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v - - go get code.google.com/p/go.tools/cmd/cover - - go build -v ./... -script: - - go test -v -cover ./... diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/README.md b/Godeps/_workspace/src/github.com/vanackere/ldap/README.md deleted file mode 100644 index 8246cef6b8..0000000000 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/README.md +++ /dev/null @@ -1,37 +0,0 @@ -[![GoDoc](https://godoc.org/github.com/vanackere/ldap?status.svg)](https://godoc.org/github.com/vanackere/ldap) [![Build Status](https://travis-ci.org/vanackere/ldap.svg)](https://travis-ci.org/vanackere/ldap) - -Basic LDAP v3 functionality for the GO programming language. ------------------------------------------------------------- - -* Required library: - - github.com/vanackere/asn1-ber - -* Working: - - Connecting to LDAP server - - Binding to LDAP server - - Searching for entries - - Compiling string filters to LDAP filters - - Paging Search Results - - Modify Requests / Responses - -* Examples: - - search - - modify - -* Tests Implemented: -- Filter Compile / Decompile - -* TODO: -- Add Requests / Responses -- Delete Requests / Responses -- Modify DN Requests / Responses -- Compare Requests / Responses -- Implement Tests / Benchmarks - - -This feature is disabled at the moment, because in some cases the "Search Request Done" packet will be handled before the last "Search Request Entry": - - Mulitple internal goroutines to handle network traffic - Makes library goroutine safe - Can perform multiple search requests at the same time and return - the results to the proper goroutine. All requests are blocking - requests, so the goroutine does not need special handling diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/bind.go b/Godeps/_workspace/src/github.com/vanackere/ldap/bind.go deleted file mode 100644 index 4947ba86f2..0000000000 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/bind.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ldap - -import ( - "errors" - - "github.com/vanackere/asn1-ber" -) - -func (l *Conn) Bind(username, password string) error { - messageID := l.nextMessageID() - - packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") - packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, int64(messageID), "MessageID")) - bindRequest := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationBindRequest, nil, "Bind Request") - bindRequest.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, 3, "Version")) - bindRequest.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, username, "User Name")) - bindRequest.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, 0, password, "Password")) - packet.AppendChild(bindRequest) - - if l.Debug { - ber.PrintPacket(packet) - } - - channel, err := l.sendMessage(packet) - if err != nil { - return err - } - if channel == nil { - return NewError(ErrorNetwork, errors.New("ldap: could not send message")) - } - defer l.finishMessage(messageID) - - packet = <-channel - if packet == nil { - return NewError(ErrorNetwork, errors.New("ldap: could not retrieve response")) - } - - if l.Debug { - if err := addLDAPDescriptions(packet); err != nil { - return err - } - ber.PrintPacket(packet) - } - - resultCode, resultDescription := getLDAPResultCode(packet) - if resultCode != 0 { - return NewError(resultCode, errors.New(resultDescription)) - } - - return nil -} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/examples/modify.go b/Godeps/_workspace/src/github.com/vanackere/ldap/examples/modify.go deleted file mode 100644 index 326598c4ee..0000000000 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/examples/modify.go +++ /dev/null @@ -1,91 +0,0 @@ -// +build ignore - -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import ( - "errors" - "fmt" - "log" - - "github.com/vanackere/ldap" -) - -var ( - LdapServer string = "localhost" - LdapPort uint16 = 389 - BaseDN string = "dc=enterprise,dc=org" - BindDN string = "cn=admin,dc=enterprise,dc=org" - BindPW string = "enterprise" - Filter string = "(cn=kirkj)" -) - -func search(l *ldap.Conn, filter string, attributes []string) (*ldap.Entry, *ldap.Error) { - search := ldap.NewSearchRequest( - BaseDN, - ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, - filter, - attributes, - nil) - - sr, err := l.Search(search) - if err != nil { - log.Fatalf("ERROR: %s\n", err) - return nil, err - } - - log.Printf("Search: %s -> num of entries = %d\n", search.Filter, len(sr.Entries)) - if len(sr.Entries) == 0 { - return nil, ldap.NewError(ldap.ErrorDebugging, errors.New(fmt.Sprintf("no entries found for: %s", filter))) - } - return sr.Entries[0], nil -} - -func main() { - l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", LdapServer, LdapPort)) - if err != nil { - log.Fatalf("ERROR: %s\n", err.Error()) - } - defer l.Close() - // l.Debug = true - - l.Bind(BindDN, BindPW) - - log.Printf("The Search for Kirk ... %s\n", Filter) - entry, err := search(l, Filter, []string{}) - if err != nil { - log.Fatal("could not get entry") - } - entry.PrettyPrint(0) - - log.Printf("modify the mail address and add a description ... \n") - modify := ldap.NewModifyRequest(entry.DN) - modify.Add("description", []string{"Captain of the USS Enterprise"}) - modify.Replace("mail", []string{"captain@enterprise.org"}) - if err := l.Modify(modify); err != nil { - log.Fatalf("ERROR: %s\n", err.Error()) - } - - entry, err = search(l, Filter, []string{}) - if err != nil { - log.Fatal("could not get entry") - } - entry.PrettyPrint(0) - - log.Printf("reset the entry ... \n") - modify = ldap.NewModifyRequest(entry.DN) - modify.Delete("description", []string{}) - modify.Replace("mail", []string{"james.kirk@enterprise.org"}) - if err := l.Modify(modify); err != nil { - log.Fatalf("ERROR: %s\n", err.Error()) - } - - entry, err = search(l, Filter, []string{}) - if err != nil { - log.Fatal("could not get entry") - } - entry.PrettyPrint(0) -} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/examples/search.go b/Godeps/_workspace/src/github.com/vanackere/ldap/examples/search.go deleted file mode 100644 index 93e941c556..0000000000 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/examples/search.go +++ /dev/null @@ -1,54 +0,0 @@ -// +build ignore - -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import ( - "fmt" - "log" - - "github.com/vanackere/ldap" -) - -var ( - ldapServer string = "adserver" - ldapPort uint16 = 3268 - baseDN string = "dc=*,dc=*" - filter string = "(&(objectClass=user)(sAMAccountName=*)(memberOf=CN=*,OU=*,DC=*,DC=*))" - Attributes []string = []string{"memberof"} - user string = "*" - passwd string = "*" -) - -func main() { - l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) - if err != nil { - log.Fatalf("ERROR: %s\n", err.Error()) - } - defer l.Close() - // l.Debug = true - - err = l.Bind(user, passwd) - if err != nil { - log.Printf("ERROR: Cannot bind: %s\n", err.Error()) - return - } - search := ldap.NewSearchRequest( - baseDN, - ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, - filter, - Attributes, - nil) - - sr, err := l.Search(search) - if err != nil { - log.Fatalf("ERROR: %s\n", err.Error()) - return - } - - log.Printf("Search: %s -> num of entries = %d\n", search.Filter, len(sr.Entries)) - sr.PrettyPrint(0) -} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/examples/searchSSL.go b/Godeps/_workspace/src/github.com/vanackere/ldap/examples/searchSSL.go deleted file mode 100644 index db2f7b88b6..0000000000 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/examples/searchSSL.go +++ /dev/null @@ -1,47 +0,0 @@ -// +build ignore - -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package main - -import ( - "fmt" - "log" - - "github.com/vanackere/ldap" -) - -var ( - LdapServer string = "localhost" - LdapPort uint16 = 636 - BaseDN string = "dc=enterprise,dc=org" - Filter string = "(cn=kirkj)" - Attributes []string = []string{"mail"} -) - -func main() { - l, err := ldap.DialSSL("tcp", fmt.Sprintf("%s:%d", LdapServer, LdapPort), nil) - if err != nil { - log.Fatalf("ERROR: %s\n", err.String()) - } - defer l.Close() - // l.Debug = true - - search := ldap.NewSearchRequest( - BaseDN, - ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false, - Filter, - Attributes, - nil) - - sr, err := l.Search(search) - if err != nil { - log.Fatalf("ERROR: %s\n", err.String()) - return - } - - log.Printf("Search: %s -> num of entries = %d\n", search.Filter, len(sr.Entries)) - sr.PrettyPrint(0) -} diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/ldap_test.go b/Godeps/_workspace/src/github.com/vanackere/ldap/ldap_test.go deleted file mode 100644 index 31cfbf02f1..0000000000 --- a/Godeps/_workspace/src/github.com/vanackere/ldap/ldap_test.go +++ /dev/null @@ -1,123 +0,0 @@ -package ldap - -import ( - "fmt" - "testing" -) - -var ldapServer = "ldap.itd.umich.edu" -var ldapPort = uint16(389) -var baseDN = "dc=umich,dc=edu" -var filter = []string{ - "(cn=cis-fac)", - "(&(objectclass=rfc822mailgroup)(cn=*Computer*))", - "(&(objectclass=rfc822mailgroup)(cn=*Mathematics*))"} -var attributes = []string{ - "cn", - "description"} - -func TestConnect(t *testing.T) { - fmt.Printf("TestConnect: starting...\n") - l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) - if err != nil { - t.Errorf(err.Error()) - return - } - defer l.Close() - fmt.Printf("TestConnect: finished...\n") -} - -func TestSearch(t *testing.T) { - fmt.Printf("TestSearch: starting...\n") - l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) - if err != nil { - t.Errorf(err.Error()) - return - } - defer l.Close() - - searchRequest := NewSearchRequest( - baseDN, - ScopeWholeSubtree, DerefAlways, 0, 0, false, - filter[0], - attributes, - nil) - - sr, err := l.Search(searchRequest) - if err != nil { - t.Errorf(err.Error()) - return - } - - fmt.Printf("TestSearch: %s -> num of entries = %d\n", searchRequest.Filter, len(sr.Entries)) -} - -func TestSearchWithPaging(t *testing.T) { - fmt.Printf("TestSearchWithPaging: starting...\n") - l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) - if err != nil { - t.Errorf(err.Error()) - return - } - defer l.Close() - - err = l.Bind("", "") - if err != nil { - t.Errorf(err.Error()) - return - } - - searchRequest := NewSearchRequest( - baseDN, - ScopeWholeSubtree, DerefAlways, 0, 0, false, - filter[1], - attributes, - nil) - sr, err := l.SearchWithPaging(searchRequest, 5) - if err != nil { - t.Errorf(err.Error()) - return - } - - fmt.Printf("TestSearchWithPaging: %s -> num of entries = %d\n", searchRequest.Filter, len(sr.Entries)) -} - -func testMultiGoroutineSearch(t *testing.T, l *Conn, results chan *SearchResult, i int) { - searchRequest := NewSearchRequest( - baseDN, - ScopeWholeSubtree, DerefAlways, 0, 0, false, - filter[i], - attributes, - nil) - sr, err := l.Search(searchRequest) - if err != nil { - t.Errorf(err.Error()) - results <- nil - return - } - results <- sr -} - -func TestMultiGoroutineSearch(t *testing.T) { - fmt.Printf("TestMultiGoroutineSearch: starting...\n") - l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) - if err != nil { - t.Errorf(err.Error()) - return - } - defer l.Close() - - results := make([]chan *SearchResult, len(filter)) - for i := range filter { - results[i] = make(chan *SearchResult) - go testMultiGoroutineSearch(t, l, results[i], i) - } - for i := range filter { - sr := <-results[i] - if sr == nil { - t.Errorf("Did not receive results from goroutine for %q", filter[i]) - } else { - fmt.Printf("TestMultiGoroutineSearch(%d): %s -> num of entries = %d\n", i, filter[i], len(sr.Entries)) - } - } -} diff --git a/Godeps/_workspace/src/github.com/vanackere/asn1-ber/.travis.yml b/Godeps/_workspace/src/gopkg.in/asn1-ber.v1/.travis.yml similarity index 100% rename from Godeps/_workspace/src/github.com/vanackere/asn1-ber/.travis.yml rename to Godeps/_workspace/src/gopkg.in/asn1-ber.v1/.travis.yml diff --git a/Godeps/_workspace/src/github.com/vanackere/ldap/LICENSE b/Godeps/_workspace/src/gopkg.in/asn1-ber.v1/LICENSE similarity index 100% rename from Godeps/_workspace/src/github.com/vanackere/ldap/LICENSE rename to Godeps/_workspace/src/gopkg.in/asn1-ber.v1/LICENSE diff --git a/Godeps/_workspace/src/github.com/vanackere/asn1-ber/README.md b/Godeps/_workspace/src/gopkg.in/asn1-ber.v1/README.md similarity index 61% rename from Godeps/_workspace/src/github.com/vanackere/asn1-ber/README.md rename to Godeps/_workspace/src/gopkg.in/asn1-ber.v1/README.md index 57ac47fabc..51fbf6546f 100644 --- a/Godeps/_workspace/src/github.com/vanackere/asn1-ber/README.md +++ b/Godeps/_workspace/src/gopkg.in/asn1-ber.v1/README.md @@ -1,4 +1,4 @@ -[![GoDoc](https://godoc.org/github.com/vanackere/asn1-ber?status.svg)](https://godoc.org/github.com/vanackere/asn1-ber) [![Build Status](https://travis-ci.org/vanackere/asn1-ber.svg)](https://travis-ci.org/vanackere/asn1-ber) +[![GoDoc](https://godoc.org/gopkg.in/asn1-ber.v1?status.svg)](https://godoc.org/gopkg.in/asn1-ber.v1) [![Build Status](https://travis-ci.org/go-asn1-ber/asn1-ber.svg)](https://travis-ci.org/go-asn1-ber/asn1-ber) ASN1 BER Encoding / Decoding Library for the GO programming language. diff --git a/Godeps/_workspace/src/github.com/vanackere/asn1-ber/ber.go b/Godeps/_workspace/src/gopkg.in/asn1-ber.v1/ber.go similarity index 100% rename from Godeps/_workspace/src/github.com/vanackere/asn1-ber/ber.go rename to Godeps/_workspace/src/gopkg.in/asn1-ber.v1/ber.go diff --git a/Godeps/_workspace/src/github.com/vanackere/asn1-ber/ber_test.go b/Godeps/_workspace/src/gopkg.in/asn1-ber.v1/ber_test.go similarity index 100% rename from Godeps/_workspace/src/github.com/vanackere/asn1-ber/ber_test.go rename to Godeps/_workspace/src/gopkg.in/asn1-ber.v1/ber_test.go diff --git a/builtin/credential/ldap/backend.go b/builtin/credential/ldap/backend.go index 4cfe8be5ee..6af988bb90 100644 --- a/builtin/credential/ldap/backend.go +++ b/builtin/credential/ldap/backend.go @@ -2,11 +2,10 @@ package ldap import ( "fmt" - "strings" "github.com/hashicorp/vault/logical" "github.com/hashicorp/vault/logical/framework" - "github.com/vanackere/ldap" + "github.com/go-ldap/ldap" ) func Factory(map[string]string) (logical.Backend, error) { @@ -45,6 +44,40 @@ type backend struct { *framework.Backend } +func EscapeLDAPValue(input string) string { + // RFC4514 forbids un-escaped: + // - leading space or hash + // - trailing space + // - special characters '"', '+', ',', ';', '<', '>', '\\' + // - null + for i := 0; i < len(input); i++ { + escaped := false + if input[i] == '\\' { + i++ + escaped = true + } + switch input[i] { + case '"', '+', ',', ';', '<', '>', '\\': + if !escaped { + input = input[0:i] + "\\" + input[i:] + i++ + } + continue + } + if escaped { + input = input[0:i] + "\\" + input[i:] + i++ + } + } + if input[0] == ' ' || input[0] == '#' { + input = "\\" + input + } + if input[len(input)-1] == ' ' { + input = input[0:len(input)-1] + "\\ " + } + return input +} + func (b *backend) Login(req *logical.Request, username string, password string) ([]string, *logical.Response, error) { cfg, err := b.Config(req) @@ -60,8 +93,9 @@ func (b *backend) Login(req *logical.Request, username string, password string) return nil, logical.ErrorResponse(err.Error()), nil } + // Try to authenticate to the server using the provided credentials - binddn := fmt.Sprintf("%s=%s,%s", cfg.UserAttr, username, cfg.UserDN) + binddn := fmt.Sprintf("%s=%s,%s", cfg.UserAttr, EscapeLDAPValue(username), cfg.UserDN) if err = c.Bind(binddn, password); err != nil { return nil, logical.ErrorResponse(fmt.Sprintf("LDAP bind failed: %v", err)), nil } @@ -80,9 +114,11 @@ func (b *backend) Login(req *logical.Request, username string, password string) var allgroups []string var policies []string for _, e := range sresult.Entries { - // Expected syntax for group DN: cn=groupanem,ou=Group,dc=example,dc=com - dn := strings.Split(e.DN, ",") - gname := strings.SplitN(dn[0], "=", 2)[1] + dn, err := ldap.ParseDN(e.DN) + if err != nil || len(dn.RDNs) == 0 || len(dn.RDNs[0].Attributes) == 0 { + continue + } + gname := dn.RDNs[0].Attributes[0].Value allgroups = append(allgroups, gname) group, err := b.Group(req.Storage, gname) if err == nil && group != nil { diff --git a/builtin/credential/ldap/backend_test.go b/builtin/credential/ldap/backend_test.go index ffdc6bfb9d..c1a6f53b1f 100644 --- a/builtin/credential/ldap/backend_test.go +++ b/builtin/credential/ldap/backend_test.go @@ -108,3 +108,20 @@ func testAccStepLogin(t *testing.T, user string, pass string) logicaltest.TestSt Check: logicaltest.TestCheckAuth([]string{"foo"}), } } + +func TestLDAPEscape(t *testing.T) { + testcases := map[string]string { + "#test": "\\#test", + "test,hello": "test\\,hello", + "test,hel+lo": "test\\,hel\\+lo", + "test\\hello": "test\\\\hello", + " test ": "\\ test \\ ", + } + + for test, answer := range testcases { + res := EscapeLDAPValue(test) + if res != answer { + t.Errorf("Failed to escape %s: %s != %s\n", test, res, answer) + } + } +} diff --git a/builtin/credential/ldap/path_config.go b/builtin/credential/ldap/path_config.go index bfd4d10bcf..818c717af4 100644 --- a/builtin/credential/ldap/path_config.go +++ b/builtin/credential/ldap/path_config.go @@ -1,6 +1,7 @@ package ldap import ( + "crypto/tls" "fmt" "net" "net/url" @@ -8,7 +9,7 @@ import ( "github.com/hashicorp/vault/logical" "github.com/hashicorp/vault/logical/framework" - "github.com/vanackere/ldap" + "github.com/go-ldap/ldap" ) func pathConfig(b *backend) *framework.Path { @@ -150,7 +151,8 @@ func (c *ConfigEntry) DialLDAP() (*ldap.Conn, error) { if port == "" { port = "636" } - conn, err = ldap.DialTLS("tcp", host+":"+port, nil) + conn, err = ldap.DialTLS( + "tcp", host+":"+port, &tls.Config{ServerName: host}) default: return nil, fmt.Errorf("invalid LDAP scheme") } diff --git a/builtin/credential/ldap/path_groups.go b/builtin/credential/ldap/path_groups.go index 670d58c84e..4c928f0675 100644 --- a/builtin/credential/ldap/path_groups.go +++ b/builtin/credential/ldap/path_groups.go @@ -9,7 +9,7 @@ import ( func pathGroups(b *backend) *framework.Path { return &framework.Path{ - Pattern: `groups/(?P\w+)`, + Pattern: `groups/(?P.+)`, Fields: map[string]*framework.FieldSchema{ "name": &framework.FieldSchema{ Type: framework.TypeString, diff --git a/builtin/credential/ldap/path_login.go b/builtin/credential/ldap/path_login.go index ad566b771a..492b0f52a8 100644 --- a/builtin/credential/ldap/path_login.go +++ b/builtin/credential/ldap/path_login.go @@ -11,7 +11,7 @@ import ( func pathLogin(b *backend) *framework.Path { return &framework.Path{ - Pattern: `login/(?P[\w.]+)`, + Pattern: `login/(?P.+)`, Fields: map[string]*framework.FieldSchema{ "username": &framework.FieldSchema{ Type: framework.TypeString, From 68ea05db0b8e0d62c2dbf2c3091f14dcee3018b7 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 29 Jun 2015 14:54:25 -0700 Subject: [PATCH 10/19] Fixing godeps file --- Godeps/Godeps.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 16c84ceb67..e3a779a577 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,9 +1,6 @@ { "ImportPath": "github.com/hashicorp/vault", "GoVersion": "go1.4.2", - "Packages": [ - "./..." - ], "Deps": [ { "ImportPath": "github.com/armon/go-metrics", @@ -61,8 +58,8 @@ { "ImportPath": "github.com/fatih/structs", "Rev": "a9f7daa9c2729e97450c2da2feda19130a367d8f" - }, - { + }, + { "ImportPath": "github.com/go-ldap/ldap", "Comment": "v1-8-g4d41e0d", "Rev": "4d41e0d546efa36b1500653d519d1b39fc007dbd" From b62cd8129975a990fc6e40e43834c2c9d230e4ee Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 29 Jun 2015 15:05:44 -0700 Subject: [PATCH 11/19] Updating Godeps --- Godeps/Godeps.json | 85 +- .../src/github.com/armon/go-metrics/inmem.go | 18 +- .../github.com/armon/go-metrics/inmem_test.go | 9 + .../src/github.com/armon/go-radix/README.md | 2 + .../aws/aws-sdk-go/aws/awserr/error.go | 17 + .../aws/aws-sdk-go/aws/awserr/types.go | 135 ++ .../aws-sdk-go/aws/awsutil/path_value_test.go | 4 +- .../github.com/aws/aws-sdk-go/aws/config.go | 27 +- .../aws/aws-sdk-go/aws/config_test.go | 92 ++ .../aws/credentials/chain_provider.go | 8 +- .../aws/credentials/chain_provider_test.go | 10 +- .../aws-sdk-go/aws/credentials/credentials.go | 47 +- .../aws/credentials/credentials_test.go | 3 +- .../aws/credentials/ec2_role_provider.go | 28 +- .../aws/credentials/ec2_role_provider_test.go | 14 +- .../aws/credentials/env_provider.go | 6 +- .../shared_credentials_provider.go | 10 +- .../aws/credentials/static_provider.go | 4 +- .../stscreds/assume_role_provider.go | 120 ++ .../stscreds/assume_role_provider_test.go | 58 + .../aws/aws-sdk-go/aws/handler_functions.go | 20 +- .../aws-sdk-go/aws/handler_functions_test.go | 6 +- .../aws/aws-sdk-go/aws/param_validator.go | 4 +- .../aws-sdk-go/aws/param_validator_test.go | 10 +- .../github.com/aws/aws-sdk-go/aws/request.go | 9 +- .../aws-sdk-go/aws/request_pagination_test.go | 54 +- .../aws/aws-sdk-go/aws/request_test.go | 37 +- .../github.com/aws/aws-sdk-go/aws/service.go | 11 +- .../github.com/aws/aws-sdk-go/aws/version.go | 2 +- .../internal/endpoints/endpoints.go | 2 + .../internal/endpoints/endpoints_map.go | 42 +- .../internal/protocol/query/build.go | 5 +- .../internal/protocol/query/build_test.go | 224 +-- .../internal/protocol/query/unmarshal.go | 4 +- .../protocol/query/unmarshal_error.go | 8 +- .../internal/protocol/query/unmarshal_test.go | 189 +-- .../internal/protocol/rest/build.go | 13 +- .../internal/protocol/rest/unmarshal.go | 12 +- .../internal/protocol/restxml/build_test.go | 498 +++--- .../internal/protocol/restxml/restxml.go | 8 +- .../protocol/restxml/unmarshal_test.go | 174 +- .../internal/protocol/xml/xmlutil/build.go | 1 + .../protocol/xml/xmlutil/unmarshal.go | 2 +- .../aws/aws-sdk-go/internal/signer/v4/v4.go | 157 +- .../aws-sdk-go/internal/signer/v4/v4_test.go | 109 +- .../aws/aws-sdk-go/service/s3/api.go | 969 ++++------- .../aws-sdk-go/service/s3/bucket_location.go | 4 +- .../aws/aws-sdk-go/service/s3/content_md5.go | 6 +- .../aws-sdk-go/service/s3/customizations.go | 2 +- .../service/s3/customizations_test.go | 8 +- .../aws-sdk-go/service/s3/examples_test.go | 134 +- .../service/s3/s3manager/download.go | 19 +- .../aws-sdk-go/service/s3/s3manager/upload.go | 41 +- .../service/s3/s3manager/upload_test.go | 88 +- .../aws/aws-sdk-go/service/s3/sse.go | 4 +- .../aws-sdk-go/service/s3/unmarshal_error.go | 12 +- .../github.com/coreos/go-etcd/etcd/client.go | 25 +- .../github.com/coreos/go-etcd/etcd/cluster.go | 18 +- .../coreos/go-etcd/etcd/response.generated.go | 1419 +++++++++++++++++ .../coreos/go-etcd/etcd/response.go | 8 +- .../coreos/go-etcd/etcd/response_test.go | 75 + .../src/github.com/go-ldap/ldap/compare.go | 85 + .../src/github.com/go-ldap/ldap/conn.go | 25 +- .../go-ldap/ldap/examples/compare/compare.go | 39 + .../src/github.com/go-ldap/ldap/ldap_test.go | 21 + .../src/github.com/go-ldap/ldap/todo | 19 - .../github.com/go-sql-driver/mysql/AUTHORS | 3 + .../github.com/go-sql-driver/mysql/README.md | 14 +- .../go-sql-driver/mysql/connection.go | 31 +- .../github.com/go-sql-driver/mysql/const.go | 10 +- .../github.com/go-sql-driver/mysql/driver.go | 9 + .../go-sql-driver/mysql/driver_test.go | 43 + .../github.com/go-sql-driver/mysql/errors.go | 20 +- .../github.com/go-sql-driver/mysql/packets.go | 51 +- .../go-sql-driver/mysql/statement.go | 38 + .../github.com/go-sql-driver/mysql/utils.go | 14 +- .../go-sql-driver/mysql/utils_test.go | 26 +- .../google/go-github/github/activity_star.go | 13 +- .../go-github/github/activity_star_test.go | 11 +- .../github.com/google/go-github/github/doc.go | 15 +- .../google/go-github/github/gists.go | 18 + .../google/go-github/github/gists_test.go | 26 + .../google/go-github/github/github.go | 31 +- .../google/go-github/github/github_test.go | 19 + .../google/go-github/github/issues.go | 16 +- .../google/go-github/github/issues_labels.go | 2 +- .../google/go-github/github/issues_test.go | 2 +- .../google/go-github/github/licenses.go | 81 + .../google/go-github/github/licenses_test.go | 64 + .../google/go-github/github/misc.go | 36 + .../google/go-github/github/misc_test.go | 35 +- .../google/go-github/github/orgs_hooks.go | 104 ++ .../go-github/github/orgs_hooks_test.go | 134 ++ .../google/go-github/github/orgs_members.go | 9 - .../go-github/github/orgs_members_test.go | 3 - .../google/go-github/github/orgs_teams.go | 35 - .../go-github/github/orgs_teams_test.go | 43 - .../google/go-github/github/pulls.go | 11 + .../google/go-github/github/pulls_comments.go | 2 +- .../google/go-github/github/pulls_test.go | 35 +- .../google/go-github/github/repos.go | 16 + .../google/go-github/github/repos_commits.go | 3 +- .../google/go-github/github/repos_contents.go | 49 +- .../go-github/github/repos_contents_test.go | 74 +- .../go-github/github/repos_deployments.go | 26 +- .../google/go-github/github/repos_hooks.go | 43 +- .../go-github/github/repos_hooks_test.go | 46 +- .../google/go-github/github/repos_releases.go | 21 +- .../go-github/github/repos_releases_test.go | 40 + .../google/go-github/github/repos_test.go | 9 +- .../hashicorp/consul/api/acl_test.go | 42 +- .../github.com/hashicorp/consul/api/agent.go | 1 + .../hashicorp/consul/api/agent_test.go | 126 +- .../hashicorp/consul/api/api_test.go | 16 + .../hashicorp/consul/api/catalog_test.go | 6 + .../hashicorp/consul/api/event_test.go | 24 +- .../hashicorp/consul/api/health_test.go | 4 + .../src/github.com/hashicorp/consul/api/kv.go | 4 + .../hashicorp/consul/api/kv_test.go | 20 +- .../github.com/hashicorp/consul/api/lock.go | 20 +- .../hashicorp/consul/api/lock_test.go | 7 + .../hashicorp/consul/api/semaphore.go | 5 - .../hashicorp/consul/api/semaphore_test.go | 7 + .../hashicorp/consul/api/session.go | 20 +- .../hashicorp/consul/api/session_test.go | 5 + .../hashicorp/consul/api/status_test.go | 2 + .../hashicorp/go-multierror/flatten.go | 26 + .../hashicorp/go-multierror/flatten_test.go | 48 + .../github.com/hashicorp/golang-lru/lru.go | 23 +- .../hashicorp/golang-lru/lru_test.go | 43 +- .../src/github.com/hashicorp/hcl/README.md | 4 +- .../github.com/hashicorp/hcl/decoder_test.go | 14 + .../src/github.com/hashicorp/hcl/hcl/lex.go | 16 +- .../hashicorp/hcl/hcl/valuetype_string.go | 2 +- .../github.com/hashicorp/logutils/README.md | 2 +- .../src/github.com/kardianos/osext/README.md | 4 +- .../src/github.com/kardianos/osext/osext.go | 8 +- .../github.com/kardianos/osext/osext_test.go | 23 + .../src/github.com/lib/pq/bench_test.go | 10 +- .../_workspace/src/github.com/lib/pq/buf.go | 28 +- .../_workspace/src/github.com/lib/pq/conn.go | 245 ++- .../src/github.com/lib/pq/conn_test.go | 13 +- .../src/github.com/lib/pq/copy_test.go | 14 +- .../src/github.com/lib/pq/encode.go | 31 +- .../src/github.com/lib/pq/encode_test.go | 29 +- .../_workspace/src/github.com/lib/pq/error.go | 13 + .../src/github.com/lib/pq/notify.go | 46 +- .../src/github.com/lib/pq/notify_test.go | 72 + .../src/github.com/mitchellh/cli/README.md | 3 + .../src/github.com/mitchellh/cli/cli.go | 35 +- .../src/github.com/mitchellh/cli/cli_test.go | 72 +- .../mitchellh/mapstructure/.travis.yml | 7 + .../mitchellh/mapstructure/decode_hooks.go | 75 +- .../mapstructure/decode_hooks_test.go | 88 +- .../mitchellh/mapstructure/error.go | 16 + .../mitchellh/mapstructure/mapstructure.go | 87 +- .../mapstructure/mapstructure_test.go | 170 ++ .../mitchellh/reflectwalk/reflectwalk.go | 12 +- .../github.com/samuel/go-zookeeper/zk/conn.go | 39 +- .../github.com/samuel/go-zookeeper/zk/lock.go | 13 +- .../samuel/go-zookeeper/zk/structs.go | 7 + .../samuel/go-zookeeper/zk/structs_test.go | 11 + .../golang.org/x/crypto/ssh/terminal/util.go | 2 +- .../src/golang.org/x/net/context/context.go | 2 +- .../src/golang.org/x/oauth2/README.md | 2 +- .../clientcredentials/clientcredentials.go | 2 +- .../golang.org/x/oauth2/facebook/facebook.go | 2 +- .../src/golang.org/x/oauth2/github/github.go | 2 +- .../src/golang.org/x/oauth2/google/google.go | 2 +- .../src/golang.org/x/oauth2/internal/token.go | 1 + .../src/golang.org/x/oauth2/jws/jws.go | 2 +- .../golang.org/x/oauth2/linkedin/linkedin.go | 2 +- .../src/golang.org/x/oauth2/oauth2.go | 18 +- .../x/oauth2/odnoklassniki/odnoklassniki.go | 2 +- .../src/golang.org/x/oauth2/paypal/paypal.go | 2 +- .../src/golang.org/x/oauth2/token.go | 10 + .../src/golang.org/x/oauth2/transport_test.go | 33 + .../src/golang.org/x/oauth2/vk/vk.go | 2 +- 178 files changed, 6061 insertions(+), 2333 deletions(-) create mode 100644 Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awserr/types.go create mode 100644 Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/config_test.go create mode 100644 Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/stscreds/assume_role_provider.go create mode 100644 Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/stscreds/assume_role_provider_test.go create mode 100644 Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response.generated.go create mode 100644 Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response_test.go create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/compare.go create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/examples/compare/compare.go delete mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/todo create mode 100644 Godeps/_workspace/src/github.com/google/go-github/github/licenses.go create mode 100644 Godeps/_workspace/src/github.com/google/go-github/github/licenses_test.go create mode 100644 Godeps/_workspace/src/github.com/google/go-github/github/orgs_hooks.go create mode 100644 Godeps/_workspace/src/github.com/google/go-github/github/orgs_hooks_test.go create mode 100644 Godeps/_workspace/src/github.com/hashicorp/go-multierror/flatten.go create mode 100644 Godeps/_workspace/src/github.com/hashicorp/go-multierror/flatten_test.go create mode 100644 Godeps/_workspace/src/github.com/mitchellh/mapstructure/.travis.yml diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index e3a779a577..4757fa2de1 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,59 +1,62 @@ { "ImportPath": "github.com/hashicorp/vault", "GoVersion": "go1.4.2", + "Packages": [ + "./..." + ], "Deps": [ { "ImportPath": "github.com/armon/go-metrics", - "Rev": "a54701ebec11868993bc198c3f315353e9de2ed6" + "Rev": "b2d95e5291cdbc26997d1301a5e467ecbb240e25" }, { "ImportPath": "github.com/armon/go-radix", - "Rev": "0bab926c3433cfd6490c6d3c504a7b471362390c" + "Rev": "fbd82e84e2b13651f3abc5ffd26b65ba71bc8f93" }, { "ImportPath": "github.com/aws/aws-sdk-go/aws", - "Comment": "v0.6.0", - "Rev": "ea83c25c44525da47e8044bbd21e4045758ea39b" + "Comment": "v0.6.4-5-g127313c", + "Rev": "127313c1b41e534a0456a68b6b3a16712dacb35d" }, { "ImportPath": "github.com/aws/aws-sdk-go/internal/endpoints", - "Comment": "v0.6.0", - "Rev": "ea83c25c44525da47e8044bbd21e4045758ea39b" + "Comment": "v0.6.4-5-g127313c", + "Rev": "127313c1b41e534a0456a68b6b3a16712dacb35d" }, { "ImportPath": "github.com/aws/aws-sdk-go/internal/protocol/query", - "Comment": "v0.6.0", - "Rev": "ea83c25c44525da47e8044bbd21e4045758ea39b" + "Comment": "v0.6.4-5-g127313c", + "Rev": "127313c1b41e534a0456a68b6b3a16712dacb35d" }, { "ImportPath": "github.com/aws/aws-sdk-go/internal/protocol/rest", - "Comment": "v0.6.0", - "Rev": "ea83c25c44525da47e8044bbd21e4045758ea39b" + "Comment": "v0.6.4-5-g127313c", + "Rev": "127313c1b41e534a0456a68b6b3a16712dacb35d" }, { "ImportPath": "github.com/aws/aws-sdk-go/internal/protocol/restxml", - "Comment": "v0.6.0", - "Rev": "ea83c25c44525da47e8044bbd21e4045758ea39b" + "Comment": "v0.6.4-5-g127313c", + "Rev": "127313c1b41e534a0456a68b6b3a16712dacb35d" }, { "ImportPath": "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil", - "Comment": "v0.6.0", - "Rev": "ea83c25c44525da47e8044bbd21e4045758ea39b" + "Comment": "v0.6.4-5-g127313c", + "Rev": "127313c1b41e534a0456a68b6b3a16712dacb35d" }, { "ImportPath": "github.com/aws/aws-sdk-go/internal/signer/v4", - "Comment": "v0.6.0", - "Rev": "ea83c25c44525da47e8044bbd21e4045758ea39b" + "Comment": "v0.6.4-5-g127313c", + "Rev": "127313c1b41e534a0456a68b6b3a16712dacb35d" }, { "ImportPath": "github.com/aws/aws-sdk-go/service/s3", - "Comment": "v0.6.0", - "Rev": "ea83c25c44525da47e8044bbd21e4045758ea39b" + "Comment": "v0.6.4-5-g127313c", + "Rev": "127313c1b41e534a0456a68b6b3a16712dacb35d" }, { "ImportPath": "github.com/coreos/go-etcd/etcd", - "Comment": "v2.0.0-7-g73a8ef7", - "Rev": "73a8ef737e8ea002281a28b4cb92a1de121ad4c6" + "Comment": "v2.0.0-18-gc904d70", + "Rev": "c904d7032a70da6551c43929f199244f6a45f4c1" }, { "ImportPath": "github.com/fatih/structs", @@ -61,17 +64,17 @@ }, { "ImportPath": "github.com/go-ldap/ldap", - "Comment": "v1-8-g4d41e0d", - "Rev": "4d41e0d546efa36b1500653d519d1b39fc007dbd" + "Comment": "v1-14-g406aa05", + "Rev": "406aa05eb8272fb8aa201e410afa6f9fdcb2bf68" }, { "ImportPath": "github.com/go-sql-driver/mysql", - "Comment": "v1.2-88-ga197e5d", - "Rev": "a197e5d40516f2e9f74dcee085a5f2d4604e94df" + "Comment": "v1.2-112-gfb72997", + "Rev": "fb7299726d2e68745a8805b14f2ff44b5c2cfa84" }, { "ImportPath": "github.com/google/go-github/github", - "Rev": "0aaa85be4f3087c6dd815a69e291775d4e83f9ea" + "Rev": "fccd5bb66f985db0a0d150342ca0a9529a23488a" }, { "ImportPath": "github.com/google/go-querystring/query", @@ -99,8 +102,8 @@ }, { "ImportPath": "github.com/hashicorp/consul/api", - "Comment": "v0.5.0-253-g7062ecc", - "Rev": "7062ecc50fef9307e532c4a188da7ce1dd759dde" + "Comment": "v0.5.2-123-gaddb614", + "Rev": "addb6145096bbce6f9dde807a78cad2a4cea3a68" }, { "ImportPath": "github.com/hashicorp/errwrap", @@ -108,7 +111,7 @@ }, { "ImportPath": "github.com/hashicorp/go-multierror", - "Rev": "fcdddc395df1ddf4247c69bd436e84cfa0733f7e" + "Rev": "56912fb08d85084aa318edcf2bba735b97cf35c5" }, { "ImportPath": "github.com/hashicorp/go-syslog", @@ -116,28 +119,28 @@ }, { "ImportPath": "github.com/hashicorp/golang-lru", - "Rev": "d85392d6bc30546d352f52f2632814cde4201d44" + "Rev": "995efda3e073b6946b175ed93901d729ad47466a" }, { "ImportPath": "github.com/hashicorp/hcl", - "Rev": "513e04c400ee2e81e97f5e011c08fb42c6f69b84" + "Rev": "54864211433d45cb780682431585b3e573b49e4a" }, { "ImportPath": "github.com/hashicorp/logutils", - "Rev": "367a65d59043b4f846d179341d138f01f988c186" + "Rev": "0dc08b1671f34c4250ce212759ebd880f743d883" }, { "ImportPath": "github.com/kardianos/osext", - "Rev": "8fef92e41e22a70e700a96b29f066cda30ea24ef" + "Rev": "6e7f843663477789fac7c02def0d0909e969b4e5" }, { "ImportPath": "github.com/lib/pq", - "Comment": "go1.0-cutoff-40-g8910d1c", - "Rev": "8910d1c3a4bda5c97c50bc38543953f1f1e1f8bb" + "Comment": "go1.0-cutoff-51-ga8d8d01", + "Rev": "a8d8d01c4f91602f876bf5aa210274e8203a6b45" }, { "ImportPath": "github.com/mitchellh/cli", - "Rev": "6cc8bc522243675a2882b81662b0b0d2e04b99c9" + "Rev": "8102d0ed5ea2709ade1243798785888175f6e415" }, { "ImportPath": "github.com/mitchellh/copystructure", @@ -149,11 +152,11 @@ }, { "ImportPath": "github.com/mitchellh/mapstructure", - "Rev": "442e588f213303bec7936deba67901f8fc8f18b1" + "Rev": "2caf8efc93669b6c43e0441cdc6aed17546c96f3" }, { "ImportPath": "github.com/mitchellh/reflectwalk", - "Rev": "242be0c275dedfba00a616563e6db75ab8f279ec" + "Rev": "eecf4c70c626c7cfbb95c90195bc34d386c74ac6" }, { "ImportPath": "github.com/ryanuber/columnize", @@ -162,7 +165,7 @@ }, { "ImportPath": "github.com/samuel/go-zookeeper/zk", - "Rev": "d0e0d8e11f318e000a8cc434616d69e329edc374" + "Rev": "c86eba8e7e95efab81f6c0455332e49d39aed12f" }, { "ImportPath": "github.com/ugorji/go/codec", @@ -174,15 +177,15 @@ }, { "ImportPath": "golang.org/x/crypto/ssh/terminal", - "Rev": "59435533c88bd0b1254c738244da1fe96b59d05d" + "Rev": "cc04154d65fb9296747569b107cfd05380b1ea3e" }, { "ImportPath": "golang.org/x/net/context", - "Rev": "a8c61998a557a37435f719980da368469c10bfed" + "Rev": "d9558e5c97f85372afee28cf2b6059d7d3818919" }, { "ImportPath": "golang.org/x/oauth2", - "Rev": "ec6d5d770f531108a6464462b2201b74fcd09314" + "Rev": "b5adcc2dcdf009d0391547edc6ecbaff889f5bb9" }, { "ImportPath": "gopkg.in/asn1-ber.v1", diff --git a/Godeps/_workspace/src/github.com/armon/go-metrics/inmem.go b/Godeps/_workspace/src/github.com/armon/go-metrics/inmem.go index 0749229bfd..da50329606 100644 --- a/Godeps/_workspace/src/github.com/armon/go-metrics/inmem.go +++ b/Godeps/_workspace/src/github.com/armon/go-metrics/inmem.go @@ -65,11 +65,12 @@ func NewIntervalMetrics(intv time.Time) *IntervalMetrics { // AggregateSample is used to hold aggregate metrics // about a sample type AggregateSample struct { - Count int // The count of emitted pairs - Sum float64 // The sum of values - SumSq float64 // The sum of squared values - Min float64 // Minimum value - Max float64 // Maximum value + Count int // The count of emitted pairs + Sum float64 // The sum of values + SumSq float64 // The sum of squared values + Min float64 // Minimum value + Max float64 // Maximum value + LastUpdated time.Time // When value was last updated } // Computes a Stddev of the values @@ -101,16 +102,17 @@ func (a *AggregateSample) Ingest(v float64) { if v > a.Max || a.Count == 1 { a.Max = v } + a.LastUpdated = time.Now() } func (a *AggregateSample) String() string { if a.Count == 0 { return "Count: 0" } else if a.Stddev() == 0 { - return fmt.Sprintf("Count: %d Sum: %0.3f", a.Count, a.Sum) + return fmt.Sprintf("Count: %d Sum: %0.3f LastUpdated: %s", a.Count, a.Sum, a.LastUpdated) } else { - return fmt.Sprintf("Count: %d Min: %0.3f Mean: %0.3f Max: %0.3f Stddev: %0.3f Sum: %0.3f", - a.Count, a.Min, a.Mean(), a.Max, a.Stddev(), a.Sum) + return fmt.Sprintf("Count: %d Min: %0.3f Mean: %0.3f Max: %0.3f Stddev: %0.3f Sum: %0.3f LastUpdated: %s", + a.Count, a.Min, a.Mean(), a.Max, a.Stddev(), a.Sum, a.LastUpdated) } } diff --git a/Godeps/_workspace/src/github.com/armon/go-metrics/inmem_test.go b/Godeps/_workspace/src/github.com/armon/go-metrics/inmem_test.go index 14ba31b382..228a2fc1af 100644 --- a/Godeps/_workspace/src/github.com/armon/go-metrics/inmem_test.go +++ b/Godeps/_workspace/src/github.com/armon/go-metrics/inmem_test.go @@ -63,6 +63,15 @@ func TestInmemSink(t *testing.T) { t.Fatalf("bad val: %v", agg) } + if agg.LastUpdated.IsZero() { + t.Fatalf("agg.LastUpdated is not set: %v", agg) + } + + diff := time.Now().Sub(agg.LastUpdated).Seconds() + if diff > 1 { + t.Fatalf("time diff too great: %f", diff) + } + if agg = intvM.Samples["foo.bar"]; agg == nil { t.Fatalf("missing sample") } diff --git a/Godeps/_workspace/src/github.com/armon/go-radix/README.md b/Godeps/_workspace/src/github.com/armon/go-radix/README.md index c054fe86c0..26f42a2837 100644 --- a/Godeps/_workspace/src/github.com/armon/go-radix/README.md +++ b/Godeps/_workspace/src/github.com/armon/go-radix/README.md @@ -10,6 +10,8 @@ As a radix tree, it provides the following: * Minimum / Maximum value lookups * Ordered iteration +For an immutable variant, see [go-immutable-radix](https://github.com/hashicorp/go-immutable-radix). + Documentation ============= diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awserr/error.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awserr/error.go index cf54d89d1e..99d8c18439 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awserr/error.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awserr/error.go @@ -42,6 +42,17 @@ type Error interface { OrigErr() error } +// New returns an Error object described by the code, message, and origErr. +// +// If origErr satisfies the Error interface it will not be wrapped within a new +// Error object and will instead be returned. +func New(code, message string, origErr error) Error { + if e, ok := origErr.(Error); ok && e != nil { + return e + } + return newBaseError(code, message, origErr) +} + // A RequestFailure is an interface to extract request failure information from // an Error such as the request ID of the failed request returned by a service. // RequestFailures may not always have a requestID value if the request failed @@ -86,3 +97,9 @@ type RequestFailure interface { // to a connection error. RequestID() string } + +// NewRequestFailure returns a new request error wrapper for the given Error +// provided. +func NewRequestFailure(err Error, statusCode int, reqID string) RequestFailure { + return newRequestError(err, statusCode, reqID) +} diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awserr/types.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awserr/types.go new file mode 100644 index 0000000000..418fc4c14b --- /dev/null +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awserr/types.go @@ -0,0 +1,135 @@ +package awserr + +import "fmt" + +// SprintError returns a string of the formatted error code. +// +// Both extra and origErr are optional. If they are included their lines +// will be added, but if they are not included their lines will be ignored. +func SprintError(code, message, extra string, origErr error) string { + msg := fmt.Sprintf("%s: %s", code, message) + if extra != "" { + msg = fmt.Sprintf("%s\n\t%s", msg, extra) + } + if origErr != nil { + msg = fmt.Sprintf("%s\ncaused by: %s", msg, origErr.Error()) + } + return msg +} + +// A baseError wraps the code and message which defines an error. It also +// can be used to wrap an original error object. +// +// Should be used as the root for errors satisfying the awserr.Error. Also +// for any error which does not fit into a specific error wrapper type. +type baseError struct { + // Classification of error + code string + + // Detailed information about error + message string + + // Optional original error this error is based off of. Allows building + // chained errors. + origErr error +} + +// newBaseError returns an error object for the code, message, and err. +// +// code is a short no whitespace phrase depicting the classification of +// the error that is being created. +// +// message is the free flow string containing detailed information about the error. +// +// origErr is the error object which will be nested under the new error to be returned. +func newBaseError(code, message string, origErr error) *baseError { + return &baseError{ + code: code, + message: message, + origErr: origErr, + } +} + +// Error returns the string representation of the error. +// +// See ErrorWithExtra for formatting. +// +// Satisfies the error interface. +func (b baseError) Error() string { + return SprintError(b.code, b.message, "", b.origErr) +} + +// String returns the string representation of the error. +// Alias for Error to satisfy the stringer interface. +func (b baseError) String() string { + return b.Error() +} + +// Code returns the short phrase depicting the classification of the error. +func (b baseError) Code() string { + return b.code +} + +// Message returns the error details message. +func (b baseError) Message() string { + return b.message +} + +// OrigErr returns the original error if one was set. Nil is returned if no error +// was set. +func (b baseError) OrigErr() error { + return b.origErr +} + +// So that the Error interface type can be included as an anonymous field +// in the requestError struct and not conflict with the error.Error() method. +type awsError Error + +// A requestError wraps a request or service error. +// +// Composed of baseError for code, message, and original error. +type requestError struct { + awsError + statusCode int + requestID string +} + +// newRequestError returns a wrapped error with additional information for request +// status code, and service requestID. +// +// Should be used to wrap all request which involve service requests. Even if +// the request failed without a service response, but had an HTTP status code +// that may be meaningful. +// +// Also wraps original errors via the baseError. +func newRequestError(err Error, statusCode int, requestID string) *requestError { + return &requestError{ + awsError: err, + statusCode: statusCode, + requestID: requestID, + } +} + +// Error returns the string representation of the error. +// Satisfies the error interface. +func (r requestError) Error() string { + extra := fmt.Sprintf("status code: %d, request id: [%s]", + r.statusCode, r.requestID) + return SprintError(r.Code(), r.Message(), extra, r.OrigErr()) +} + +// String returns the string representation of the error. +// Alias for Error to satisfy the stringer interface. +func (r requestError) String() string { + return r.Error() +} + +// StatusCode returns the wrapped status code for the error +func (r requestError) StatusCode() int { + return r.statusCode +} + +// RequestID returns the wrapped requestID +func (r requestError) RequestID() string { + return r.requestID +} diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awsutil/path_value_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awsutil/path_value_test.go index 1262cf6bef..ed10aec192 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awsutil/path_value_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/awsutil/path_value_test.go @@ -16,8 +16,8 @@ type Struct struct { } var data = Struct{ - A: []Struct{Struct{C: "value1"}, Struct{C: "value2"}, Struct{C: "value3"}}, - z: []Struct{Struct{C: "value1"}, Struct{C: "value2"}, Struct{C: "value3"}}, + A: []Struct{{C: "value1"}, {C: "value2"}, {C: "value3"}}, + z: []Struct{{C: "value1"}, {C: "value2"}, {C: "value3"}}, B: &Struct{B: &Struct{C: "terminal"}, D: &Struct{C: "terminal2"}}, C: "initial", } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/config.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/config.go index bd805f36b8..4699070714 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/config.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/config.go @@ -68,6 +68,7 @@ func (c Config) Copy() Config { dst.DisableSSL = c.DisableSSL dst.ManualSend = c.ManualSend dst.HTTPClient = c.HTTPClient + dst.LogHTTPBody = c.LogHTTPBody dst.LogLevel = c.LogLevel dst.Logger = c.Logger dst.MaxRetries = c.MaxRetries @@ -90,79 +91,79 @@ func (c Config) Merge(newcfg *Config) *Config { cfg := Config{} - if newcfg != nil && newcfg.Credentials != nil { + if newcfg.Credentials != nil { cfg.Credentials = newcfg.Credentials } else { cfg.Credentials = c.Credentials } - if newcfg != nil && newcfg.Endpoint != "" { + if newcfg.Endpoint != "" { cfg.Endpoint = newcfg.Endpoint } else { cfg.Endpoint = c.Endpoint } - if newcfg != nil && newcfg.Region != "" { + if newcfg.Region != "" { cfg.Region = newcfg.Region } else { cfg.Region = c.Region } - if newcfg != nil && newcfg.DisableSSL { + if newcfg.DisableSSL { cfg.DisableSSL = newcfg.DisableSSL } else { cfg.DisableSSL = c.DisableSSL } - if newcfg != nil && newcfg.ManualSend { + if newcfg.ManualSend { cfg.ManualSend = newcfg.ManualSend } else { cfg.ManualSend = c.ManualSend } - if newcfg != nil && newcfg.HTTPClient != nil { + if newcfg.HTTPClient != nil { cfg.HTTPClient = newcfg.HTTPClient } else { cfg.HTTPClient = c.HTTPClient } - if newcfg != nil && newcfg.LogHTTPBody { + if newcfg.LogHTTPBody { cfg.LogHTTPBody = newcfg.LogHTTPBody } else { cfg.LogHTTPBody = c.LogHTTPBody } - if newcfg != nil && newcfg.LogLevel != 0 { + if newcfg.LogLevel != 0 { cfg.LogLevel = newcfg.LogLevel } else { cfg.LogLevel = c.LogLevel } - if newcfg != nil && newcfg.Logger != nil { + if newcfg.Logger != nil { cfg.Logger = newcfg.Logger } else { cfg.Logger = c.Logger } - if newcfg != nil && newcfg.MaxRetries != DefaultRetries { + if newcfg.MaxRetries != DefaultRetries { cfg.MaxRetries = newcfg.MaxRetries } else { cfg.MaxRetries = c.MaxRetries } - if newcfg != nil && newcfg.DisableParamValidation { + if newcfg.DisableParamValidation { cfg.DisableParamValidation = newcfg.DisableParamValidation } else { cfg.DisableParamValidation = c.DisableParamValidation } - if newcfg != nil && newcfg.DisableComputeChecksums { + if newcfg.DisableComputeChecksums { cfg.DisableComputeChecksums = newcfg.DisableComputeChecksums } else { cfg.DisableComputeChecksums = c.DisableComputeChecksums } - if newcfg != nil && newcfg.S3ForcePathStyle { + if newcfg.S3ForcePathStyle { cfg.S3ForcePathStyle = newcfg.S3ForcePathStyle } else { cfg.S3ForcePathStyle = c.S3ForcePathStyle diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/config_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/config_test.go new file mode 100644 index 0000000000..fc5a77bd0c --- /dev/null +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/config_test.go @@ -0,0 +1,92 @@ +package aws + +import ( + "net/http" + "os" + "reflect" + "testing" + "time" + + "github.com/aws/aws-sdk-go/aws/credentials" +) + +var testCredentials = credentials.NewChainCredentials([]credentials.Provider{ + &credentials.EnvProvider{}, + &credentials.SharedCredentialsProvider{ + Filename: "TestFilename", + Profile: "TestProfile"}, + &credentials.EC2RoleProvider{ExpiryWindow: 5 * time.Minute}, +}) + +var copyTestConfig = Config{ + Credentials: testCredentials, + Endpoint: "CopyTestEndpoint", + Region: "COPY_TEST_AWS_REGION", + DisableSSL: true, + ManualSend: true, + HTTPClient: http.DefaultClient, + LogHTTPBody: true, + LogLevel: 2, + Logger: os.Stdout, + MaxRetries: DefaultRetries, + DisableParamValidation: true, + DisableComputeChecksums: true, + S3ForcePathStyle: true, +} + +func TestCopy(t *testing.T) { + want := copyTestConfig + got := copyTestConfig.Copy() + if !reflect.DeepEqual(got, want) { + t.Errorf("Copy() = %+v", got) + t.Errorf(" want %+v", want) + } +} + +func TestCopyReturnsNewInstance(t *testing.T) { + want := copyTestConfig + got := copyTestConfig.Copy() + if &got == &want { + t.Errorf("Copy() = %p; want different instance as source %p", &got, &want) + } +} + +var mergeTestZeroValueConfig = Config{MaxRetries: DefaultRetries} + +var mergeTestConfig = Config{ + Credentials: testCredentials, + Endpoint: "MergeTestEndpoint", + Region: "MERGE_TEST_AWS_REGION", + DisableSSL: true, + ManualSend: true, + HTTPClient: http.DefaultClient, + LogHTTPBody: true, + LogLevel: 2, + Logger: os.Stdout, + MaxRetries: 10, + DisableParamValidation: true, + DisableComputeChecksums: true, + S3ForcePathStyle: true, +} + +var mergeTests = []struct { + cfg *Config + in *Config + want *Config +}{ + {&Config{}, nil, &Config{}}, + {&Config{}, &mergeTestZeroValueConfig, &Config{}}, + {&Config{}, &mergeTestConfig, &mergeTestConfig}, +} + +func TestMerge(t *testing.T) { + for _, tt := range mergeTests { + got := tt.cfg.Merge(tt.in) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("Config %+v", tt.cfg) + t.Errorf(" Merge(%+v)", tt.in) + t.Errorf(" got %+v", got) + t.Errorf(" want %+v", tt.want) + } + } +} diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/chain_provider.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/chain_provider.go index 196be7c172..ce66dc831b 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/chain_provider.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/chain_provider.go @@ -1,13 +1,13 @@ package credentials import ( - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" ) var ( // ErrNoValidProvidersFoundInChain Is returned when there are no valid // providers in the ChainProvider. - ErrNoValidProvidersFoundInChain = apierr.New("NoCredentialProviders", "no valid providers in chain", nil) + ErrNoValidProvidersFoundInChain = awserr.New("NoCredentialProviders", "no valid providers in chain", nil) ) // A ChainProvider will search for a provider which returns credentials @@ -36,7 +36,9 @@ var ( // &EnvProvider{}, // &EC2RoleProvider{}, // }) -// creds.Retrieve() +// +// // Usage of ChainCredentials with aws.Config +// svc := ec2.New(&aws.Config{Credentials: creds}) // type ChainProvider struct { Providers []Provider diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/chain_provider_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/chain_provider_test.go index 1a275fcac2..4fba22f29f 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/chain_provider_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/chain_provider_test.go @@ -3,15 +3,15 @@ package credentials import ( "testing" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/stretchr/testify/assert" ) func TestChainProviderGet(t *testing.T) { p := &ChainProvider{ Providers: []Provider{ - &stubProvider{err: apierr.New("FirstError", "first provider error", nil)}, - &stubProvider{err: apierr.New("SecondError", "second provider error", nil)}, + &stubProvider{err: awserr.New("FirstError", "first provider error", nil)}, + &stubProvider{err: awserr.New("SecondError", "second provider error", nil)}, &stubProvider{ creds: Value{ AccessKeyID: "AKID", @@ -62,8 +62,8 @@ func TestChainProviderWithNoProvider(t *testing.T) { func TestChainProviderWithNoValidProvider(t *testing.T) { p := &ChainProvider{ Providers: []Provider{ - &stubProvider{err: apierr.New("FirstError", "first provider error", nil)}, - &stubProvider{err: apierr.New("SecondError", "second provider error", nil)}, + &stubProvider{err: awserr.New("FirstError", "first provider error", nil)}, + &stubProvider{err: awserr.New("SecondError", "second provider error", nil)}, }, } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/credentials.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/credentials.go index 6f6ec03127..3d6ac4d291 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/credentials.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/credentials.go @@ -93,6 +93,50 @@ type Provider interface { IsExpired() bool } +// A Expiry provides shared expiration logic to be used by credentials +// providers to implement expiry functionality. +// +// The best method to use this struct is as an anonymous field within the +// provider's struct. +// +// Example: +// type EC2RoleProvider struct { +// Expiry +// ... +// } +type Expiry struct { + // The date/time when to expire on + expiration time.Time + + // If set will be used by IsExpired to determine the current time. + // Defaults to time.Now if CurrentTime is not set. Available for testing + // to be able to mock out the current time. + CurrentTime func() time.Time +} + +// SetExpiration sets the expiration IsExpired will check when called. +// +// If window is greater than 0 the expiration time will be reduced by the +// window value. +// +// Using a window is helpful to trigger credentials to expire sooner than +// the expiration time given to ensure no requests are made with expired +// tokens. +func (e *Expiry) SetExpiration(expiration time.Time, window time.Duration) { + e.expiration = expiration + if window > 0 { + e.expiration = e.expiration.Add(-window) + } +} + +// IsExpired returns if the credentials are expired. +func (e *Expiry) IsExpired() bool { + if e.CurrentTime == nil { + e.CurrentTime = time.Now + } + return e.expiration.Before(e.CurrentTime()) +} + // A Credentials provides synchronous safe retrieval of AWS credentials Value. // Credentials will cache the credentials value until they expire. Once the value // expires the next Get will attempt to retrieve valid credentials. @@ -173,6 +217,3 @@ func (c *Credentials) IsExpired() bool { func (c *Credentials) isExpired() bool { return c.forceRefresh || c.provider.IsExpired() } - -// Provide a stub-able time.Now for unit tests so expiry can be tested. -var currentTime = time.Now diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/credentials_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/credentials_test.go index 779bb0da4a..99c2b47742 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/credentials_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/credentials_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/aws/aws-sdk-go/aws/awserr" - "github.com/aws/aws-sdk-go/internal/apierr" "github.com/stretchr/testify/assert" ) @@ -40,7 +39,7 @@ func TestCredentialsGet(t *testing.T) { } func TestCredentialsGetWithError(t *testing.T) { - c := NewCredentials(&stubProvider{err: apierr.New("provider error", "", nil), expired: true}) + c := NewCredentials(&stubProvider{err: awserr.New("provider error", "", nil), expired: true}) _, err := c.Get() assert.Equal(t, "provider error", err.(awserr.Error).Code(), "Expected provider error") diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/ec2_role_provider.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/ec2_role_provider.go index ed0c8ba9cd..7691b624ff 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/ec2_role_provider.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/ec2_role_provider.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" ) const metadataCredentialsEndpoint = "http://169.254.169.254/latest/meta-data/iam/security-credentials/" @@ -33,6 +33,8 @@ const metadataCredentialsEndpoint = "http://169.254.169.254/latest/meta-data/iam // } // type EC2RoleProvider struct { + Expiry + // Endpoint must be fully quantified URL Endpoint string @@ -49,9 +51,6 @@ type EC2RoleProvider struct { // // If ExpiryWindow is 0 or less it will be ignored. ExpiryWindow time.Duration - - // The date/time at which the credentials expire. - expiresOn time.Time } // NewEC2RoleCredentials returns a pointer to a new Credentials object @@ -91,7 +90,7 @@ func (m *EC2RoleProvider) Retrieve() (Value, error) { } if len(credsList) == 0 { - return Value{}, apierr.New("EmptyEC2RoleList", "empty EC2 Role list", nil) + return Value{}, awserr.New("EmptyEC2RoleList", "empty EC2 Role list", nil) } credsName := credsList[0] @@ -100,11 +99,7 @@ func (m *EC2RoleProvider) Retrieve() (Value, error) { return Value{}, err } - m.expiresOn = roleCreds.Expiration - if m.ExpiryWindow > 0 { - // Offset based on expiry window if set. - m.expiresOn = m.expiresOn.Add(-m.ExpiryWindow) - } + m.SetExpiration(roleCreds.Expiration, m.ExpiryWindow) return Value{ AccessKeyID: roleCreds.AccessKeyID, @@ -113,11 +108,6 @@ func (m *EC2RoleProvider) Retrieve() (Value, error) { }, nil } -// IsExpired returns if the credentials are expired. -func (m *EC2RoleProvider) IsExpired() bool { - return m.expiresOn.Before(currentTime()) -} - // A ec2RoleCredRespBody provides the shape for deserializing credential // request responses. type ec2RoleCredRespBody struct { @@ -132,7 +122,7 @@ type ec2RoleCredRespBody struct { func requestCredList(client *http.Client, endpoint string) ([]string, error) { resp, err := client.Get(endpoint) if err != nil { - return nil, apierr.New("ListEC2Role", "failed to list EC2 Roles", err) + return nil, awserr.New("ListEC2Role", "failed to list EC2 Roles", err) } defer resp.Body.Close() @@ -143,7 +133,7 @@ func requestCredList(client *http.Client, endpoint string) ([]string, error) { } if err := s.Err(); err != nil { - return nil, apierr.New("ReadEC2Role", "failed to read list of EC2 Roles", err) + return nil, awserr.New("ReadEC2Role", "failed to read list of EC2 Roles", err) } return credsList, nil @@ -156,7 +146,7 @@ func requestCredList(client *http.Client, endpoint string) ([]string, error) { func requestCred(client *http.Client, endpoint, credsName string) (*ec2RoleCredRespBody, error) { resp, err := client.Get(endpoint + credsName) if err != nil { - return nil, apierr.New("GetEC2RoleCredentials", + return nil, awserr.New("GetEC2RoleCredentials", fmt.Sprintf("failed to get %s EC2 Role credentials", credsName), err) } @@ -164,7 +154,7 @@ func requestCred(client *http.Client, endpoint, credsName string) (*ec2RoleCredR respCreds := &ec2RoleCredRespBody{} if err := json.NewDecoder(resp.Body).Decode(respCreds); err != nil { - return nil, apierr.New("DecodeEC2RoleCredentials", + return nil, awserr.New("DecodeEC2RoleCredentials", fmt.Sprintf("failed to decode %s EC2 Role credentials", credsName), err) } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/ec2_role_provider_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/ec2_role_provider_test.go index 5232a1dcaf..da1549a4f2 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/ec2_role_provider_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/ec2_role_provider_test.go @@ -45,10 +45,7 @@ func TestEC2RoleProviderIsExpired(t *testing.T) { defer server.Close() p := &EC2RoleProvider{Client: http.DefaultClient, Endpoint: server.URL} - defer func() { - currentTime = time.Now - }() - currentTime = func() time.Time { + p.CurrentTime = func() time.Time { return time.Date(2014, 12, 15, 21, 26, 0, 0, time.UTC) } @@ -59,7 +56,7 @@ func TestEC2RoleProviderIsExpired(t *testing.T) { assert.False(t, p.IsExpired(), "Expect creds to not be expired after retrieve.") - currentTime = func() time.Time { + p.CurrentTime = func() time.Time { return time.Date(3014, 12, 15, 21, 26, 0, 0, time.UTC) } @@ -71,10 +68,7 @@ func TestEC2RoleProviderExpiryWindowIsExpired(t *testing.T) { defer server.Close() p := &EC2RoleProvider{Client: http.DefaultClient, Endpoint: server.URL, ExpiryWindow: time.Hour * 1} - defer func() { - currentTime = time.Now - }() - currentTime = func() time.Time { + p.CurrentTime = func() time.Time { return time.Date(2014, 12, 15, 0, 51, 37, 0, time.UTC) } @@ -85,7 +79,7 @@ func TestEC2RoleProviderExpiryWindowIsExpired(t *testing.T) { assert.False(t, p.IsExpired(), "Expect creds to not be expired after retrieve.") - currentTime = func() time.Time { + p.CurrentTime = func() time.Time { return time.Date(2014, 12, 16, 0, 55, 37, 0, time.UTC) } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/env_provider.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/env_provider.go index e9c575292e..3e556be7f7 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/env_provider.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/env_provider.go @@ -3,16 +3,16 @@ package credentials import ( "os" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" ) var ( // ErrAccessKeyIDNotFound is returned when the AWS Access Key ID can't be // found in the process's environment. - ErrAccessKeyIDNotFound = apierr.New("EnvAccessKeyNotFound", "AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY not found in environment", nil) + ErrAccessKeyIDNotFound = awserr.New("EnvAccessKeyNotFound", "AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY not found in environment", nil) // ErrSecretAccessKeyNotFound is returned when the AWS Secret Access Key // can't be found in the process's environment. - ErrSecretAccessKeyNotFound = apierr.New("EnvSecretNotFound", "AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY not found in environment", nil) + ErrSecretAccessKeyNotFound = awserr.New("EnvSecretNotFound", "AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY not found in environment", nil) ) // A EnvProvider retrieves credentials from the environment variables of the diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/shared_credentials_provider.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/shared_credentials_provider.go index d61b140be4..7367f733af 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/shared_credentials_provider.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/shared_credentials_provider.go @@ -7,12 +7,12 @@ import ( "github.com/vaughan0/go-ini" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" ) var ( // ErrSharedCredentialsHomeNotFound is emitted when the user directory cannot be found. - ErrSharedCredentialsHomeNotFound = apierr.New("UserHomeNotFound", "user home directory not found.", nil) + ErrSharedCredentialsHomeNotFound = awserr.New("UserHomeNotFound", "user home directory not found.", nil) ) // A SharedCredentialsProvider retrieves credentials from the current user's home @@ -72,20 +72,20 @@ func (p *SharedCredentialsProvider) IsExpired() bool { func loadProfile(filename, profile string) (Value, error) { config, err := ini.LoadFile(filename) if err != nil { - return Value{}, apierr.New("SharedCredsLoad", "failed to load shared credentials file", err) + return Value{}, awserr.New("SharedCredsLoad", "failed to load shared credentials file", err) } iniProfile := config.Section(profile) id, ok := iniProfile["aws_access_key_id"] if !ok { - return Value{}, apierr.New("SharedCredsAccessKey", + return Value{}, awserr.New("SharedCredsAccessKey", fmt.Sprintf("shared credentials %s in %s did not contain aws_access_key_id", profile, filename), nil) } secret, ok := iniProfile["aws_secret_access_key"] if !ok { - return Value{}, apierr.New("SharedCredsSecret", + return Value{}, awserr.New("SharedCredsSecret", fmt.Sprintf("shared credentials %s in %s did not contain aws_secret_access_key", profile, filename), nil) } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/static_provider.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/static_provider.go index 4466cd263c..a114713625 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/static_provider.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/static_provider.go @@ -1,12 +1,12 @@ package credentials import ( - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" ) var ( // ErrStaticCredentialsEmpty is emitted when static credentials are empty. - ErrStaticCredentialsEmpty = apierr.New("EmptyStaticCreds", "static credentials are empty", nil) + ErrStaticCredentialsEmpty = awserr.New("EmptyStaticCreds", "static credentials are empty", nil) ) // A StaticProvider is a set of credentials which are set pragmatically, diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/stscreds/assume_role_provider.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/stscreds/assume_role_provider.go new file mode 100644 index 0000000000..1499b44973 --- /dev/null +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/stscreds/assume_role_provider.go @@ -0,0 +1,120 @@ +// Package stscreds are credential Providers to retrieve STS AWS credentials. +// +// STS provides multiple ways to retrieve credentials which can be used when making +// future AWS service API operation calls. +package stscreds + +import ( + "fmt" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/service/sts" + "time" +) + +// AssumeRoler represents the minimal subset of the STS client API used by this provider. +type AssumeRoler interface { + AssumeRole(input *sts.AssumeRoleInput) (*sts.AssumeRoleOutput, error) +} + +// AssumeRoleProvider retrieves temporary credentials from the STS service, and +// keeps track of their expiration time. This provider must be used explicitly, +// as it is not included in the credentials chain. +// +// Example how to configure a service to use this provider: +// +// config := &aws.Config{ +// Credentials: stscreds.NewCredentials(nil, "arn-of-the-role-to-assume", 10*time.Second), +// }) +// // Use config for creating your AWS service. +// +// Example how to obtain customised credentials: +// +// provider := &stscreds.Provider{ +// // Extend the duration to 1 hour. +// Duration: time.Hour, +// // Custom role name. +// RoleSessionName: "custom-session-name", +// } +// creds := credentials.NewCredentials(provider) +// +type AssumeRoleProvider struct { + credentials.Expiry + + // Custom STS client. If not set the default STS client will be used. + Client AssumeRoler + + // Role to be assumed. + RoleARN string + + // Session name, if you wish to reuse the credentials elsewhere. + RoleSessionName string + + // Expiry duration of the STS credentials. Defaults to 15 minutes if not set. + Duration time.Duration + + // ExpiryWindow will allow the credentials to trigger refreshing prior to + // the credentials actually expiring. This is beneficial so race conditions + // with expiring credentials do not cause request to fail unexpectedly + // due to ExpiredTokenException exceptions. + // + // So a ExpiryWindow of 10s would cause calls to IsExpired() to return true + // 10 seconds before the credentials are actually expired. + // + // If ExpiryWindow is 0 or less it will be ignored. + ExpiryWindow time.Duration +} + +// NewCredentials returns a pointer to a new Credentials object wrapping the +// AssumeRoleProvider. The credentials will expire every 15 minutes and the +// role will be named after a nanosecond timestamp of this operation. +// +// The sts and roleARN parameters are used for building the "AssumeRole" call. +// Pass nil as sts to use the default client. +// +// Window is the expiry window that will be subtracted from the expiry returned +// by the role credential request. This is done so that the credentials will +// expire sooner than their actual lifespan. +func NewCredentials(client AssumeRoler, roleARN string, window time.Duration) *credentials.Credentials { + return credentials.NewCredentials(&AssumeRoleProvider{ + Client: client, + RoleARN: roleARN, + ExpiryWindow: window, + }) +} + +// Retrieve generates a new set of temporary credentials using STS. +func (p *AssumeRoleProvider) Retrieve() (credentials.Value, error) { + + // Apply defaults where parameters are not set. + if p.Client == nil { + p.Client = sts.New(nil) + } + if p.RoleSessionName == "" { + // Try to work out a role name that will hopefully end up unique. + p.RoleSessionName = fmt.Sprintf("%d", time.Now().UTC().UnixNano()) + } + if p.Duration == 0 { + // Expire as often as AWS permits. + p.Duration = 15 * time.Minute + } + + roleOutput, err := p.Client.AssumeRole(&sts.AssumeRoleInput{ + DurationSeconds: aws.Long(int64(p.Duration / time.Second)), + RoleARN: aws.String(p.RoleARN), + RoleSessionName: aws.String(p.RoleSessionName), + }) + + if err != nil { + return credentials.Value{}, err + } + + // We will proactively generate new credentials before they expire. + p.SetExpiration(*roleOutput.Credentials.Expiration, p.ExpiryWindow) + + return credentials.Value{ + AccessKeyID: *roleOutput.Credentials.AccessKeyID, + SecretAccessKey: *roleOutput.Credentials.SecretAccessKey, + SessionToken: *roleOutput.Credentials.SessionToken, + }, nil +} diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/stscreds/assume_role_provider_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/stscreds/assume_role_provider_test.go new file mode 100644 index 0000000000..98b7690026 --- /dev/null +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/credentials/stscreds/assume_role_provider_test.go @@ -0,0 +1,58 @@ +package stscreds + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/sts" + "github.com/stretchr/testify/assert" + "testing" + "time" +) + +type stubSTS struct { +} + +func (s *stubSTS) AssumeRole(input *sts.AssumeRoleInput) (*sts.AssumeRoleOutput, error) { + expiry := time.Now().Add(60 * time.Minute) + return &sts.AssumeRoleOutput{ + Credentials: &sts.Credentials{ + // Just reflect the role arn to the provider. + AccessKeyID: input.RoleARN, + SecretAccessKey: aws.String("assumedSecretAccessKey"), + SessionToken: aws.String("assumedSessionToken"), + Expiration: &expiry, + }, + }, nil +} + +func TestAssumeRoleProvider(t *testing.T) { + stub := &stubSTS{} + p := &AssumeRoleProvider{ + Client: stub, + RoleARN: "roleARN", + } + + creds, err := p.Retrieve() + assert.Nil(t, err, "Expect no error") + + assert.Equal(t, "roleARN", creds.AccessKeyID, "Expect access key ID to be reflected role ARN") + assert.Equal(t, "assumedSecretAccessKey", creds.SecretAccessKey, "Expect secret access key to match") + assert.Equal(t, "assumedSessionToken", creds.SessionToken, "Expect session token to match") +} + +func BenchmarkAssumeRoleProvider(b *testing.B) { + stub := &stubSTS{} + p := &AssumeRoleProvider{ + Client: stub, + RoleARN: "roleARN", + } + + b.ResetTimer() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + _, err := p.Retrieve() + if err != nil { + b.Fatal(err) + } + } + }) +} diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/handler_functions.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/handler_functions.go index e15ab8291f..a2a88a9195 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/handler_functions.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/handler_functions.go @@ -12,7 +12,6 @@ import ( "time" "github.com/aws/aws-sdk-go/aws/awserr" - "github.com/aws/aws-sdk-go/internal/apierr" ) var sleepDelay = func(delay time.Duration) { @@ -80,8 +79,17 @@ func SendHandler(r *Request) { return } } + if r.HTTPRequest == nil { + // Add a dummy request response object to ensure the HTTPResponse + // value is consistent. + r.HTTPResponse = &http.Response{ + StatusCode: int(0), + Status: http.StatusText(int(0)), + Body: ioutil.NopCloser(bytes.NewReader([]byte{})), + } + } // Catch all other request errors. - r.Error = apierr.New("RequestError", "send request failed", err) + r.Error = awserr.New("RequestError", "send request failed", err) r.Retryable.Set(true) // network errors are retryable } } @@ -90,7 +98,7 @@ func SendHandler(r *Request) { func ValidateResponseHandler(r *Request) { if r.HTTPResponse.StatusCode == 0 || r.HTTPResponse.StatusCode >= 300 { // this may be replaced by an UnmarshalError handler - r.Error = apierr.New("UnknownError", "unknown error", nil) + r.Error = awserr.New("UnknownError", "unknown error", nil) } } @@ -114,8 +122,6 @@ func AfterRetryHandler(r *Request) { if err, ok := r.Error.(awserr.Error); ok { if isCodeExpiredCreds(err.Code()) { r.Config.Credentials.Expire() - // The credentials will need to be resigned with new credentials - r.signed = false } } } @@ -128,11 +134,11 @@ func AfterRetryHandler(r *Request) { var ( // ErrMissingRegion is an error that is returned if region configuration is // not found. - ErrMissingRegion error = apierr.New("MissingRegion", "could not find region configuration", nil) + ErrMissingRegion error = awserr.New("MissingRegion", "could not find region configuration", nil) // ErrMissingEndpoint is an error that is returned if an endpoint cannot be // resolved for a service. - ErrMissingEndpoint error = apierr.New("MissingEndpoint", "'Endpoint' configuration is required for this service", nil) + ErrMissingEndpoint error = awserr.New("MissingEndpoint", "'Endpoint' configuration is required for this service", nil) ) // ValidateEndpointHandler is a request handler to validate a request had the diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/handler_functions_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/handler_functions_test.go index 822db9fe20..c6a30c0fcb 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/handler_functions_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/handler_functions_test.go @@ -5,8 +5,8 @@ import ( "os" "testing" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/credentials" - "github.com/aws/aws-sdk-go/internal/apierr" "github.com/stretchr/testify/assert" ) @@ -56,11 +56,11 @@ func TestAfterRetryRefreshCreds(t *testing.T) { svc.Handlers.Clear() svc.Handlers.ValidateResponse.PushBack(func(r *Request) { - r.Error = apierr.New("UnknownError", "", nil) + r.Error = awserr.New("UnknownError", "", nil) r.HTTPResponse = &http.Response{StatusCode: 400} }) svc.Handlers.UnmarshalError.PushBack(func(r *Request) { - r.Error = apierr.New("ExpiredTokenException", "", nil) + r.Error = awserr.New("ExpiredTokenException", "", nil) }) svc.Handlers.AfterRetry.PushBack(func(r *Request) { AfterRetryHandler(r) diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/param_validator.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/param_validator.go index 7c1377281d..b4e95cebd5 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/param_validator.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/param_validator.go @@ -5,7 +5,7 @@ import ( "reflect" "strings" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" ) // ValidateParameters is a request handler to validate the input parameters. @@ -18,7 +18,7 @@ func ValidateParameters(r *Request) { if count := len(v.errors); count > 0 { format := "%d validation errors:\n- %s" msg := fmt.Sprintf(format, count, strings.Join(v.errors, "\n- ")) - r.Error = apierr.New("InvalidParameter", msg, nil) + r.Error = awserr.New("InvalidParameter", msg, nil) } } } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/param_validator_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/param_validator_test.go index 6651567307..b8239f4a71 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/param_validator_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/param_validator_test.go @@ -41,8 +41,8 @@ func TestNoErrors(t *testing.T) { input := &StructShape{ RequiredList: []*ConditionalStructShape{}, RequiredMap: map[string]*ConditionalStructShape{ - "key1": &ConditionalStructShape{Name: aws.String("Name")}, - "key2": &ConditionalStructShape{Name: aws.String("Name")}, + "key1": {Name: aws.String("Name")}, + "key2": {Name: aws.String("Name")}, }, RequiredBool: aws.Boolean(true), OptionalStruct: &ConditionalStructShape{Name: aws.String("Name")}, @@ -65,10 +65,10 @@ func TestMissingRequiredParameters(t *testing.T) { func TestNestedMissingRequiredParameters(t *testing.T) { input := &StructShape{ - RequiredList: []*ConditionalStructShape{&ConditionalStructShape{}}, + RequiredList: []*ConditionalStructShape{{}}, RequiredMap: map[string]*ConditionalStructShape{ - "key1": &ConditionalStructShape{Name: aws.String("Name")}, - "key2": &ConditionalStructShape{}, + "key1": {Name: aws.String("Name")}, + "key2": {}, }, RequiredBool: aws.Boolean(true), OptionalStruct: &ConditionalStructShape{}, diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request.go index 6473a642a0..68d1a4dd1f 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request.go @@ -32,8 +32,7 @@ type Request struct { Retryable SettableBool RetryDelay time.Duration - built bool - signed bool + built bool } // An Operation is the service API operation to be made. @@ -164,17 +163,12 @@ func (r *Request) Build() error { // Send will build the request prior to signing. All Sign Handlers will // be executed in the order they were set. func (r *Request) Sign() error { - if r.signed { - return r.Error - } - r.Build() if r.Error != nil { return r.Error } r.Handlers.Sign.Run(r) - r.signed = r.Error != nil return r.Error } @@ -203,6 +197,7 @@ func (r *Request) Send() error { if r.Error != nil { return r.Error } + continue } r.Handlers.UnmarshalMeta.Run(r) diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request_pagination_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request_pagination_test.go index eabd9aea7a..35b7ee8d93 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request_pagination_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request_pagination_test.go @@ -19,9 +19,9 @@ func TestPagination(t *testing.T) { reqNum := 0 resps := []*dynamodb.ListTablesOutput{ - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("Table1"), aws.String("Table2")}, LastEvaluatedTableName: aws.String("Table2")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("Table3"), aws.String("Table4")}, LastEvaluatedTableName: aws.String("Table4")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("Table5")}}, + {TableNames: []*string{aws.String("Table1"), aws.String("Table2")}, LastEvaluatedTableName: aws.String("Table2")}, + {TableNames: []*string{aws.String("Table3"), aws.String("Table4")}, LastEvaluatedTableName: aws.String("Table4")}, + {TableNames: []*string{aws.String("Table5")}}, } db.Handlers.Send.Clear() // mock sending @@ -71,9 +71,9 @@ func TestPaginationEachPage(t *testing.T) { reqNum := 0 resps := []*dynamodb.ListTablesOutput{ - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("Table1"), aws.String("Table2")}, LastEvaluatedTableName: aws.String("Table2")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("Table3"), aws.String("Table4")}, LastEvaluatedTableName: aws.String("Table4")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("Table5")}}, + {TableNames: []*string{aws.String("Table1"), aws.String("Table2")}, LastEvaluatedTableName: aws.String("Table2")}, + {TableNames: []*string{aws.String("Table3"), aws.String("Table4")}, LastEvaluatedTableName: aws.String("Table4")}, + {TableNames: []*string{aws.String("Table5")}}, } db.Handlers.Send.Clear() // mock sending @@ -124,9 +124,9 @@ func TestPaginationEarlyExit(t *testing.T) { reqNum := 0 resps := []*dynamodb.ListTablesOutput{ - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("Table1"), aws.String("Table2")}, LastEvaluatedTableName: aws.String("Table2")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("Table3"), aws.String("Table4")}, LastEvaluatedTableName: aws.String("Table4")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("Table5")}}, + {TableNames: []*string{aws.String("Table1"), aws.String("Table2")}, LastEvaluatedTableName: aws.String("Table2")}, + {TableNames: []*string{aws.String("Table3"), aws.String("Table4")}, LastEvaluatedTableName: aws.String("Table4")}, + {TableNames: []*string{aws.String("Table5")}}, } db.Handlers.Send.Clear() // mock sending @@ -189,10 +189,10 @@ func TestPaginationTruncation(t *testing.T) { reqNum := &count resps := []*s3.ListObjectsOutput{ - &s3.ListObjectsOutput{IsTruncated: aws.Boolean(true), Contents: []*s3.Object{&s3.Object{Key: aws.String("Key1")}}}, - &s3.ListObjectsOutput{IsTruncated: aws.Boolean(true), Contents: []*s3.Object{&s3.Object{Key: aws.String("Key2")}}}, - &s3.ListObjectsOutput{IsTruncated: aws.Boolean(false), Contents: []*s3.Object{&s3.Object{Key: aws.String("Key3")}}}, - &s3.ListObjectsOutput{IsTruncated: aws.Boolean(true), Contents: []*s3.Object{&s3.Object{Key: aws.String("Key4")}}}, + {IsTruncated: aws.Boolean(true), Contents: []*s3.Object{{Key: aws.String("Key1")}}}, + {IsTruncated: aws.Boolean(true), Contents: []*s3.Object{{Key: aws.String("Key2")}}}, + {IsTruncated: aws.Boolean(false), Contents: []*s3.Object{{Key: aws.String("Key3")}}}, + {IsTruncated: aws.Boolean(true), Contents: []*s3.Object{{Key: aws.String("Key4")}}}, } client.Handlers.Send.Clear() // mock sending @@ -232,20 +232,20 @@ func TestPaginationTruncation(t *testing.T) { // Benchmarks var benchResps = []*dynamodb.ListTablesOutput{ - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, - &dynamodb.ListTablesOutput{TableNames: []*string{aws.String("TABLE")}}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE"), aws.String("NXT")}, LastEvaluatedTableName: aws.String("NXT")}, + {TableNames: []*string{aws.String("TABLE")}}, } var benchDb = func() *dynamodb.DynamoDB { diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request_test.go index 27507f039d..fcb4718722 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/request_test.go @@ -13,7 +13,6 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/credentials" - "github.com/aws/aws-sdk-go/internal/apierr" "github.com/stretchr/testify/assert" ) @@ -36,12 +35,12 @@ func unmarshal(req *Request) { func unmarshalError(req *Request) { bodyBytes, err := ioutil.ReadAll(req.HTTPResponse.Body) if err != nil { - req.Error = apierr.New("UnmarshaleError", req.HTTPResponse.Status, err) + req.Error = awserr.New("UnmarshaleError", req.HTTPResponse.Status, err) return } if len(bodyBytes) == 0 { - req.Error = apierr.NewRequestError( - apierr.New("UnmarshaleError", req.HTTPResponse.Status, fmt.Errorf("empty body")), + req.Error = awserr.NewRequestFailure( + awserr.New("UnmarshaleError", req.HTTPResponse.Status, fmt.Errorf("empty body")), req.HTTPResponse.StatusCode, "", ) @@ -49,11 +48,11 @@ func unmarshalError(req *Request) { } var jsonErr jsonErrorResponse if err := json.Unmarshal(bodyBytes, &jsonErr); err != nil { - req.Error = apierr.New("UnmarshaleError", "JSON unmarshal", err) + req.Error = awserr.New("UnmarshaleError", "JSON unmarshal", err) return } - req.Error = apierr.NewRequestError( - apierr.New(jsonErr.Code, jsonErr.Message, nil), + req.Error = awserr.NewRequestFailure( + awserr.New(jsonErr.Code, jsonErr.Message, nil), req.HTTPResponse.StatusCode, "", ) @@ -68,9 +67,9 @@ type jsonErrorResponse struct { func TestRequestRecoverRetry5xx(t *testing.T) { reqNum := 0 reqs := []http.Response{ - http.Response{StatusCode: 500, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, - http.Response{StatusCode: 501, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, - http.Response{StatusCode: 200, Body: body(`{"data":"valid"}`)}, + {StatusCode: 500, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, + {StatusCode: 501, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, + {StatusCode: 200, Body: body(`{"data":"valid"}`)}, } s := NewService(&Config{MaxRetries: 10}) @@ -94,9 +93,9 @@ func TestRequestRecoverRetry5xx(t *testing.T) { func TestRequestRecoverRetry4xxRetryable(t *testing.T) { reqNum := 0 reqs := []http.Response{ - http.Response{StatusCode: 400, Body: body(`{"__type":"Throttling","message":"Rate exceeded."}`)}, - http.Response{StatusCode: 429, Body: body(`{"__type":"ProvisionedThroughputExceededException","message":"Rate exceeded."}`)}, - http.Response{StatusCode: 200, Body: body(`{"data":"valid"}`)}, + {StatusCode: 400, Body: body(`{"__type":"Throttling","message":"Rate exceeded."}`)}, + {StatusCode: 429, Body: body(`{"__type":"ProvisionedThroughputExceededException","message":"Rate exceeded."}`)}, + {StatusCode: 200, Body: body(`{"data":"valid"}`)}, } s := NewService(&Config{MaxRetries: 10}) @@ -148,10 +147,10 @@ func TestRequestExhaustRetries(t *testing.T) { reqNum := 0 reqs := []http.Response{ - http.Response{StatusCode: 500, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, - http.Response{StatusCode: 500, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, - http.Response{StatusCode: 500, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, - http.Response{StatusCode: 500, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, + {StatusCode: 500, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, + {StatusCode: 500, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, + {StatusCode: 500, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, + {StatusCode: 500, Body: body(`{"__type":"UnknownError","message":"An error occurred."}`)}, } s := NewService(&Config{MaxRetries: -1}) @@ -181,8 +180,8 @@ func TestRequestExhaustRetries(t *testing.T) { func TestRequestRecoverExpiredCreds(t *testing.T) { reqNum := 0 reqs := []http.Response{ - http.Response{StatusCode: 400, Body: body(`{"__type":"ExpiredTokenException","message":"expired token"}`)}, - http.Response{StatusCode: 200, Body: body(`{"data":"valid"}`)}, + {StatusCode: 400, Body: body(`{"__type":"ExpiredTokenException","message":"expired token"}`)}, + {StatusCode: 200, Body: body(`{"data":"valid"}`)}, } s := NewService(&Config{MaxRetries: 10, Credentials: credentials.NewStaticCredentials("AKID", "SECRET", "")}) diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/service.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/service.go index 3e862f8eac..42d1be4eea 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/service.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/service.go @@ -136,17 +136,18 @@ func retryRules(r *Request) time.Duration { // retryableCodes is a collection of service response codes which are retry-able // without any further action. var retryableCodes = map[string]struct{}{ - "ProvisionedThroughputExceededException": struct{}{}, - "Throttling": struct{}{}, + "RequestError": {}, + "ProvisionedThroughputExceededException": {}, + "Throttling": {}, } // credsExpiredCodes is a collection of error codes which signify the credentials // need to be refreshed. Expired tokens require refreshing of credentials, and // resigning before the request can be retried. var credsExpiredCodes = map[string]struct{}{ - "ExpiredToken": struct{}{}, - "ExpiredTokenException": struct{}{}, - "RequestExpired": struct{}{}, // EC2 Only + "ExpiredToken": {}, + "ExpiredTokenException": {}, + "RequestExpired": {}, // EC2 Only } func isCodeRetryable(code string) bool { diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/version.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/version.go index 7c156dbe2a..94b8c729f9 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/version.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/aws/version.go @@ -5,4 +5,4 @@ package aws const SDKName = "aws-sdk-go" // SDKVersion is the version of this SDK -const SDKVersion = "0.6.0" +const SDKVersion = "0.6.4" diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/endpoints/endpoints.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/endpoints/endpoints.go index 8298a5b20b..d040cccd57 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/endpoints/endpoints.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/endpoints/endpoints.go @@ -1,6 +1,8 @@ +// Package endpoints validates regional endpoints for services. package endpoints //go:generate go run ../model/cli/gen-endpoints/main.go endpoints.json endpoints_map.go +//go:generate gofmt -s -w endpoints_map.go import "strings" diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/endpoints/endpoints_map.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/endpoints/endpoints_map.go index 637fcbe43a..894c1a6434 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/endpoints/endpoints_map.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/endpoints/endpoints_map.go @@ -15,74 +15,74 @@ type endpointEntry struct { var endpointsMap = endpointStruct{ Version: 2, Endpoints: map[string]endpointEntry{ - "*/*": endpointEntry{ + "*/*": { Endpoint: "{service}.{region}.amazonaws.com", }, - "*/cloudfront": endpointEntry{ + "*/cloudfront": { Endpoint: "cloudfront.amazonaws.com", SigningRegion: "us-east-1", }, - "*/cloudsearchdomain": endpointEntry{ + "*/cloudsearchdomain": { Endpoint: "", SigningRegion: "us-east-1", }, - "*/iam": endpointEntry{ + "*/iam": { Endpoint: "iam.amazonaws.com", SigningRegion: "us-east-1", }, - "*/importexport": endpointEntry{ + "*/importexport": { Endpoint: "importexport.amazonaws.com", SigningRegion: "us-east-1", }, - "*/route53": endpointEntry{ + "*/route53": { Endpoint: "route53.amazonaws.com", SigningRegion: "us-east-1", }, - "*/sts": endpointEntry{ + "*/sts": { Endpoint: "sts.amazonaws.com", SigningRegion: "us-east-1", }, - "ap-northeast-1/s3": endpointEntry{ + "ap-northeast-1/s3": { Endpoint: "s3-{region}.amazonaws.com", }, - "ap-southeast-1/s3": endpointEntry{ + "ap-southeast-1/s3": { Endpoint: "s3-{region}.amazonaws.com", }, - "ap-southeast-2/s3": endpointEntry{ + "ap-southeast-2/s3": { Endpoint: "s3-{region}.amazonaws.com", }, - "cn-north-1/*": endpointEntry{ + "cn-north-1/*": { Endpoint: "{service}.{region}.amazonaws.com.cn", }, - "eu-central-1/s3": endpointEntry{ + "eu-central-1/s3": { Endpoint: "{service}.{region}.amazonaws.com", }, - "eu-west-1/s3": endpointEntry{ + "eu-west-1/s3": { Endpoint: "s3-{region}.amazonaws.com", }, - "sa-east-1/s3": endpointEntry{ + "sa-east-1/s3": { Endpoint: "s3-{region}.amazonaws.com", }, - "us-east-1/s3": endpointEntry{ + "us-east-1/s3": { Endpoint: "s3.amazonaws.com", }, - "us-east-1/sdb": endpointEntry{ + "us-east-1/sdb": { Endpoint: "sdb.amazonaws.com", SigningRegion: "us-east-1", }, - "us-gov-west-1/iam": endpointEntry{ + "us-gov-west-1/iam": { Endpoint: "iam.us-gov.amazonaws.com", }, - "us-gov-west-1/s3": endpointEntry{ + "us-gov-west-1/s3": { Endpoint: "s3-{region}.amazonaws.com", }, - "us-gov-west-1/sts": endpointEntry{ + "us-gov-west-1/sts": { Endpoint: "sts.us-gov-west-1.amazonaws.com", }, - "us-west-1/s3": endpointEntry{ + "us-west-1/s3": { Endpoint: "s3-{region}.amazonaws.com", }, - "us-west-2/s3": endpointEntry{ + "us-west-2/s3": { Endpoint: "s3-{region}.amazonaws.com", }, }, diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/build.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/build.go index c7c95627d7..c4d8dd2635 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/build.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/build.go @@ -1,3 +1,4 @@ +// Package query provides serialisation of AWS query requests, and responses. package query //go:generate go run ../../fixtures/protocol/generate.go ../../fixtures/protocol/input/query.json build_test.go @@ -6,7 +7,7 @@ import ( "net/url" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/internal/protocol/query/queryutil" ) @@ -17,7 +18,7 @@ func Build(r *aws.Request) { "Version": {r.Service.APIVersion}, } if err := queryutil.Parse(body, r.Params, false); err != nil { - r.Error = apierr.New("Marshal", "failed encoding Query request", err) + r.Error = awserr.New("SerializationError", "failed encoding Query request", err) return } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/build_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/build_test.go index da266758b4..b54829838e 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/build_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/build_test.go @@ -1,10 +1,6 @@ package query_test import ( - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/protocol/query" - "github.com/aws/aws-sdk-go/internal/signer/v4" - "bytes" "encoding/json" "encoding/xml" @@ -15,7 +11,10 @@ import ( "testing" "time" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/internal/protocol/query" "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" + "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" "github.com/stretchr/testify/assert" ) @@ -63,20 +62,19 @@ func (c *InputService1ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService1TestCaseOperation1 = "OperationName" + // InputService1TestCaseOperation1Request generates a request for the InputService1TestCaseOperation1 operation. func (c *InputService1ProtocolTest) InputService1TestCaseOperation1Request(input *InputService1TestShapeInputShape) (req *aws.Request, output *InputService1TestShapeInputService1TestCaseOperation1Output) { - - if opInputService1TestCaseOperation1 == nil { - opInputService1TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService1TestCaseOperation1, } if input == nil { input = &InputService1TestShapeInputShape{} } - req = c.newRequest(opInputService1TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService1TestShapeInputService1TestCaseOperation1Output{} req.Data = output return @@ -88,8 +86,6 @@ func (c *InputService1ProtocolTest) InputService1TestCaseOperation1(input *Input return out, err } -var opInputService1TestCaseOperation1 *aws.Operation - type InputService1TestShapeInputService1TestCaseOperation1Output struct { metadataInputService1TestShapeInputService1TestCaseOperation1Output `json:"-" xml:"-"` } @@ -142,20 +138,19 @@ func (c *InputService2ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService2TestCaseOperation1 = "OperationName" + // InputService2TestCaseOperation1Request generates a request for the InputService2TestCaseOperation1 operation. func (c *InputService2ProtocolTest) InputService2TestCaseOperation1Request(input *InputService2TestShapeInputShape) (req *aws.Request, output *InputService2TestShapeInputService2TestCaseOperation1Output) { - - if opInputService2TestCaseOperation1 == nil { - opInputService2TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService2TestCaseOperation1, } if input == nil { input = &InputService2TestShapeInputShape{} } - req = c.newRequest(opInputService2TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService2TestShapeInputService2TestCaseOperation1Output{} req.Data = output return @@ -167,8 +162,6 @@ func (c *InputService2ProtocolTest) InputService2TestCaseOperation1(input *Input return out, err } -var opInputService2TestCaseOperation1 *aws.Operation - type InputService2TestShapeInputService2TestCaseOperation1Output struct { metadataInputService2TestShapeInputService2TestCaseOperation1Output `json:"-" xml:"-"` } @@ -229,20 +222,19 @@ func (c *InputService3ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService3TestCaseOperation1 = "OperationName" + // InputService3TestCaseOperation1Request generates a request for the InputService3TestCaseOperation1 operation. func (c *InputService3ProtocolTest) InputService3TestCaseOperation1Request(input *InputService3TestShapeInputShape) (req *aws.Request, output *InputService3TestShapeInputService3TestCaseOperation1Output) { - - if opInputService3TestCaseOperation1 == nil { - opInputService3TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService3TestCaseOperation1, } if input == nil { input = &InputService3TestShapeInputShape{} } - req = c.newRequest(opInputService3TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService3TestShapeInputService3TestCaseOperation1Output{} req.Data = output return @@ -254,22 +246,19 @@ func (c *InputService3ProtocolTest) InputService3TestCaseOperation1(input *Input return out, err } -var opInputService3TestCaseOperation1 *aws.Operation +const opInputService3TestCaseOperation2 = "OperationName" // InputService3TestCaseOperation2Request generates a request for the InputService3TestCaseOperation2 operation. func (c *InputService3ProtocolTest) InputService3TestCaseOperation2Request(input *InputService3TestShapeInputShape) (req *aws.Request, output *InputService3TestShapeInputService3TestCaseOperation2Output) { - - if opInputService3TestCaseOperation2 == nil { - opInputService3TestCaseOperation2 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService3TestCaseOperation2, } if input == nil { input = &InputService3TestShapeInputShape{} } - req = c.newRequest(opInputService3TestCaseOperation2, input, output) + req = c.newRequest(op, input, output) output = &InputService3TestShapeInputService3TestCaseOperation2Output{} req.Data = output return @@ -281,8 +270,6 @@ func (c *InputService3ProtocolTest) InputService3TestCaseOperation2(input *Input return out, err } -var opInputService3TestCaseOperation2 *aws.Operation - type InputService3TestShapeInputService3TestCaseOperation1Output struct { metadataInputService3TestShapeInputService3TestCaseOperation1Output `json:"-" xml:"-"` } @@ -341,20 +328,19 @@ func (c *InputService4ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService4TestCaseOperation1 = "OperationName" + // InputService4TestCaseOperation1Request generates a request for the InputService4TestCaseOperation1 operation. func (c *InputService4ProtocolTest) InputService4TestCaseOperation1Request(input *InputService4TestShapeInputShape) (req *aws.Request, output *InputService4TestShapeInputService4TestCaseOperation1Output) { - - if opInputService4TestCaseOperation1 == nil { - opInputService4TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService4TestCaseOperation1, } if input == nil { input = &InputService4TestShapeInputShape{} } - req = c.newRequest(opInputService4TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService4TestShapeInputService4TestCaseOperation1Output{} req.Data = output return @@ -366,22 +352,19 @@ func (c *InputService4ProtocolTest) InputService4TestCaseOperation1(input *Input return out, err } -var opInputService4TestCaseOperation1 *aws.Operation +const opInputService4TestCaseOperation2 = "OperationName" // InputService4TestCaseOperation2Request generates a request for the InputService4TestCaseOperation2 operation. func (c *InputService4ProtocolTest) InputService4TestCaseOperation2Request(input *InputService4TestShapeInputShape) (req *aws.Request, output *InputService4TestShapeInputService4TestCaseOperation2Output) { - - if opInputService4TestCaseOperation2 == nil { - opInputService4TestCaseOperation2 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService4TestCaseOperation2, } if input == nil { input = &InputService4TestShapeInputShape{} } - req = c.newRequest(opInputService4TestCaseOperation2, input, output) + req = c.newRequest(op, input, output) output = &InputService4TestShapeInputService4TestCaseOperation2Output{} req.Data = output return @@ -393,8 +376,6 @@ func (c *InputService4ProtocolTest) InputService4TestCaseOperation2(input *Input return out, err } -var opInputService4TestCaseOperation2 *aws.Operation - type InputService4TestShapeInputService4TestCaseOperation1Output struct { metadataInputService4TestShapeInputService4TestCaseOperation1Output `json:"-" xml:"-"` } @@ -455,20 +436,19 @@ func (c *InputService5ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService5TestCaseOperation1 = "OperationName" + // InputService5TestCaseOperation1Request generates a request for the InputService5TestCaseOperation1 operation. func (c *InputService5ProtocolTest) InputService5TestCaseOperation1Request(input *InputService5TestShapeInputShape) (req *aws.Request, output *InputService5TestShapeInputService5TestCaseOperation1Output) { - - if opInputService5TestCaseOperation1 == nil { - opInputService5TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService5TestCaseOperation1, } if input == nil { input = &InputService5TestShapeInputShape{} } - req = c.newRequest(opInputService5TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService5TestShapeInputService5TestCaseOperation1Output{} req.Data = output return @@ -480,22 +460,19 @@ func (c *InputService5ProtocolTest) InputService5TestCaseOperation1(input *Input return out, err } -var opInputService5TestCaseOperation1 *aws.Operation +const opInputService5TestCaseOperation2 = "OperationName" // InputService5TestCaseOperation2Request generates a request for the InputService5TestCaseOperation2 operation. func (c *InputService5ProtocolTest) InputService5TestCaseOperation2Request(input *InputService5TestShapeInputShape) (req *aws.Request, output *InputService5TestShapeInputService5TestCaseOperation2Output) { - - if opInputService5TestCaseOperation2 == nil { - opInputService5TestCaseOperation2 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService5TestCaseOperation2, } if input == nil { input = &InputService5TestShapeInputShape{} } - req = c.newRequest(opInputService5TestCaseOperation2, input, output) + req = c.newRequest(op, input, output) output = &InputService5TestShapeInputService5TestCaseOperation2Output{} req.Data = output return @@ -507,8 +484,6 @@ func (c *InputService5ProtocolTest) InputService5TestCaseOperation2(input *Input return out, err } -var opInputService5TestCaseOperation2 *aws.Operation - type InputService5TestShapeInputService5TestCaseOperation1Output struct { metadataInputService5TestShapeInputService5TestCaseOperation1Output `json:"-" xml:"-"` } @@ -567,20 +542,19 @@ func (c *InputService6ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService6TestCaseOperation1 = "OperationName" + // InputService6TestCaseOperation1Request generates a request for the InputService6TestCaseOperation1 operation. func (c *InputService6ProtocolTest) InputService6TestCaseOperation1Request(input *InputService6TestShapeInputShape) (req *aws.Request, output *InputService6TestShapeInputService6TestCaseOperation1Output) { - - if opInputService6TestCaseOperation1 == nil { - opInputService6TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService6TestCaseOperation1, } if input == nil { input = &InputService6TestShapeInputShape{} } - req = c.newRequest(opInputService6TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService6TestShapeInputService6TestCaseOperation1Output{} req.Data = output return @@ -592,8 +566,6 @@ func (c *InputService6ProtocolTest) InputService6TestCaseOperation1(input *Input return out, err } -var opInputService6TestCaseOperation1 *aws.Operation - type InputService6TestShapeInputService6TestCaseOperation1Output struct { metadataInputService6TestShapeInputService6TestCaseOperation1Output `json:"-" xml:"-"` } @@ -644,20 +616,19 @@ func (c *InputService7ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService7TestCaseOperation1 = "OperationName" + // InputService7TestCaseOperation1Request generates a request for the InputService7TestCaseOperation1 operation. func (c *InputService7ProtocolTest) InputService7TestCaseOperation1Request(input *InputService7TestShapeInputShape) (req *aws.Request, output *InputService7TestShapeInputService7TestCaseOperation1Output) { - - if opInputService7TestCaseOperation1 == nil { - opInputService7TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService7TestCaseOperation1, } if input == nil { input = &InputService7TestShapeInputShape{} } - req = c.newRequest(opInputService7TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService7TestShapeInputService7TestCaseOperation1Output{} req.Data = output return @@ -669,8 +640,6 @@ func (c *InputService7ProtocolTest) InputService7TestCaseOperation1(input *Input return out, err } -var opInputService7TestCaseOperation1 *aws.Operation - type InputService7TestShapeInputService7TestCaseOperation1Output struct { metadataInputService7TestShapeInputService7TestCaseOperation1Output `json:"-" xml:"-"` } @@ -721,20 +690,19 @@ func (c *InputService8ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService8TestCaseOperation1 = "OperationName" + // InputService8TestCaseOperation1Request generates a request for the InputService8TestCaseOperation1 operation. func (c *InputService8ProtocolTest) InputService8TestCaseOperation1Request(input *InputService8TestShapeInputShape) (req *aws.Request, output *InputService8TestShapeInputService8TestCaseOperation1Output) { - - if opInputService8TestCaseOperation1 == nil { - opInputService8TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService8TestCaseOperation1, } if input == nil { input = &InputService8TestShapeInputShape{} } - req = c.newRequest(opInputService8TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService8TestShapeInputService8TestCaseOperation1Output{} req.Data = output return @@ -746,8 +714,6 @@ func (c *InputService8ProtocolTest) InputService8TestCaseOperation1(input *Input return out, err } -var opInputService8TestCaseOperation1 *aws.Operation - type InputService8TestShapeInputService8TestCaseOperation1Output struct { metadataInputService8TestShapeInputService8TestCaseOperation1Output `json:"-" xml:"-"` } @@ -798,20 +764,19 @@ func (c *InputService9ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService9TestCaseOperation1 = "OperationName" + // InputService9TestCaseOperation1Request generates a request for the InputService9TestCaseOperation1 operation. func (c *InputService9ProtocolTest) InputService9TestCaseOperation1Request(input *InputService9TestShapeInputShape) (req *aws.Request, output *InputService9TestShapeInputService9TestCaseOperation1Output) { - - if opInputService9TestCaseOperation1 == nil { - opInputService9TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService9TestCaseOperation1, } if input == nil { input = &InputService9TestShapeInputShape{} } - req = c.newRequest(opInputService9TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService9TestShapeInputService9TestCaseOperation1Output{} req.Data = output return @@ -823,22 +788,19 @@ func (c *InputService9ProtocolTest) InputService9TestCaseOperation1(input *Input return out, err } -var opInputService9TestCaseOperation1 *aws.Operation +const opInputService9TestCaseOperation2 = "OperationName" // InputService9TestCaseOperation2Request generates a request for the InputService9TestCaseOperation2 operation. func (c *InputService9ProtocolTest) InputService9TestCaseOperation2Request(input *InputService9TestShapeInputShape) (req *aws.Request, output *InputService9TestShapeInputService9TestCaseOperation2Output) { - - if opInputService9TestCaseOperation2 == nil { - opInputService9TestCaseOperation2 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService9TestCaseOperation2, } if input == nil { input = &InputService9TestShapeInputShape{} } - req = c.newRequest(opInputService9TestCaseOperation2, input, output) + req = c.newRequest(op, input, output) output = &InputService9TestShapeInputService9TestCaseOperation2Output{} req.Data = output return @@ -850,22 +812,19 @@ func (c *InputService9ProtocolTest) InputService9TestCaseOperation2(input *Input return out, err } -var opInputService9TestCaseOperation2 *aws.Operation +const opInputService9TestCaseOperation3 = "OperationName" // InputService9TestCaseOperation3Request generates a request for the InputService9TestCaseOperation3 operation. func (c *InputService9ProtocolTest) InputService9TestCaseOperation3Request(input *InputService9TestShapeInputShape) (req *aws.Request, output *InputService9TestShapeInputService9TestCaseOperation3Output) { - - if opInputService9TestCaseOperation3 == nil { - opInputService9TestCaseOperation3 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService9TestCaseOperation3, } if input == nil { input = &InputService9TestShapeInputShape{} } - req = c.newRequest(opInputService9TestCaseOperation3, input, output) + req = c.newRequest(op, input, output) output = &InputService9TestShapeInputService9TestCaseOperation3Output{} req.Data = output return @@ -877,22 +836,19 @@ func (c *InputService9ProtocolTest) InputService9TestCaseOperation3(input *Input return out, err } -var opInputService9TestCaseOperation3 *aws.Operation +const opInputService9TestCaseOperation4 = "OperationName" // InputService9TestCaseOperation4Request generates a request for the InputService9TestCaseOperation4 operation. func (c *InputService9ProtocolTest) InputService9TestCaseOperation4Request(input *InputService9TestShapeInputShape) (req *aws.Request, output *InputService9TestShapeInputService9TestCaseOperation4Output) { - - if opInputService9TestCaseOperation4 == nil { - opInputService9TestCaseOperation4 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService9TestCaseOperation4, } if input == nil { input = &InputService9TestShapeInputShape{} } - req = c.newRequest(opInputService9TestCaseOperation4, input, output) + req = c.newRequest(op, input, output) output = &InputService9TestShapeInputService9TestCaseOperation4Output{} req.Data = output return @@ -904,22 +860,19 @@ func (c *InputService9ProtocolTest) InputService9TestCaseOperation4(input *Input return out, err } -var opInputService9TestCaseOperation4 *aws.Operation +const opInputService9TestCaseOperation5 = "OperationName" // InputService9TestCaseOperation5Request generates a request for the InputService9TestCaseOperation5 operation. func (c *InputService9ProtocolTest) InputService9TestCaseOperation5Request(input *InputService9TestShapeInputShape) (req *aws.Request, output *InputService9TestShapeInputService9TestCaseOperation5Output) { - - if opInputService9TestCaseOperation5 == nil { - opInputService9TestCaseOperation5 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService9TestCaseOperation5, } if input == nil { input = &InputService9TestShapeInputShape{} } - req = c.newRequest(opInputService9TestCaseOperation5, input, output) + req = c.newRequest(op, input, output) output = &InputService9TestShapeInputService9TestCaseOperation5Output{} req.Data = output return @@ -931,22 +884,19 @@ func (c *InputService9ProtocolTest) InputService9TestCaseOperation5(input *Input return out, err } -var opInputService9TestCaseOperation5 *aws.Operation +const opInputService9TestCaseOperation6 = "OperationName" // InputService9TestCaseOperation6Request generates a request for the InputService9TestCaseOperation6 operation. func (c *InputService9ProtocolTest) InputService9TestCaseOperation6Request(input *InputService9TestShapeInputShape) (req *aws.Request, output *InputService9TestShapeInputService9TestCaseOperation6Output) { - - if opInputService9TestCaseOperation6 == nil { - opInputService9TestCaseOperation6 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opInputService9TestCaseOperation6, } if input == nil { input = &InputService9TestShapeInputShape{} } - req = c.newRequest(opInputService9TestCaseOperation6, input, output) + req = c.newRequest(op, input, output) output = &InputService9TestShapeInputService9TestCaseOperation6Output{} req.Data = output return @@ -958,8 +908,6 @@ func (c *InputService9ProtocolTest) InputService9TestCaseOperation6(input *Input return out, err } -var opInputService9TestCaseOperation6 *aws.Operation - type InputService9TestShapeInputService9TestCaseOperation1Output struct { metadataInputService9TestShapeInputService9TestCaseOperation1Output `json:"-" xml:"-"` } @@ -1442,10 +1390,10 @@ func TestInputService9ProtocolTestRecursiveShapesCase4(t *testing.T) { input := &InputService9TestShapeInputShape{ RecursiveStruct: &InputService9TestShapeRecursiveStructType{ RecursiveList: []*InputService9TestShapeRecursiveStructType{ - &InputService9TestShapeRecursiveStructType{ + { NoRecurse: aws.String("foo"), }, - &InputService9TestShapeRecursiveStructType{ + { NoRecurse: aws.String("bar"), }, }, @@ -1477,10 +1425,10 @@ func TestInputService9ProtocolTestRecursiveShapesCase5(t *testing.T) { input := &InputService9TestShapeInputShape{ RecursiveStruct: &InputService9TestShapeRecursiveStructType{ RecursiveList: []*InputService9TestShapeRecursiveStructType{ - &InputService9TestShapeRecursiveStructType{ + { NoRecurse: aws.String("foo"), }, - &InputService9TestShapeRecursiveStructType{ + { RecursiveStruct: &InputService9TestShapeRecursiveStructType{ NoRecurse: aws.String("bar"), }, @@ -1514,10 +1462,10 @@ func TestInputService9ProtocolTestRecursiveShapesCase6(t *testing.T) { input := &InputService9TestShapeInputShape{ RecursiveStruct: &InputService9TestShapeRecursiveStructType{ RecursiveMap: map[string]*InputService9TestShapeRecursiveStructType{ - "bar": &InputService9TestShapeRecursiveStructType{ + "bar": { NoRecurse: aws.String("bar"), }, - "foo": &InputService9TestShapeRecursiveStructType{ + "foo": { NoRecurse: aws.String("foo"), }, }, diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal.go index 8acdd2274c..e8cfa926b6 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal.go @@ -6,7 +6,7 @@ import ( "encoding/xml" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" ) @@ -17,7 +17,7 @@ func Unmarshal(r *aws.Request) { decoder := xml.NewDecoder(r.HTTPResponse.Body) err := xmlutil.UnmarshalXML(r.Data, decoder, r.Operation.Name+"Result") if err != nil { - r.Error = apierr.New("Unmarshal", "failed decoding Query response", err) + r.Error = awserr.New("SerializationError", "failed decoding Query response", err) return } } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal_error.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal_error.go index deb529524a..d88ee33580 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal_error.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal_error.go @@ -5,7 +5,7 @@ import ( "io" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" ) type xmlErrorResponse struct { @@ -22,10 +22,10 @@ func UnmarshalError(r *aws.Request) { resp := &xmlErrorResponse{} err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp) if err != nil && err != io.EOF { - r.Error = apierr.New("Unmarshal", "failed to decode query XML error response", err) + r.Error = awserr.New("SerializationError", "failed to decode query XML error response", err) } else { - r.Error = apierr.NewRequestError( - apierr.New(resp.Code, resp.Message, nil), + r.Error = awserr.NewRequestFailure( + awserr.New(resp.Code, resp.Message, nil), r.HTTPResponse.StatusCode, resp.RequestID, ) diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal_test.go index a17f56ccd5..924d3d4e85 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/query/unmarshal_test.go @@ -1,10 +1,6 @@ package query_test import ( - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/protocol/query" - "github.com/aws/aws-sdk-go/internal/signer/v4" - "bytes" "encoding/json" "encoding/xml" @@ -15,7 +11,10 @@ import ( "testing" "time" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/internal/protocol/query" "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" + "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" "github.com/stretchr/testify/assert" ) @@ -63,20 +62,19 @@ func (c *OutputService1ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService1TestCaseOperation1 = "OperationName" + // OutputService1TestCaseOperation1Request generates a request for the OutputService1TestCaseOperation1 operation. func (c *OutputService1ProtocolTest) OutputService1TestCaseOperation1Request(input *OutputService1TestShapeOutputService1TestCaseOperation1Input) (req *aws.Request, output *OutputService1TestShapeOutputShape) { - - if opOutputService1TestCaseOperation1 == nil { - opOutputService1TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService1TestCaseOperation1, } if input == nil { input = &OutputService1TestShapeOutputService1TestCaseOperation1Input{} } - req = c.newRequest(opOutputService1TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService1TestShapeOutputShape{} req.Data = output return @@ -88,8 +86,6 @@ func (c *OutputService1ProtocolTest) OutputService1TestCaseOperation1(input *Out return out, err } -var opOutputService1TestCaseOperation1 *aws.Operation - type OutputService1TestShapeOutputService1TestCaseOperation1Input struct { metadataOutputService1TestShapeOutputService1TestCaseOperation1Input `json:"-" xml:"-"` } @@ -156,20 +152,19 @@ func (c *OutputService2ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService2TestCaseOperation1 = "OperationName" + // OutputService2TestCaseOperation1Request generates a request for the OutputService2TestCaseOperation1 operation. func (c *OutputService2ProtocolTest) OutputService2TestCaseOperation1Request(input *OutputService2TestShapeOutputService2TestCaseOperation1Input) (req *aws.Request, output *OutputService2TestShapeOutputShape) { - - if opOutputService2TestCaseOperation1 == nil { - opOutputService2TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService2TestCaseOperation1, } if input == nil { input = &OutputService2TestShapeOutputService2TestCaseOperation1Input{} } - req = c.newRequest(opOutputService2TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService2TestShapeOutputShape{} req.Data = output return @@ -181,8 +176,6 @@ func (c *OutputService2ProtocolTest) OutputService2TestCaseOperation1(input *Out return out, err } -var opOutputService2TestCaseOperation1 *aws.Operation - type OutputService2TestShapeOutputService2TestCaseOperation1Input struct { metadataOutputService2TestShapeOutputService2TestCaseOperation1Input `json:"-" xml:"-"` } @@ -235,20 +228,19 @@ func (c *OutputService3ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService3TestCaseOperation1 = "OperationName" + // OutputService3TestCaseOperation1Request generates a request for the OutputService3TestCaseOperation1 operation. func (c *OutputService3ProtocolTest) OutputService3TestCaseOperation1Request(input *OutputService3TestShapeOutputService3TestCaseOperation1Input) (req *aws.Request, output *OutputService3TestShapeOutputShape) { - - if opOutputService3TestCaseOperation1 == nil { - opOutputService3TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService3TestCaseOperation1, } if input == nil { input = &OutputService3TestShapeOutputService3TestCaseOperation1Input{} } - req = c.newRequest(opOutputService3TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService3TestShapeOutputShape{} req.Data = output return @@ -260,8 +252,6 @@ func (c *OutputService3ProtocolTest) OutputService3TestCaseOperation1(input *Out return out, err } -var opOutputService3TestCaseOperation1 *aws.Operation - type OutputService3TestShapeOutputService3TestCaseOperation1Input struct { metadataOutputService3TestShapeOutputService3TestCaseOperation1Input `json:"-" xml:"-"` } @@ -312,20 +302,19 @@ func (c *OutputService4ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService4TestCaseOperation1 = "OperationName" + // OutputService4TestCaseOperation1Request generates a request for the OutputService4TestCaseOperation1 operation. func (c *OutputService4ProtocolTest) OutputService4TestCaseOperation1Request(input *OutputService4TestShapeOutputService4TestCaseOperation1Input) (req *aws.Request, output *OutputService4TestShapeOutputShape) { - - if opOutputService4TestCaseOperation1 == nil { - opOutputService4TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService4TestCaseOperation1, } if input == nil { input = &OutputService4TestShapeOutputService4TestCaseOperation1Input{} } - req = c.newRequest(opOutputService4TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService4TestShapeOutputShape{} req.Data = output return @@ -337,8 +326,6 @@ func (c *OutputService4ProtocolTest) OutputService4TestCaseOperation1(input *Out return out, err } -var opOutputService4TestCaseOperation1 *aws.Operation - type OutputService4TestShapeOutputService4TestCaseOperation1Input struct { metadataOutputService4TestShapeOutputService4TestCaseOperation1Input `json:"-" xml:"-"` } @@ -389,20 +376,19 @@ func (c *OutputService5ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService5TestCaseOperation1 = "OperationName" + // OutputService5TestCaseOperation1Request generates a request for the OutputService5TestCaseOperation1 operation. func (c *OutputService5ProtocolTest) OutputService5TestCaseOperation1Request(input *OutputService5TestShapeOutputService5TestCaseOperation1Input) (req *aws.Request, output *OutputService5TestShapeOutputShape) { - - if opOutputService5TestCaseOperation1 == nil { - opOutputService5TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService5TestCaseOperation1, } if input == nil { input = &OutputService5TestShapeOutputService5TestCaseOperation1Input{} } - req = c.newRequest(opOutputService5TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService5TestShapeOutputShape{} req.Data = output return @@ -414,8 +400,6 @@ func (c *OutputService5ProtocolTest) OutputService5TestCaseOperation1(input *Out return out, err } -var opOutputService5TestCaseOperation1 *aws.Operation - type OutputService5TestShapeOutputService5TestCaseOperation1Input struct { metadataOutputService5TestShapeOutputService5TestCaseOperation1Input `json:"-" xml:"-"` } @@ -466,20 +450,19 @@ func (c *OutputService6ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService6TestCaseOperation1 = "OperationName" + // OutputService6TestCaseOperation1Request generates a request for the OutputService6TestCaseOperation1 operation. func (c *OutputService6ProtocolTest) OutputService6TestCaseOperation1Request(input *OutputService6TestShapeOutputService6TestCaseOperation1Input) (req *aws.Request, output *OutputService6TestShapeOutputShape) { - - if opOutputService6TestCaseOperation1 == nil { - opOutputService6TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService6TestCaseOperation1, } if input == nil { input = &OutputService6TestShapeOutputService6TestCaseOperation1Input{} } - req = c.newRequest(opOutputService6TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService6TestShapeOutputShape{} req.Data = output return @@ -491,8 +474,6 @@ func (c *OutputService6ProtocolTest) OutputService6TestCaseOperation1(input *Out return out, err } -var opOutputService6TestCaseOperation1 *aws.Operation - type OutputService6TestShapeOutputService6TestCaseOperation1Input struct { metadataOutputService6TestShapeOutputService6TestCaseOperation1Input `json:"-" xml:"-"` } @@ -543,20 +524,19 @@ func (c *OutputService7ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService7TestCaseOperation1 = "OperationName" + // OutputService7TestCaseOperation1Request generates a request for the OutputService7TestCaseOperation1 operation. func (c *OutputService7ProtocolTest) OutputService7TestCaseOperation1Request(input *OutputService7TestShapeOutputService7TestCaseOperation1Input) (req *aws.Request, output *OutputService7TestShapeOutputShape) { - - if opOutputService7TestCaseOperation1 == nil { - opOutputService7TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService7TestCaseOperation1, } if input == nil { input = &OutputService7TestShapeOutputService7TestCaseOperation1Input{} } - req = c.newRequest(opOutputService7TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService7TestShapeOutputShape{} req.Data = output return @@ -568,8 +548,6 @@ func (c *OutputService7ProtocolTest) OutputService7TestCaseOperation1(input *Out return out, err } -var opOutputService7TestCaseOperation1 *aws.Operation - type OutputService7TestShapeOutputService7TestCaseOperation1Input struct { metadataOutputService7TestShapeOutputService7TestCaseOperation1Input `json:"-" xml:"-"` } @@ -620,20 +598,19 @@ func (c *OutputService8ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService8TestCaseOperation1 = "OperationName" + // OutputService8TestCaseOperation1Request generates a request for the OutputService8TestCaseOperation1 operation. func (c *OutputService8ProtocolTest) OutputService8TestCaseOperation1Request(input *OutputService8TestShapeOutputService8TestCaseOperation1Input) (req *aws.Request, output *OutputService8TestShapeOutputShape) { - - if opOutputService8TestCaseOperation1 == nil { - opOutputService8TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService8TestCaseOperation1, } if input == nil { input = &OutputService8TestShapeOutputService8TestCaseOperation1Input{} } - req = c.newRequest(opOutputService8TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService8TestShapeOutputShape{} req.Data = output return @@ -645,8 +622,6 @@ func (c *OutputService8ProtocolTest) OutputService8TestCaseOperation1(input *Out return out, err } -var opOutputService8TestCaseOperation1 *aws.Operation - type OutputService8TestShapeOutputService8TestCaseOperation1Input struct { metadataOutputService8TestShapeOutputService8TestCaseOperation1Input `json:"-" xml:"-"` } @@ -711,20 +686,19 @@ func (c *OutputService9ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService9TestCaseOperation1 = "OperationName" + // OutputService9TestCaseOperation1Request generates a request for the OutputService9TestCaseOperation1 operation. func (c *OutputService9ProtocolTest) OutputService9TestCaseOperation1Request(input *OutputService9TestShapeOutputService9TestCaseOperation1Input) (req *aws.Request, output *OutputService9TestShapeOutputShape) { - - if opOutputService9TestCaseOperation1 == nil { - opOutputService9TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService9TestCaseOperation1, } if input == nil { input = &OutputService9TestShapeOutputService9TestCaseOperation1Input{} } - req = c.newRequest(opOutputService9TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService9TestShapeOutputShape{} req.Data = output return @@ -736,8 +710,6 @@ func (c *OutputService9ProtocolTest) OutputService9TestCaseOperation1(input *Out return out, err } -var opOutputService9TestCaseOperation1 *aws.Operation - type OutputService9TestShapeOutputService9TestCaseOperation1Input struct { metadataOutputService9TestShapeOutputService9TestCaseOperation1Input `json:"-" xml:"-"` } @@ -802,20 +774,19 @@ func (c *OutputService10ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService10TestCaseOperation1 = "OperationName" + // OutputService10TestCaseOperation1Request generates a request for the OutputService10TestCaseOperation1 operation. func (c *OutputService10ProtocolTest) OutputService10TestCaseOperation1Request(input *OutputService10TestShapeOutputService10TestCaseOperation1Input) (req *aws.Request, output *OutputService10TestShapeOutputShape) { - - if opOutputService10TestCaseOperation1 == nil { - opOutputService10TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService10TestCaseOperation1, } if input == nil { input = &OutputService10TestShapeOutputService10TestCaseOperation1Input{} } - req = c.newRequest(opOutputService10TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService10TestShapeOutputShape{} req.Data = output return @@ -827,8 +798,6 @@ func (c *OutputService10ProtocolTest) OutputService10TestCaseOperation1(input *O return out, err } -var opOutputService10TestCaseOperation1 *aws.Operation - type OutputService10TestShapeOutputService10TestCaseOperation1Input struct { metadataOutputService10TestShapeOutputService10TestCaseOperation1Input `json:"-" xml:"-"` } @@ -879,20 +848,19 @@ func (c *OutputService11ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService11TestCaseOperation1 = "OperationName" + // OutputService11TestCaseOperation1Request generates a request for the OutputService11TestCaseOperation1 operation. func (c *OutputService11ProtocolTest) OutputService11TestCaseOperation1Request(input *OutputService11TestShapeOutputService11TestCaseOperation1Input) (req *aws.Request, output *OutputService11TestShapeOutputShape) { - - if opOutputService11TestCaseOperation1 == nil { - opOutputService11TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService11TestCaseOperation1, } if input == nil { input = &OutputService11TestShapeOutputService11TestCaseOperation1Input{} } - req = c.newRequest(opOutputService11TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService11TestShapeOutputShape{} req.Data = output return @@ -904,8 +872,6 @@ func (c *OutputService11ProtocolTest) OutputService11TestCaseOperation1(input *O return out, err } -var opOutputService11TestCaseOperation1 *aws.Operation - type OutputService11TestShapeOutputService11TestCaseOperation1Input struct { metadataOutputService11TestShapeOutputService11TestCaseOperation1Input `json:"-" xml:"-"` } @@ -966,20 +932,19 @@ func (c *OutputService12ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService12TestCaseOperation1 = "OperationName" + // OutputService12TestCaseOperation1Request generates a request for the OutputService12TestCaseOperation1 operation. func (c *OutputService12ProtocolTest) OutputService12TestCaseOperation1Request(input *OutputService12TestShapeOutputService12TestCaseOperation1Input) (req *aws.Request, output *OutputService12TestShapeOutputShape) { - - if opOutputService12TestCaseOperation1 == nil { - opOutputService12TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService12TestCaseOperation1, } if input == nil { input = &OutputService12TestShapeOutputService12TestCaseOperation1Input{} } - req = c.newRequest(opOutputService12TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService12TestShapeOutputShape{} req.Data = output return @@ -991,8 +956,6 @@ func (c *OutputService12ProtocolTest) OutputService12TestCaseOperation1(input *O return out, err } -var opOutputService12TestCaseOperation1 *aws.Operation - type OutputService12TestShapeOutputService12TestCaseOperation1Input struct { metadataOutputService12TestShapeOutputService12TestCaseOperation1Input `json:"-" xml:"-"` } @@ -1043,20 +1006,19 @@ func (c *OutputService13ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService13TestCaseOperation1 = "OperationName" + // OutputService13TestCaseOperation1Request generates a request for the OutputService13TestCaseOperation1 operation. func (c *OutputService13ProtocolTest) OutputService13TestCaseOperation1Request(input *OutputService13TestShapeOutputService13TestCaseOperation1Input) (req *aws.Request, output *OutputService13TestShapeOutputShape) { - - if opOutputService13TestCaseOperation1 == nil { - opOutputService13TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService13TestCaseOperation1, } if input == nil { input = &OutputService13TestShapeOutputService13TestCaseOperation1Input{} } - req = c.newRequest(opOutputService13TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService13TestShapeOutputShape{} req.Data = output return @@ -1068,8 +1030,6 @@ func (c *OutputService13ProtocolTest) OutputService13TestCaseOperation1(input *O return out, err } -var opOutputService13TestCaseOperation1 *aws.Operation - type OutputService13TestShapeOutputService13TestCaseOperation1Input struct { metadataOutputService13TestShapeOutputService13TestCaseOperation1Input `json:"-" xml:"-"` } @@ -1120,20 +1080,19 @@ func (c *OutputService14ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService14TestCaseOperation1 = "OperationName" + // OutputService14TestCaseOperation1Request generates a request for the OutputService14TestCaseOperation1 operation. func (c *OutputService14ProtocolTest) OutputService14TestCaseOperation1Request(input *OutputService14TestShapeOutputService14TestCaseOperation1Input) (req *aws.Request, output *OutputService14TestShapeOutputShape) { - - if opOutputService14TestCaseOperation1 == nil { - opOutputService14TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService14TestCaseOperation1, } if input == nil { input = &OutputService14TestShapeOutputService14TestCaseOperation1Input{} } - req = c.newRequest(opOutputService14TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService14TestShapeOutputShape{} req.Data = output return @@ -1145,8 +1104,6 @@ func (c *OutputService14ProtocolTest) OutputService14TestCaseOperation1(input *O return out, err } -var opOutputService14TestCaseOperation1 *aws.Operation - type OutputService14TestShapeOutputService14TestCaseOperation1Input struct { metadataOutputService14TestShapeOutputService14TestCaseOperation1Input `json:"-" xml:"-"` } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/rest/build.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/rest/build.go index aa5493849f..cd5eef2351 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/rest/build.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/rest/build.go @@ -1,3 +1,4 @@ +// Package rest provides RESTful serialisation of AWS requests and responses. package rest import ( @@ -13,7 +14,7 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" ) // RFC822 returns an RFC822 formatted timestamp for AWS protocols @@ -101,7 +102,7 @@ func buildBody(r *aws.Request, v reflect.Value) { case string: r.SetStringBody(reader) default: - r.Error = apierr.New("Marshal", + r.Error = awserr.New("SerializationError", "failed to encode REST request", fmt.Errorf("unknown payload type %s", payload.Type())) } @@ -114,7 +115,7 @@ func buildBody(r *aws.Request, v reflect.Value) { func buildHeader(r *aws.Request, v reflect.Value, name string) { str, err := convertType(v) if err != nil { - r.Error = apierr.New("Marshal", "failed to encode REST request", err) + r.Error = awserr.New("SerializationError", "failed to encode REST request", err) } else if str != nil { r.HTTPRequest.Header.Add(name, *str) } @@ -124,7 +125,7 @@ func buildHeaderMap(r *aws.Request, v reflect.Value, prefix string) { for _, key := range v.MapKeys() { str, err := convertType(v.MapIndex(key)) if err != nil { - r.Error = apierr.New("Marshal", "failed to encode REST request", err) + r.Error = awserr.New("SerializationError", "failed to encode REST request", err) } else if str != nil { r.HTTPRequest.Header.Add(prefix+key.String(), *str) } @@ -134,7 +135,7 @@ func buildHeaderMap(r *aws.Request, v reflect.Value, prefix string) { func buildURI(r *aws.Request, v reflect.Value, name string) { value, err := convertType(v) if err != nil { - r.Error = apierr.New("Marshal", "failed to encode REST request", err) + r.Error = awserr.New("SerializationError", "failed to encode REST request", err) } else if value != nil { uri := r.HTTPRequest.URL.Path uri = strings.Replace(uri, "{"+name+"}", EscapePath(*value, true), -1) @@ -146,7 +147,7 @@ func buildURI(r *aws.Request, v reflect.Value, name string) { func buildQueryString(r *aws.Request, v reflect.Value, name string, query url.Values) { str, err := convertType(v) if err != nil { - r.Error = apierr.New("Marshal", "failed to encode REST request", err) + r.Error = awserr.New("SerializationError", "failed to encode REST request", err) } else if str != nil { query.Set(name, *str) } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/rest/unmarshal.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/rest/unmarshal.go index 009c5c9509..a4155f1669 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/rest/unmarshal.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/rest/unmarshal.go @@ -11,7 +11,7 @@ import ( "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" ) // Unmarshal unmarshals the REST component of a response in a REST service. @@ -34,14 +34,14 @@ func unmarshalBody(r *aws.Request, v reflect.Value) { case []byte: b, err := ioutil.ReadAll(r.HTTPResponse.Body) if err != nil { - r.Error = apierr.New("Unmarshal", "failed to decode REST response", err) + r.Error = awserr.New("SerializationError", "failed to decode REST response", err) } else { payload.Set(reflect.ValueOf(b)) } case *string: b, err := ioutil.ReadAll(r.HTTPResponse.Body) if err != nil { - r.Error = apierr.New("Unmarshal", "failed to decode REST response", err) + r.Error = awserr.New("SerializationError", "failed to decode REST response", err) } else { str := string(b) payload.Set(reflect.ValueOf(&str)) @@ -53,7 +53,7 @@ func unmarshalBody(r *aws.Request, v reflect.Value) { case "aws.ReadSeekCloser", "io.ReadCloser": payload.Set(reflect.ValueOf(r.HTTPResponse.Body)) default: - r.Error = apierr.New("Unmarshal", + r.Error = awserr.New("SerializationError", "failed to decode REST response", fmt.Errorf("unknown payload type %s", payload.Type())) } @@ -83,14 +83,14 @@ func unmarshalLocationElements(r *aws.Request, v reflect.Value) { case "header": err := unmarshalHeader(m, r.HTTPResponse.Header.Get(name)) if err != nil { - r.Error = apierr.New("Unmarshal", "failed to decode REST response", err) + r.Error = awserr.New("SerializationError", "failed to decode REST response", err) break } case "headers": prefix := field.Tag.Get("locationName") err := unmarshalHeaderMap(m, r.HTTPResponse.Header, prefix) if err != nil { - r.Error = apierr.New("Unmarshal", "failed to decode REST response", err) + r.Error = awserr.New("SerializationError", "failed to decode REST response", err) break } } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/build_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/build_test.go index 17c0d91cc3..6fcd3f8dc9 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/build_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/build_test.go @@ -1,10 +1,6 @@ package restxml_test import ( - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/protocol/restxml" - "github.com/aws/aws-sdk-go/internal/signer/v4" - "bytes" "encoding/json" "encoding/xml" @@ -15,7 +11,10 @@ import ( "testing" "time" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/internal/protocol/restxml" "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" + "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" "github.com/stretchr/testify/assert" ) @@ -63,22 +62,21 @@ func (c *InputService1ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService1TestCaseOperation1 = "OperationName" + // InputService1TestCaseOperation1Request generates a request for the InputService1TestCaseOperation1 operation. func (c *InputService1ProtocolTest) InputService1TestCaseOperation1Request(input *InputService1TestShapeInputShape) (req *aws.Request, output *InputService1TestShapeInputService1TestCaseOperation1Output) { - - if opInputService1TestCaseOperation1 == nil { - opInputService1TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/2014-01-01/hostedzone", - } + op := &aws.Operation{ + Name: opInputService1TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/2014-01-01/hostedzone", } if input == nil { input = &InputService1TestShapeInputShape{} } - req = c.newRequest(opInputService1TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService1TestShapeInputService1TestCaseOperation1Output{} req.Data = output return @@ -90,24 +88,21 @@ func (c *InputService1ProtocolTest) InputService1TestCaseOperation1(input *Input return out, err } -var opInputService1TestCaseOperation1 *aws.Operation +const opInputService1TestCaseOperation2 = "OperationName" // InputService1TestCaseOperation2Request generates a request for the InputService1TestCaseOperation2 operation. func (c *InputService1ProtocolTest) InputService1TestCaseOperation2Request(input *InputService1TestShapeInputShape) (req *aws.Request, output *InputService1TestShapeInputService1TestCaseOperation2Output) { - - if opInputService1TestCaseOperation2 == nil { - opInputService1TestCaseOperation2 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "PUT", - HTTPPath: "/2014-01-01/hostedzone", - } + op := &aws.Operation{ + Name: opInputService1TestCaseOperation2, + HTTPMethod: "PUT", + HTTPPath: "/2014-01-01/hostedzone", } if input == nil { input = &InputService1TestShapeInputShape{} } - req = c.newRequest(opInputService1TestCaseOperation2, input, output) + req = c.newRequest(op, input, output) output = &InputService1TestShapeInputService1TestCaseOperation2Output{} req.Data = output return @@ -119,8 +114,6 @@ func (c *InputService1ProtocolTest) InputService1TestCaseOperation2(input *Input return out, err } -var opInputService1TestCaseOperation2 *aws.Operation - type InputService1TestShapeInputService1TestCaseOperation1Output struct { metadataInputService1TestShapeInputService1TestCaseOperation1Output `json:"-" xml:"-"` } @@ -181,22 +174,21 @@ func (c *InputService2ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService2TestCaseOperation1 = "OperationName" + // InputService2TestCaseOperation1Request generates a request for the InputService2TestCaseOperation1 operation. func (c *InputService2ProtocolTest) InputService2TestCaseOperation1Request(input *InputService2TestShapeInputShape) (req *aws.Request, output *InputService2TestShapeInputService2TestCaseOperation1Output) { - - if opInputService2TestCaseOperation1 == nil { - opInputService2TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/2014-01-01/hostedzone", - } + op := &aws.Operation{ + Name: opInputService2TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/2014-01-01/hostedzone", } if input == nil { input = &InputService2TestShapeInputShape{} } - req = c.newRequest(opInputService2TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService2TestShapeInputService2TestCaseOperation1Output{} req.Data = output return @@ -208,8 +200,6 @@ func (c *InputService2ProtocolTest) InputService2TestCaseOperation1(input *Input return out, err } -var opInputService2TestCaseOperation1 *aws.Operation - type InputService2TestShapeInputService2TestCaseOperation1Output struct { metadataInputService2TestShapeInputService2TestCaseOperation1Output `json:"-" xml:"-"` } @@ -266,22 +256,21 @@ func (c *InputService3ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService3TestCaseOperation1 = "OperationName" + // InputService3TestCaseOperation1Request generates a request for the InputService3TestCaseOperation1 operation. func (c *InputService3ProtocolTest) InputService3TestCaseOperation1Request(input *InputService3TestShapeInputShape) (req *aws.Request, output *InputService3TestShapeInputService3TestCaseOperation1Output) { - - if opInputService3TestCaseOperation1 == nil { - opInputService3TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/2014-01-01/hostedzone", - } + op := &aws.Operation{ + Name: opInputService3TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/2014-01-01/hostedzone", } if input == nil { input = &InputService3TestShapeInputShape{} } - req = c.newRequest(opInputService3TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService3TestShapeInputService3TestCaseOperation1Output{} req.Data = output return @@ -293,8 +282,6 @@ func (c *InputService3ProtocolTest) InputService3TestCaseOperation1(input *Input return out, err } -var opInputService3TestCaseOperation1 *aws.Operation - type InputService3TestShapeInputService3TestCaseOperation1Output struct { metadataInputService3TestShapeInputService3TestCaseOperation1Output `json:"-" xml:"-"` } @@ -359,22 +346,21 @@ func (c *InputService4ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService4TestCaseOperation1 = "OperationName" + // InputService4TestCaseOperation1Request generates a request for the InputService4TestCaseOperation1 operation. func (c *InputService4ProtocolTest) InputService4TestCaseOperation1Request(input *InputService4TestShapeInputShape) (req *aws.Request, output *InputService4TestShapeInputService4TestCaseOperation1Output) { - - if opInputService4TestCaseOperation1 == nil { - opInputService4TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/2014-01-01/hostedzone", - } + op := &aws.Operation{ + Name: opInputService4TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/2014-01-01/hostedzone", } if input == nil { input = &InputService4TestShapeInputShape{} } - req = c.newRequest(opInputService4TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService4TestShapeInputService4TestCaseOperation1Output{} req.Data = output return @@ -386,8 +372,6 @@ func (c *InputService4ProtocolTest) InputService4TestCaseOperation1(input *Input return out, err } -var opInputService4TestCaseOperation1 *aws.Operation - type InputService4TestShapeInputService4TestCaseOperation1Output struct { metadataInputService4TestShapeInputService4TestCaseOperation1Output `json:"-" xml:"-"` } @@ -452,22 +436,21 @@ func (c *InputService5ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService5TestCaseOperation1 = "OperationName" + // InputService5TestCaseOperation1Request generates a request for the InputService5TestCaseOperation1 operation. func (c *InputService5ProtocolTest) InputService5TestCaseOperation1Request(input *InputService5TestShapeInputShape) (req *aws.Request, output *InputService5TestShapeInputService5TestCaseOperation1Output) { - - if opInputService5TestCaseOperation1 == nil { - opInputService5TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/2014-01-01/hostedzone", - } + op := &aws.Operation{ + Name: opInputService5TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/2014-01-01/hostedzone", } if input == nil { input = &InputService5TestShapeInputShape{} } - req = c.newRequest(opInputService5TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService5TestShapeInputService5TestCaseOperation1Output{} req.Data = output return @@ -479,8 +462,6 @@ func (c *InputService5ProtocolTest) InputService5TestCaseOperation1(input *Input return out, err } -var opInputService5TestCaseOperation1 *aws.Operation - type InputService5TestShapeInputService5TestCaseOperation1Output struct { metadataInputService5TestShapeInputService5TestCaseOperation1Output `json:"-" xml:"-"` } @@ -531,22 +512,21 @@ func (c *InputService6ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService6TestCaseOperation1 = "OperationName" + // InputService6TestCaseOperation1Request generates a request for the InputService6TestCaseOperation1 operation. func (c *InputService6ProtocolTest) InputService6TestCaseOperation1Request(input *InputService6TestShapeInputShape) (req *aws.Request, output *InputService6TestShapeInputService6TestCaseOperation1Output) { - - if opInputService6TestCaseOperation1 == nil { - opInputService6TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/2014-01-01/hostedzone", - } + op := &aws.Operation{ + Name: opInputService6TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/2014-01-01/hostedzone", } if input == nil { input = &InputService6TestShapeInputShape{} } - req = c.newRequest(opInputService6TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService6TestShapeInputService6TestCaseOperation1Output{} req.Data = output return @@ -558,8 +538,6 @@ func (c *InputService6ProtocolTest) InputService6TestCaseOperation1(input *Input return out, err } -var opInputService6TestCaseOperation1 *aws.Operation - type InputService6TestShapeInputService6TestCaseOperation1Output struct { metadataInputService6TestShapeInputService6TestCaseOperation1Output `json:"-" xml:"-"` } @@ -610,22 +588,21 @@ func (c *InputService7ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService7TestCaseOperation1 = "OperationName" + // InputService7TestCaseOperation1Request generates a request for the InputService7TestCaseOperation1 operation. func (c *InputService7ProtocolTest) InputService7TestCaseOperation1Request(input *InputService7TestShapeInputShape) (req *aws.Request, output *InputService7TestShapeInputService7TestCaseOperation1Output) { - - if opInputService7TestCaseOperation1 == nil { - opInputService7TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/2014-01-01/hostedzone", - } + op := &aws.Operation{ + Name: opInputService7TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/2014-01-01/hostedzone", } if input == nil { input = &InputService7TestShapeInputShape{} } - req = c.newRequest(opInputService7TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService7TestShapeInputService7TestCaseOperation1Output{} req.Data = output return @@ -637,8 +614,6 @@ func (c *InputService7ProtocolTest) InputService7TestCaseOperation1(input *Input return out, err } -var opInputService7TestCaseOperation1 *aws.Operation - type InputService7TestShapeInputService7TestCaseOperation1Output struct { metadataInputService7TestShapeInputService7TestCaseOperation1Output `json:"-" xml:"-"` } @@ -689,22 +664,21 @@ func (c *InputService8ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService8TestCaseOperation1 = "OperationName" + // InputService8TestCaseOperation1Request generates a request for the InputService8TestCaseOperation1 operation. func (c *InputService8ProtocolTest) InputService8TestCaseOperation1Request(input *InputService8TestShapeInputShape) (req *aws.Request, output *InputService8TestShapeInputService8TestCaseOperation1Output) { - - if opInputService8TestCaseOperation1 == nil { - opInputService8TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/2014-01-01/hostedzone", - } + op := &aws.Operation{ + Name: opInputService8TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/2014-01-01/hostedzone", } if input == nil { input = &InputService8TestShapeInputShape{} } - req = c.newRequest(opInputService8TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService8TestShapeInputService8TestCaseOperation1Output{} req.Data = output return @@ -716,8 +690,6 @@ func (c *InputService8ProtocolTest) InputService8TestCaseOperation1(input *Input return out, err } -var opInputService8TestCaseOperation1 *aws.Operation - type InputService8TestShapeInputService8TestCaseOperation1Output struct { metadataInputService8TestShapeInputService8TestCaseOperation1Output `json:"-" xml:"-"` } @@ -768,22 +740,21 @@ func (c *InputService9ProtocolTest) newRequest(op *aws.Operation, params, data i return req } +const opInputService9TestCaseOperation1 = "OperationName" + // InputService9TestCaseOperation1Request generates a request for the InputService9TestCaseOperation1 operation. func (c *InputService9ProtocolTest) InputService9TestCaseOperation1Request(input *InputService9TestShapeInputShape) (req *aws.Request, output *InputService9TestShapeInputService9TestCaseOperation1Output) { - - if opInputService9TestCaseOperation1 == nil { - opInputService9TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/2014-01-01/hostedzone", - } + op := &aws.Operation{ + Name: opInputService9TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/2014-01-01/hostedzone", } if input == nil { input = &InputService9TestShapeInputShape{} } - req = c.newRequest(opInputService9TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService9TestShapeInputService9TestCaseOperation1Output{} req.Data = output return @@ -795,8 +766,6 @@ func (c *InputService9ProtocolTest) InputService9TestCaseOperation1(input *Input return out, err } -var opInputService9TestCaseOperation1 *aws.Operation - type InputService9TestShapeInputService9TestCaseOperation1Output struct { metadataInputService9TestShapeInputService9TestCaseOperation1Output `json:"-" xml:"-"` } @@ -857,22 +826,21 @@ func (c *InputService10ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opInputService10TestCaseOperation1 = "OperationName" + // InputService10TestCaseOperation1Request generates a request for the InputService10TestCaseOperation1 operation. func (c *InputService10ProtocolTest) InputService10TestCaseOperation1Request(input *InputService10TestShapeInputShape) (req *aws.Request, output *InputService10TestShapeInputService10TestCaseOperation1Output) { - - if opInputService10TestCaseOperation1 == nil { - opInputService10TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/2014-01-01/hostedzone", - } + op := &aws.Operation{ + Name: opInputService10TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/2014-01-01/hostedzone", } if input == nil { input = &InputService10TestShapeInputShape{} } - req = c.newRequest(opInputService10TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService10TestShapeInputService10TestCaseOperation1Output{} req.Data = output return @@ -884,8 +852,6 @@ func (c *InputService10ProtocolTest) InputService10TestCaseOperation1(input *Inp return out, err } -var opInputService10TestCaseOperation1 *aws.Operation - type InputService10TestShapeInputService10TestCaseOperation1Output struct { metadataInputService10TestShapeInputService10TestCaseOperation1Output `json:"-" xml:"-"` } @@ -948,22 +914,21 @@ func (c *InputService11ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opInputService11TestCaseOperation1 = "OperationName" + // InputService11TestCaseOperation1Request generates a request for the InputService11TestCaseOperation1 operation. func (c *InputService11ProtocolTest) InputService11TestCaseOperation1Request(input *InputService11TestShapeInputShape) (req *aws.Request, output *InputService11TestShapeInputService11TestCaseOperation1Output) { - - if opInputService11TestCaseOperation1 == nil { - opInputService11TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/", - } + op := &aws.Operation{ + Name: opInputService11TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/", } if input == nil { input = &InputService11TestShapeInputShape{} } - req = c.newRequest(opInputService11TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService11TestShapeInputService11TestCaseOperation1Output{} req.Data = output return @@ -975,8 +940,6 @@ func (c *InputService11ProtocolTest) InputService11TestCaseOperation1(input *Inp return out, err } -var opInputService11TestCaseOperation1 *aws.Operation - type InputService11TestShapeInputService11TestCaseOperation1Output struct { metadataInputService11TestShapeInputService11TestCaseOperation1Output `json:"-" xml:"-"` } @@ -1027,22 +990,21 @@ func (c *InputService12ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opInputService12TestCaseOperation1 = "OperationName" + // InputService12TestCaseOperation1Request generates a request for the InputService12TestCaseOperation1 operation. func (c *InputService12ProtocolTest) InputService12TestCaseOperation1Request(input *InputService12TestShapeInputShape) (req *aws.Request, output *InputService12TestShapeInputService12TestCaseOperation1Output) { - - if opInputService12TestCaseOperation1 == nil { - opInputService12TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/", - } + op := &aws.Operation{ + Name: opInputService12TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/", } if input == nil { input = &InputService12TestShapeInputShape{} } - req = c.newRequest(opInputService12TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService12TestShapeInputService12TestCaseOperation1Output{} req.Data = output return @@ -1054,8 +1016,6 @@ func (c *InputService12ProtocolTest) InputService12TestCaseOperation1(input *Inp return out, err } -var opInputService12TestCaseOperation1 *aws.Operation - type InputService12TestShapeInputService12TestCaseOperation1Output struct { metadataInputService12TestShapeInputService12TestCaseOperation1Output `json:"-" xml:"-"` } @@ -1106,22 +1066,21 @@ func (c *InputService13ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opInputService13TestCaseOperation1 = "OperationName" + // InputService13TestCaseOperation1Request generates a request for the InputService13TestCaseOperation1 operation. func (c *InputService13ProtocolTest) InputService13TestCaseOperation1Request(input *InputService13TestShapeInputShape) (req *aws.Request, output *InputService13TestShapeInputService13TestCaseOperation1Output) { - - if opInputService13TestCaseOperation1 == nil { - opInputService13TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/", - } + op := &aws.Operation{ + Name: opInputService13TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/", } if input == nil { input = &InputService13TestShapeInputShape{} } - req = c.newRequest(opInputService13TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService13TestShapeInputService13TestCaseOperation1Output{} req.Data = output return @@ -1133,24 +1092,21 @@ func (c *InputService13ProtocolTest) InputService13TestCaseOperation1(input *Inp return out, err } -var opInputService13TestCaseOperation1 *aws.Operation +const opInputService13TestCaseOperation2 = "OperationName" // InputService13TestCaseOperation2Request generates a request for the InputService13TestCaseOperation2 operation. func (c *InputService13ProtocolTest) InputService13TestCaseOperation2Request(input *InputService13TestShapeInputShape) (req *aws.Request, output *InputService13TestShapeInputService13TestCaseOperation2Output) { - - if opInputService13TestCaseOperation2 == nil { - opInputService13TestCaseOperation2 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/", - } + op := &aws.Operation{ + Name: opInputService13TestCaseOperation2, + HTTPMethod: "POST", + HTTPPath: "/", } if input == nil { input = &InputService13TestShapeInputShape{} } - req = c.newRequest(opInputService13TestCaseOperation2, input, output) + req = c.newRequest(op, input, output) output = &InputService13TestShapeInputService13TestCaseOperation2Output{} req.Data = output return @@ -1162,8 +1118,6 @@ func (c *InputService13ProtocolTest) InputService13TestCaseOperation2(input *Inp return out, err } -var opInputService13TestCaseOperation2 *aws.Operation - type InputService13TestShapeInputService13TestCaseOperation1Output struct { metadataInputService13TestShapeInputService13TestCaseOperation1Output `json:"-" xml:"-"` } @@ -1222,22 +1176,21 @@ func (c *InputService14ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opInputService14TestCaseOperation1 = "OperationName" + // InputService14TestCaseOperation1Request generates a request for the InputService14TestCaseOperation1 operation. func (c *InputService14ProtocolTest) InputService14TestCaseOperation1Request(input *InputService14TestShapeInputShape) (req *aws.Request, output *InputService14TestShapeInputService14TestCaseOperation1Output) { - - if opInputService14TestCaseOperation1 == nil { - opInputService14TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/", - } + op := &aws.Operation{ + Name: opInputService14TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/", } if input == nil { input = &InputService14TestShapeInputShape{} } - req = c.newRequest(opInputService14TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService14TestShapeInputService14TestCaseOperation1Output{} req.Data = output return @@ -1249,24 +1202,21 @@ func (c *InputService14ProtocolTest) InputService14TestCaseOperation1(input *Inp return out, err } -var opInputService14TestCaseOperation1 *aws.Operation +const opInputService14TestCaseOperation2 = "OperationName" // InputService14TestCaseOperation2Request generates a request for the InputService14TestCaseOperation2 operation. func (c *InputService14ProtocolTest) InputService14TestCaseOperation2Request(input *InputService14TestShapeInputShape) (req *aws.Request, output *InputService14TestShapeInputService14TestCaseOperation2Output) { - - if opInputService14TestCaseOperation2 == nil { - opInputService14TestCaseOperation2 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/", - } + op := &aws.Operation{ + Name: opInputService14TestCaseOperation2, + HTTPMethod: "POST", + HTTPPath: "/", } if input == nil { input = &InputService14TestShapeInputShape{} } - req = c.newRequest(opInputService14TestCaseOperation2, input, output) + req = c.newRequest(op, input, output) output = &InputService14TestShapeInputService14TestCaseOperation2Output{} req.Data = output return @@ -1278,24 +1228,21 @@ func (c *InputService14ProtocolTest) InputService14TestCaseOperation2(input *Inp return out, err } -var opInputService14TestCaseOperation2 *aws.Operation +const opInputService14TestCaseOperation3 = "OperationName" // InputService14TestCaseOperation3Request generates a request for the InputService14TestCaseOperation3 operation. func (c *InputService14ProtocolTest) InputService14TestCaseOperation3Request(input *InputService14TestShapeInputShape) (req *aws.Request, output *InputService14TestShapeInputService14TestCaseOperation3Output) { - - if opInputService14TestCaseOperation3 == nil { - opInputService14TestCaseOperation3 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/", - } + op := &aws.Operation{ + Name: opInputService14TestCaseOperation3, + HTTPMethod: "POST", + HTTPPath: "/", } if input == nil { input = &InputService14TestShapeInputShape{} } - req = c.newRequest(opInputService14TestCaseOperation3, input, output) + req = c.newRequest(op, input, output) output = &InputService14TestShapeInputService14TestCaseOperation3Output{} req.Data = output return @@ -1307,8 +1254,6 @@ func (c *InputService14ProtocolTest) InputService14TestCaseOperation3(input *Inp return out, err } -var opInputService14TestCaseOperation3 *aws.Operation - type InputService14TestShapeFooShape struct { Baz *string `locationName:"baz" type:"string"` @@ -1385,22 +1330,21 @@ func (c *InputService15ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opInputService15TestCaseOperation1 = "OperationName" + // InputService15TestCaseOperation1Request generates a request for the InputService15TestCaseOperation1 operation. func (c *InputService15ProtocolTest) InputService15TestCaseOperation1Request(input *InputService15TestShapeInputShape) (req *aws.Request, output *InputService15TestShapeInputService15TestCaseOperation1Output) { - - if opInputService15TestCaseOperation1 == nil { - opInputService15TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/", - } + op := &aws.Operation{ + Name: opInputService15TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/", } if input == nil { input = &InputService15TestShapeInputShape{} } - req = c.newRequest(opInputService15TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService15TestShapeInputService15TestCaseOperation1Output{} req.Data = output return @@ -1412,8 +1356,6 @@ func (c *InputService15ProtocolTest) InputService15TestCaseOperation1(input *Inp return out, err } -var opInputService15TestCaseOperation1 *aws.Operation - type InputService15TestShapeGrant struct { Grantee *InputService15TestShapeGrantee `type:"structure"` @@ -1486,22 +1428,21 @@ func (c *InputService16ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opInputService16TestCaseOperation1 = "OperationName" + // InputService16TestCaseOperation1Request generates a request for the InputService16TestCaseOperation1 operation. func (c *InputService16ProtocolTest) InputService16TestCaseOperation1Request(input *InputService16TestShapeInputShape) (req *aws.Request, output *InputService16TestShapeInputService16TestCaseOperation1Output) { - - if opInputService16TestCaseOperation1 == nil { - opInputService16TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}/{Key+}", - } + op := &aws.Operation{ + Name: opInputService16TestCaseOperation1, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}/{Key+}", } if input == nil { input = &InputService16TestShapeInputShape{} } - req = c.newRequest(opInputService16TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService16TestShapeInputService16TestCaseOperation1Output{} req.Data = output return @@ -1513,8 +1454,6 @@ func (c *InputService16ProtocolTest) InputService16TestCaseOperation1(input *Inp return out, err } -var opInputService16TestCaseOperation1 *aws.Operation - type InputService16TestShapeInputService16TestCaseOperation1Output struct { metadataInputService16TestShapeInputService16TestCaseOperation1Output `json:"-" xml:"-"` } @@ -1567,22 +1506,21 @@ func (c *InputService17ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opInputService17TestCaseOperation1 = "OperationName" + // InputService17TestCaseOperation1Request generates a request for the InputService17TestCaseOperation1 operation. func (c *InputService17ProtocolTest) InputService17TestCaseOperation1Request(input *InputService17TestShapeInputShape) (req *aws.Request, output *InputService17TestShapeInputService17TestCaseOperation1Output) { - - if opInputService17TestCaseOperation1 == nil { - opInputService17TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/path", - } + op := &aws.Operation{ + Name: opInputService17TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/path", } if input == nil { input = &InputService17TestShapeInputShape{} } - req = c.newRequest(opInputService17TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService17TestShapeInputService17TestCaseOperation1Output{} req.Data = output return @@ -1594,24 +1532,21 @@ func (c *InputService17ProtocolTest) InputService17TestCaseOperation1(input *Inp return out, err } -var opInputService17TestCaseOperation1 *aws.Operation +const opInputService17TestCaseOperation2 = "OperationName" // InputService17TestCaseOperation2Request generates a request for the InputService17TestCaseOperation2 operation. func (c *InputService17ProtocolTest) InputService17TestCaseOperation2Request(input *InputService17TestShapeInputShape) (req *aws.Request, output *InputService17TestShapeInputService17TestCaseOperation2Output) { - - if opInputService17TestCaseOperation2 == nil { - opInputService17TestCaseOperation2 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/path?abc=mno", - } + op := &aws.Operation{ + Name: opInputService17TestCaseOperation2, + HTTPMethod: "POST", + HTTPPath: "/path?abc=mno", } if input == nil { input = &InputService17TestShapeInputShape{} } - req = c.newRequest(opInputService17TestCaseOperation2, input, output) + req = c.newRequest(op, input, output) output = &InputService17TestShapeInputService17TestCaseOperation2Output{} req.Data = output return @@ -1623,8 +1558,6 @@ func (c *InputService17ProtocolTest) InputService17TestCaseOperation2(input *Inp return out, err } -var opInputService17TestCaseOperation2 *aws.Operation - type InputService17TestShapeInputService17TestCaseOperation1Output struct { metadataInputService17TestShapeInputService17TestCaseOperation1Output `json:"-" xml:"-"` } @@ -1683,22 +1616,21 @@ func (c *InputService18ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opInputService18TestCaseOperation1 = "OperationName" + // InputService18TestCaseOperation1Request generates a request for the InputService18TestCaseOperation1 operation. func (c *InputService18ProtocolTest) InputService18TestCaseOperation1Request(input *InputService18TestShapeInputShape) (req *aws.Request, output *InputService18TestShapeInputService18TestCaseOperation1Output) { - - if opInputService18TestCaseOperation1 == nil { - opInputService18TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/path", - } + op := &aws.Operation{ + Name: opInputService18TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/path", } if input == nil { input = &InputService18TestShapeInputShape{} } - req = c.newRequest(opInputService18TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService18TestShapeInputService18TestCaseOperation1Output{} req.Data = output return @@ -1710,24 +1642,21 @@ func (c *InputService18ProtocolTest) InputService18TestCaseOperation1(input *Inp return out, err } -var opInputService18TestCaseOperation1 *aws.Operation +const opInputService18TestCaseOperation2 = "OperationName" // InputService18TestCaseOperation2Request generates a request for the InputService18TestCaseOperation2 operation. func (c *InputService18ProtocolTest) InputService18TestCaseOperation2Request(input *InputService18TestShapeInputShape) (req *aws.Request, output *InputService18TestShapeInputService18TestCaseOperation2Output) { - - if opInputService18TestCaseOperation2 == nil { - opInputService18TestCaseOperation2 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/path", - } + op := &aws.Operation{ + Name: opInputService18TestCaseOperation2, + HTTPMethod: "POST", + HTTPPath: "/path", } if input == nil { input = &InputService18TestShapeInputShape{} } - req = c.newRequest(opInputService18TestCaseOperation2, input, output) + req = c.newRequest(op, input, output) output = &InputService18TestShapeInputService18TestCaseOperation2Output{} req.Data = output return @@ -1739,24 +1668,21 @@ func (c *InputService18ProtocolTest) InputService18TestCaseOperation2(input *Inp return out, err } -var opInputService18TestCaseOperation2 *aws.Operation +const opInputService18TestCaseOperation3 = "OperationName" // InputService18TestCaseOperation3Request generates a request for the InputService18TestCaseOperation3 operation. func (c *InputService18ProtocolTest) InputService18TestCaseOperation3Request(input *InputService18TestShapeInputShape) (req *aws.Request, output *InputService18TestShapeInputService18TestCaseOperation3Output) { - - if opInputService18TestCaseOperation3 == nil { - opInputService18TestCaseOperation3 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/path", - } + op := &aws.Operation{ + Name: opInputService18TestCaseOperation3, + HTTPMethod: "POST", + HTTPPath: "/path", } if input == nil { input = &InputService18TestShapeInputShape{} } - req = c.newRequest(opInputService18TestCaseOperation3, input, output) + req = c.newRequest(op, input, output) output = &InputService18TestShapeInputService18TestCaseOperation3Output{} req.Data = output return @@ -1768,24 +1694,21 @@ func (c *InputService18ProtocolTest) InputService18TestCaseOperation3(input *Inp return out, err } -var opInputService18TestCaseOperation3 *aws.Operation +const opInputService18TestCaseOperation4 = "OperationName" // InputService18TestCaseOperation4Request generates a request for the InputService18TestCaseOperation4 operation. func (c *InputService18ProtocolTest) InputService18TestCaseOperation4Request(input *InputService18TestShapeInputShape) (req *aws.Request, output *InputService18TestShapeInputService18TestCaseOperation4Output) { - - if opInputService18TestCaseOperation4 == nil { - opInputService18TestCaseOperation4 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/path", - } + op := &aws.Operation{ + Name: opInputService18TestCaseOperation4, + HTTPMethod: "POST", + HTTPPath: "/path", } if input == nil { input = &InputService18TestShapeInputShape{} } - req = c.newRequest(opInputService18TestCaseOperation4, input, output) + req = c.newRequest(op, input, output) output = &InputService18TestShapeInputService18TestCaseOperation4Output{} req.Data = output return @@ -1797,24 +1720,21 @@ func (c *InputService18ProtocolTest) InputService18TestCaseOperation4(input *Inp return out, err } -var opInputService18TestCaseOperation4 *aws.Operation +const opInputService18TestCaseOperation5 = "OperationName" // InputService18TestCaseOperation5Request generates a request for the InputService18TestCaseOperation5 operation. func (c *InputService18ProtocolTest) InputService18TestCaseOperation5Request(input *InputService18TestShapeInputShape) (req *aws.Request, output *InputService18TestShapeInputService18TestCaseOperation5Output) { - - if opInputService18TestCaseOperation5 == nil { - opInputService18TestCaseOperation5 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/path", - } + op := &aws.Operation{ + Name: opInputService18TestCaseOperation5, + HTTPMethod: "POST", + HTTPPath: "/path", } if input == nil { input = &InputService18TestShapeInputShape{} } - req = c.newRequest(opInputService18TestCaseOperation5, input, output) + req = c.newRequest(op, input, output) output = &InputService18TestShapeInputService18TestCaseOperation5Output{} req.Data = output return @@ -1826,24 +1746,21 @@ func (c *InputService18ProtocolTest) InputService18TestCaseOperation5(input *Inp return out, err } -var opInputService18TestCaseOperation5 *aws.Operation +const opInputService18TestCaseOperation6 = "OperationName" // InputService18TestCaseOperation6Request generates a request for the InputService18TestCaseOperation6 operation. func (c *InputService18ProtocolTest) InputService18TestCaseOperation6Request(input *InputService18TestShapeInputShape) (req *aws.Request, output *InputService18TestShapeInputService18TestCaseOperation6Output) { - - if opInputService18TestCaseOperation6 == nil { - opInputService18TestCaseOperation6 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/path", - } + op := &aws.Operation{ + Name: opInputService18TestCaseOperation6, + HTTPMethod: "POST", + HTTPPath: "/path", } if input == nil { input = &InputService18TestShapeInputShape{} } - req = c.newRequest(opInputService18TestCaseOperation6, input, output) + req = c.newRequest(op, input, output) output = &InputService18TestShapeInputService18TestCaseOperation6Output{} req.Data = output return @@ -1855,8 +1772,6 @@ func (c *InputService18ProtocolTest) InputService18TestCaseOperation6(input *Inp return out, err } -var opInputService18TestCaseOperation6 *aws.Operation - type InputService18TestShapeInputService18TestCaseOperation1Output struct { metadataInputService18TestShapeInputService18TestCaseOperation1Output `json:"-" xml:"-"` } @@ -1963,22 +1878,21 @@ func (c *InputService19ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opInputService19TestCaseOperation1 = "OperationName" + // InputService19TestCaseOperation1Request generates a request for the InputService19TestCaseOperation1 operation. func (c *InputService19ProtocolTest) InputService19TestCaseOperation1Request(input *InputService19TestShapeInputShape) (req *aws.Request, output *InputService19TestShapeInputService19TestCaseOperation1Output) { - - if opInputService19TestCaseOperation1 == nil { - opInputService19TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - HTTPMethod: "POST", - HTTPPath: "/path", - } + op := &aws.Operation{ + Name: opInputService19TestCaseOperation1, + HTTPMethod: "POST", + HTTPPath: "/path", } if input == nil { input = &InputService19TestShapeInputShape{} } - req = c.newRequest(opInputService19TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &InputService19TestShapeInputService19TestCaseOperation1Output{} req.Data = output return @@ -1990,8 +1904,6 @@ func (c *InputService19ProtocolTest) InputService19TestCaseOperation1(input *Inp return out, err } -var opInputService19TestCaseOperation1 *aws.Operation - type InputService19TestShapeInputService19TestCaseOperation1Output struct { metadataInputService19TestShapeInputService19TestCaseOperation1Output `json:"-" xml:"-"` } @@ -2280,13 +2192,13 @@ func TestInputService9ProtocolTestListOfStructuresCase1(t *testing.T) { input := &InputService9TestShapeInputShape{ ListParam: []*InputService9TestShapeSingleFieldStruct{ - &InputService9TestShapeSingleFieldStruct{ + { Element: aws.String("one"), }, - &InputService9TestShapeSingleFieldStruct{ + { Element: aws.String("two"), }, - &InputService9TestShapeSingleFieldStruct{ + { Element: aws.String("three"), }, }, @@ -2701,10 +2613,10 @@ func TestInputService18ProtocolTestRecursiveShapesCase4(t *testing.T) { input := &InputService18TestShapeInputShape{ RecursiveStruct: &InputService18TestShapeRecursiveStructType{ RecursiveList: []*InputService18TestShapeRecursiveStructType{ - &InputService18TestShapeRecursiveStructType{ + { NoRecurse: aws.String("foo"), }, - &InputService18TestShapeRecursiveStructType{ + { NoRecurse: aws.String("bar"), }, }, @@ -2736,10 +2648,10 @@ func TestInputService18ProtocolTestRecursiveShapesCase5(t *testing.T) { input := &InputService18TestShapeInputShape{ RecursiveStruct: &InputService18TestShapeRecursiveStructType{ RecursiveList: []*InputService18TestShapeRecursiveStructType{ - &InputService18TestShapeRecursiveStructType{ + { NoRecurse: aws.String("foo"), }, - &InputService18TestShapeRecursiveStructType{ + { RecursiveStruct: &InputService18TestShapeRecursiveStructType{ NoRecurse: aws.String("bar"), }, @@ -2773,10 +2685,10 @@ func TestInputService18ProtocolTestRecursiveShapesCase6(t *testing.T) { input := &InputService18TestShapeInputShape{ RecursiveStruct: &InputService18TestShapeRecursiveStructType{ RecursiveMap: map[string]*InputService18TestShapeRecursiveStructType{ - "bar": &InputService18TestShapeRecursiveStructType{ + "bar": { NoRecurse: aws.String("bar"), }, - "foo": &InputService18TestShapeRecursiveStructType{ + "foo": { NoRecurse: aws.String("foo"), }, }, diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/restxml.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/restxml.go index cd4187738f..d6cbff4f2c 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/restxml.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/restxml.go @@ -1,3 +1,5 @@ +// Package restxml provides RESTful XML serialisation of AWS +// requests and responses. package restxml //go:generate go run ../../fixtures/protocol/generate.go ../../fixtures/protocol/input/rest-xml.json build_test.go @@ -8,7 +10,7 @@ import ( "encoding/xml" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/internal/protocol/query" "github.com/aws/aws-sdk-go/internal/protocol/rest" "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" @@ -22,7 +24,7 @@ func Build(r *aws.Request) { var buf bytes.Buffer err := xmlutil.BuildXML(r.Params, xml.NewEncoder(&buf)) if err != nil { - r.Error = apierr.New("Marshal", "failed to enode rest XML request", err) + r.Error = awserr.New("SerializationError", "failed to enode rest XML request", err) return } r.SetBufferBody(buf.Bytes()) @@ -36,7 +38,7 @@ func Unmarshal(r *aws.Request) { decoder := xml.NewDecoder(r.HTTPResponse.Body) err := xmlutil.UnmarshalXML(r.Data, decoder, "") if err != nil { - r.Error = apierr.New("Unmarshal", "failed to decode REST XML response", err) + r.Error = awserr.New("SerializationError", "failed to decode REST XML response", err) return } } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/unmarshal_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/unmarshal_test.go index 3016d33cf1..7efb93d150 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/unmarshal_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/restxml/unmarshal_test.go @@ -1,10 +1,6 @@ package restxml_test import ( - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/protocol/restxml" - "github.com/aws/aws-sdk-go/internal/signer/v4" - "bytes" "encoding/json" "encoding/xml" @@ -15,7 +11,10 @@ import ( "testing" "time" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/internal/protocol/restxml" "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil" + "github.com/aws/aws-sdk-go/internal/signer/v4" "github.com/aws/aws-sdk-go/internal/util" "github.com/stretchr/testify/assert" ) @@ -63,20 +62,19 @@ func (c *OutputService1ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService1TestCaseOperation1 = "OperationName" + // OutputService1TestCaseOperation1Request generates a request for the OutputService1TestCaseOperation1 operation. func (c *OutputService1ProtocolTest) OutputService1TestCaseOperation1Request(input *OutputService1TestShapeOutputService1TestCaseOperation1Input) (req *aws.Request, output *OutputService1TestShapeOutputShape) { - - if opOutputService1TestCaseOperation1 == nil { - opOutputService1TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService1TestCaseOperation1, } if input == nil { input = &OutputService1TestShapeOutputService1TestCaseOperation1Input{} } - req = c.newRequest(opOutputService1TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService1TestShapeOutputShape{} req.Data = output return @@ -88,22 +86,19 @@ func (c *OutputService1ProtocolTest) OutputService1TestCaseOperation1(input *Out return out, err } -var opOutputService1TestCaseOperation1 *aws.Operation +const opOutputService1TestCaseOperation2 = "OperationName" // OutputService1TestCaseOperation2Request generates a request for the OutputService1TestCaseOperation2 operation. func (c *OutputService1ProtocolTest) OutputService1TestCaseOperation2Request(input *OutputService1TestShapeOutputService1TestCaseOperation2Input) (req *aws.Request, output *OutputService1TestShapeOutputShape) { - - if opOutputService1TestCaseOperation2 == nil { - opOutputService1TestCaseOperation2 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService1TestCaseOperation2, } if input == nil { input = &OutputService1TestShapeOutputService1TestCaseOperation2Input{} } - req = c.newRequest(opOutputService1TestCaseOperation2, input, output) + req = c.newRequest(op, input, output) output = &OutputService1TestShapeOutputShape{} req.Data = output return @@ -115,8 +110,6 @@ func (c *OutputService1ProtocolTest) OutputService1TestCaseOperation2(input *Out return out, err } -var opOutputService1TestCaseOperation2 *aws.Operation - type OutputService1TestShapeOutputService1TestCaseOperation1Input struct { metadataOutputService1TestShapeOutputService1TestCaseOperation1Input `json:"-" xml:"-"` } @@ -195,20 +188,19 @@ func (c *OutputService2ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService2TestCaseOperation1 = "OperationName" + // OutputService2TestCaseOperation1Request generates a request for the OutputService2TestCaseOperation1 operation. func (c *OutputService2ProtocolTest) OutputService2TestCaseOperation1Request(input *OutputService2TestShapeOutputService2TestCaseOperation1Input) (req *aws.Request, output *OutputService2TestShapeOutputShape) { - - if opOutputService2TestCaseOperation1 == nil { - opOutputService2TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService2TestCaseOperation1, } if input == nil { input = &OutputService2TestShapeOutputService2TestCaseOperation1Input{} } - req = c.newRequest(opOutputService2TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService2TestShapeOutputShape{} req.Data = output return @@ -220,8 +212,6 @@ func (c *OutputService2ProtocolTest) OutputService2TestCaseOperation1(input *Out return out, err } -var opOutputService2TestCaseOperation1 *aws.Operation - type OutputService2TestShapeOutputService2TestCaseOperation1Input struct { metadataOutputService2TestShapeOutputService2TestCaseOperation1Input `json:"-" xml:"-"` } @@ -272,20 +262,19 @@ func (c *OutputService3ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService3TestCaseOperation1 = "OperationName" + // OutputService3TestCaseOperation1Request generates a request for the OutputService3TestCaseOperation1 operation. func (c *OutputService3ProtocolTest) OutputService3TestCaseOperation1Request(input *OutputService3TestShapeOutputService3TestCaseOperation1Input) (req *aws.Request, output *OutputService3TestShapeOutputShape) { - - if opOutputService3TestCaseOperation1 == nil { - opOutputService3TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService3TestCaseOperation1, } if input == nil { input = &OutputService3TestShapeOutputService3TestCaseOperation1Input{} } - req = c.newRequest(opOutputService3TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService3TestShapeOutputShape{} req.Data = output return @@ -297,8 +286,6 @@ func (c *OutputService3ProtocolTest) OutputService3TestCaseOperation1(input *Out return out, err } -var opOutputService3TestCaseOperation1 *aws.Operation - type OutputService3TestShapeOutputService3TestCaseOperation1Input struct { metadataOutputService3TestShapeOutputService3TestCaseOperation1Input `json:"-" xml:"-"` } @@ -349,20 +336,19 @@ func (c *OutputService4ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService4TestCaseOperation1 = "OperationName" + // OutputService4TestCaseOperation1Request generates a request for the OutputService4TestCaseOperation1 operation. func (c *OutputService4ProtocolTest) OutputService4TestCaseOperation1Request(input *OutputService4TestShapeOutputService4TestCaseOperation1Input) (req *aws.Request, output *OutputService4TestShapeOutputShape) { - - if opOutputService4TestCaseOperation1 == nil { - opOutputService4TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService4TestCaseOperation1, } if input == nil { input = &OutputService4TestShapeOutputService4TestCaseOperation1Input{} } - req = c.newRequest(opOutputService4TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService4TestShapeOutputShape{} req.Data = output return @@ -374,8 +360,6 @@ func (c *OutputService4ProtocolTest) OutputService4TestCaseOperation1(input *Out return out, err } -var opOutputService4TestCaseOperation1 *aws.Operation - type OutputService4TestShapeOutputService4TestCaseOperation1Input struct { metadataOutputService4TestShapeOutputService4TestCaseOperation1Input `json:"-" xml:"-"` } @@ -426,20 +410,19 @@ func (c *OutputService5ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService5TestCaseOperation1 = "OperationName" + // OutputService5TestCaseOperation1Request generates a request for the OutputService5TestCaseOperation1 operation. func (c *OutputService5ProtocolTest) OutputService5TestCaseOperation1Request(input *OutputService5TestShapeOutputService5TestCaseOperation1Input) (req *aws.Request, output *OutputService5TestShapeOutputShape) { - - if opOutputService5TestCaseOperation1 == nil { - opOutputService5TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService5TestCaseOperation1, } if input == nil { input = &OutputService5TestShapeOutputService5TestCaseOperation1Input{} } - req = c.newRequest(opOutputService5TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService5TestShapeOutputShape{} req.Data = output return @@ -451,8 +434,6 @@ func (c *OutputService5ProtocolTest) OutputService5TestCaseOperation1(input *Out return out, err } -var opOutputService5TestCaseOperation1 *aws.Operation - type OutputService5TestShapeOutputService5TestCaseOperation1Input struct { metadataOutputService5TestShapeOutputService5TestCaseOperation1Input `json:"-" xml:"-"` } @@ -503,20 +484,19 @@ func (c *OutputService6ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService6TestCaseOperation1 = "OperationName" + // OutputService6TestCaseOperation1Request generates a request for the OutputService6TestCaseOperation1 operation. func (c *OutputService6ProtocolTest) OutputService6TestCaseOperation1Request(input *OutputService6TestShapeOutputService6TestCaseOperation1Input) (req *aws.Request, output *OutputService6TestShapeOutputShape) { - - if opOutputService6TestCaseOperation1 == nil { - opOutputService6TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService6TestCaseOperation1, } if input == nil { input = &OutputService6TestShapeOutputService6TestCaseOperation1Input{} } - req = c.newRequest(opOutputService6TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService6TestShapeOutputShape{} req.Data = output return @@ -528,8 +508,6 @@ func (c *OutputService6ProtocolTest) OutputService6TestCaseOperation1(input *Out return out, err } -var opOutputService6TestCaseOperation1 *aws.Operation - type OutputService6TestShapeOutputService6TestCaseOperation1Input struct { metadataOutputService6TestShapeOutputService6TestCaseOperation1Input `json:"-" xml:"-"` } @@ -590,20 +568,19 @@ func (c *OutputService7ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService7TestCaseOperation1 = "OperationName" + // OutputService7TestCaseOperation1Request generates a request for the OutputService7TestCaseOperation1 operation. func (c *OutputService7ProtocolTest) OutputService7TestCaseOperation1Request(input *OutputService7TestShapeOutputService7TestCaseOperation1Input) (req *aws.Request, output *OutputService7TestShapeOutputShape) { - - if opOutputService7TestCaseOperation1 == nil { - opOutputService7TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService7TestCaseOperation1, } if input == nil { input = &OutputService7TestShapeOutputService7TestCaseOperation1Input{} } - req = c.newRequest(opOutputService7TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService7TestShapeOutputShape{} req.Data = output return @@ -615,8 +592,6 @@ func (c *OutputService7ProtocolTest) OutputService7TestCaseOperation1(input *Out return out, err } -var opOutputService7TestCaseOperation1 *aws.Operation - type OutputService7TestShapeOutputService7TestCaseOperation1Input struct { metadataOutputService7TestShapeOutputService7TestCaseOperation1Input `json:"-" xml:"-"` } @@ -667,20 +642,19 @@ func (c *OutputService8ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService8TestCaseOperation1 = "OperationName" + // OutputService8TestCaseOperation1Request generates a request for the OutputService8TestCaseOperation1 operation. func (c *OutputService8ProtocolTest) OutputService8TestCaseOperation1Request(input *OutputService8TestShapeOutputService8TestCaseOperation1Input) (req *aws.Request, output *OutputService8TestShapeOutputShape) { - - if opOutputService8TestCaseOperation1 == nil { - opOutputService8TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService8TestCaseOperation1, } if input == nil { input = &OutputService8TestShapeOutputService8TestCaseOperation1Input{} } - req = c.newRequest(opOutputService8TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService8TestShapeOutputShape{} req.Data = output return @@ -692,8 +666,6 @@ func (c *OutputService8ProtocolTest) OutputService8TestCaseOperation1(input *Out return out, err } -var opOutputService8TestCaseOperation1 *aws.Operation - type OutputService8TestShapeOutputService8TestCaseOperation1Input struct { metadataOutputService8TestShapeOutputService8TestCaseOperation1Input `json:"-" xml:"-"` } @@ -744,20 +716,19 @@ func (c *OutputService9ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService9TestCaseOperation1 = "OperationName" + // OutputService9TestCaseOperation1Request generates a request for the OutputService9TestCaseOperation1 operation. func (c *OutputService9ProtocolTest) OutputService9TestCaseOperation1Request(input *OutputService9TestShapeOutputService9TestCaseOperation1Input) (req *aws.Request, output *OutputService9TestShapeOutputShape) { - - if opOutputService9TestCaseOperation1 == nil { - opOutputService9TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService9TestCaseOperation1, } if input == nil { input = &OutputService9TestShapeOutputService9TestCaseOperation1Input{} } - req = c.newRequest(opOutputService9TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService9TestShapeOutputShape{} req.Data = output return @@ -769,8 +740,6 @@ func (c *OutputService9ProtocolTest) OutputService9TestCaseOperation1(input *Out return out, err } -var opOutputService9TestCaseOperation1 *aws.Operation - type OutputService9TestShapeOutputService9TestCaseOperation1Input struct { metadataOutputService9TestShapeOutputService9TestCaseOperation1Input `json:"-" xml:"-"` } @@ -833,20 +802,19 @@ func (c *OutputService10ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService10TestCaseOperation1 = "OperationName" + // OutputService10TestCaseOperation1Request generates a request for the OutputService10TestCaseOperation1 operation. func (c *OutputService10ProtocolTest) OutputService10TestCaseOperation1Request(input *OutputService10TestShapeOutputService10TestCaseOperation1Input) (req *aws.Request, output *OutputService10TestShapeOutputShape) { - - if opOutputService10TestCaseOperation1 == nil { - opOutputService10TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService10TestCaseOperation1, } if input == nil { input = &OutputService10TestShapeOutputService10TestCaseOperation1Input{} } - req = c.newRequest(opOutputService10TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService10TestShapeOutputShape{} req.Data = output return @@ -858,8 +826,6 @@ func (c *OutputService10ProtocolTest) OutputService10TestCaseOperation1(input *O return out, err } -var opOutputService10TestCaseOperation1 *aws.Operation - type OutputService10TestShapeOutputService10TestCaseOperation1Input struct { metadataOutputService10TestShapeOutputService10TestCaseOperation1Input `json:"-" xml:"-"` } @@ -910,20 +876,19 @@ func (c *OutputService11ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService11TestCaseOperation1 = "OperationName" + // OutputService11TestCaseOperation1Request generates a request for the OutputService11TestCaseOperation1 operation. func (c *OutputService11ProtocolTest) OutputService11TestCaseOperation1Request(input *OutputService11TestShapeOutputService11TestCaseOperation1Input) (req *aws.Request, output *OutputService11TestShapeOutputShape) { - - if opOutputService11TestCaseOperation1 == nil { - opOutputService11TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService11TestCaseOperation1, } if input == nil { input = &OutputService11TestShapeOutputService11TestCaseOperation1Input{} } - req = c.newRequest(opOutputService11TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService11TestShapeOutputShape{} req.Data = output return @@ -935,8 +900,6 @@ func (c *OutputService11ProtocolTest) OutputService11TestCaseOperation1(input *O return out, err } -var opOutputService11TestCaseOperation1 *aws.Operation - type OutputService11TestShapeOutputService11TestCaseOperation1Input struct { metadataOutputService11TestShapeOutputService11TestCaseOperation1Input `json:"-" xml:"-"` } @@ -1003,20 +966,19 @@ func (c *OutputService12ProtocolTest) newRequest(op *aws.Operation, params, data return req } +const opOutputService12TestCaseOperation1 = "OperationName" + // OutputService12TestCaseOperation1Request generates a request for the OutputService12TestCaseOperation1 operation. func (c *OutputService12ProtocolTest) OutputService12TestCaseOperation1Request(input *OutputService12TestShapeOutputService12TestCaseOperation1Input) (req *aws.Request, output *OutputService12TestShapeOutputShape) { - - if opOutputService12TestCaseOperation1 == nil { - opOutputService12TestCaseOperation1 = &aws.Operation{ - Name: "OperationName", - } + op := &aws.Operation{ + Name: opOutputService12TestCaseOperation1, } if input == nil { input = &OutputService12TestShapeOutputService12TestCaseOperation1Input{} } - req = c.newRequest(opOutputService12TestCaseOperation1, input, output) + req = c.newRequest(op, input, output) output = &OutputService12TestShapeOutputShape{} req.Data = output return @@ -1028,8 +990,6 @@ func (c *OutputService12ProtocolTest) OutputService12TestCaseOperation1(input *O return out, err } -var opOutputService12TestCaseOperation1 *aws.Operation - type OutputService12TestShapeOutputService12TestCaseOperation1Input struct { metadataOutputService12TestShapeOutputService12TestCaseOperation1Input `json:"-" xml:"-"` } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil/build.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil/build.go index 8791bfdabf..d3db250231 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil/build.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil/build.go @@ -1,3 +1,4 @@ +// Package xmlutil provides XML serialisation of AWS requests and responses. package xmlutil import ( diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil/unmarshal.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil/unmarshal.go index a7b7a60b2e..5e4fe210b3 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil/unmarshal.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil/unmarshal.go @@ -114,7 +114,7 @@ func parseStruct(r reflect.Value, node *XMLNode, tag reflect.StructTag) error { for _, a := range node.Attr { if name == a.Name.Local { // turn this into a text node for de-serializing - elems = []*XMLNode{&XMLNode{Text: a.Value}} + elems = []*XMLNode{{Text: a.Value}} } } } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/signer/v4/v4.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/signer/v4/v4.go index 05d5dad7da..6fef0d6661 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/signer/v4/v4.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/signer/v4/v4.go @@ -1,3 +1,4 @@ +// Package v4 implements signing for AWS V4 signer package v4 import ( @@ -33,18 +34,17 @@ var ignoredHeaders = map[string]bool{ } type signer struct { - Request *http.Request - Time time.Time - ExpireTime time.Duration - ServiceName string - Region string - AccessKeyID string - SecretAccessKey string - SessionToken string - Query url.Values - Body io.ReadSeeker - Debug uint - Logger io.Writer + Request *http.Request + Time time.Time + ExpireTime time.Duration + ServiceName string + Region string + CredValues credentials.Value + Credentials *credentials.Credentials + Query url.Values + Body io.ReadSeeker + Debug uint + Logger io.Writer isPresign bool formattedTime string @@ -70,11 +70,6 @@ func Sign(req *aws.Request) { if req.Service.Config.Credentials == credentials.AnonymousCredentials { return } - creds, err := req.Service.Config.Credentials.Get() - if err != nil { - req.Error = err - return - } region := req.Service.SigningRegion if region == "" { @@ -87,56 +82,84 @@ func Sign(req *aws.Request) { } s := signer{ - Request: req.HTTPRequest, - Time: req.Time, - ExpireTime: req.ExpireTime, - Query: req.HTTPRequest.URL.Query(), - Body: req.Body, - ServiceName: name, - Region: region, - AccessKeyID: creds.AccessKeyID, - SecretAccessKey: creds.SecretAccessKey, - SessionToken: creds.SessionToken, - Debug: req.Service.Config.LogLevel, - Logger: req.Service.Config.Logger, + Request: req.HTTPRequest, + Time: req.Time, + ExpireTime: req.ExpireTime, + Query: req.HTTPRequest.URL.Query(), + Body: req.Body, + ServiceName: name, + Region: region, + Credentials: req.Service.Config.Credentials, + Debug: req.Service.Config.LogLevel, + Logger: req.Service.Config.Logger, } - s.sign() - return + + req.Error = s.sign() } -func (v4 *signer) sign() { +func (v4 *signer) sign() error { if v4.ExpireTime != 0 { v4.isPresign = true } + if v4.isRequestSigned() { + if !v4.Credentials.IsExpired() { + // If the request is already signed, and the credentials have not + // expired yet ignore the signing request. + return nil + } + + // The credentials have expired for this request. The current signing + // is invalid, and needs to be request because the request will fail. + if v4.isPresign { + v4.removePresign() + // Update the request's query string to ensure the values stays in + // sync in the case retrieving the new credentials fails. + v4.Request.URL.RawQuery = v4.Query.Encode() + } + } + + var err error + v4.CredValues, err = v4.Credentials.Get() + if err != nil { + return err + } + if v4.isPresign { v4.Query.Set("X-Amz-Algorithm", authHeaderPrefix) - if v4.SessionToken != "" { - v4.Query.Set("X-Amz-Security-Token", v4.SessionToken) + if v4.CredValues.SessionToken != "" { + v4.Query.Set("X-Amz-Security-Token", v4.CredValues.SessionToken) } else { v4.Query.Del("X-Amz-Security-Token") } - } else if v4.SessionToken != "" { - v4.Request.Header.Set("X-Amz-Security-Token", v4.SessionToken) + } else if v4.CredValues.SessionToken != "" { + v4.Request.Header.Set("X-Amz-Security-Token", v4.CredValues.SessionToken) } v4.build() if v4.Debug > 0 { - out := v4.Logger - fmt.Fprintf(out, "---[ CANONICAL STRING ]-----------------------------\n") - fmt.Fprintln(out, v4.canonicalString) - fmt.Fprintf(out, "---[ STRING TO SIGN ]--------------------------------\n") - fmt.Fprintln(out, v4.stringToSign) - if v4.isPresign { - fmt.Fprintf(out, "---[ SIGNED URL ]--------------------------------\n") - fmt.Fprintln(out, v4.Request.URL) - } - fmt.Fprintf(out, "-----------------------------------------------------\n") + v4.logSigningInfo() } + + return nil +} + +func (v4 *signer) logSigningInfo() { + out := v4.Logger + fmt.Fprintf(out, "---[ CANONICAL STRING ]-----------------------------\n") + fmt.Fprintln(out, v4.canonicalString) + fmt.Fprintf(out, "---[ STRING TO SIGN ]--------------------------------\n") + fmt.Fprintln(out, v4.stringToSign) + if v4.isPresign { + fmt.Fprintf(out, "---[ SIGNED URL ]--------------------------------\n") + fmt.Fprintln(out, v4.Request.URL) + } + fmt.Fprintf(out, "-----------------------------------------------------\n") } func (v4 *signer) build() { + v4.buildTime() // no depends v4.buildCredentialString() // no depends if v4.isPresign { @@ -151,7 +174,7 @@ func (v4 *signer) build() { v4.Request.URL.RawQuery += "&X-Amz-Signature=" + v4.signature } else { parts := []string{ - authHeaderPrefix + " Credential=" + v4.AccessKeyID + "/" + v4.credentialString, + authHeaderPrefix + " Credential=" + v4.CredValues.AccessKeyID + "/" + v4.credentialString, "SignedHeaders=" + v4.signedHeaders, "Signature=" + v4.signature, } @@ -181,7 +204,7 @@ func (v4 *signer) buildCredentialString() { }, "/") if v4.isPresign { - v4.Query.Set("X-Amz-Credential", v4.AccessKeyID+"/"+v4.credentialString) + v4.Query.Set("X-Amz-Credential", v4.CredValues.AccessKeyID+"/"+v4.credentialString) } } @@ -268,7 +291,7 @@ func (v4 *signer) buildStringToSign() { } func (v4 *signer) buildSignature() { - secret := v4.SecretAccessKey + secret := v4.CredValues.SecretAccessKey date := makeHmac([]byte("AWS4"+secret), []byte(v4.formattedShortTime)) region := makeHmac(date, []byte(v4.Region)) service := makeHmac(region, []byte(v4.ServiceName)) @@ -292,6 +315,29 @@ func (v4 *signer) bodyDigest() string { return hash } +// isRequestSigned returns if the request is currently signed or presigned +func (v4 *signer) isRequestSigned() bool { + if v4.isPresign && v4.Query.Get("X-Amz-Signature") != "" { + return true + } + if v4.Request.Header.Get("Authorization") != "" { + return true + } + + return false +} + +// unsign removes signing flags for both signed and presigned requests. +func (v4 *signer) removePresign() { + v4.Query.Del("X-Amz-Algorithm") + v4.Query.Del("X-Amz-Signature") + v4.Query.Del("X-Amz-Security-Token") + v4.Query.Del("X-Amz-Date") + v4.Query.Del("X-Amz-Expires") + v4.Query.Del("X-Amz-Credential") + v4.Query.Del("X-Amz-SignedHeaders") +} + func makeHmac(key []byte, data []byte) []byte { hash := hmac.New(sha256.New, key) hash.Write(data) @@ -305,21 +351,10 @@ func makeSha256(data []byte) []byte { } func makeSha256Reader(reader io.ReadSeeker) []byte { - packet := make([]byte, 4096) hash := sha256.New() - start, _ := reader.Seek(0, 1) defer reader.Seek(start, 0) - for { - n, err := reader.Read(packet) - if n > 0 { - hash.Write(packet[0:n]) - } - if err == io.EOF || n == 0 { - break - } - } - + io.Copy(hash, reader) return hash.Sum(nil) } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/signer/v4/v4_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/signer/v4/v4_test.go index 20f655ac6c..99966f809d 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/signer/v4/v4_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/internal/signer/v4/v4_test.go @@ -22,16 +22,14 @@ func buildSigner(serviceName string, region string, signTime time.Time, expireTi req.Header.Add("X-Amz-Meta-Other-Header", "some-value=!@#$%^&* (+)") return signer{ - Request: req, - Time: signTime, - ExpireTime: expireTime, - Query: req.URL.Query(), - Body: reader, - ServiceName: serviceName, - Region: region, - AccessKeyID: "AKID", - SecretAccessKey: "SECRET", - SessionToken: "SESSION", + Request: req, + Time: signTime, + ExpireTime: expireTime, + Query: req.URL.Query(), + Body: reader, + ServiceName: serviceName, + Region: region, + Credentials: credentials.NewStaticCredentials("AKID", "SECRET", "SESSION"), } } @@ -141,6 +139,97 @@ func TestAnonymousCredentials(t *testing.T) { assert.Empty(t, hQ.Get("X-Amz-Date")) } +func TestIgnoreResignRequestWithValidCreds(t *testing.T) { + r := aws.NewRequest( + aws.NewService(&aws.Config{ + Credentials: credentials.NewStaticCredentials("AKID", "SECRET", "SESSION"), + Region: "us-west-2", + }), + &aws.Operation{ + Name: "BatchGetItem", + HTTPMethod: "POST", + HTTPPath: "/", + }, + nil, + nil, + ) + + Sign(r) + sig := r.HTTPRequest.Header.Get("Authorization") + + Sign(r) + assert.Equal(t, sig, r.HTTPRequest.Header.Get("Authorization")) +} + +func TestIgnorePreResignRequestWithValidCreds(t *testing.T) { + r := aws.NewRequest( + aws.NewService(&aws.Config{ + Credentials: credentials.NewStaticCredentials("AKID", "SECRET", "SESSION"), + Region: "us-west-2", + }), + &aws.Operation{ + Name: "BatchGetItem", + HTTPMethod: "POST", + HTTPPath: "/", + }, + nil, + nil, + ) + r.ExpireTime = time.Minute * 10 + + Sign(r) + sig := r.HTTPRequest.Header.Get("X-Amz-Signature") + + Sign(r) + assert.Equal(t, sig, r.HTTPRequest.Header.Get("X-Amz-Signature")) +} + +func TestResignRequestExpiredCreds(t *testing.T) { + creds := credentials.NewStaticCredentials("AKID", "SECRET", "SESSION") + r := aws.NewRequest( + aws.NewService(&aws.Config{Credentials: creds}), + &aws.Operation{ + Name: "BatchGetItem", + HTTPMethod: "POST", + HTTPPath: "/", + }, + nil, + nil, + ) + Sign(r) + querySig := r.HTTPRequest.Header.Get("Authorization") + + creds.Expire() + + Sign(r) + assert.NotEqual(t, querySig, r.HTTPRequest.Header.Get("Authorization")) +} + +func TestPreResignRequestExpiredCreds(t *testing.T) { + provider := &credentials.StaticProvider{credentials.Value{"AKID", "SECRET", "SESSION"}} + creds := credentials.NewCredentials(provider) + r := aws.NewRequest( + aws.NewService(&aws.Config{Credentials: creds}), + &aws.Operation{ + Name: "BatchGetItem", + HTTPMethod: "POST", + HTTPPath: "/", + }, + nil, + nil, + ) + r.ExpireTime = time.Minute * 10 + + Sign(r) + querySig := r.HTTPRequest.URL.Query().Get("X-Amz-Signature") + + creds.Expire() + r.Time = time.Now().Add(time.Hour * 48) + + Sign(r) + assert.NotEqual(t, querySig, r.HTTPRequest.URL.Query().Get("X-Amz-Signature")) +} + func BenchmarkPresignRequest(b *testing.B) { signer := buildSigner("dynamodb", "us-east-1", time.Now(), 300*time.Second, "{}") for i := 0; i < b.N; i++ { diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/api.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/api.go index c1293baf50..e70258332b 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/api.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/api.go @@ -5,32 +5,26 @@ package s3 import ( "io" - "sync" "time" "github.com/aws/aws-sdk-go/aws" ) -var oprw sync.Mutex +const opAbortMultipartUpload = "AbortMultipartUpload" // AbortMultipartUploadRequest generates a request for the AbortMultipartUpload operation. func (c *S3) AbortMultipartUploadRequest(input *AbortMultipartUploadInput) (req *aws.Request, output *AbortMultipartUploadOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opAbortMultipartUpload == nil { - opAbortMultipartUpload = &aws.Operation{ - Name: "AbortMultipartUpload", - HTTPMethod: "DELETE", - HTTPPath: "/{Bucket}/{Key+}", - } + op := &aws.Operation{ + Name: opAbortMultipartUpload, + HTTPMethod: "DELETE", + HTTPPath: "/{Bucket}/{Key+}", } if input == nil { input = &AbortMultipartUploadInput{} } - req = c.newRequest(opAbortMultipartUpload, input, output) + req = c.newRequest(op, input, output) output = &AbortMultipartUploadOutput{} req.Data = output return @@ -47,26 +41,21 @@ func (c *S3) AbortMultipartUpload(input *AbortMultipartUploadInput) (*AbortMulti return out, err } -var opAbortMultipartUpload *aws.Operation +const opCompleteMultipartUpload = "CompleteMultipartUpload" // CompleteMultipartUploadRequest generates a request for the CompleteMultipartUpload operation. func (c *S3) CompleteMultipartUploadRequest(input *CompleteMultipartUploadInput) (req *aws.Request, output *CompleteMultipartUploadOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opCompleteMultipartUpload == nil { - opCompleteMultipartUpload = &aws.Operation{ - Name: "CompleteMultipartUpload", - HTTPMethod: "POST", - HTTPPath: "/{Bucket}/{Key+}", - } + op := &aws.Operation{ + Name: opCompleteMultipartUpload, + HTTPMethod: "POST", + HTTPPath: "/{Bucket}/{Key+}", } if input == nil { input = &CompleteMultipartUploadInput{} } - req = c.newRequest(opCompleteMultipartUpload, input, output) + req = c.newRequest(op, input, output) output = &CompleteMultipartUploadOutput{} req.Data = output return @@ -79,26 +68,21 @@ func (c *S3) CompleteMultipartUpload(input *CompleteMultipartUploadInput) (*Comp return out, err } -var opCompleteMultipartUpload *aws.Operation +const opCopyObject = "CopyObject" // CopyObjectRequest generates a request for the CopyObject operation. func (c *S3) CopyObjectRequest(input *CopyObjectInput) (req *aws.Request, output *CopyObjectOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opCopyObject == nil { - opCopyObject = &aws.Operation{ - Name: "CopyObject", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}/{Key+}", - } + op := &aws.Operation{ + Name: opCopyObject, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}/{Key+}", } if input == nil { input = &CopyObjectInput{} } - req = c.newRequest(opCopyObject, input, output) + req = c.newRequest(op, input, output) output = &CopyObjectOutput{} req.Data = output return @@ -111,26 +95,21 @@ func (c *S3) CopyObject(input *CopyObjectInput) (*CopyObjectOutput, error) { return out, err } -var opCopyObject *aws.Operation +const opCreateBucket = "CreateBucket" // CreateBucketRequest generates a request for the CreateBucket operation. func (c *S3) CreateBucketRequest(input *CreateBucketInput) (req *aws.Request, output *CreateBucketOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opCreateBucket == nil { - opCreateBucket = &aws.Operation{ - Name: "CreateBucket", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}", - } + op := &aws.Operation{ + Name: opCreateBucket, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}", } if input == nil { input = &CreateBucketInput{} } - req = c.newRequest(opCreateBucket, input, output) + req = c.newRequest(op, input, output) output = &CreateBucketOutput{} req.Data = output return @@ -143,26 +122,21 @@ func (c *S3) CreateBucket(input *CreateBucketInput) (*CreateBucketOutput, error) return out, err } -var opCreateBucket *aws.Operation +const opCreateMultipartUpload = "CreateMultipartUpload" // CreateMultipartUploadRequest generates a request for the CreateMultipartUpload operation. func (c *S3) CreateMultipartUploadRequest(input *CreateMultipartUploadInput) (req *aws.Request, output *CreateMultipartUploadOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opCreateMultipartUpload == nil { - opCreateMultipartUpload = &aws.Operation{ - Name: "CreateMultipartUpload", - HTTPMethod: "POST", - HTTPPath: "/{Bucket}/{Key+}?uploads", - } + op := &aws.Operation{ + Name: opCreateMultipartUpload, + HTTPMethod: "POST", + HTTPPath: "/{Bucket}/{Key+}?uploads", } if input == nil { input = &CreateMultipartUploadInput{} } - req = c.newRequest(opCreateMultipartUpload, input, output) + req = c.newRequest(op, input, output) output = &CreateMultipartUploadOutput{} req.Data = output return @@ -181,26 +155,21 @@ func (c *S3) CreateMultipartUpload(input *CreateMultipartUploadInput) (*CreateMu return out, err } -var opCreateMultipartUpload *aws.Operation +const opDeleteBucket = "DeleteBucket" // DeleteBucketRequest generates a request for the DeleteBucket operation. func (c *S3) DeleteBucketRequest(input *DeleteBucketInput) (req *aws.Request, output *DeleteBucketOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opDeleteBucket == nil { - opDeleteBucket = &aws.Operation{ - Name: "DeleteBucket", - HTTPMethod: "DELETE", - HTTPPath: "/{Bucket}", - } + op := &aws.Operation{ + Name: opDeleteBucket, + HTTPMethod: "DELETE", + HTTPPath: "/{Bucket}", } if input == nil { input = &DeleteBucketInput{} } - req = c.newRequest(opDeleteBucket, input, output) + req = c.newRequest(op, input, output) output = &DeleteBucketOutput{} req.Data = output return @@ -214,26 +183,21 @@ func (c *S3) DeleteBucket(input *DeleteBucketInput) (*DeleteBucketOutput, error) return out, err } -var opDeleteBucket *aws.Operation +const opDeleteBucketCORS = "DeleteBucketCors" // DeleteBucketCORSRequest generates a request for the DeleteBucketCORS operation. func (c *S3) DeleteBucketCORSRequest(input *DeleteBucketCORSInput) (req *aws.Request, output *DeleteBucketCORSOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opDeleteBucketCORS == nil { - opDeleteBucketCORS = &aws.Operation{ - Name: "DeleteBucketCors", - HTTPMethod: "DELETE", - HTTPPath: "/{Bucket}?cors", - } + op := &aws.Operation{ + Name: opDeleteBucketCORS, + HTTPMethod: "DELETE", + HTTPPath: "/{Bucket}?cors", } if input == nil { input = &DeleteBucketCORSInput{} } - req = c.newRequest(opDeleteBucketCORS, input, output) + req = c.newRequest(op, input, output) output = &DeleteBucketCORSOutput{} req.Data = output return @@ -246,26 +210,21 @@ func (c *S3) DeleteBucketCORS(input *DeleteBucketCORSInput) (*DeleteBucketCORSOu return out, err } -var opDeleteBucketCORS *aws.Operation +const opDeleteBucketLifecycle = "DeleteBucketLifecycle" // DeleteBucketLifecycleRequest generates a request for the DeleteBucketLifecycle operation. func (c *S3) DeleteBucketLifecycleRequest(input *DeleteBucketLifecycleInput) (req *aws.Request, output *DeleteBucketLifecycleOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opDeleteBucketLifecycle == nil { - opDeleteBucketLifecycle = &aws.Operation{ - Name: "DeleteBucketLifecycle", - HTTPMethod: "DELETE", - HTTPPath: "/{Bucket}?lifecycle", - } + op := &aws.Operation{ + Name: opDeleteBucketLifecycle, + HTTPMethod: "DELETE", + HTTPPath: "/{Bucket}?lifecycle", } if input == nil { input = &DeleteBucketLifecycleInput{} } - req = c.newRequest(opDeleteBucketLifecycle, input, output) + req = c.newRequest(op, input, output) output = &DeleteBucketLifecycleOutput{} req.Data = output return @@ -278,26 +237,21 @@ func (c *S3) DeleteBucketLifecycle(input *DeleteBucketLifecycleInput) (*DeleteBu return out, err } -var opDeleteBucketLifecycle *aws.Operation +const opDeleteBucketPolicy = "DeleteBucketPolicy" // DeleteBucketPolicyRequest generates a request for the DeleteBucketPolicy operation. func (c *S3) DeleteBucketPolicyRequest(input *DeleteBucketPolicyInput) (req *aws.Request, output *DeleteBucketPolicyOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opDeleteBucketPolicy == nil { - opDeleteBucketPolicy = &aws.Operation{ - Name: "DeleteBucketPolicy", - HTTPMethod: "DELETE", - HTTPPath: "/{Bucket}?policy", - } + op := &aws.Operation{ + Name: opDeleteBucketPolicy, + HTTPMethod: "DELETE", + HTTPPath: "/{Bucket}?policy", } if input == nil { input = &DeleteBucketPolicyInput{} } - req = c.newRequest(opDeleteBucketPolicy, input, output) + req = c.newRequest(op, input, output) output = &DeleteBucketPolicyOutput{} req.Data = output return @@ -310,26 +264,21 @@ func (c *S3) DeleteBucketPolicy(input *DeleteBucketPolicyInput) (*DeleteBucketPo return out, err } -var opDeleteBucketPolicy *aws.Operation +const opDeleteBucketReplication = "DeleteBucketReplication" // DeleteBucketReplicationRequest generates a request for the DeleteBucketReplication operation. func (c *S3) DeleteBucketReplicationRequest(input *DeleteBucketReplicationInput) (req *aws.Request, output *DeleteBucketReplicationOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opDeleteBucketReplication == nil { - opDeleteBucketReplication = &aws.Operation{ - Name: "DeleteBucketReplication", - HTTPMethod: "DELETE", - HTTPPath: "/{Bucket}?replication", - } + op := &aws.Operation{ + Name: opDeleteBucketReplication, + HTTPMethod: "DELETE", + HTTPPath: "/{Bucket}?replication", } if input == nil { input = &DeleteBucketReplicationInput{} } - req = c.newRequest(opDeleteBucketReplication, input, output) + req = c.newRequest(op, input, output) output = &DeleteBucketReplicationOutput{} req.Data = output return @@ -341,26 +290,21 @@ func (c *S3) DeleteBucketReplication(input *DeleteBucketReplicationInput) (*Dele return out, err } -var opDeleteBucketReplication *aws.Operation +const opDeleteBucketTagging = "DeleteBucketTagging" // DeleteBucketTaggingRequest generates a request for the DeleteBucketTagging operation. func (c *S3) DeleteBucketTaggingRequest(input *DeleteBucketTaggingInput) (req *aws.Request, output *DeleteBucketTaggingOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opDeleteBucketTagging == nil { - opDeleteBucketTagging = &aws.Operation{ - Name: "DeleteBucketTagging", - HTTPMethod: "DELETE", - HTTPPath: "/{Bucket}?tagging", - } + op := &aws.Operation{ + Name: opDeleteBucketTagging, + HTTPMethod: "DELETE", + HTTPPath: "/{Bucket}?tagging", } if input == nil { input = &DeleteBucketTaggingInput{} } - req = c.newRequest(opDeleteBucketTagging, input, output) + req = c.newRequest(op, input, output) output = &DeleteBucketTaggingOutput{} req.Data = output return @@ -373,26 +317,21 @@ func (c *S3) DeleteBucketTagging(input *DeleteBucketTaggingInput) (*DeleteBucket return out, err } -var opDeleteBucketTagging *aws.Operation +const opDeleteBucketWebsite = "DeleteBucketWebsite" // DeleteBucketWebsiteRequest generates a request for the DeleteBucketWebsite operation. func (c *S3) DeleteBucketWebsiteRequest(input *DeleteBucketWebsiteInput) (req *aws.Request, output *DeleteBucketWebsiteOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opDeleteBucketWebsite == nil { - opDeleteBucketWebsite = &aws.Operation{ - Name: "DeleteBucketWebsite", - HTTPMethod: "DELETE", - HTTPPath: "/{Bucket}?website", - } + op := &aws.Operation{ + Name: opDeleteBucketWebsite, + HTTPMethod: "DELETE", + HTTPPath: "/{Bucket}?website", } if input == nil { input = &DeleteBucketWebsiteInput{} } - req = c.newRequest(opDeleteBucketWebsite, input, output) + req = c.newRequest(op, input, output) output = &DeleteBucketWebsiteOutput{} req.Data = output return @@ -405,26 +344,21 @@ func (c *S3) DeleteBucketWebsite(input *DeleteBucketWebsiteInput) (*DeleteBucket return out, err } -var opDeleteBucketWebsite *aws.Operation +const opDeleteObject = "DeleteObject" // DeleteObjectRequest generates a request for the DeleteObject operation. func (c *S3) DeleteObjectRequest(input *DeleteObjectInput) (req *aws.Request, output *DeleteObjectOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opDeleteObject == nil { - opDeleteObject = &aws.Operation{ - Name: "DeleteObject", - HTTPMethod: "DELETE", - HTTPPath: "/{Bucket}/{Key+}", - } + op := &aws.Operation{ + Name: opDeleteObject, + HTTPMethod: "DELETE", + HTTPPath: "/{Bucket}/{Key+}", } if input == nil { input = &DeleteObjectInput{} } - req = c.newRequest(opDeleteObject, input, output) + req = c.newRequest(op, input, output) output = &DeleteObjectOutput{} req.Data = output return @@ -439,26 +373,21 @@ func (c *S3) DeleteObject(input *DeleteObjectInput) (*DeleteObjectOutput, error) return out, err } -var opDeleteObject *aws.Operation +const opDeleteObjects = "DeleteObjects" // DeleteObjectsRequest generates a request for the DeleteObjects operation. func (c *S3) DeleteObjectsRequest(input *DeleteObjectsInput) (req *aws.Request, output *DeleteObjectsOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opDeleteObjects == nil { - opDeleteObjects = &aws.Operation{ - Name: "DeleteObjects", - HTTPMethod: "POST", - HTTPPath: "/{Bucket}?delete", - } + op := &aws.Operation{ + Name: opDeleteObjects, + HTTPMethod: "POST", + HTTPPath: "/{Bucket}?delete", } if input == nil { input = &DeleteObjectsInput{} } - req = c.newRequest(opDeleteObjects, input, output) + req = c.newRequest(op, input, output) output = &DeleteObjectsOutput{} req.Data = output return @@ -472,26 +401,21 @@ func (c *S3) DeleteObjects(input *DeleteObjectsInput) (*DeleteObjectsOutput, err return out, err } -var opDeleteObjects *aws.Operation +const opGetBucketACL = "GetBucketAcl" // GetBucketACLRequest generates a request for the GetBucketACL operation. func (c *S3) GetBucketACLRequest(input *GetBucketACLInput) (req *aws.Request, output *GetBucketACLOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketACL == nil { - opGetBucketACL = &aws.Operation{ - Name: "GetBucketAcl", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?acl", - } + op := &aws.Operation{ + Name: opGetBucketACL, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?acl", } if input == nil { input = &GetBucketACLInput{} } - req = c.newRequest(opGetBucketACL, input, output) + req = c.newRequest(op, input, output) output = &GetBucketACLOutput{} req.Data = output return @@ -504,26 +428,21 @@ func (c *S3) GetBucketACL(input *GetBucketACLInput) (*GetBucketACLOutput, error) return out, err } -var opGetBucketACL *aws.Operation +const opGetBucketCORS = "GetBucketCors" // GetBucketCORSRequest generates a request for the GetBucketCORS operation. func (c *S3) GetBucketCORSRequest(input *GetBucketCORSInput) (req *aws.Request, output *GetBucketCORSOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketCORS == nil { - opGetBucketCORS = &aws.Operation{ - Name: "GetBucketCors", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?cors", - } + op := &aws.Operation{ + Name: opGetBucketCORS, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?cors", } if input == nil { input = &GetBucketCORSInput{} } - req = c.newRequest(opGetBucketCORS, input, output) + req = c.newRequest(op, input, output) output = &GetBucketCORSOutput{} req.Data = output return @@ -536,26 +455,21 @@ func (c *S3) GetBucketCORS(input *GetBucketCORSInput) (*GetBucketCORSOutput, err return out, err } -var opGetBucketCORS *aws.Operation +const opGetBucketLifecycle = "GetBucketLifecycle" // GetBucketLifecycleRequest generates a request for the GetBucketLifecycle operation. func (c *S3) GetBucketLifecycleRequest(input *GetBucketLifecycleInput) (req *aws.Request, output *GetBucketLifecycleOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketLifecycle == nil { - opGetBucketLifecycle = &aws.Operation{ - Name: "GetBucketLifecycle", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?lifecycle", - } + op := &aws.Operation{ + Name: opGetBucketLifecycle, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?lifecycle", } if input == nil { input = &GetBucketLifecycleInput{} } - req = c.newRequest(opGetBucketLifecycle, input, output) + req = c.newRequest(op, input, output) output = &GetBucketLifecycleOutput{} req.Data = output return @@ -568,26 +482,21 @@ func (c *S3) GetBucketLifecycle(input *GetBucketLifecycleInput) (*GetBucketLifec return out, err } -var opGetBucketLifecycle *aws.Operation +const opGetBucketLocation = "GetBucketLocation" // GetBucketLocationRequest generates a request for the GetBucketLocation operation. func (c *S3) GetBucketLocationRequest(input *GetBucketLocationInput) (req *aws.Request, output *GetBucketLocationOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketLocation == nil { - opGetBucketLocation = &aws.Operation{ - Name: "GetBucketLocation", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?location", - } + op := &aws.Operation{ + Name: opGetBucketLocation, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?location", } if input == nil { input = &GetBucketLocationInput{} } - req = c.newRequest(opGetBucketLocation, input, output) + req = c.newRequest(op, input, output) output = &GetBucketLocationOutput{} req.Data = output return @@ -600,26 +509,21 @@ func (c *S3) GetBucketLocation(input *GetBucketLocationInput) (*GetBucketLocatio return out, err } -var opGetBucketLocation *aws.Operation +const opGetBucketLogging = "GetBucketLogging" // GetBucketLoggingRequest generates a request for the GetBucketLogging operation. func (c *S3) GetBucketLoggingRequest(input *GetBucketLoggingInput) (req *aws.Request, output *GetBucketLoggingOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketLogging == nil { - opGetBucketLogging = &aws.Operation{ - Name: "GetBucketLogging", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?logging", - } + op := &aws.Operation{ + Name: opGetBucketLogging, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?logging", } if input == nil { input = &GetBucketLoggingInput{} } - req = c.newRequest(opGetBucketLogging, input, output) + req = c.newRequest(op, input, output) output = &GetBucketLoggingOutput{} req.Data = output return @@ -633,26 +537,21 @@ func (c *S3) GetBucketLogging(input *GetBucketLoggingInput) (*GetBucketLoggingOu return out, err } -var opGetBucketLogging *aws.Operation +const opGetBucketNotification = "GetBucketNotification" // GetBucketNotificationRequest generates a request for the GetBucketNotification operation. func (c *S3) GetBucketNotificationRequest(input *GetBucketNotificationConfigurationRequest) (req *aws.Request, output *NotificationConfigurationDeprecated) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketNotification == nil { - opGetBucketNotification = &aws.Operation{ - Name: "GetBucketNotification", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?notification", - } + op := &aws.Operation{ + Name: opGetBucketNotification, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?notification", } if input == nil { input = &GetBucketNotificationConfigurationRequest{} } - req = c.newRequest(opGetBucketNotification, input, output) + req = c.newRequest(op, input, output) output = &NotificationConfigurationDeprecated{} req.Data = output return @@ -665,26 +564,21 @@ func (c *S3) GetBucketNotification(input *GetBucketNotificationConfigurationRequ return out, err } -var opGetBucketNotification *aws.Operation +const opGetBucketNotificationConfiguration = "GetBucketNotificationConfiguration" // GetBucketNotificationConfigurationRequest generates a request for the GetBucketNotificationConfiguration operation. func (c *S3) GetBucketNotificationConfigurationRequest(input *GetBucketNotificationConfigurationRequest) (req *aws.Request, output *NotificationConfiguration) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketNotificationConfiguration == nil { - opGetBucketNotificationConfiguration = &aws.Operation{ - Name: "GetBucketNotificationConfiguration", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?notification", - } + op := &aws.Operation{ + Name: opGetBucketNotificationConfiguration, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?notification", } if input == nil { input = &GetBucketNotificationConfigurationRequest{} } - req = c.newRequest(opGetBucketNotificationConfiguration, input, output) + req = c.newRequest(op, input, output) output = &NotificationConfiguration{} req.Data = output return @@ -697,26 +591,21 @@ func (c *S3) GetBucketNotificationConfiguration(input *GetBucketNotificationConf return out, err } -var opGetBucketNotificationConfiguration *aws.Operation +const opGetBucketPolicy = "GetBucketPolicy" // GetBucketPolicyRequest generates a request for the GetBucketPolicy operation. func (c *S3) GetBucketPolicyRequest(input *GetBucketPolicyInput) (req *aws.Request, output *GetBucketPolicyOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketPolicy == nil { - opGetBucketPolicy = &aws.Operation{ - Name: "GetBucketPolicy", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?policy", - } + op := &aws.Operation{ + Name: opGetBucketPolicy, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?policy", } if input == nil { input = &GetBucketPolicyInput{} } - req = c.newRequest(opGetBucketPolicy, input, output) + req = c.newRequest(op, input, output) output = &GetBucketPolicyOutput{} req.Data = output return @@ -729,26 +618,21 @@ func (c *S3) GetBucketPolicy(input *GetBucketPolicyInput) (*GetBucketPolicyOutpu return out, err } -var opGetBucketPolicy *aws.Operation +const opGetBucketReplication = "GetBucketReplication" // GetBucketReplicationRequest generates a request for the GetBucketReplication operation. func (c *S3) GetBucketReplicationRequest(input *GetBucketReplicationInput) (req *aws.Request, output *GetBucketReplicationOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketReplication == nil { - opGetBucketReplication = &aws.Operation{ - Name: "GetBucketReplication", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?replication", - } + op := &aws.Operation{ + Name: opGetBucketReplication, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?replication", } if input == nil { input = &GetBucketReplicationInput{} } - req = c.newRequest(opGetBucketReplication, input, output) + req = c.newRequest(op, input, output) output = &GetBucketReplicationOutput{} req.Data = output return @@ -760,26 +644,21 @@ func (c *S3) GetBucketReplication(input *GetBucketReplicationInput) (*GetBucketR return out, err } -var opGetBucketReplication *aws.Operation +const opGetBucketRequestPayment = "GetBucketRequestPayment" // GetBucketRequestPaymentRequest generates a request for the GetBucketRequestPayment operation. func (c *S3) GetBucketRequestPaymentRequest(input *GetBucketRequestPaymentInput) (req *aws.Request, output *GetBucketRequestPaymentOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketRequestPayment == nil { - opGetBucketRequestPayment = &aws.Operation{ - Name: "GetBucketRequestPayment", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?requestPayment", - } + op := &aws.Operation{ + Name: opGetBucketRequestPayment, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?requestPayment", } if input == nil { input = &GetBucketRequestPaymentInput{} } - req = c.newRequest(opGetBucketRequestPayment, input, output) + req = c.newRequest(op, input, output) output = &GetBucketRequestPaymentOutput{} req.Data = output return @@ -792,26 +671,21 @@ func (c *S3) GetBucketRequestPayment(input *GetBucketRequestPaymentInput) (*GetB return out, err } -var opGetBucketRequestPayment *aws.Operation +const opGetBucketTagging = "GetBucketTagging" // GetBucketTaggingRequest generates a request for the GetBucketTagging operation. func (c *S3) GetBucketTaggingRequest(input *GetBucketTaggingInput) (req *aws.Request, output *GetBucketTaggingOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketTagging == nil { - opGetBucketTagging = &aws.Operation{ - Name: "GetBucketTagging", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?tagging", - } + op := &aws.Operation{ + Name: opGetBucketTagging, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?tagging", } if input == nil { input = &GetBucketTaggingInput{} } - req = c.newRequest(opGetBucketTagging, input, output) + req = c.newRequest(op, input, output) output = &GetBucketTaggingOutput{} req.Data = output return @@ -824,26 +698,21 @@ func (c *S3) GetBucketTagging(input *GetBucketTaggingInput) (*GetBucketTaggingOu return out, err } -var opGetBucketTagging *aws.Operation +const opGetBucketVersioning = "GetBucketVersioning" // GetBucketVersioningRequest generates a request for the GetBucketVersioning operation. func (c *S3) GetBucketVersioningRequest(input *GetBucketVersioningInput) (req *aws.Request, output *GetBucketVersioningOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketVersioning == nil { - opGetBucketVersioning = &aws.Operation{ - Name: "GetBucketVersioning", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?versioning", - } + op := &aws.Operation{ + Name: opGetBucketVersioning, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?versioning", } if input == nil { input = &GetBucketVersioningInput{} } - req = c.newRequest(opGetBucketVersioning, input, output) + req = c.newRequest(op, input, output) output = &GetBucketVersioningOutput{} req.Data = output return @@ -856,26 +725,21 @@ func (c *S3) GetBucketVersioning(input *GetBucketVersioningInput) (*GetBucketVer return out, err } -var opGetBucketVersioning *aws.Operation +const opGetBucketWebsite = "GetBucketWebsite" // GetBucketWebsiteRequest generates a request for the GetBucketWebsite operation. func (c *S3) GetBucketWebsiteRequest(input *GetBucketWebsiteInput) (req *aws.Request, output *GetBucketWebsiteOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetBucketWebsite == nil { - opGetBucketWebsite = &aws.Operation{ - Name: "GetBucketWebsite", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?website", - } + op := &aws.Operation{ + Name: opGetBucketWebsite, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?website", } if input == nil { input = &GetBucketWebsiteInput{} } - req = c.newRequest(opGetBucketWebsite, input, output) + req = c.newRequest(op, input, output) output = &GetBucketWebsiteOutput{} req.Data = output return @@ -888,26 +752,21 @@ func (c *S3) GetBucketWebsite(input *GetBucketWebsiteInput) (*GetBucketWebsiteOu return out, err } -var opGetBucketWebsite *aws.Operation +const opGetObject = "GetObject" // GetObjectRequest generates a request for the GetObject operation. func (c *S3) GetObjectRequest(input *GetObjectInput) (req *aws.Request, output *GetObjectOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetObject == nil { - opGetObject = &aws.Operation{ - Name: "GetObject", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}/{Key+}", - } + op := &aws.Operation{ + Name: opGetObject, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}/{Key+}", } if input == nil { input = &GetObjectInput{} } - req = c.newRequest(opGetObject, input, output) + req = c.newRequest(op, input, output) output = &GetObjectOutput{} req.Data = output return @@ -920,26 +779,21 @@ func (c *S3) GetObject(input *GetObjectInput) (*GetObjectOutput, error) { return out, err } -var opGetObject *aws.Operation +const opGetObjectACL = "GetObjectAcl" // GetObjectACLRequest generates a request for the GetObjectACL operation. func (c *S3) GetObjectACLRequest(input *GetObjectACLInput) (req *aws.Request, output *GetObjectACLOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetObjectACL == nil { - opGetObjectACL = &aws.Operation{ - Name: "GetObjectAcl", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}/{Key+}?acl", - } + op := &aws.Operation{ + Name: opGetObjectACL, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}/{Key+}?acl", } if input == nil { input = &GetObjectACLInput{} } - req = c.newRequest(opGetObjectACL, input, output) + req = c.newRequest(op, input, output) output = &GetObjectACLOutput{} req.Data = output return @@ -952,26 +806,21 @@ func (c *S3) GetObjectACL(input *GetObjectACLInput) (*GetObjectACLOutput, error) return out, err } -var opGetObjectACL *aws.Operation +const opGetObjectTorrent = "GetObjectTorrent" // GetObjectTorrentRequest generates a request for the GetObjectTorrent operation. func (c *S3) GetObjectTorrentRequest(input *GetObjectTorrentInput) (req *aws.Request, output *GetObjectTorrentOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opGetObjectTorrent == nil { - opGetObjectTorrent = &aws.Operation{ - Name: "GetObjectTorrent", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}/{Key+}?torrent", - } + op := &aws.Operation{ + Name: opGetObjectTorrent, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}/{Key+}?torrent", } if input == nil { input = &GetObjectTorrentInput{} } - req = c.newRequest(opGetObjectTorrent, input, output) + req = c.newRequest(op, input, output) output = &GetObjectTorrentOutput{} req.Data = output return @@ -984,26 +833,21 @@ func (c *S3) GetObjectTorrent(input *GetObjectTorrentInput) (*GetObjectTorrentOu return out, err } -var opGetObjectTorrent *aws.Operation +const opHeadBucket = "HeadBucket" // HeadBucketRequest generates a request for the HeadBucket operation. func (c *S3) HeadBucketRequest(input *HeadBucketInput) (req *aws.Request, output *HeadBucketOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opHeadBucket == nil { - opHeadBucket = &aws.Operation{ - Name: "HeadBucket", - HTTPMethod: "HEAD", - HTTPPath: "/{Bucket}", - } + op := &aws.Operation{ + Name: opHeadBucket, + HTTPMethod: "HEAD", + HTTPPath: "/{Bucket}", } if input == nil { input = &HeadBucketInput{} } - req = c.newRequest(opHeadBucket, input, output) + req = c.newRequest(op, input, output) output = &HeadBucketOutput{} req.Data = output return @@ -1017,26 +861,21 @@ func (c *S3) HeadBucket(input *HeadBucketInput) (*HeadBucketOutput, error) { return out, err } -var opHeadBucket *aws.Operation +const opHeadObject = "HeadObject" // HeadObjectRequest generates a request for the HeadObject operation. func (c *S3) HeadObjectRequest(input *HeadObjectInput) (req *aws.Request, output *HeadObjectOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opHeadObject == nil { - opHeadObject = &aws.Operation{ - Name: "HeadObject", - HTTPMethod: "HEAD", - HTTPPath: "/{Bucket}/{Key+}", - } + op := &aws.Operation{ + Name: opHeadObject, + HTTPMethod: "HEAD", + HTTPPath: "/{Bucket}/{Key+}", } if input == nil { input = &HeadObjectInput{} } - req = c.newRequest(opHeadObject, input, output) + req = c.newRequest(op, input, output) output = &HeadObjectOutput{} req.Data = output return @@ -1051,26 +890,21 @@ func (c *S3) HeadObject(input *HeadObjectInput) (*HeadObjectOutput, error) { return out, err } -var opHeadObject *aws.Operation +const opListBuckets = "ListBuckets" // ListBucketsRequest generates a request for the ListBuckets operation. func (c *S3) ListBucketsRequest(input *ListBucketsInput) (req *aws.Request, output *ListBucketsOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opListBuckets == nil { - opListBuckets = &aws.Operation{ - Name: "ListBuckets", - HTTPMethod: "GET", - HTTPPath: "/", - } + op := &aws.Operation{ + Name: opListBuckets, + HTTPMethod: "GET", + HTTPPath: "/", } if input == nil { input = &ListBucketsInput{} } - req = c.newRequest(opListBuckets, input, output) + req = c.newRequest(op, input, output) output = &ListBucketsOutput{} req.Data = output return @@ -1083,32 +917,27 @@ func (c *S3) ListBuckets(input *ListBucketsInput) (*ListBucketsOutput, error) { return out, err } -var opListBuckets *aws.Operation +const opListMultipartUploads = "ListMultipartUploads" // ListMultipartUploadsRequest generates a request for the ListMultipartUploads operation. func (c *S3) ListMultipartUploadsRequest(input *ListMultipartUploadsInput) (req *aws.Request, output *ListMultipartUploadsOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opListMultipartUploads == nil { - opListMultipartUploads = &aws.Operation{ - Name: "ListMultipartUploads", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?uploads", - Paginator: &aws.Paginator{ - InputTokens: []string{"KeyMarker", "UploadIdMarker"}, - OutputTokens: []string{"NextKeyMarker", "NextUploadIdMarker"}, - LimitToken: "MaxUploads", - TruncationToken: "IsTruncated", - }, - } + op := &aws.Operation{ + Name: opListMultipartUploads, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?uploads", + Paginator: &aws.Paginator{ + InputTokens: []string{"KeyMarker", "UploadIdMarker"}, + OutputTokens: []string{"NextKeyMarker", "NextUploadIdMarker"}, + LimitToken: "MaxUploads", + TruncationToken: "IsTruncated", + }, } if input == nil { input = &ListMultipartUploadsInput{} } - req = c.newRequest(opListMultipartUploads, input, output) + req = c.newRequest(op, input, output) output = &ListMultipartUploadsOutput{} req.Data = output return @@ -1128,32 +957,27 @@ func (c *S3) ListMultipartUploadsPages(input *ListMultipartUploadsInput, fn func }) } -var opListMultipartUploads *aws.Operation +const opListObjectVersions = "ListObjectVersions" // ListObjectVersionsRequest generates a request for the ListObjectVersions operation. func (c *S3) ListObjectVersionsRequest(input *ListObjectVersionsInput) (req *aws.Request, output *ListObjectVersionsOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opListObjectVersions == nil { - opListObjectVersions = &aws.Operation{ - Name: "ListObjectVersions", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}?versions", - Paginator: &aws.Paginator{ - InputTokens: []string{"KeyMarker", "VersionIdMarker"}, - OutputTokens: []string{"NextKeyMarker", "NextVersionIdMarker"}, - LimitToken: "MaxKeys", - TruncationToken: "IsTruncated", - }, - } + op := &aws.Operation{ + Name: opListObjectVersions, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}?versions", + Paginator: &aws.Paginator{ + InputTokens: []string{"KeyMarker", "VersionIdMarker"}, + OutputTokens: []string{"NextKeyMarker", "NextVersionIdMarker"}, + LimitToken: "MaxKeys", + TruncationToken: "IsTruncated", + }, } if input == nil { input = &ListObjectVersionsInput{} } - req = c.newRequest(opListObjectVersions, input, output) + req = c.newRequest(op, input, output) output = &ListObjectVersionsOutput{} req.Data = output return @@ -1173,32 +997,27 @@ func (c *S3) ListObjectVersionsPages(input *ListObjectVersionsInput, fn func(p * }) } -var opListObjectVersions *aws.Operation +const opListObjects = "ListObjects" // ListObjectsRequest generates a request for the ListObjects operation. func (c *S3) ListObjectsRequest(input *ListObjectsInput) (req *aws.Request, output *ListObjectsOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opListObjects == nil { - opListObjects = &aws.Operation{ - Name: "ListObjects", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}", - Paginator: &aws.Paginator{ - InputTokens: []string{"Marker"}, - OutputTokens: []string{"NextMarker || Contents[-1].Key"}, - LimitToken: "MaxKeys", - TruncationToken: "IsTruncated", - }, - } + op := &aws.Operation{ + Name: opListObjects, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}", + Paginator: &aws.Paginator{ + InputTokens: []string{"Marker"}, + OutputTokens: []string{"NextMarker || Contents[-1].Key"}, + LimitToken: "MaxKeys", + TruncationToken: "IsTruncated", + }, } if input == nil { input = &ListObjectsInput{} } - req = c.newRequest(opListObjects, input, output) + req = c.newRequest(op, input, output) output = &ListObjectsOutput{} req.Data = output return @@ -1220,32 +1039,27 @@ func (c *S3) ListObjectsPages(input *ListObjectsInput, fn func(p *ListObjectsOut }) } -var opListObjects *aws.Operation +const opListParts = "ListParts" // ListPartsRequest generates a request for the ListParts operation. func (c *S3) ListPartsRequest(input *ListPartsInput) (req *aws.Request, output *ListPartsOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opListParts == nil { - opListParts = &aws.Operation{ - Name: "ListParts", - HTTPMethod: "GET", - HTTPPath: "/{Bucket}/{Key+}", - Paginator: &aws.Paginator{ - InputTokens: []string{"PartNumberMarker"}, - OutputTokens: []string{"NextPartNumberMarker"}, - LimitToken: "MaxParts", - TruncationToken: "IsTruncated", - }, - } + op := &aws.Operation{ + Name: opListParts, + HTTPMethod: "GET", + HTTPPath: "/{Bucket}/{Key+}", + Paginator: &aws.Paginator{ + InputTokens: []string{"PartNumberMarker"}, + OutputTokens: []string{"NextPartNumberMarker"}, + LimitToken: "MaxParts", + TruncationToken: "IsTruncated", + }, } if input == nil { input = &ListPartsInput{} } - req = c.newRequest(opListParts, input, output) + req = c.newRequest(op, input, output) output = &ListPartsOutput{} req.Data = output return @@ -1265,26 +1079,21 @@ func (c *S3) ListPartsPages(input *ListPartsInput, fn func(p *ListPartsOutput, l }) } -var opListParts *aws.Operation +const opPutBucketACL = "PutBucketAcl" // PutBucketACLRequest generates a request for the PutBucketACL operation. func (c *S3) PutBucketACLRequest(input *PutBucketACLInput) (req *aws.Request, output *PutBucketACLOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketACL == nil { - opPutBucketACL = &aws.Operation{ - Name: "PutBucketAcl", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?acl", - } + op := &aws.Operation{ + Name: opPutBucketACL, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?acl", } if input == nil { input = &PutBucketACLInput{} } - req = c.newRequest(opPutBucketACL, input, output) + req = c.newRequest(op, input, output) output = &PutBucketACLOutput{} req.Data = output return @@ -1297,26 +1106,21 @@ func (c *S3) PutBucketACL(input *PutBucketACLInput) (*PutBucketACLOutput, error) return out, err } -var opPutBucketACL *aws.Operation +const opPutBucketCORS = "PutBucketCors" // PutBucketCORSRequest generates a request for the PutBucketCORS operation. func (c *S3) PutBucketCORSRequest(input *PutBucketCORSInput) (req *aws.Request, output *PutBucketCORSOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketCORS == nil { - opPutBucketCORS = &aws.Operation{ - Name: "PutBucketCors", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?cors", - } + op := &aws.Operation{ + Name: opPutBucketCORS, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?cors", } if input == nil { input = &PutBucketCORSInput{} } - req = c.newRequest(opPutBucketCORS, input, output) + req = c.newRequest(op, input, output) output = &PutBucketCORSOutput{} req.Data = output return @@ -1329,26 +1133,21 @@ func (c *S3) PutBucketCORS(input *PutBucketCORSInput) (*PutBucketCORSOutput, err return out, err } -var opPutBucketCORS *aws.Operation +const opPutBucketLifecycle = "PutBucketLifecycle" // PutBucketLifecycleRequest generates a request for the PutBucketLifecycle operation. func (c *S3) PutBucketLifecycleRequest(input *PutBucketLifecycleInput) (req *aws.Request, output *PutBucketLifecycleOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketLifecycle == nil { - opPutBucketLifecycle = &aws.Operation{ - Name: "PutBucketLifecycle", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?lifecycle", - } + op := &aws.Operation{ + Name: opPutBucketLifecycle, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?lifecycle", } if input == nil { input = &PutBucketLifecycleInput{} } - req = c.newRequest(opPutBucketLifecycle, input, output) + req = c.newRequest(op, input, output) output = &PutBucketLifecycleOutput{} req.Data = output return @@ -1362,26 +1161,21 @@ func (c *S3) PutBucketLifecycle(input *PutBucketLifecycleInput) (*PutBucketLifec return out, err } -var opPutBucketLifecycle *aws.Operation +const opPutBucketLogging = "PutBucketLogging" // PutBucketLoggingRequest generates a request for the PutBucketLogging operation. func (c *S3) PutBucketLoggingRequest(input *PutBucketLoggingInput) (req *aws.Request, output *PutBucketLoggingOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketLogging == nil { - opPutBucketLogging = &aws.Operation{ - Name: "PutBucketLogging", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?logging", - } + op := &aws.Operation{ + Name: opPutBucketLogging, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?logging", } if input == nil { input = &PutBucketLoggingInput{} } - req = c.newRequest(opPutBucketLogging, input, output) + req = c.newRequest(op, input, output) output = &PutBucketLoggingOutput{} req.Data = output return @@ -1396,26 +1190,21 @@ func (c *S3) PutBucketLogging(input *PutBucketLoggingInput) (*PutBucketLoggingOu return out, err } -var opPutBucketLogging *aws.Operation +const opPutBucketNotification = "PutBucketNotification" // PutBucketNotificationRequest generates a request for the PutBucketNotification operation. func (c *S3) PutBucketNotificationRequest(input *PutBucketNotificationInput) (req *aws.Request, output *PutBucketNotificationOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketNotification == nil { - opPutBucketNotification = &aws.Operation{ - Name: "PutBucketNotification", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?notification", - } + op := &aws.Operation{ + Name: opPutBucketNotification, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?notification", } if input == nil { input = &PutBucketNotificationInput{} } - req = c.newRequest(opPutBucketNotification, input, output) + req = c.newRequest(op, input, output) output = &PutBucketNotificationOutput{} req.Data = output return @@ -1428,26 +1217,21 @@ func (c *S3) PutBucketNotification(input *PutBucketNotificationInput) (*PutBucke return out, err } -var opPutBucketNotification *aws.Operation +const opPutBucketNotificationConfiguration = "PutBucketNotificationConfiguration" // PutBucketNotificationConfigurationRequest generates a request for the PutBucketNotificationConfiguration operation. func (c *S3) PutBucketNotificationConfigurationRequest(input *PutBucketNotificationConfigurationInput) (req *aws.Request, output *PutBucketNotificationConfigurationOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketNotificationConfiguration == nil { - opPutBucketNotificationConfiguration = &aws.Operation{ - Name: "PutBucketNotificationConfiguration", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?notification", - } + op := &aws.Operation{ + Name: opPutBucketNotificationConfiguration, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?notification", } if input == nil { input = &PutBucketNotificationConfigurationInput{} } - req = c.newRequest(opPutBucketNotificationConfiguration, input, output) + req = c.newRequest(op, input, output) output = &PutBucketNotificationConfigurationOutput{} req.Data = output return @@ -1460,26 +1244,21 @@ func (c *S3) PutBucketNotificationConfiguration(input *PutBucketNotificationConf return out, err } -var opPutBucketNotificationConfiguration *aws.Operation +const opPutBucketPolicy = "PutBucketPolicy" // PutBucketPolicyRequest generates a request for the PutBucketPolicy operation. func (c *S3) PutBucketPolicyRequest(input *PutBucketPolicyInput) (req *aws.Request, output *PutBucketPolicyOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketPolicy == nil { - opPutBucketPolicy = &aws.Operation{ - Name: "PutBucketPolicy", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?policy", - } + op := &aws.Operation{ + Name: opPutBucketPolicy, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?policy", } if input == nil { input = &PutBucketPolicyInput{} } - req = c.newRequest(opPutBucketPolicy, input, output) + req = c.newRequest(op, input, output) output = &PutBucketPolicyOutput{} req.Data = output return @@ -1493,26 +1272,21 @@ func (c *S3) PutBucketPolicy(input *PutBucketPolicyInput) (*PutBucketPolicyOutpu return out, err } -var opPutBucketPolicy *aws.Operation +const opPutBucketReplication = "PutBucketReplication" // PutBucketReplicationRequest generates a request for the PutBucketReplication operation. func (c *S3) PutBucketReplicationRequest(input *PutBucketReplicationInput) (req *aws.Request, output *PutBucketReplicationOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketReplication == nil { - opPutBucketReplication = &aws.Operation{ - Name: "PutBucketReplication", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?replication", - } + op := &aws.Operation{ + Name: opPutBucketReplication, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?replication", } if input == nil { input = &PutBucketReplicationInput{} } - req = c.newRequest(opPutBucketReplication, input, output) + req = c.newRequest(op, input, output) output = &PutBucketReplicationOutput{} req.Data = output return @@ -1526,26 +1300,21 @@ func (c *S3) PutBucketReplication(input *PutBucketReplicationInput) (*PutBucketR return out, err } -var opPutBucketReplication *aws.Operation +const opPutBucketRequestPayment = "PutBucketRequestPayment" // PutBucketRequestPaymentRequest generates a request for the PutBucketRequestPayment operation. func (c *S3) PutBucketRequestPaymentRequest(input *PutBucketRequestPaymentInput) (req *aws.Request, output *PutBucketRequestPaymentOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketRequestPayment == nil { - opPutBucketRequestPayment = &aws.Operation{ - Name: "PutBucketRequestPayment", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?requestPayment", - } + op := &aws.Operation{ + Name: opPutBucketRequestPayment, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?requestPayment", } if input == nil { input = &PutBucketRequestPaymentInput{} } - req = c.newRequest(opPutBucketRequestPayment, input, output) + req = c.newRequest(op, input, output) output = &PutBucketRequestPaymentOutput{} req.Data = output return @@ -1562,26 +1331,21 @@ func (c *S3) PutBucketRequestPayment(input *PutBucketRequestPaymentInput) (*PutB return out, err } -var opPutBucketRequestPayment *aws.Operation +const opPutBucketTagging = "PutBucketTagging" // PutBucketTaggingRequest generates a request for the PutBucketTagging operation. func (c *S3) PutBucketTaggingRequest(input *PutBucketTaggingInput) (req *aws.Request, output *PutBucketTaggingOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketTagging == nil { - opPutBucketTagging = &aws.Operation{ - Name: "PutBucketTagging", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?tagging", - } + op := &aws.Operation{ + Name: opPutBucketTagging, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?tagging", } if input == nil { input = &PutBucketTaggingInput{} } - req = c.newRequest(opPutBucketTagging, input, output) + req = c.newRequest(op, input, output) output = &PutBucketTaggingOutput{} req.Data = output return @@ -1594,26 +1358,21 @@ func (c *S3) PutBucketTagging(input *PutBucketTaggingInput) (*PutBucketTaggingOu return out, err } -var opPutBucketTagging *aws.Operation +const opPutBucketVersioning = "PutBucketVersioning" // PutBucketVersioningRequest generates a request for the PutBucketVersioning operation. func (c *S3) PutBucketVersioningRequest(input *PutBucketVersioningInput) (req *aws.Request, output *PutBucketVersioningOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketVersioning == nil { - opPutBucketVersioning = &aws.Operation{ - Name: "PutBucketVersioning", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?versioning", - } + op := &aws.Operation{ + Name: opPutBucketVersioning, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?versioning", } if input == nil { input = &PutBucketVersioningInput{} } - req = c.newRequest(opPutBucketVersioning, input, output) + req = c.newRequest(op, input, output) output = &PutBucketVersioningOutput{} req.Data = output return @@ -1627,26 +1386,21 @@ func (c *S3) PutBucketVersioning(input *PutBucketVersioningInput) (*PutBucketVer return out, err } -var opPutBucketVersioning *aws.Operation +const opPutBucketWebsite = "PutBucketWebsite" // PutBucketWebsiteRequest generates a request for the PutBucketWebsite operation. func (c *S3) PutBucketWebsiteRequest(input *PutBucketWebsiteInput) (req *aws.Request, output *PutBucketWebsiteOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutBucketWebsite == nil { - opPutBucketWebsite = &aws.Operation{ - Name: "PutBucketWebsite", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}?website", - } + op := &aws.Operation{ + Name: opPutBucketWebsite, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}?website", } if input == nil { input = &PutBucketWebsiteInput{} } - req = c.newRequest(opPutBucketWebsite, input, output) + req = c.newRequest(op, input, output) output = &PutBucketWebsiteOutput{} req.Data = output return @@ -1659,26 +1413,21 @@ func (c *S3) PutBucketWebsite(input *PutBucketWebsiteInput) (*PutBucketWebsiteOu return out, err } -var opPutBucketWebsite *aws.Operation +const opPutObject = "PutObject" // PutObjectRequest generates a request for the PutObject operation. func (c *S3) PutObjectRequest(input *PutObjectInput) (req *aws.Request, output *PutObjectOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutObject == nil { - opPutObject = &aws.Operation{ - Name: "PutObject", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}/{Key+}", - } + op := &aws.Operation{ + Name: opPutObject, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}/{Key+}", } if input == nil { input = &PutObjectInput{} } - req = c.newRequest(opPutObject, input, output) + req = c.newRequest(op, input, output) output = &PutObjectOutput{} req.Data = output return @@ -1691,26 +1440,21 @@ func (c *S3) PutObject(input *PutObjectInput) (*PutObjectOutput, error) { return out, err } -var opPutObject *aws.Operation +const opPutObjectACL = "PutObjectAcl" // PutObjectACLRequest generates a request for the PutObjectACL operation. func (c *S3) PutObjectACLRequest(input *PutObjectACLInput) (req *aws.Request, output *PutObjectACLOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opPutObjectACL == nil { - opPutObjectACL = &aws.Operation{ - Name: "PutObjectAcl", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}/{Key+}?acl", - } + op := &aws.Operation{ + Name: opPutObjectACL, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}/{Key+}?acl", } if input == nil { input = &PutObjectACLInput{} } - req = c.newRequest(opPutObjectACL, input, output) + req = c.newRequest(op, input, output) output = &PutObjectACLOutput{} req.Data = output return @@ -1724,26 +1468,21 @@ func (c *S3) PutObjectACL(input *PutObjectACLInput) (*PutObjectACLOutput, error) return out, err } -var opPutObjectACL *aws.Operation +const opRestoreObject = "RestoreObject" // RestoreObjectRequest generates a request for the RestoreObject operation. func (c *S3) RestoreObjectRequest(input *RestoreObjectInput) (req *aws.Request, output *RestoreObjectOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opRestoreObject == nil { - opRestoreObject = &aws.Operation{ - Name: "RestoreObject", - HTTPMethod: "POST", - HTTPPath: "/{Bucket}/{Key+}?restore", - } + op := &aws.Operation{ + Name: opRestoreObject, + HTTPMethod: "POST", + HTTPPath: "/{Bucket}/{Key+}?restore", } if input == nil { input = &RestoreObjectInput{} } - req = c.newRequest(opRestoreObject, input, output) + req = c.newRequest(op, input, output) output = &RestoreObjectOutput{} req.Data = output return @@ -1756,26 +1495,21 @@ func (c *S3) RestoreObject(input *RestoreObjectInput) (*RestoreObjectOutput, err return out, err } -var opRestoreObject *aws.Operation +const opUploadPart = "UploadPart" // UploadPartRequest generates a request for the UploadPart operation. func (c *S3) UploadPartRequest(input *UploadPartInput) (req *aws.Request, output *UploadPartOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opUploadPart == nil { - opUploadPart = &aws.Operation{ - Name: "UploadPart", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}/{Key+}", - } + op := &aws.Operation{ + Name: opUploadPart, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}/{Key+}", } if input == nil { input = &UploadPartInput{} } - req = c.newRequest(opUploadPart, input, output) + req = c.newRequest(op, input, output) output = &UploadPartOutput{} req.Data = output return @@ -1794,26 +1528,21 @@ func (c *S3) UploadPart(input *UploadPartInput) (*UploadPartOutput, error) { return out, err } -var opUploadPart *aws.Operation +const opUploadPartCopy = "UploadPartCopy" // UploadPartCopyRequest generates a request for the UploadPartCopy operation. func (c *S3) UploadPartCopyRequest(input *UploadPartCopyInput) (req *aws.Request, output *UploadPartCopyOutput) { - oprw.Lock() - defer oprw.Unlock() - - if opUploadPartCopy == nil { - opUploadPartCopy = &aws.Operation{ - Name: "UploadPartCopy", - HTTPMethod: "PUT", - HTTPPath: "/{Bucket}/{Key+}", - } + op := &aws.Operation{ + Name: opUploadPartCopy, + HTTPMethod: "PUT", + HTTPPath: "/{Bucket}/{Key+}", } if input == nil { input = &UploadPartCopyInput{} } - req = c.newRequest(opUploadPartCopy, input, output) + req = c.newRequest(op, input, output) output = &UploadPartCopyOutput{} req.Data = output return @@ -1826,8 +1555,6 @@ func (c *S3) UploadPartCopy(input *UploadPartCopyInput) (*UploadPartCopyOutput, return out, err } -var opUploadPartCopy *aws.Operation - type AbortMultipartUploadInput struct { Bucket *string `location:"uri" locationName:"Bucket" type:"string" required:"true"` diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/bucket_location.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/bucket_location.go index 8cc0dedeaf..59eb84524b 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/bucket_location.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/bucket_location.go @@ -5,8 +5,8 @@ import ( "regexp" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awsutil" - "github.com/aws/aws-sdk-go/internal/apierr" ) var reBucketLocation = regexp.MustCompile(`>([^<>]+)<\/Location`) @@ -16,7 +16,7 @@ func buildGetBucketLocation(r *aws.Request) { out := r.Data.(*GetBucketLocationOutput) b, err := ioutil.ReadAll(r.HTTPResponse.Body) if err != nil { - r.Error = apierr.New("Unmarshal", "failed reading response body", err) + r.Error = awserr.New("SerializationError", "failed reading response body", err) return } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/content_md5.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/content_md5.go index 25e9a8aaec..386f09a3f2 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/content_md5.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/content_md5.go @@ -6,7 +6,7 @@ import ( "io" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" ) // contentMD5 computes and sets the HTTP Content-MD5 header for requests that @@ -19,12 +19,12 @@ func contentMD5(r *aws.Request) { // body. _, err := io.Copy(h, r.Body) if err != nil { - r.Error = apierr.New("ContentMD5", "failed to read body", err) + r.Error = awserr.New("ContentMD5", "failed to read body", err) return } _, err = r.Body.Seek(0, 0) if err != nil { - r.Error = apierr.New("ContentMD5", "failed to seek body", err) + r.Error = awserr.New("ContentMD5", "failed to seek body", err) return } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/customizations.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/customizations.go index de12c8f00c..490ff2d8ab 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/customizations.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/customizations.go @@ -17,7 +17,7 @@ func init() { } initRequest = func(r *aws.Request) { - switch r.Operation { + switch r.Operation.Name { case opPutBucketCORS, opPutBucketLifecycle, opPutBucketPolicy, opPutBucketTagging, opDeleteObjects: // These S3 operations require Content-MD5 to be set r.Handlers.Build.PushBack(contentMD5) diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/customizations_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/customizations_test.go index 2096f91044..523b4870e8 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/customizations_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/customizations_test.go @@ -30,7 +30,7 @@ func TestMD5InPutBucketCORS(t *testing.T) { Bucket: aws.String("bucketname"), CORSConfiguration: &s3.CORSConfiguration{ CORSRules: []*s3.CORSRule{ - &s3.CORSRule{AllowedMethods: []*string{aws.String("GET")}}, + {AllowedMethods: []*string{aws.String("GET")}}, }, }, }) @@ -43,7 +43,7 @@ func TestMD5InPutBucketLifecycle(t *testing.T) { Bucket: aws.String("bucketname"), LifecycleConfiguration: &s3.LifecycleConfiguration{ Rules: []*s3.LifecycleRule{ - &s3.LifecycleRule{ + { ID: aws.String("ID"), Prefix: aws.String("Prefix"), Status: aws.String("Enabled"), @@ -69,7 +69,7 @@ func TestMD5InPutBucketTagging(t *testing.T) { Bucket: aws.String("bucketname"), Tagging: &s3.Tagging{ TagSet: []*s3.Tag{ - &s3.Tag{Key: aws.String("KEY"), Value: aws.String("VALUE")}, + {Key: aws.String("KEY"), Value: aws.String("VALUE")}, }, }, }) @@ -82,7 +82,7 @@ func TestMD5InDeleteObjects(t *testing.T) { Bucket: aws.String("bucketname"), Delete: &s3.Delete{ Objects: []*s3.ObjectIdentifier{ - &s3.ObjectIdentifier{Key: aws.String("key")}, + {Key: aws.String("key")}, }, }, }) diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/examples_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/examples_test.go index 6ea0e769cd..7dde748c80 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/examples_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/examples_test.go @@ -36,7 +36,7 @@ func ExampleS3_AbortMultipartUpload() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -55,7 +55,7 @@ func ExampleS3_CompleteMultipartUpload() { UploadID: aws.String("MultipartUploadId"), // Required MultipartUpload: &s3.CompletedMultipartUpload{ Parts: []*s3.CompletedPart{ - &s3.CompletedPart{ // Required + { // Required ETag: aws.String("ETag"), PartNumber: aws.Long(1), }, @@ -75,7 +75,7 @@ func ExampleS3_CompleteMultipartUpload() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -135,7 +135,7 @@ func ExampleS3_CopyObject() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -171,7 +171,7 @@ func ExampleS3_CreateBucket() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -222,7 +222,7 @@ func ExampleS3_CreateMultipartUpload() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -249,7 +249,7 @@ func ExampleS3_DeleteBucket() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -276,7 +276,7 @@ func ExampleS3_DeleteBucketCORS() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -303,7 +303,7 @@ func ExampleS3_DeleteBucketLifecycle() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -330,7 +330,7 @@ func ExampleS3_DeleteBucketPolicy() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -357,7 +357,7 @@ func ExampleS3_DeleteBucketReplication() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -384,7 +384,7 @@ func ExampleS3_DeleteBucketTagging() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -411,7 +411,7 @@ func ExampleS3_DeleteBucketWebsite() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -442,7 +442,7 @@ func ExampleS3_DeleteObject() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -459,7 +459,7 @@ func ExampleS3_DeleteObjects() { Bucket: aws.String("BucketName"), // Required Delete: &s3.Delete{ // Required Objects: []*s3.ObjectIdentifier{ // Required - &s3.ObjectIdentifier{ // Required + { // Required Key: aws.String("ObjectKey"), // Required VersionID: aws.String("ObjectVersionId"), }, @@ -481,7 +481,7 @@ func ExampleS3_DeleteObjects() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -508,7 +508,7 @@ func ExampleS3_GetBucketACL() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -535,7 +535,7 @@ func ExampleS3_GetBucketCORS() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -562,7 +562,7 @@ func ExampleS3_GetBucketLifecycle() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -589,7 +589,7 @@ func ExampleS3_GetBucketLocation() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -616,7 +616,7 @@ func ExampleS3_GetBucketLogging() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -643,7 +643,7 @@ func ExampleS3_GetBucketNotification() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -670,7 +670,7 @@ func ExampleS3_GetBucketNotificationConfiguration() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -697,7 +697,7 @@ func ExampleS3_GetBucketPolicy() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -724,7 +724,7 @@ func ExampleS3_GetBucketReplication() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -751,7 +751,7 @@ func ExampleS3_GetBucketRequestPayment() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -778,7 +778,7 @@ func ExampleS3_GetBucketTagging() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -805,7 +805,7 @@ func ExampleS3_GetBucketVersioning() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -832,7 +832,7 @@ func ExampleS3_GetBucketWebsite() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -876,7 +876,7 @@ func ExampleS3_GetObject() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -906,7 +906,7 @@ func ExampleS3_GetObjectACL() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -935,7 +935,7 @@ func ExampleS3_GetObjectTorrent() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -962,7 +962,7 @@ func ExampleS3_HeadBucket() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1000,7 +1000,7 @@ func ExampleS3_HeadObject() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1025,7 +1025,7 @@ func ExampleS3_ListBuckets() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1058,7 +1058,7 @@ func ExampleS3_ListMultipartUploads() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1091,7 +1091,7 @@ func ExampleS3_ListObjectVersions() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1123,7 +1123,7 @@ func ExampleS3_ListObjects() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1155,7 +1155,7 @@ func ExampleS3_ListParts() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1173,7 +1173,7 @@ func ExampleS3_PutBucketACL() { ACL: aws.String("BucketCannedACL"), AccessControlPolicy: &s3.AccessControlPolicy{ Grants: []*s3.Grant{ - &s3.Grant{ // Required + { // Required Grantee: &s3.Grantee{ Type: aws.String("Type"), // Required DisplayName: aws.String("DisplayName"), @@ -1207,7 +1207,7 @@ func ExampleS3_PutBucketACL() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1224,7 +1224,7 @@ func ExampleS3_PutBucketCORS() { Bucket: aws.String("BucketName"), // Required CORSConfiguration: &s3.CORSConfiguration{ CORSRules: []*s3.CORSRule{ - &s3.CORSRule{ // Required + { // Required AllowedHeaders: []*string{ aws.String("AllowedHeader"), // Required // More values... @@ -1258,7 +1258,7 @@ func ExampleS3_PutBucketCORS() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1275,7 +1275,7 @@ func ExampleS3_PutBucketLifecycle() { Bucket: aws.String("BucketName"), // Required LifecycleConfiguration: &s3.LifecycleConfiguration{ Rules: []*s3.LifecycleRule{ // Required - &s3.LifecycleRule{ // Required + { // Required Prefix: aws.String("Prefix"), // Required Status: aws.String("ExpirationStatus"), // Required Expiration: &s3.LifecycleExpiration{ @@ -1311,7 +1311,7 @@ func ExampleS3_PutBucketLifecycle() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1330,7 +1330,7 @@ func ExampleS3_PutBucketLogging() { LoggingEnabled: &s3.LoggingEnabled{ TargetBucket: aws.String("TargetBucket"), TargetGrants: []*s3.TargetGrant{ - &s3.TargetGrant{ // Required + { // Required Grantee: &s3.Grantee{ Type: aws.String("Type"), // Required DisplayName: aws.String("DisplayName"), @@ -1357,7 +1357,7 @@ func ExampleS3_PutBucketLogging() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1414,7 +1414,7 @@ func ExampleS3_PutBucketNotification() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1431,7 +1431,7 @@ func ExampleS3_PutBucketNotificationConfiguration() { Bucket: aws.String("BucketName"), // Required NotificationConfiguration: &s3.NotificationConfiguration{ // Required LambdaFunctionConfigurations: []*s3.LambdaFunctionConfiguration{ - &s3.LambdaFunctionConfiguration{ // Required + { // Required Events: []*string{ // Required aws.String("Event"), // Required // More values... @@ -1442,7 +1442,7 @@ func ExampleS3_PutBucketNotificationConfiguration() { // More values... }, QueueConfigurations: []*s3.QueueConfiguration{ - &s3.QueueConfiguration{ // Required + { // Required Events: []*string{ // Required aws.String("Event"), // Required // More values... @@ -1453,7 +1453,7 @@ func ExampleS3_PutBucketNotificationConfiguration() { // More values... }, TopicConfigurations: []*s3.TopicConfiguration{ - &s3.TopicConfiguration{ // Required + { // Required Events: []*string{ // Required aws.String("Event"), // Required // More values... @@ -1476,7 +1476,7 @@ func ExampleS3_PutBucketNotificationConfiguration() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1504,7 +1504,7 @@ func ExampleS3_PutBucketPolicy() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1522,7 +1522,7 @@ func ExampleS3_PutBucketReplication() { ReplicationConfiguration: &s3.ReplicationConfiguration{ // Required Role: aws.String("Role"), // Required Rules: []*s3.ReplicationRule{ // Required - &s3.ReplicationRule{ // Required + { // Required Destination: &s3.Destination{ // Required Bucket: aws.String("BucketName"), // Required }, @@ -1545,7 +1545,7 @@ func ExampleS3_PutBucketReplication() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1575,7 +1575,7 @@ func ExampleS3_PutBucketRequestPayment() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1592,7 +1592,7 @@ func ExampleS3_PutBucketTagging() { Bucket: aws.String("BucketName"), // Required Tagging: &s3.Tagging{ // Required TagSet: []*s3.Tag{ // Required - &s3.Tag{ // Required + { // Required Key: aws.String("ObjectKey"), // Required Value: aws.String("Value"), // Required }, @@ -1611,7 +1611,7 @@ func ExampleS3_PutBucketTagging() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1643,7 +1643,7 @@ func ExampleS3_PutBucketVersioning() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1670,7 +1670,7 @@ func ExampleS3_PutBucketWebsite() { Protocol: aws.String("Protocol"), }, RoutingRules: []*s3.RoutingRule{ - &s3.RoutingRule{ // Required + { // Required Redirect: &s3.Redirect{ // Required HTTPRedirectCode: aws.String("HttpRedirectCode"), HostName: aws.String("HostName"), @@ -1698,7 +1698,7 @@ func ExampleS3_PutBucketWebsite() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1751,7 +1751,7 @@ func ExampleS3_PutObject() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1770,7 +1770,7 @@ func ExampleS3_PutObjectACL() { ACL: aws.String("ObjectCannedACL"), AccessControlPolicy: &s3.AccessControlPolicy{ Grants: []*s3.Grant{ - &s3.Grant{ // Required + { // Required Grantee: &s3.Grantee{ Type: aws.String("Type"), // Required DisplayName: aws.String("DisplayName"), @@ -1805,7 +1805,7 @@ func ExampleS3_PutObjectACL() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1838,7 +1838,7 @@ func ExampleS3_RestoreObject() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1874,7 +1874,7 @@ func ExampleS3_UploadPart() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } @@ -1917,7 +1917,7 @@ func ExampleS3_UploadPartCopy() { fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) } } else { - // This case should never be hit, The SDK should alwsy return an + // This case should never be hit, the SDK should always return an // error which satisfies the awserr.Error interface. fmt.Println(err.Error()) } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/download.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/download.go index 87dbe03a4e..d6ebe024ed 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/download.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/download.go @@ -129,12 +129,7 @@ func (d *downloader) download() (n int64, err error) { } // Queue the next range of bytes to read. - ch <- dlchunk{ - dlchunkcounter: &dlchunkcounter{}, - w: d.w, - start: d.pos, - size: d.opts.PartSize, - } + ch <- dlchunk{w: d.w, start: d.pos, size: d.opts.PartSize} d.pos += d.opts.PartSize } @@ -175,7 +170,7 @@ func (d *downloader) downloadPart(ch chan dlchunk) { } else { d.setTotalBytes(resp) // Set total if not yet set. - n, err := io.Copy(chunk, resp.Body) + n, err := io.Copy(&chunk, resp.Body) resp.Body.Close() if err != nil { @@ -242,21 +237,15 @@ func (d *downloader) seterr(e error) { // io.WriterAt, effectively making it an io.SectionWriter (which does not // exist). type dlchunk struct { - *dlchunkcounter w io.WriterAt start int64 size int64 -} - -// dlchunkcounter keeps track of the current position the dlchunk struct is -// writing to. -type dlchunkcounter struct { - cur int64 + cur int64 } // Write wraps io.WriterAt for the dlchunk, writing from the dlchunk's start // position to its end (or EOF). -func (c dlchunk) Write(p []byte) (n int, err error) { +func (c *dlchunk) Write(p []byte) (n int, err error) { if c.cur >= c.size { return 0, io.EOF } diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/upload.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/upload.go index cdb83e47ae..db556805d3 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/upload.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/upload.go @@ -10,7 +10,6 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awsutil" - "github.com/aws/aws-sdk-go/internal/apierr" "github.com/aws/aws-sdk-go/service/s3" ) @@ -60,13 +59,17 @@ type MultiUploadFailure interface { UploadID() string } +// So that the Error interface type can be included as an anonymous field +// in the multiUploadError struct and not conflict with the error.Error() method. +type awsError awserr.Error + // A multiUploadError wraps the upload ID of a failed s3 multipart upload. // Composed of BaseError for code, message, and original error // // Should be used for an error that occurred failing a S3 multipart upload, // and a upload ID is available. If an uploadID is not available a more relevant type multiUploadError struct { - *apierr.BaseError + awsError // ID for multipart upload which failed. uploadID string @@ -77,18 +80,19 @@ type multiUploadError struct { // See apierr.BaseError ErrorWithExtra for output format // // Satisfies the error interface. -func (m *multiUploadError) Error() string { - return m.ErrorWithExtra(fmt.Sprintf("upload id: %s", m.uploadID)) +func (m multiUploadError) Error() string { + extra := fmt.Sprintf("upload id: %s", m.uploadID) + return awserr.SprintError(m.Code(), m.Message(), extra, m.OrigErr()) } // String returns the string representation of the error. // Alias for Error to satisfy the stringer interface. -func (m *multiUploadError) String() string { +func (m multiUploadError) String() string { return m.Error() } // UploadID returns the id of the S3 upload which failed. -func (m *multiUploadError) UploadID() string { +func (m multiUploadError) UploadID() string { return m.uploadID } @@ -258,7 +262,7 @@ func (u *uploader) upload() (*UploadOutput, error) { if u.opts.PartSize < MinUploadPartSize { msg := fmt.Sprintf("part size must be at least %d bytes", MinUploadPartSize) - return nil, apierr.New("ConfigError", msg, nil) + return nil, awserr.New("ConfigError", msg, nil) } // Do one read to determine if we have more than one part @@ -266,7 +270,7 @@ func (u *uploader) upload() (*UploadOutput, error) { if err == io.EOF || err == io.ErrUnexpectedEOF { // single part return u.singlePart(buf) } else if err != nil { - return nil, apierr.New("ReadRequestBody", "read upload data failed", err) + return nil, awserr.New("ReadRequestBody", "read upload data failed", err) } mu := multiuploader{uploader: u} @@ -418,7 +422,7 @@ func (u *multiuploader) upload(firstBuf io.ReadSeeker) (*UploadOutput, error) { if num > int64(MaxUploadParts) { msg := fmt.Sprintf("exceeded total allowed parts (%d). "+ "Adjust PartSize to fit in this limit", MaxUploadParts) - u.seterr(apierr.New("TotalPartsExceeded", msg, nil)) + u.seterr(awserr.New("TotalPartsExceeded", msg, nil)) break } @@ -432,7 +436,10 @@ func (u *multiuploader) upload(firstBuf io.ReadSeeker) (*UploadOutput, error) { ch <- chunk{buf: buf, num: num} if err != nil && err != io.ErrUnexpectedEOF { - u.seterr(apierr.New("ReadRequestBody", "read multipart upload data failed", err)) + u.seterr(awserr.New( + "ReadRequestBody", + "read multipart upload data failed", + err)) break } } @@ -443,16 +450,12 @@ func (u *multiuploader) upload(firstBuf io.ReadSeeker) (*UploadOutput, error) { complete := u.complete() if err := u.geterr(); err != nil { - var berr *apierr.BaseError - switch t := err.(type) { - case *apierr.BaseError: - berr = t - default: - berr = apierr.New("MultipartUpload", "upload multipart failed", err) - } return nil, &multiUploadError{ - BaseError: berr, - uploadID: u.uploadID, + awsError: awserr.New( + "MultipartUpload", + "upload multipart failed", + err), + uploadID: u.uploadID, } } return &UploadOutput{ diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/upload_test.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/upload_test.go index 25639d8ab1..9016419342 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/upload_test.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/s3manager/upload_test.go @@ -23,11 +23,22 @@ var _ = unit.Imported var buf12MB = make([]byte, 1024*1024*12) var buf2MB = make([]byte, 1024*1024*2) +var emptyList = []string{} + func val(i interface{}, s string) interface{} { return awsutil.ValuesAtPath(i, s)[0] } -func loggingSvc() (*s3.S3, *[]string, *[]interface{}) { +func contains(src []string, s string) bool { + for _, v := range src { + if s == v { + return true + } + } + return false +} + +func loggingSvc(ignoreOps []string) (*s3.S3, *[]string, *[]interface{}) { var m sync.Mutex partNum := 0 names := []string{} @@ -41,8 +52,10 @@ func loggingSvc() (*s3.S3, *[]string, *[]interface{}) { m.Lock() defer m.Unlock() - names = append(names, r.Operation.Name) - params = append(params, r.Params) + if !contains(ignoreOps, r.Operation.Name) { + names = append(names, r.Operation.Name) + params = append(params, r.Params) + } r.HTTPResponse = &http.Response{ StatusCode: 200, @@ -70,7 +83,7 @@ func buflen(i interface{}) int { } func TestUploadOrderMulti(t *testing.T) { - s, ops, args := loggingSvc() + s, ops, args := loggingSvc(emptyList) mgr := s3manager.NewUploader(&s3manager.UploadOptions{S3: s}) resp, err := mgr.Upload(&s3manager.UploadInput{ Bucket: aws.String("Bucket"), @@ -107,7 +120,7 @@ func TestUploadOrderMulti(t *testing.T) { } func TestUploadOrderMultiDifferentPartSize(t *testing.T) { - s, ops, args := loggingSvc() + s, ops, args := loggingSvc(emptyList) mgr := s3manager.NewUploader(&s3manager.UploadOptions{ S3: s, PartSize: 1024 * 1024 * 7, @@ -131,7 +144,7 @@ func TestUploadIncreasePartSize(t *testing.T) { s3manager.MaxUploadParts = 2 defer func() { s3manager.MaxUploadParts = 10000 }() - s, ops, args := loggingSvc() + s, ops, args := loggingSvc(emptyList) opts := &s3manager.UploadOptions{S3: s, Concurrency: 1} mgr := s3manager.NewUploader(opts) _, err := mgr.Upload(&s3manager.UploadInput{ @@ -167,7 +180,7 @@ func TestUploadFailIfPartSizeTooSmall(t *testing.T) { } func TestUploadOrderSingle(t *testing.T) { - s, ops, args := loggingSvc() + s, ops, args := loggingSvc(emptyList) mgr := s3manager.NewUploader(&s3manager.UploadOptions{S3: s}) resp, err := mgr.Upload(&s3manager.UploadInput{ Bucket: aws.String("Bucket"), @@ -186,7 +199,7 @@ func TestUploadOrderSingle(t *testing.T) { } func TestUploadOrderSingleFailure(t *testing.T) { - s, ops, _ := loggingSvc() + s, ops, _ := loggingSvc(emptyList) s.Handlers.Send.PushBack(func(r *aws.Request) { r.HTTPResponse.StatusCode = 400 }) @@ -203,7 +216,7 @@ func TestUploadOrderSingleFailure(t *testing.T) { } func TestUploadOrderZero(t *testing.T) { - s, ops, args := loggingSvc() + s, ops, args := loggingSvc(emptyList) mgr := s3manager.NewUploader(&s3manager.UploadOptions{S3: s}) resp, err := mgr.Upload(&s3manager.UploadInput{ Bucket: aws.String("Bucket"), @@ -219,7 +232,7 @@ func TestUploadOrderZero(t *testing.T) { } func TestUploadOrderMultiFailure(t *testing.T) { - s, ops, _ := loggingSvc() + s, ops, _ := loggingSvc(emptyList) s.Handlers.Send.PushBack(func(r *aws.Request) { switch t := r.Data.(type) { case *s3.UploadPartOutput: @@ -241,7 +254,7 @@ func TestUploadOrderMultiFailure(t *testing.T) { } func TestUploadOrderMultiFailureOnComplete(t *testing.T) { - s, ops, _ := loggingSvc() + s, ops, _ := loggingSvc(emptyList) s.Handlers.Send.PushBack(func(r *aws.Request) { switch r.Data.(type) { case *s3.CompleteMultipartUploadOutput: @@ -249,7 +262,7 @@ func TestUploadOrderMultiFailureOnComplete(t *testing.T) { } }) - mgr := s3manager.NewUploader(&s3manager.UploadOptions{S3: s}) + mgr := s3manager.NewUploader(&s3manager.UploadOptions{S3: s, Concurrency: 1}) _, err := mgr.Upload(&s3manager.UploadInput{ Bucket: aws.String("Bucket"), Key: aws.String("Key"), @@ -262,7 +275,7 @@ func TestUploadOrderMultiFailureOnComplete(t *testing.T) { } func TestUploadOrderMultiFailureOnCreate(t *testing.T) { - s, ops, _ := loggingSvc() + s, ops, _ := loggingSvc(emptyList) s.Handlers.Send.PushBack(func(r *aws.Request) { switch r.Data.(type) { case *s3.CreateMultipartUploadOutput: @@ -282,7 +295,7 @@ func TestUploadOrderMultiFailureOnCreate(t *testing.T) { } func TestUploadOrderMultiFailureLeaveParts(t *testing.T) { - s, ops, _ := loggingSvc() + s, ops, _ := loggingSvc(emptyList) s.Handlers.Send.PushBack(func(r *aws.Request) { switch data := r.Data.(type) { case *s3.UploadPartOutput: @@ -307,26 +320,26 @@ func TestUploadOrderMultiFailureLeaveParts(t *testing.T) { assert.Equal(t, []string{"CreateMultipartUpload", "UploadPart", "UploadPart"}, *ops) } -var failreaderCount = 0 +type failreader struct { + times int + failCount int +} -type failreader struct{ times int } - -func (f failreader) Read(b []byte) (int, error) { - failreaderCount++ - if failreaderCount >= f.times { +func (f *failreader) Read(b []byte) (int, error) { + f.failCount++ + if f.failCount >= f.times { return 0, fmt.Errorf("random failure") } return len(b), nil } func TestUploadOrderReadFail1(t *testing.T) { - failreaderCount = 0 - s, ops, _ := loggingSvc() + s, ops, _ := loggingSvc(emptyList) mgr := s3manager.NewUploader(&s3manager.UploadOptions{S3: s}) _, err := mgr.Upload(&s3manager.UploadInput{ Bucket: aws.String("Bucket"), Key: aws.String("Key"), - Body: failreader{1}, + Body: &failreader{times: 1}, }) assert.Equal(t, "ReadRequestBody", err.(awserr.Error).Code()) @@ -335,13 +348,12 @@ func TestUploadOrderReadFail1(t *testing.T) { } func TestUploadOrderReadFail2(t *testing.T) { - failreaderCount = 0 - s, ops, _ := loggingSvc() - mgr := s3manager.NewUploader(&s3manager.UploadOptions{S3: s}) + s, ops, _ := loggingSvc([]string{"UploadPart"}) + mgr := s3manager.NewUploader(&s3manager.UploadOptions{S3: s, Concurrency: 1}) _, err := mgr.Upload(&s3manager.UploadInput{ Bucket: aws.String("Bucket"), Key: aws.String("Key"), - Body: failreader{2}, + Body: &failreader{times: 2}, }) assert.Equal(t, "ReadRequestBody", err.(awserr.Error).Code()) @@ -349,16 +361,12 @@ func TestUploadOrderReadFail2(t *testing.T) { assert.Equal(t, []string{"CreateMultipartUpload", "AbortMultipartUpload"}, *ops) } -type sizedReaderImpl struct { +type sizedReader struct { size int cur int } -type sizedReader struct { - *sizedReaderImpl -} - -func (s sizedReader) Read(p []byte) (n int, err error) { +func (s *sizedReader) Read(p []byte) (n int, err error) { if s.cur >= s.size { return 0, io.EOF } @@ -373,12 +381,12 @@ func (s sizedReader) Read(p []byte) (n int, err error) { } func TestUploadOrderMultiBufferedReader(t *testing.T) { - s, ops, args := loggingSvc() + s, ops, args := loggingSvc(emptyList) mgr := s3manager.NewUploader(&s3manager.UploadOptions{S3: s}) _, err := mgr.Upload(&s3manager.UploadInput{ Bucket: aws.String("Bucket"), Key: aws.String("Key"), - Body: sizedReader{&sizedReaderImpl{size: 1024 * 1024 * 12}}, + Body: &sizedReader{size: 1024 * 1024 * 12}, }) assert.NoError(t, err) @@ -397,17 +405,17 @@ func TestUploadOrderMultiBufferedReader(t *testing.T) { func TestUploadOrderMultiBufferedReaderExceedTotalParts(t *testing.T) { s3manager.MaxUploadParts = 2 defer func() { s3manager.MaxUploadParts = 10000 }() - s, ops, _ := loggingSvc() + s, ops, _ := loggingSvc([]string{"UploadPart"}) mgr := s3manager.NewUploader(&s3manager.UploadOptions{S3: s, Concurrency: 1}) resp, err := mgr.Upload(&s3manager.UploadInput{ Bucket: aws.String("Bucket"), Key: aws.String("Key"), - Body: sizedReader{&sizedReaderImpl{size: 1024 * 1024 * 12}}, + Body: &sizedReader{size: 1024 * 1024 * 12}, }) assert.Error(t, err) assert.Nil(t, resp) - assert.Equal(t, []string{"CreateMultipartUpload", "UploadPart", "UploadPart", "AbortMultipartUpload"}, *ops) + assert.Equal(t, []string{"CreateMultipartUpload", "AbortMultipartUpload"}, *ops) aerr := err.(awserr.Error) assert.Equal(t, "TotalPartsExceeded", aerr.Code()) @@ -415,12 +423,12 @@ func TestUploadOrderMultiBufferedReaderExceedTotalParts(t *testing.T) { } func TestUploadOrderSingleBufferedReader(t *testing.T) { - s, ops, _ := loggingSvc() + s, ops, _ := loggingSvc(emptyList) mgr := s3manager.NewUploader(&s3manager.UploadOptions{S3: s}) resp, err := mgr.Upload(&s3manager.UploadInput{ Bucket: aws.String("Bucket"), Key: aws.String("Key"), - Body: sizedReader{&sizedReaderImpl{size: 1024 * 1024 * 2}}, + Body: &sizedReader{size: 1024 * 1024 * 2}, }) assert.NoError(t, err) diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/sse.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/sse.go index dd54163f87..01350f7c15 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/sse.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/sse.go @@ -5,11 +5,11 @@ import ( "encoding/base64" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awsutil" - "github.com/aws/aws-sdk-go/internal/apierr" ) -var errSSERequiresSSL = apierr.New("ConfigError", "cannot send SSE keys over HTTP.", nil) +var errSSERequiresSSL = awserr.New("ConfigError", "cannot send SSE keys over HTTP.", nil) func validateSSERequiresSSL(r *aws.Request) { if r.HTTPRequest.URL.Scheme != "https" { diff --git a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/unmarshal_error.go b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/unmarshal_error.go index e14cd3a7fd..c27d4342fb 100644 --- a/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/unmarshal_error.go +++ b/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/unmarshal_error.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/internal/apierr" + "github.com/aws/aws-sdk-go/aws/awserr" ) type xmlErrorResponse struct { @@ -20,8 +20,8 @@ func unmarshalError(r *aws.Request) { if r.HTTPResponse.ContentLength == int64(0) { // No body, use status code to generate an awserr.Error - r.Error = apierr.NewRequestError( - apierr.New(strings.Replace(r.HTTPResponse.Status, " ", "", -1), r.HTTPResponse.Status, nil), + r.Error = awserr.NewRequestFailure( + awserr.New(strings.Replace(r.HTTPResponse.Status, " ", "", -1), r.HTTPResponse.Status, nil), r.HTTPResponse.StatusCode, "", ) @@ -31,10 +31,10 @@ func unmarshalError(r *aws.Request) { resp := &xmlErrorResponse{} err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp) if err != nil && err != io.EOF { - r.Error = apierr.New("Unmarshal", "failed to decode S3 XML error response", nil) + r.Error = awserr.New("SerializationError", "failed to decode S3 XML error response", nil) } else { - r.Error = apierr.NewRequestError( - apierr.New(resp.Code, resp.Message, nil), + r.Error = awserr.NewRequestFailure( + awserr.New(resp.Code, resp.Message, nil), r.HTTPResponse.StatusCode, "", ) diff --git a/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/client.go b/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/client.go index c6cf3341ba..a1cbb8bcbc 100644 --- a/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/client.go +++ b/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/client.go @@ -192,7 +192,7 @@ func (c *Client) Close() { // initHTTPClient initializes a HTTP client for etcd client func (c *Client) initHTTPClient() { c.transport = &http.Transport{ - Dial: c.dial, + Dial: c.DefaultDial, TLSClientConfig: &tls.Config{ InsecureSkipVerify: true, }, @@ -218,7 +218,7 @@ func (c *Client) initHTTPSClient(cert, key string) error { tr := &http.Transport{ TLSClientConfig: tlsConfig, - Dial: c.dial, + Dial: c.DefaultDial, } c.httpClient = &http.Client{Transport: tr} @@ -306,12 +306,16 @@ func (c *Client) GetCluster() []string { } // SyncCluster updates the cluster information using the internal machine list. +// If no members are found, the intenral machine list is left untouched. func (c *Client) SyncCluster() bool { return c.internalSyncCluster(c.cluster.Machines) } // internalSyncCluster syncs cluster information using the given machine list. func (c *Client) internalSyncCluster(machines []string) bool { + // comma-separated list of machines in the cluster. + members := "" + for _, machine := range machines { httpPath := c.createHttpPath(machine, path.Join(version, "members")) resp, err := c.httpClient.Get(httpPath) @@ -333,8 +337,7 @@ func (c *Client) internalSyncCluster(machines []string) bool { // try another machine in the cluster continue } - // update Machines List - c.cluster.updateFromStr(string(b)) + members = string(b) } else { b, err := ioutil.ReadAll(resp.Body) resp.Body.Close() @@ -354,10 +357,16 @@ func (c *Client) internalSyncCluster(machines []string) bool { urls = append(urls, m.ClientURLs...) } - // update Machines List - c.cluster.updateFromStr(strings.Join(urls, ",")) + members = strings.Join(urls, ",") } + // We should never do an empty cluster update. + if members == "" { + continue + } + + // update Machines List + c.cluster.updateFromStr(members) logger.Debug("sync.machines ", c.cluster.Machines) c.saveConfig() return true @@ -382,9 +391,9 @@ func (c *Client) createHttpPath(serverName string, _path string) string { return u.String() } -// dial attempts to open a TCP connection to the provided address, explicitly +// DefaultDial attempts to open a TCP connection to the provided address, explicitly // enabling keep-alives with a one-second interval. -func (c *Client) dial(network, addr string) (net.Conn, error) { +func (c *Client) DefaultDial(network, addr string) (net.Conn, error) { conn, err := net.DialTimeout(network, addr, c.config.DialTimeout) if err != nil { return nil, err diff --git a/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/cluster.go b/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/cluster.go index 1ad3e155be..173a27356f 100644 --- a/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/cluster.go +++ b/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/cluster.go @@ -3,12 +3,14 @@ package etcd import ( "math/rand" "strings" + "sync" ) type Cluster struct { Leader string `json:"leader"` Machines []string `json:"machines"` picked int + mu sync.RWMutex } func NewCluster(machines []string) *Cluster { @@ -25,10 +27,22 @@ func NewCluster(machines []string) *Cluster { } } -func (cl *Cluster) failure() { cl.picked = rand.Intn(len(cl.Machines)) } -func (cl *Cluster) pick() string { return cl.Machines[cl.picked] } +func (cl *Cluster) failure() { + cl.mu.Lock() + defer cl.mu.Unlock() + cl.picked = rand.Intn(len(cl.Machines)) +} + +func (cl *Cluster) pick() string { + cl.mu.Lock() + defer cl.mu.Unlock() + return cl.Machines[cl.picked] +} func (cl *Cluster) updateFromStr(machines string) { + cl.mu.Lock() + defer cl.mu.Unlock() + cl.Machines = strings.Split(machines, ",") for i := range cl.Machines { cl.Machines[i] = strings.TrimSpace(cl.Machines[i]) diff --git a/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response.generated.go b/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response.generated.go new file mode 100644 index 0000000000..eb05e4c893 --- /dev/null +++ b/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response.generated.go @@ -0,0 +1,1419 @@ +// ************************************************************ +// DO NOT EDIT. +// THIS FILE IS AUTO-GENERATED BY codecgen. +// ************************************************************ + +package etcd + +import ( + "errors" + "fmt" + codec1978 "github.com/ugorji/go/codec" + "net/http" + "reflect" + "runtime" + "time" +) + +const ( + codecSelferC_UTF84402 = 1 + codecSelferC_RAW4402 = 0 + codecSelverValueTypeArray4402 = 10 + codecSelverValueTypeMap4402 = 9 +) + +var ( + codecSelferBitsize4402 = uint8(reflect.TypeOf(uint(0)).Bits()) + codecSelferOnlyMapOrArrayEncodeToStructErr4402 = errors.New(`only encoded map or array can be decoded into a struct`) +) + +type codecSelfer4402 struct{} + +func init() { + if codec1978.GenVersion != 2 { + _, file, _, _ := runtime.Caller(0) + err := fmt.Errorf("codecgen version mismatch: current: %v, need %v. Re-generate file: %v", + 2, codec1978.GenVersion, file) + panic(err) + } + if false { // reference the types, but skip this branch at build/run time + var v0 http.Header + var v1 time.Time + _, _ = v0, v1 + } +} + +func (x responseType) CodecEncodeSelf(e *codec1978.Encoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + r.EncodeInt(int64(x)) +} + +func (x *responseType) CodecDecodeSelf(d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + *((*int)(x)) = int(r.DecodeInt(codecSelferBitsize4402)) +} + +func (x *RawResponse) CodecEncodeSelf(e *codec1978.Encoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + if x == nil { + r.EncodeNil() + } else { + yysep1 := !z.EncBinary() + yy2arr1 := z.EncBasicHandle().StructToArray + var yyfirst1 bool + var yyq1 [3]bool + _, _, _, _ = yysep1, yyfirst1, yyq1, yy2arr1 + const yyr1 bool = false + if yyr1 || yy2arr1 { + r.EncodeArrayStart(3) + } else { + var yynn1 int = 3 + for _, b := range yyq1 { + if b { + yynn1++ + } + } + r.EncodeMapStart(yynn1) + } + if yyr1 || yy2arr1 { + r.EncodeInt(int64(x.StatusCode)) + } else { + yyfirst1 = true + r.EncodeString(codecSelferC_UTF84402, string("StatusCode")) + if yysep1 { + r.EncodeMapKVSeparator() + } + r.EncodeInt(int64(x.StatusCode)) + } + if yyr1 || yy2arr1 { + if yysep1 { + r.EncodeArrayEntrySeparator() + } + if x.Body == nil { + r.EncodeNil() + } else { + r.EncodeStringBytes(codecSelferC_RAW4402, []byte(x.Body)) + } + } else { + if yyfirst1 { + r.EncodeMapEntrySeparator() + } else { + yyfirst1 = true + } + r.EncodeString(codecSelferC_UTF84402, string("Body")) + if yysep1 { + r.EncodeMapKVSeparator() + } + if x.Body == nil { + r.EncodeNil() + } else { + r.EncodeStringBytes(codecSelferC_RAW4402, []byte(x.Body)) + } + } + if yyr1 || yy2arr1 { + if yysep1 { + r.EncodeArrayEntrySeparator() + } + if x.Header == nil { + r.EncodeNil() + } else { + h.enchttp_Header(http.Header(x.Header), e) + } + } else { + if yyfirst1 { + r.EncodeMapEntrySeparator() + } else { + yyfirst1 = true + } + r.EncodeString(codecSelferC_UTF84402, string("Header")) + if yysep1 { + r.EncodeMapKVSeparator() + } + if x.Header == nil { + r.EncodeNil() + } else { + h.enchttp_Header(http.Header(x.Header), e) + } + } + if yysep1 { + if yyr1 || yy2arr1 { + r.EncodeArrayEnd() + } else { + r.EncodeMapEnd() + } + } + } +} + +func (x *RawResponse) CodecDecodeSelf(d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + if r.IsContainerType(codecSelverValueTypeMap4402) { + yyl5 := r.ReadMapStart() + if yyl5 == 0 { + r.ReadMapEnd() + } else { + x.codecDecodeSelfFromMap(yyl5, d) + } + } else if r.IsContainerType(codecSelverValueTypeArray4402) { + yyl5 := r.ReadArrayStart() + if yyl5 == 0 { + r.ReadArrayEnd() + } else { + x.codecDecodeSelfFromArray(yyl5, d) + } + } else { + panic(codecSelferOnlyMapOrArrayEncodeToStructErr4402) + } +} + +func (x *RawResponse) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yys6Slc = z.DecScratchBuffer() // default slice to decode into + _ = yys6Slc + var yyhl6 bool = l >= 0 + for yyj6 := 0; ; yyj6++ { + if yyhl6 { + if yyj6 >= l { + break + } + } else { + if r.CheckBreak() { + break + } + if yyj6 > 0 { + r.ReadMapEntrySeparator() + } + } + yys6Slc = r.DecodeBytes(yys6Slc, true, true) + yys6 := string(yys6Slc) + if !yyhl6 { + r.ReadMapKVSeparator() + } + switch yys6 { + case "StatusCode": + if r.TryDecodeAsNil() { + x.StatusCode = 0 + } else { + x.StatusCode = int(r.DecodeInt(codecSelferBitsize4402)) + } + case "Body": + if r.TryDecodeAsNil() { + x.Body = nil + } else { + yyv8 := &x.Body + *yyv8 = r.DecodeBytes(*(*[]byte)(yyv8), false, false) + } + case "Header": + if r.TryDecodeAsNil() { + x.Header = nil + } else { + yyv9 := &x.Header + h.dechttp_Header((*http.Header)(yyv9), d) + } + default: + z.DecStructFieldNotFound(-1, yys6) + } // end switch yys6 + } // end for yyj6 + if !yyhl6 { + r.ReadMapEnd() + } +} + +func (x *RawResponse) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yyj10 int + var yyb10 bool + var yyhl10 bool = l >= 0 + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l + } else { + yyb10 = r.CheckBreak() + } + if yyb10 { + r.ReadArrayEnd() + return + } + if r.TryDecodeAsNil() { + x.StatusCode = 0 + } else { + x.StatusCode = int(r.DecodeInt(codecSelferBitsize4402)) + } + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l + } else { + yyb10 = r.CheckBreak() + } + if yyb10 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + x.Body = nil + } else { + yyv12 := &x.Body + *yyv12 = r.DecodeBytes(*(*[]byte)(yyv12), false, false) + } + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l + } else { + yyb10 = r.CheckBreak() + } + if yyb10 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + x.Header = nil + } else { + yyv13 := &x.Header + h.dechttp_Header((*http.Header)(yyv13), d) + } + for { + yyj10++ + if yyhl10 { + yyb10 = yyj10 > l + } else { + yyb10 = r.CheckBreak() + } + if yyb10 { + break + } + if yyj10 > 1 { + r.ReadArrayEntrySeparator() + } + z.DecStructFieldNotFound(yyj10-1, "") + } + r.ReadArrayEnd() +} + +func (x *Response) CodecEncodeSelf(e *codec1978.Encoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + if x == nil { + r.EncodeNil() + } else { + yysep14 := !z.EncBinary() + yy2arr14 := z.EncBasicHandle().StructToArray + var yyfirst14 bool + var yyq14 [6]bool + _, _, _, _ = yysep14, yyfirst14, yyq14, yy2arr14 + const yyr14 bool = false + yyq14[2] = x.PrevNode != nil + if yyr14 || yy2arr14 { + r.EncodeArrayStart(6) + } else { + var yynn14 int = 5 + for _, b := range yyq14 { + if b { + yynn14++ + } + } + r.EncodeMapStart(yynn14) + } + if yyr14 || yy2arr14 { + r.EncodeString(codecSelferC_UTF84402, string(x.Action)) + } else { + yyfirst14 = true + r.EncodeString(codecSelferC_UTF84402, string("action")) + if yysep14 { + r.EncodeMapKVSeparator() + } + r.EncodeString(codecSelferC_UTF84402, string(x.Action)) + } + if yyr14 || yy2arr14 { + if yysep14 { + r.EncodeArrayEntrySeparator() + } + if x.Node == nil { + r.EncodeNil() + } else { + x.Node.CodecEncodeSelf(e) + } + } else { + if yyfirst14 { + r.EncodeMapEntrySeparator() + } else { + yyfirst14 = true + } + r.EncodeString(codecSelferC_UTF84402, string("node")) + if yysep14 { + r.EncodeMapKVSeparator() + } + if x.Node == nil { + r.EncodeNil() + } else { + x.Node.CodecEncodeSelf(e) + } + } + if yyr14 || yy2arr14 { + if yysep14 { + r.EncodeArrayEntrySeparator() + } + if yyq14[2] { + if x.PrevNode == nil { + r.EncodeNil() + } else { + x.PrevNode.CodecEncodeSelf(e) + } + } else { + r.EncodeNil() + } + } else { + if yyq14[2] { + if yyfirst14 { + r.EncodeMapEntrySeparator() + } else { + yyfirst14 = true + } + r.EncodeString(codecSelferC_UTF84402, string("prevNode")) + if yysep14 { + r.EncodeMapKVSeparator() + } + if x.PrevNode == nil { + r.EncodeNil() + } else { + x.PrevNode.CodecEncodeSelf(e) + } + } + } + if yyr14 || yy2arr14 { + if yysep14 { + r.EncodeArrayEntrySeparator() + } + r.EncodeUint(uint64(x.EtcdIndex)) + } else { + if yyfirst14 { + r.EncodeMapEntrySeparator() + } else { + yyfirst14 = true + } + r.EncodeString(codecSelferC_UTF84402, string("etcdIndex")) + if yysep14 { + r.EncodeMapKVSeparator() + } + r.EncodeUint(uint64(x.EtcdIndex)) + } + if yyr14 || yy2arr14 { + if yysep14 { + r.EncodeArrayEntrySeparator() + } + r.EncodeUint(uint64(x.RaftIndex)) + } else { + if yyfirst14 { + r.EncodeMapEntrySeparator() + } else { + yyfirst14 = true + } + r.EncodeString(codecSelferC_UTF84402, string("raftIndex")) + if yysep14 { + r.EncodeMapKVSeparator() + } + r.EncodeUint(uint64(x.RaftIndex)) + } + if yyr14 || yy2arr14 { + if yysep14 { + r.EncodeArrayEntrySeparator() + } + r.EncodeUint(uint64(x.RaftTerm)) + } else { + if yyfirst14 { + r.EncodeMapEntrySeparator() + } else { + yyfirst14 = true + } + r.EncodeString(codecSelferC_UTF84402, string("raftTerm")) + if yysep14 { + r.EncodeMapKVSeparator() + } + r.EncodeUint(uint64(x.RaftTerm)) + } + if yysep14 { + if yyr14 || yy2arr14 { + r.EncodeArrayEnd() + } else { + r.EncodeMapEnd() + } + } + } +} + +func (x *Response) CodecDecodeSelf(d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + if r.IsContainerType(codecSelverValueTypeMap4402) { + yyl21 := r.ReadMapStart() + if yyl21 == 0 { + r.ReadMapEnd() + } else { + x.codecDecodeSelfFromMap(yyl21, d) + } + } else if r.IsContainerType(codecSelverValueTypeArray4402) { + yyl21 := r.ReadArrayStart() + if yyl21 == 0 { + r.ReadArrayEnd() + } else { + x.codecDecodeSelfFromArray(yyl21, d) + } + } else { + panic(codecSelferOnlyMapOrArrayEncodeToStructErr4402) + } +} + +func (x *Response) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yys22Slc = z.DecScratchBuffer() // default slice to decode into + _ = yys22Slc + var yyhl22 bool = l >= 0 + for yyj22 := 0; ; yyj22++ { + if yyhl22 { + if yyj22 >= l { + break + } + } else { + if r.CheckBreak() { + break + } + if yyj22 > 0 { + r.ReadMapEntrySeparator() + } + } + yys22Slc = r.DecodeBytes(yys22Slc, true, true) + yys22 := string(yys22Slc) + if !yyhl22 { + r.ReadMapKVSeparator() + } + switch yys22 { + case "action": + if r.TryDecodeAsNil() { + x.Action = "" + } else { + x.Action = string(r.DecodeString()) + } + case "node": + if r.TryDecodeAsNil() { + if x.Node != nil { + x.Node = nil + } + } else { + if x.Node == nil { + x.Node = new(Node) + } + x.Node.CodecDecodeSelf(d) + } + case "prevNode": + if r.TryDecodeAsNil() { + if x.PrevNode != nil { + x.PrevNode = nil + } + } else { + if x.PrevNode == nil { + x.PrevNode = new(Node) + } + x.PrevNode.CodecDecodeSelf(d) + } + case "etcdIndex": + if r.TryDecodeAsNil() { + x.EtcdIndex = 0 + } else { + x.EtcdIndex = uint64(r.DecodeUint(64)) + } + case "raftIndex": + if r.TryDecodeAsNil() { + x.RaftIndex = 0 + } else { + x.RaftIndex = uint64(r.DecodeUint(64)) + } + case "raftTerm": + if r.TryDecodeAsNil() { + x.RaftTerm = 0 + } else { + x.RaftTerm = uint64(r.DecodeUint(64)) + } + default: + z.DecStructFieldNotFound(-1, yys22) + } // end switch yys22 + } // end for yyj22 + if !yyhl22 { + r.ReadMapEnd() + } +} + +func (x *Response) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yyj29 int + var yyb29 bool + var yyhl29 bool = l >= 0 + yyj29++ + if yyhl29 { + yyb29 = yyj29 > l + } else { + yyb29 = r.CheckBreak() + } + if yyb29 { + r.ReadArrayEnd() + return + } + if r.TryDecodeAsNil() { + x.Action = "" + } else { + x.Action = string(r.DecodeString()) + } + yyj29++ + if yyhl29 { + yyb29 = yyj29 > l + } else { + yyb29 = r.CheckBreak() + } + if yyb29 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + if x.Node != nil { + x.Node = nil + } + } else { + if x.Node == nil { + x.Node = new(Node) + } + x.Node.CodecDecodeSelf(d) + } + yyj29++ + if yyhl29 { + yyb29 = yyj29 > l + } else { + yyb29 = r.CheckBreak() + } + if yyb29 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + if x.PrevNode != nil { + x.PrevNode = nil + } + } else { + if x.PrevNode == nil { + x.PrevNode = new(Node) + } + x.PrevNode.CodecDecodeSelf(d) + } + yyj29++ + if yyhl29 { + yyb29 = yyj29 > l + } else { + yyb29 = r.CheckBreak() + } + if yyb29 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + x.EtcdIndex = 0 + } else { + x.EtcdIndex = uint64(r.DecodeUint(64)) + } + yyj29++ + if yyhl29 { + yyb29 = yyj29 > l + } else { + yyb29 = r.CheckBreak() + } + if yyb29 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + x.RaftIndex = 0 + } else { + x.RaftIndex = uint64(r.DecodeUint(64)) + } + yyj29++ + if yyhl29 { + yyb29 = yyj29 > l + } else { + yyb29 = r.CheckBreak() + } + if yyb29 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + x.RaftTerm = 0 + } else { + x.RaftTerm = uint64(r.DecodeUint(64)) + } + for { + yyj29++ + if yyhl29 { + yyb29 = yyj29 > l + } else { + yyb29 = r.CheckBreak() + } + if yyb29 { + break + } + if yyj29 > 1 { + r.ReadArrayEntrySeparator() + } + z.DecStructFieldNotFound(yyj29-1, "") + } + r.ReadArrayEnd() +} + +func (x *Node) CodecEncodeSelf(e *codec1978.Encoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + if x == nil { + r.EncodeNil() + } else { + yysep36 := !z.EncBinary() + yy2arr36 := z.EncBasicHandle().StructToArray + var yyfirst36 bool + var yyq36 [8]bool + _, _, _, _ = yysep36, yyfirst36, yyq36, yy2arr36 + const yyr36 bool = false + yyq36[1] = x.Value != "" + yyq36[2] = x.Dir != false + yyq36[3] = x.Expiration != nil + yyq36[4] = x.TTL != 0 + yyq36[5] = len(x.Nodes) != 0 + yyq36[6] = x.ModifiedIndex != 0 + yyq36[7] = x.CreatedIndex != 0 + if yyr36 || yy2arr36 { + r.EncodeArrayStart(8) + } else { + var yynn36 int = 1 + for _, b := range yyq36 { + if b { + yynn36++ + } + } + r.EncodeMapStart(yynn36) + } + if yyr36 || yy2arr36 { + r.EncodeString(codecSelferC_UTF84402, string(x.Key)) + } else { + yyfirst36 = true + r.EncodeString(codecSelferC_UTF84402, string("key")) + if yysep36 { + r.EncodeMapKVSeparator() + } + r.EncodeString(codecSelferC_UTF84402, string(x.Key)) + } + if yyr36 || yy2arr36 { + if yysep36 { + r.EncodeArrayEntrySeparator() + } + if yyq36[1] { + r.EncodeString(codecSelferC_UTF84402, string(x.Value)) + } else { + r.EncodeString(codecSelferC_UTF84402, "") + } + } else { + if yyq36[1] { + if yyfirst36 { + r.EncodeMapEntrySeparator() + } else { + yyfirst36 = true + } + r.EncodeString(codecSelferC_UTF84402, string("value")) + if yysep36 { + r.EncodeMapKVSeparator() + } + r.EncodeString(codecSelferC_UTF84402, string(x.Value)) + } + } + if yyr36 || yy2arr36 { + if yysep36 { + r.EncodeArrayEntrySeparator() + } + if yyq36[2] { + r.EncodeBool(bool(x.Dir)) + } else { + r.EncodeBool(false) + } + } else { + if yyq36[2] { + if yyfirst36 { + r.EncodeMapEntrySeparator() + } else { + yyfirst36 = true + } + r.EncodeString(codecSelferC_UTF84402, string("dir")) + if yysep36 { + r.EncodeMapKVSeparator() + } + r.EncodeBool(bool(x.Dir)) + } + } + if yyr36 || yy2arr36 { + if yysep36 { + r.EncodeArrayEntrySeparator() + } + if yyq36[3] { + if x.Expiration == nil { + r.EncodeNil() + } else { + z.EncFallback(x.Expiration) + } + } else { + r.EncodeNil() + } + } else { + if yyq36[3] { + if yyfirst36 { + r.EncodeMapEntrySeparator() + } else { + yyfirst36 = true + } + r.EncodeString(codecSelferC_UTF84402, string("expiration")) + if yysep36 { + r.EncodeMapKVSeparator() + } + if x.Expiration == nil { + r.EncodeNil() + } else { + z.EncFallback(x.Expiration) + } + } + } + if yyr36 || yy2arr36 { + if yysep36 { + r.EncodeArrayEntrySeparator() + } + if yyq36[4] { + r.EncodeInt(int64(x.TTL)) + } else { + r.EncodeInt(0) + } + } else { + if yyq36[4] { + if yyfirst36 { + r.EncodeMapEntrySeparator() + } else { + yyfirst36 = true + } + r.EncodeString(codecSelferC_UTF84402, string("ttl")) + if yysep36 { + r.EncodeMapKVSeparator() + } + r.EncodeInt(int64(x.TTL)) + } + } + if yyr36 || yy2arr36 { + if yysep36 { + r.EncodeArrayEntrySeparator() + } + if yyq36[5] { + if x.Nodes == nil { + r.EncodeNil() + } else { + x.Nodes.CodecEncodeSelf(e) + } + } else { + r.EncodeNil() + } + } else { + if yyq36[5] { + if yyfirst36 { + r.EncodeMapEntrySeparator() + } else { + yyfirst36 = true + } + r.EncodeString(codecSelferC_UTF84402, string("nodes")) + if yysep36 { + r.EncodeMapKVSeparator() + } + if x.Nodes == nil { + r.EncodeNil() + } else { + x.Nodes.CodecEncodeSelf(e) + } + } + } + if yyr36 || yy2arr36 { + if yysep36 { + r.EncodeArrayEntrySeparator() + } + if yyq36[6] { + r.EncodeUint(uint64(x.ModifiedIndex)) + } else { + r.EncodeUint(0) + } + } else { + if yyq36[6] { + if yyfirst36 { + r.EncodeMapEntrySeparator() + } else { + yyfirst36 = true + } + r.EncodeString(codecSelferC_UTF84402, string("modifiedIndex")) + if yysep36 { + r.EncodeMapKVSeparator() + } + r.EncodeUint(uint64(x.ModifiedIndex)) + } + } + if yyr36 || yy2arr36 { + if yysep36 { + r.EncodeArrayEntrySeparator() + } + if yyq36[7] { + r.EncodeUint(uint64(x.CreatedIndex)) + } else { + r.EncodeUint(0) + } + } else { + if yyq36[7] { + if yyfirst36 { + r.EncodeMapEntrySeparator() + } else { + yyfirst36 = true + } + r.EncodeString(codecSelferC_UTF84402, string("createdIndex")) + if yysep36 { + r.EncodeMapKVSeparator() + } + r.EncodeUint(uint64(x.CreatedIndex)) + } + } + if yysep36 { + if yyr36 || yy2arr36 { + r.EncodeArrayEnd() + } else { + r.EncodeMapEnd() + } + } + } +} + +func (x *Node) CodecDecodeSelf(d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + if r.IsContainerType(codecSelverValueTypeMap4402) { + yyl45 := r.ReadMapStart() + if yyl45 == 0 { + r.ReadMapEnd() + } else { + x.codecDecodeSelfFromMap(yyl45, d) + } + } else if r.IsContainerType(codecSelverValueTypeArray4402) { + yyl45 := r.ReadArrayStart() + if yyl45 == 0 { + r.ReadArrayEnd() + } else { + x.codecDecodeSelfFromArray(yyl45, d) + } + } else { + panic(codecSelferOnlyMapOrArrayEncodeToStructErr4402) + } +} + +func (x *Node) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yys46Slc = z.DecScratchBuffer() // default slice to decode into + _ = yys46Slc + var yyhl46 bool = l >= 0 + for yyj46 := 0; ; yyj46++ { + if yyhl46 { + if yyj46 >= l { + break + } + } else { + if r.CheckBreak() { + break + } + if yyj46 > 0 { + r.ReadMapEntrySeparator() + } + } + yys46Slc = r.DecodeBytes(yys46Slc, true, true) + yys46 := string(yys46Slc) + if !yyhl46 { + r.ReadMapKVSeparator() + } + switch yys46 { + case "key": + if r.TryDecodeAsNil() { + x.Key = "" + } else { + x.Key = string(r.DecodeString()) + } + case "value": + if r.TryDecodeAsNil() { + x.Value = "" + } else { + x.Value = string(r.DecodeString()) + } + case "dir": + if r.TryDecodeAsNil() { + x.Dir = false + } else { + x.Dir = bool(r.DecodeBool()) + } + case "expiration": + if r.TryDecodeAsNil() { + if x.Expiration != nil { + x.Expiration = nil + } + } else { + if x.Expiration == nil { + x.Expiration = new(time.Time) + } + z.DecFallback(x.Expiration, false) + } + case "ttl": + if r.TryDecodeAsNil() { + x.TTL = 0 + } else { + x.TTL = int64(r.DecodeInt(64)) + } + case "nodes": + if r.TryDecodeAsNil() { + x.Nodes = nil + } else { + yyv52 := &x.Nodes + yyv52.CodecDecodeSelf(d) + } + case "modifiedIndex": + if r.TryDecodeAsNil() { + x.ModifiedIndex = 0 + } else { + x.ModifiedIndex = uint64(r.DecodeUint(64)) + } + case "createdIndex": + if r.TryDecodeAsNil() { + x.CreatedIndex = 0 + } else { + x.CreatedIndex = uint64(r.DecodeUint(64)) + } + default: + z.DecStructFieldNotFound(-1, yys46) + } // end switch yys46 + } // end for yyj46 + if !yyhl46 { + r.ReadMapEnd() + } +} + +func (x *Node) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yyj55 int + var yyb55 bool + var yyhl55 bool = l >= 0 + yyj55++ + if yyhl55 { + yyb55 = yyj55 > l + } else { + yyb55 = r.CheckBreak() + } + if yyb55 { + r.ReadArrayEnd() + return + } + if r.TryDecodeAsNil() { + x.Key = "" + } else { + x.Key = string(r.DecodeString()) + } + yyj55++ + if yyhl55 { + yyb55 = yyj55 > l + } else { + yyb55 = r.CheckBreak() + } + if yyb55 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + x.Value = "" + } else { + x.Value = string(r.DecodeString()) + } + yyj55++ + if yyhl55 { + yyb55 = yyj55 > l + } else { + yyb55 = r.CheckBreak() + } + if yyb55 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + x.Dir = false + } else { + x.Dir = bool(r.DecodeBool()) + } + yyj55++ + if yyhl55 { + yyb55 = yyj55 > l + } else { + yyb55 = r.CheckBreak() + } + if yyb55 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + if x.Expiration != nil { + x.Expiration = nil + } + } else { + if x.Expiration == nil { + x.Expiration = new(time.Time) + } + z.DecFallback(x.Expiration, false) + } + yyj55++ + if yyhl55 { + yyb55 = yyj55 > l + } else { + yyb55 = r.CheckBreak() + } + if yyb55 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + x.TTL = 0 + } else { + x.TTL = int64(r.DecodeInt(64)) + } + yyj55++ + if yyhl55 { + yyb55 = yyj55 > l + } else { + yyb55 = r.CheckBreak() + } + if yyb55 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + x.Nodes = nil + } else { + yyv61 := &x.Nodes + yyv61.CodecDecodeSelf(d) + } + yyj55++ + if yyhl55 { + yyb55 = yyj55 > l + } else { + yyb55 = r.CheckBreak() + } + if yyb55 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + x.ModifiedIndex = 0 + } else { + x.ModifiedIndex = uint64(r.DecodeUint(64)) + } + yyj55++ + if yyhl55 { + yyb55 = yyj55 > l + } else { + yyb55 = r.CheckBreak() + } + if yyb55 { + r.ReadArrayEnd() + return + } + r.ReadArrayEntrySeparator() + if r.TryDecodeAsNil() { + x.CreatedIndex = 0 + } else { + x.CreatedIndex = uint64(r.DecodeUint(64)) + } + for { + yyj55++ + if yyhl55 { + yyb55 = yyj55 > l + } else { + yyb55 = r.CheckBreak() + } + if yyb55 { + break + } + if yyj55 > 1 { + r.ReadArrayEntrySeparator() + } + z.DecStructFieldNotFound(yyj55-1, "") + } + r.ReadArrayEnd() +} + +func (x Nodes) CodecEncodeSelf(e *codec1978.Encoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + if x == nil { + r.EncodeNil() + } else { + h.encNodes(Nodes(x), e) + } +} + +func (x *Nodes) CodecDecodeSelf(d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + h.decNodes((*Nodes)(x), d) +} + +func (x codecSelfer4402) enchttp_Header(v http.Header, e *codec1978.Encoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + r.EncodeMapStart(len(v)) + yys64 := !z.EncBinary() + yyj64 := 0 + if yys64 { + for yyk64, yyv64 := range v { + if yyj64 > 0 { + r.EncodeMapEntrySeparator() + } + r.EncodeString(codecSelferC_UTF84402, string(yyk64)) + r.EncodeMapKVSeparator() + if yyv64 == nil { + r.EncodeNil() + } else { + z.F.EncSliceStringV(yyv64, false, e) + } + yyj64++ + } + r.EncodeMapEnd() + } else { + for yyk64, yyv64 := range v { + r.EncodeString(codecSelferC_UTF84402, string(yyk64)) + if yyv64 == nil { + r.EncodeNil() + } else { + z.F.EncSliceStringV(yyv64, false, e) + } + } + } +} + +func (x codecSelfer4402) dechttp_Header(v *http.Header, d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + + yyv65 := *v + yyl65 := r.ReadMapStart() + if yyv65 == nil { + if yyl65 > 0 { + yyv65 = make(map[string][]string, yyl65) + } else { + yyv65 = make(map[string][]string) // supports indefinite-length, etc + } + *v = yyv65 + } + if yyl65 > 0 { + for yyj65 := 0; yyj65 < yyl65; yyj65++ { + var yymk65 string + if r.TryDecodeAsNil() { + yymk65 = "" + } else { + yymk65 = string(r.DecodeString()) + } + + yymv65 := yyv65[yymk65] + if r.TryDecodeAsNil() { + yymv65 = nil + } else { + yyv67 := &yymv65 + z.F.DecSliceStringX(yyv67, false, d) + } + + if yyv65 != nil { + yyv65[yymk65] = yymv65 + } + } + } else if yyl65 < 0 { + for yyj65 := 0; !r.CheckBreak(); yyj65++ { + if yyj65 > 0 { + r.ReadMapEntrySeparator() + } + var yymk65 string + if r.TryDecodeAsNil() { + yymk65 = "" + } else { + yymk65 = string(r.DecodeString()) + } + + r.ReadMapKVSeparator() + yymv65 := yyv65[yymk65] + if r.TryDecodeAsNil() { + yymv65 = nil + } else { + yyv69 := &yymv65 + z.F.DecSliceStringX(yyv69, false, d) + } + + if yyv65 != nil { + yyv65[yymk65] = yymv65 + } + } + r.ReadMapEnd() + } // else len==0: TODO: Should we clear map entries? +} + +func (x codecSelfer4402) encNodes(v Nodes, e *codec1978.Encoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + r.EncodeArrayStart(len(v)) + yys70 := !z.EncBinary() + if yys70 { + for yyi70, yyv70 := range v { + if yyi70 > 0 { + r.EncodeArrayEntrySeparator() + } + if yyv70 == nil { + r.EncodeNil() + } else { + yyv70.CodecEncodeSelf(e) + } + } + r.EncodeArrayEnd() + } else { + for _, yyv70 := range v { + if yyv70 == nil { + r.EncodeNil() + } else { + yyv70.CodecEncodeSelf(e) + } + } + } +} + +func (x codecSelfer4402) decNodes(v *Nodes, d *codec1978.Decoder) { + var h codecSelfer4402 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + + yyv71 := *v + yyh71, yyl71 := z.DecSliceHelperStart() + + var yyc71 bool + if yyv71 == nil { + if yyl71 <= 0 { + yyv71 = make(Nodes, 0) + } else { + yyv71 = make(Nodes, yyl71) + } + yyc71 = true + } + + if yyl71 == 0 { + if len(yyv71) != 0 { + yyv71 = yyv71[:0] + yyc71 = true + } + } else if yyl71 > 0 { + + yyn71 := yyl71 + if yyl71 > cap(yyv71) { + yyv71 = make([]*Node, yyl71, yyl71) + yyc71 = true + + } else if yyl71 != len(yyv71) { + yyv71 = yyv71[:yyl71] + yyc71 = true + } + yyj71 := 0 + for ; yyj71 < yyn71; yyj71++ { + if r.TryDecodeAsNil() { + if yyv71[yyj71] != nil { + *yyv71[yyj71] = Node{} + } + } else { + if yyv71[yyj71] == nil { + yyv71[yyj71] = new(Node) + } + yyw72 := yyv71[yyj71] + yyw72.CodecDecodeSelf(d) + } + + } + + } else { + for yyj71 := 0; !r.CheckBreak(); yyj71++ { + if yyj71 >= len(yyv71) { + yyv71 = append(yyv71, nil) // var yyz71 *Node + yyc71 = true + } + if yyj71 > 0 { + yyh71.Sep(yyj71) + } + + if yyj71 < len(yyv71) { + if r.TryDecodeAsNil() { + if yyv71[yyj71] != nil { + *yyv71[yyj71] = Node{} + } + } else { + if yyv71[yyj71] == nil { + yyv71[yyj71] = new(Node) + } + yyw73 := yyv71[yyj71] + yyw73.CodecDecodeSelf(d) + } + + } else { + z.DecSwallow() + } + + } + yyh71.End() + } + if yyc71 { + *v = yyv71 + } +} diff --git a/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response.go b/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response.go index 1fe9b4e871..dff20c3561 100644 --- a/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response.go +++ b/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response.go @@ -1,10 +1,13 @@ package etcd +//go:generate codecgen -o response.generated.go response.go + import ( - "encoding/json" "net/http" "strconv" "time" + + "github.com/ugorji/go/codec" ) const ( @@ -28,6 +31,7 @@ var ( http.StatusNotFound: true, http.StatusPreconditionFailed: true, http.StatusForbidden: true, + http.StatusUnauthorized: true, } ) @@ -39,7 +43,7 @@ func (rr *RawResponse) Unmarshal() (*Response, error) { resp := new(Response) - err := json.Unmarshal(rr.Body, resp) + err := codec.NewDecoderBytes(rr.Body, new(codec.JsonHandle)).Decode(resp) if err != nil { return nil, err diff --git a/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response_test.go b/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response_test.go new file mode 100644 index 0000000000..23e0c56eb3 --- /dev/null +++ b/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/response_test.go @@ -0,0 +1,75 @@ +package etcd + +import ( + "net/http" + "reflect" + "strings" + "testing" + + "github.com/ugorji/go/codec" +) + +func createTestNode(size int) *Node { + return &Node{ + Key: strings.Repeat("a", 30), + Value: strings.Repeat("a", size), + TTL: 123456789, + ModifiedIndex: 123456, + CreatedIndex: 123456, + } +} + +func createTestNodeWithChildren(children, size int) *Node { + node := createTestNode(size) + for i := 0; i < children; i++ { + node.Nodes = append(node.Nodes, createTestNode(size)) + } + return node +} + +func createTestResponse(children, size int) *Response { + return &Response{ + Action: "aaaaa", + Node: createTestNodeWithChildren(children, size), + PrevNode: nil, + EtcdIndex: 123456, + RaftIndex: 123456, + RaftTerm: 123456, + } +} + +func benchmarkResponseUnmarshalling(b *testing.B, children, size int) { + response := createTestResponse(children, size) + + rr := RawResponse{http.StatusOK, make([]byte, 0), http.Header{}} + codec.NewEncoderBytes(&rr.Body, new(codec.JsonHandle)).Encode(response) + + b.ResetTimer() + newResponse := new(Response) + var err error + for i := 0; i < b.N; i++ { + if newResponse, err = rr.Unmarshal(); err != nil { + b.Errorf("Error: %v", err) + } + + } + if !reflect.DeepEqual(response.Node, newResponse.Node) { + b.Errorf("Unexpected difference in a parsed response: \n%+v\n%+v", response, newResponse) + } +} + +func BenchmarkSmallResponseUnmarshal(b *testing.B) { + benchmarkResponseUnmarshalling(b, 30, 20) +} + +func BenchmarkManySmallResponseUnmarshal(b *testing.B) { + benchmarkResponseUnmarshalling(b, 3000, 20) +} + +func BenchmarkMediumResponseUnmarshal(b *testing.B) { + benchmarkResponseUnmarshalling(b, 300, 200) +} + +func BenchmarkLargeResponseUnmarshal(b *testing.B) { + benchmarkResponseUnmarshalling(b, 3000, 2000) +} diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/compare.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/compare.go new file mode 100644 index 0000000000..802e9cc932 --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/compare.go @@ -0,0 +1,85 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// +// File contains Compare functionality +// +// https://tools.ietf.org/html/rfc4511 +// +// CompareRequest ::= [APPLICATION 14] SEQUENCE { +// entry LDAPDN, +// ava AttributeValueAssertion } +// +// AttributeValueAssertion ::= SEQUENCE { +// attributeDesc AttributeDescription, +// assertionValue AssertionValue } +// +// AttributeDescription ::= LDAPString +// -- Constrained to +// -- [RFC4512] +// +// AttributeValue ::= OCTET STRING +// + +package ldap + +import ( + "errors" + "fmt" + + "gopkg.in/asn1-ber.v1" +) + +// Compare checks to see if the attribute of the dn matches value. Returns true if it does otherwise +// false with any error that occurs if any. +func (l *Conn) Compare(dn, attribute, value string) (bool, error) { + messageID := l.nextMessageID() + packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") + packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, messageID, "MessageID")) + + request := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationCompareRequest, nil, "Compare Request") + request.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, dn, "DN")) + + ava := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "AttributeValueAssertion") + ava.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, attribute, "AttributeDesc")) + ava.AppendChild(ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagOctetString, value, "AssertionValue")) + request.AppendChild(ava) + packet.AppendChild(request) + + l.Debug.PrintPacket(packet) + + channel, err := l.sendMessage(packet) + if err != nil { + return false, err + } + if channel == nil { + return false, NewError(ErrorNetwork, errors.New("ldap: could not send message")) + } + defer l.finishMessage(messageID) + + l.Debug.Printf("%d: waiting for response", messageID) + packet = <-channel + l.Debug.Printf("%d: got response %p", messageID, packet) + if packet == nil { + return false, NewError(ErrorNetwork, errors.New("ldap: could not retrieve message")) + } + + if l.Debug { + if err := addLDAPDescriptions(packet); err != nil { + return false, err + } + ber.PrintPacket(packet) + } + + if packet.Children[1].Tag == ApplicationCompareResponse { + resultCode, resultDescription := getLDAPResultCode(packet) + if resultCode == LDAPResultCompareTrue { + return true, nil + } else if resultCode == LDAPResultCompareFalse { + return false, nil + } else { + return false, NewError(resultCode, errors.New(resultDescription)) + } + } + return false, fmt.Errorf("Unexpected Response: %d", packet.Children[1].Tag) +} diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go index d4b1027be3..a3b0fa4e22 100644 --- a/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go @@ -7,7 +7,6 @@ package ldap import ( "crypto/tls" "errors" - "flag" "fmt" "gopkg.in/asn1-ber.v1" "log" @@ -54,25 +53,17 @@ type Conn struct { messageMutex sync.Mutex } -var ldapTimeout time.Duration - -func init() { - var timeoutVar string - flag.StringVar(&timeoutVar, "ldapConnectionTimeout", "60s", "Default connection timeout for ldap") - flag.Parse() - timeout, err := time.ParseDuration(timeoutVar) - if err != nil { - ldapTimeout = 60 * time.Second - return - } - ldapTimeout = timeout - return -} +// DefaultTimeout is a package-level variable that sets the timeout value +// used for the Dial and DialTLS methods. +// +// WARNING: since this is a package-level variable, setting this value from +// multiple places will probably result in undesired behaviour. +var DefaultTimeout = 60 * time.Second // Dial connects to the given address on the given network using net.Dial // and then returns a new Conn for the connection. func Dial(network, addr string) (*Conn, error) { - c, err := net.DialTimeout(network, addr, ldapTimeout) + c, err := net.DialTimeout(network, addr, DefaultTimeout) if err != nil { return nil, NewError(ErrorNetwork, err) } @@ -84,7 +75,7 @@ func Dial(network, addr string) (*Conn, error) { // DialTLS connects to the given address on the given network using tls.Dial // and then returns a new Conn for the connection. func DialTLS(network, addr string, config *tls.Config) (*Conn, error) { - dc, err := net.DialTimeout(network, addr, ldapTimeout) + dc, err := net.DialTimeout(network, addr, DefaultTimeout) if err != nil { return nil, NewError(ErrorNetwork, err) } diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/compare/compare.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/compare/compare.go new file mode 100644 index 0000000000..97e0a2d51b --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/examples/compare/compare.go @@ -0,0 +1,39 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "log" + + "github.com/go-ldap/ldap" +) + +var ( + ldapServer string = "localhost" + ldapPort uint16 = 389 + user string = "*" + passwd string = "*" + dn string = "uid=*,cn=*,dc=*,dc=*" + attribute string = "uid" + value string = "username" +) + +func main() { + l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) + if err != nil { + log.Fatalf("ERROR: %s\n", err.Error()) + } + defer l.Close() + // l.Debug = true + + err = l.Bind(user, passwd) + if err != nil { + log.Printf("ERROR: Cannot bind: %s\n", err.Error()) + return + } + + fmt.Println(l.Compare(dn, attribute, value)) +} diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/ldap_test.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/ldap_test.go index d6211bdc30..e9933f99a6 100644 --- a/Godeps/_workspace/src/github.com/go-ldap/ldap/ldap_test.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/ldap_test.go @@ -224,3 +224,24 @@ func TestEscapeFilter(t *testing.T) { t.Errorf("Got %s, expected %s", want, got) } } + +func TestCompare(t *testing.T) { + fmt.Printf("TestCompare: starting...\n") + l, err := Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort)) + if err != nil { + t.Fatal(err.Error()) + } + defer l.Close() + + dn := "cn=math mich,ou=User Groups,ou=Groups,dc=umich,dc=edu" + attribute := "cn" + value := "math mich" + + sr, err := l.Compare(dn, attribute, value) + if err != nil { + t.Errorf(err.Error()) + return + } + + fmt.Printf("TestCompare: -> num of entries = %d\n", sr) +} diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/todo b/Godeps/_workspace/src/github.com/go-ldap/ldap/todo deleted file mode 100644 index 4a7be3d26b..0000000000 --- a/Godeps/_workspace/src/github.com/go-ldap/ldap/todo +++ /dev/null @@ -1,19 +0,0 @@ -"" => [] -sep is always , -multivalue is + - -type=value - -type is numericoid or keystring: - keystring = leadkeychar *keychar - leadkeychar = ALPHA - keychar = ALPHA / DIGIT / HYPHEN - numericoid = number 1*( DOT number ) - -example oid: -givenname = 2.5.4.42 - - If the AttributeType is of the dotted-decimal form, the - AttributeValue is represented by an number sign ('#' U+0023) - character followed by the hexadecimal encoding of each of the octets - of the BER encoding of the X.500 AttributeValue. diff --git a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/AUTHORS b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/AUTHORS index 2a7db63eed..6fc4c6f7b2 100644 --- a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/AUTHORS +++ b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/AUTHORS @@ -23,6 +23,7 @@ Henri Yandell INADA Naoki James Harr Jian Zhen +Joshua Prunier Julien Schmidt Kamil Dziedzic Leonardo YongUk Kim @@ -31,6 +32,8 @@ Luke Scott Michael Woolnough Nicola Peduzzi Runrioter Wung +Soroush Pour +Stan Putrya Xiaobing Jiang Xiuming Chen diff --git a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/README.md b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/README.md index 8c76711cde..6a2bb2ca37 100644 --- a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/README.md +++ b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/README.md @@ -123,6 +123,16 @@ Default: false `allowAllFiles=true` disables the file Whitelist for `LOAD DATA LOCAL INFILE` and allows *all* files. [*Might be insecure!*](http://dev.mysql.com/doc/refman/5.7/en/load-data-local.html) +##### `allowCleartextPasswords` + +``` +Type: bool +Valid Values: true, false +Default: false +``` + +`allowCleartextPasswords=true` allows using the [cleartext client side plugin](http://dev.mysql.com/doc/en/cleartext-authentication-plugin.html) if required by an account, such as one defined with the [PAM authentication plugin](http://dev.mysql.com/doc/en/pam-authentication-plugin.html). Sending passwords in clear text may be a security problem in some configurations. To avoid problems if there is any possibility that the password would be intercepted, clients should connect to MySQL Server using a method that protects the password. Possibilities include [TLS / SSL](#tls), IPsec, or a private network. + ##### `allowOldPasswords` ``` @@ -205,6 +215,8 @@ Default: UTC Sets the location for time.Time values (when using `parseTime=true`). *"Local"* sets the system's location. See [time.LoadLocation](http://golang.org/pkg/time/#LoadLocation) for details. +Note that this sets the location for time.Time values but does not change MySQL's [time_zone setting](https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html). For that see the [time_zone system variable](#system-variables), which can also be set as a DSN parameter. + Please keep in mind, that param values must be [url.QueryEscape](http://golang.org/pkg/net/url/#QueryEscape)'ed. Alternatively you can manually replace the `/` with `%2F`. For example `US/Pacific` would be `loc=US%2FPacific`. @@ -257,7 +269,7 @@ Default: false All other parameters are interpreted as system variables: * `autocommit`: `"SET autocommit="` - * `time_zone`: `"SET time_zone="` + * [`time_zone`](https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html): `"SET time_zone="` * [`tx_isolation`](https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_tx_isolation): `"SET tx_isolation="` * `param`: `"SET ="` diff --git a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/connection.go b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/connection.go index a6d39bec95..caaae013f5 100644 --- a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/connection.go +++ b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/connection.go @@ -34,21 +34,22 @@ type mysqlConn struct { } type config struct { - user string - passwd string - net string - addr string - dbname string - params map[string]string - loc *time.Location - tls *tls.Config - timeout time.Duration - collation uint8 - allowAllFiles bool - allowOldPasswords bool - clientFoundRows bool - columnsWithAlias bool - interpolateParams bool + user string + passwd string + net string + addr string + dbname string + params map[string]string + loc *time.Location + tls *tls.Config + timeout time.Duration + collation uint8 + allowAllFiles bool + allowOldPasswords bool + allowCleartextPasswords bool + clientFoundRows bool + columnsWithAlias bool + interpolateParams bool } // Handles parameters set in DSN after the connection is established diff --git a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/const.go b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/const.go index baa81f0220..dddc12908f 100644 --- a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/const.go +++ b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/const.go @@ -24,6 +24,7 @@ const ( iERR byte = 0xff ) +// https://dev.mysql.com/doc/internals/en/capability-flags.html#packet-Protocol::CapabilityFlags type clientFlag uint32 const ( @@ -45,6 +46,13 @@ const ( clientSecureConn clientMultiStatements clientMultiResults + clientPSMultiResults + clientPluginAuth + clientConnectAttrs + clientPluginAuthLenEncClientData + clientCanHandleExpiredPasswords + clientSessionTrack + clientDeprecateEOF ) const ( @@ -78,6 +86,7 @@ const ( comStmtFetch ) +// https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-Protocol::ColumnType const ( fieldTypeDecimal byte = iota fieldTypeTiny @@ -132,7 +141,6 @@ const ( ) // http://dev.mysql.com/doc/internals/en/status-flags.html - type statusFlag uint16 const ( diff --git a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/driver.go b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/driver.go index 3cbbe6031c..d310624ad1 100644 --- a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/driver.go +++ b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/driver.go @@ -107,6 +107,15 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) { mc.Close() return nil, err } + } else if mc.cfg != nil && mc.cfg.allowCleartextPasswords && err == ErrCleartextPassword { + if err = mc.writeClearAuthPacket(); err != nil { + mc.Close() + return nil, err + } + if err = mc.readResultOK(); err != nil { + mc.Close() + return nil, err + } } else { mc.Close() return nil, err diff --git a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/driver_test.go b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/driver_test.go index bda62eebcc..cb0d5f5ec8 100644 --- a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/driver_test.go +++ b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/driver_test.go @@ -780,6 +780,49 @@ func TestNULL(t *testing.T) { }) } +func TestUint64(t *testing.T) { + const ( + u0 = uint64(0) + uall = ^u0 + uhigh = uall >> 1 + utop = ^uhigh + s0 = int64(0) + sall = ^s0 + shigh = int64(uhigh) + stop = ^shigh + ) + runTests(t, dsn, func(dbt *DBTest) { + stmt, err := dbt.db.Prepare(`SELECT ?, ?, ? ,?, ?, ?, ?, ?`) + if err != nil { + dbt.Fatal(err) + } + defer stmt.Close() + row := stmt.QueryRow( + u0, uhigh, utop, uall, + s0, shigh, stop, sall, + ) + + var ua, ub, uc, ud uint64 + var sa, sb, sc, sd int64 + + err = row.Scan(&ua, &ub, &uc, &ud, &sa, &sb, &sc, &sd) + if err != nil { + dbt.Fatal(err) + } + switch { + case ua != u0, + ub != uhigh, + uc != utop, + ud != uall, + sa != s0, + sb != shigh, + sc != stop, + sd != sall: + dbt.Fatal("Unexpected result value") + } + }) +} + func TestLongData(t *testing.T) { runTests(t, dsn, func(dbt *DBTest) { var maxAllowedPacketSize int diff --git a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/errors.go b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/errors.go index 97d7b39962..44cf30db60 100644 --- a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/errors.go +++ b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/errors.go @@ -19,15 +19,17 @@ import ( // Various errors the driver might return. Can change between driver versions. var ( - ErrInvalidConn = errors.New("Invalid Connection") - ErrMalformPkt = errors.New("Malformed Packet") - ErrNoTLS = errors.New("TLS encryption requested but server does not support TLS") - ErrOldPassword = errors.New("This server only supports the insecure old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords") - ErrOldProtocol = errors.New("MySQL-Server does not support required Protocol 41+") - ErrPktSync = errors.New("Commands out of sync. You can't run this command now") - ErrPktSyncMul = errors.New("Commands out of sync. Did you run multiple statements at once?") - ErrPktTooLarge = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.") - ErrBusyBuffer = errors.New("Busy buffer") + ErrInvalidConn = errors.New("Invalid Connection") + ErrMalformPkt = errors.New("Malformed Packet") + ErrNoTLS = errors.New("TLS encryption requested but server does not support TLS") + ErrOldPassword = errors.New("This user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords") + ErrCleartextPassword = errors.New("This user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN.") + ErrUnknownPlugin = errors.New("The authentication plugin is not supported.") + ErrOldProtocol = errors.New("MySQL-Server does not support required Protocol 41+") + ErrPktSync = errors.New("Commands out of sync. You can't run this command now") + ErrPktSyncMul = errors.New("Commands out of sync. Did you run multiple statements at once?") + ErrPktTooLarge = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.") + ErrBusyBuffer = errors.New("Busy buffer") ) var errLog Logger = log.New(os.Stderr, "[MySQL] ", log.Ldate|log.Ltime|log.Lshortfile) diff --git a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/packets.go b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/packets.go index 290a3887a7..14395bf9ab 100644 --- a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/packets.go +++ b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/packets.go @@ -196,7 +196,11 @@ func (mc *mysqlConn) readInitPacket() ([]byte, error) { // return //} //return ErrMalformPkt - return cipher, nil + + // make a memory safe copy of the cipher slice + var b [20]byte + copy(b[:], cipher) + return b[:], nil } // make a memory safe copy of the cipher slice @@ -214,6 +218,7 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error { clientLongPassword | clientTransactions | clientLocalFiles | + clientPluginAuth | mc.flags&clientLongFlag if mc.cfg.clientFoundRows { @@ -228,7 +233,7 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error { // User Password scrambleBuff := scramblePassword(cipher, []byte(mc.cfg.passwd)) - pktLen := 4 + 4 + 1 + 23 + len(mc.cfg.user) + 1 + 1 + len(scrambleBuff) + pktLen := 4 + 4 + 1 + 23 + len(mc.cfg.user) + 1 + 1 + len(scrambleBuff) + 21 + 1 // To specify a db name if n := len(mc.cfg.dbname); n > 0 { @@ -294,8 +299,13 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error { if len(mc.cfg.dbname) > 0 { pos += copy(data[pos:], mc.cfg.dbname) data[pos] = 0x00 + pos++ } + // Assume native client during response + pos += copy(data[pos:], "mysql_native_password") + data[pos] = 0x00 + // Send Auth packet return mc.writePacket(data) } @@ -306,7 +316,7 @@ func (mc *mysqlConn) writeOldAuthPacket(cipher []byte) error { // User password scrambleBuff := scrambleOldPassword(cipher, []byte(mc.cfg.passwd)) - // Calculate the packet lenght and add a tailing 0 + // Calculate the packet length and add a tailing 0 pktLen := len(scrambleBuff) + 1 data := mc.buf.takeSmallBuffer(4 + pktLen) if data == nil { @@ -322,6 +332,25 @@ func (mc *mysqlConn) writeOldAuthPacket(cipher []byte) error { return mc.writePacket(data) } +// Client clear text authentication packet +// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse +func (mc *mysqlConn) writeClearAuthPacket() error { + // Calculate the packet length and add a tailing 0 + pktLen := len(mc.cfg.passwd) + 1 + data := mc.buf.takeSmallBuffer(4 + pktLen) + if data == nil { + // can not take the buffer. Something must be wrong with the connection + errLog.Print(ErrBusyBuffer) + return driver.ErrBadConn + } + + // Add the clear password [null terminated string] + copy(data[4:], mc.cfg.passwd) + data[4+pktLen-1] = 0x00 + + return mc.writePacket(data) +} + /****************************************************************************** * Command Packets * ******************************************************************************/ @@ -405,8 +434,20 @@ func (mc *mysqlConn) readResultOK() error { return mc.handleOkPacket(data) case iEOF: - // someone is using old_passwords - return ErrOldPassword + if len(data) > 1 { + plugin := string(data[1:bytes.IndexByte(data, 0x00)]) + if plugin == "mysql_old_password" { + // using old_passwords + return ErrOldPassword + } else if plugin == "mysql_clear_password" { + // using clear text password + return ErrCleartextPassword + } else { + return ErrUnknownPlugin + } + } else { + return ErrOldPassword + } default: // Error otherwise return mc.handleErrorPacket(data) diff --git a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/statement.go b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/statement.go index 142ef5416a..6e869b3405 100644 --- a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/statement.go +++ b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/statement.go @@ -10,6 +10,9 @@ package mysql import ( "database/sql/driver" + "fmt" + "reflect" + "strconv" ) type mysqlStmt struct { @@ -34,6 +37,10 @@ func (stmt *mysqlStmt) NumInput() int { return stmt.paramCount } +func (stmt *mysqlStmt) ColumnConverter(idx int) driver.ValueConverter { + return converter{} +} + func (stmt *mysqlStmt) Exec(args []driver.Value) (driver.Result, error) { if stmt.mc.netConn == nil { errLog.Print(ErrInvalidConn) @@ -110,3 +117,34 @@ func (stmt *mysqlStmt) Query(args []driver.Value) (driver.Rows, error) { return rows, err } + +type converter struct{} + +func (c converter) ConvertValue(v interface{}) (driver.Value, error) { + if driver.IsValue(v) { + return v, nil + } + + rv := reflect.ValueOf(v) + switch rv.Kind() { + case reflect.Ptr: + // indirect pointers + if rv.IsNil() { + return nil, nil + } + return c.ConvertValue(rv.Elem().Interface()) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return rv.Int(), nil + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32: + return int64(rv.Uint()), nil + case reflect.Uint64: + u64 := rv.Uint() + if u64 >= 1<<63 { + return strconv.FormatUint(u64, 10), nil + } + return int64(u64), nil + case reflect.Float32, reflect.Float64: + return rv.Float(), nil + } + return nil, fmt.Errorf("unsupported type %T, a %s", v, rv.Kind()) +} diff --git a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/utils.go b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/utils.go index 6693d29709..6a26ad129c 100644 --- a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/utils.go +++ b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/utils.go @@ -80,8 +80,6 @@ func parseDSN(dsn string) (cfg *config, err error) { collation: defaultCollation, } - // TODO: use strings.IndexByte when we can depend on Go 1.2 - // [user[:password]@][net[(addr)]]/dbname[?param1=value1¶mN=valueN] // Find the last '/' (since the password or the net addr might contain a '/') foundSlash := false @@ -201,6 +199,14 @@ func parseDSNParams(cfg *config, params string) (err error) { return fmt.Errorf("Invalid Bool value: %s", value) } + // Use cleartext authentication mode (MySQL 5.5.10+) + case "allowCleartextPasswords": + var isBool bool + cfg.allowCleartextPasswords, isBool = readBool(value) + if !isBool { + return fmt.Errorf("Invalid Bool value: %s", value) + } + // Use old authentication mode (pre MySQL 4.1) case "allowOldPasswords": var isBool bool @@ -771,6 +777,10 @@ func skipLengthEncodedString(b []byte) (int, error) { // returns the number read, whether the value is NULL and the number of bytes read func readLengthEncodedInteger(b []byte) (uint64, bool, int) { + // See issue #349 + if len(b) == 0 { + return 0, true, 1 + } switch b[0] { // 251: NULL diff --git a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/utils_test.go b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/utils_test.go index adb8dcbd1b..79fbdd1eb3 100644 --- a/Godeps/_workspace/src/github.com/go-sql-driver/mysql/utils_test.go +++ b/Godeps/_workspace/src/github.com/go-sql-driver/mysql/utils_test.go @@ -22,19 +22,19 @@ var testDSNs = []struct { out string loc *time.Location }{ - {"username:password@protocol(address)/dbname?param=value", "&{user:username passwd:password net:protocol addr:address dbname:dbname params:map[param:value] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, - {"username:password@protocol(address)/dbname?param=value&columnsWithAlias=true", "&{user:username passwd:password net:protocol addr:address dbname:dbname params:map[param:value] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:true interpolateParams:false}", time.UTC}, - {"user@unix(/path/to/socket)/dbname?charset=utf8", "&{user:user passwd: net:unix addr:/path/to/socket dbname:dbname params:map[charset:utf8] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, - {"user:password@tcp(localhost:5555)/dbname?charset=utf8&tls=true", "&{user:user passwd:password net:tcp addr:localhost:5555 dbname:dbname params:map[charset:utf8] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, - {"user:password@tcp(localhost:5555)/dbname?charset=utf8mb4,utf8&tls=skip-verify", "&{user:user passwd:password net:tcp addr:localhost:5555 dbname:dbname params:map[charset:utf8mb4,utf8] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, - {"user:password@/dbname?loc=UTC&timeout=30s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci", "&{user:user passwd:password net:tcp addr:127.0.0.1:3306 dbname:dbname params:map[] loc:%p tls: timeout:30000000000 collation:224 allowAllFiles:true allowOldPasswords:true clientFoundRows:true columnsWithAlias:false interpolateParams:false}", time.UTC}, - {"user:p@ss(word)@tcp([de:ad:be:ef::ca:fe]:80)/dbname?loc=Local", "&{user:user passwd:p@ss(word) net:tcp addr:[de:ad:be:ef::ca:fe]:80 dbname:dbname params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.Local}, - {"/dbname", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname:dbname params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, - {"@/", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, - {"/", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, - {"", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, - {"user:p@/ssword@/", "&{user:user passwd:p@/ssword net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, - {"unix/?arg=%2Fsome%2Fpath.ext", "&{user: passwd: net:unix addr:/tmp/mysql.sock dbname: params:map[arg:/some/path.ext] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, + {"username:password@protocol(address)/dbname?param=value", "&{user:username passwd:password net:protocol addr:address dbname:dbname params:map[param:value] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, + {"username:password@protocol(address)/dbname?param=value&columnsWithAlias=true", "&{user:username passwd:password net:protocol addr:address dbname:dbname params:map[param:value] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:true interpolateParams:false}", time.UTC}, + {"user@unix(/path/to/socket)/dbname?charset=utf8", "&{user:user passwd: net:unix addr:/path/to/socket dbname:dbname params:map[charset:utf8] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, + {"user:password@tcp(localhost:5555)/dbname?charset=utf8&tls=true", "&{user:user passwd:password net:tcp addr:localhost:5555 dbname:dbname params:map[charset:utf8] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, + {"user:password@tcp(localhost:5555)/dbname?charset=utf8mb4,utf8&tls=skip-verify", "&{user:user passwd:password net:tcp addr:localhost:5555 dbname:dbname params:map[charset:utf8mb4,utf8] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, + {"user:password@/dbname?loc=UTC&timeout=30s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci", "&{user:user passwd:password net:tcp addr:127.0.0.1:3306 dbname:dbname params:map[] loc:%p tls: timeout:30000000000 collation:224 allowAllFiles:true allowOldPasswords:true allowCleartextPasswords:false clientFoundRows:true columnsWithAlias:false interpolateParams:false}", time.UTC}, + {"user:p@ss(word)@tcp([de:ad:be:ef::ca:fe]:80)/dbname?loc=Local", "&{user:user passwd:p@ss(word) net:tcp addr:[de:ad:be:ef::ca:fe]:80 dbname:dbname params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.Local}, + {"/dbname", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname:dbname params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, + {"@/", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, + {"/", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, + {"", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, + {"user:p@/ssword@/", "&{user:user passwd:p@/ssword net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, + {"unix/?arg=%2Fsome%2Fpath.ext", "&{user: passwd: net:unix addr:/tmp/mysql.sock dbname: params:map[arg:/some/path.ext] loc:%p tls: timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC}, } func TestDSNParser(t *testing.T) { diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/activity_star.go b/Godeps/_workspace/src/github.com/google/go-github/github/activity_star.go index 982f24d717..fac4f41d2c 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/activity_star.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/activity_star.go @@ -7,6 +7,12 @@ package github import "fmt" +// StarredRepository is returned by ListStarred. +type StarredRepository struct { + StarredAt *Timestamp `json:"starred_at,omitempty"` + Repository *Repository `json:"repo,omitempty"` +} + // ListStargazers lists people who have starred the specified repo. // // GitHub API Docs: https://developer.github.com/v3/activity/starring/#list-stargazers @@ -49,7 +55,7 @@ type ActivityListStarredOptions struct { // will list the starred repositories for the authenticated user. // // GitHub API docs: http://developer.github.com/v3/activity/starring/#list-repositories-being-starred -func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptions) ([]Repository, *Response, error) { +func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptions) ([]StarredRepository, *Response, error) { var u string if user != "" { u = fmt.Sprintf("users/%v/starred", user) @@ -66,7 +72,10 @@ func (s *ActivityService) ListStarred(user string, opt *ActivityListStarredOptio return nil, nil, err } - repos := new([]Repository) + // TODO: remove custom Accept header when this API fully launches + req.Header.Set("Accept", mediaTypeStarringPreview) + + repos := new([]StarredRepository) resp, err := s.client.Do(req, repos) if err != nil { return nil, resp, err diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/activity_star_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/activity_star_test.go index ae33b93cff..eb2c4055e7 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/activity_star_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/activity_star_test.go @@ -10,6 +10,7 @@ import ( "net/http" "reflect" "testing" + "time" ) func TestActivityService_ListStargazers(t *testing.T) { @@ -42,7 +43,8 @@ func TestActivityService_ListStarred_authenticatedUser(t *testing.T) { mux.HandleFunc("/user/starred", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `[{"id":1}]`) + testHeader(t, r, "Accept", mediaTypeStarringPreview) + fmt.Fprint(w, `[{"starred_at":"2002-02-10T15:30:00Z","repo":{"id":1}}]`) }) repos, _, err := client.Activity.ListStarred("", nil) @@ -50,7 +52,7 @@ func TestActivityService_ListStarred_authenticatedUser(t *testing.T) { t.Errorf("Activity.ListStarred returned error: %v", err) } - want := []Repository{{ID: Int(1)}} + want := []StarredRepository{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, Repository: &Repository{ID: Int(1)}}} if !reflect.DeepEqual(repos, want) { t.Errorf("Activity.ListStarred returned %+v, want %+v", repos, want) } @@ -62,12 +64,13 @@ func TestActivityService_ListStarred_specifiedUser(t *testing.T) { mux.HandleFunc("/users/u/starred", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeStarringPreview) testFormValues(t, r, values{ "sort": "created", "direction": "asc", "page": "2", }) - fmt.Fprint(w, `[{"id":2}]`) + fmt.Fprint(w, `[{"starred_at":"2002-02-10T15:30:00Z","repo":{"id":2}}]`) }) opt := &ActivityListStarredOptions{"created", "asc", ListOptions{Page: 2}} @@ -76,7 +79,7 @@ func TestActivityService_ListStarred_specifiedUser(t *testing.T) { t.Errorf("Activity.ListStarred returned error: %v", err) } - want := []Repository{{ID: Int(2)}} + want := []StarredRepository{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, Repository: &Repository{ID: Int(2)}}} if !reflect.DeepEqual(repos, want) { t.Errorf("Activity.ListStarred returned %+v, want %+v", repos, want) } diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/doc.go b/Godeps/_workspace/src/github.com/google/go-github/github/doc.go index 9e48242d21..b4ac8e640a 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/doc.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/doc.go @@ -35,21 +35,10 @@ use it with the oauth2 library using: import "golang.org/x/oauth2" - // tokenSource is an oauth2.TokenSource which returns a static access token - type tokenSource struct { - token *oauth2.Token - } - - // Token implements the oauth2.TokenSource interface - func (t *tokenSource) Token() (*oauth2.Token, error){ - return t.token, nil - } - func main() { - ts := &tokenSource{ + ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: "... your access token ..."}, - } - + ) tc := oauth2.NewClient(oauth2.NoContext, ts) client := github.NewClient(tc) diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/gists.go b/Godeps/_workspace/src/github.com/google/go-github/github/gists.go index 20c3536c1e..14bf5dc50a 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/gists.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/gists.go @@ -157,6 +157,24 @@ func (s *GistsService) Get(id string) (*Gist, *Response, error) { return gist, resp, err } +// Get a specific revision of a gist. +// +// GitHub API docs: https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist +func (s *GistsService) GetRevision(id, sha string) (*Gist, *Response, error) { + u := fmt.Sprintf("gists/%v/%v", id, sha) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + gist := new(Gist) + resp, err := s.client.Do(req, gist) + if err != nil { + return nil, resp, err + } + + return gist, resp, err +} + // Create a gist for authenticated user. // // GitHub API docs: http://developer.github.com/v3/gists/#create-a-gist diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/gists_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/gists_test.go index bd755da0d2..573120129e 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/gists_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/gists_test.go @@ -146,6 +146,32 @@ func TestGistsService_Get_invalidID(t *testing.T) { testURLParseError(t, err) } +func TestGistsService_GetRevision(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/gists/1/s", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{"id": "1"}`) + }) + + gist, _, err := client.Gists.GetRevision("1", "s") + + if err != nil { + t.Errorf("Gists.Get returned error: %v", err) + } + + want := &Gist{ID: String("1")} + if !reflect.DeepEqual(gist, want) { + t.Errorf("Gists.Get returned %+v, want %+v", gist, want) + } +} + +func TestGistsService_GetRevision_invalidID(t *testing.T) { + _, _, err := client.Gists.GetRevision("%", "%") + testURLParseError(t, err) +} + func TestGistsService_Create(t *testing.T) { setup() defer teardown() diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/github.go b/Godeps/_workspace/src/github.com/google/go-github/github/github.go index 52699eb8c6..3aa643cb62 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/github.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/github.go @@ -37,11 +37,14 @@ const ( // Media Type values to access preview APIs - // https://developer.github.com/changes/2014-08-05-team-memberships-api/ - mediaTypeMembershipPreview = "application/vnd.github.the-wasp-preview+json" + // https://developer.github.com/changes/2015-03-09-licenses-api/ + mediaTypeLicensesPreview = "application/vnd.github.drax-preview+json" - // https://developer.github.com/changes/2014-01-09-preview-the-new-deployments-api/ - mediaTypeDeploymentPreview = "application/vnd.github.cannonball-preview+json" + // https://developer.github.com/changes/2014-12-09-new-attributes-for-stars-api/ + mediaTypeStarringPreview = "application/vnd.github.v3.star+json" + + // https://developer.github.com/changes/2014-12-08-organization-permissions-api-preview/ + mediaTypeOrganizationsPreview = "application/vnd.github.moondragon+json" ) // A Client manages communication with the GitHub API. @@ -77,6 +80,7 @@ type Client struct { Repositories *RepositoriesService Search *SearchService Users *UsersService + Licenses *LicensesService } // ListOptions specifies the optional parameters to various List methods that @@ -138,6 +142,7 @@ func NewClient(httpClient *http.Client) *Client { c.Repositories = &RepositoriesService{client: c} c.Search = &SearchService{client: c} c.Users = &UsersService{client: c} + c.Licenses = &LicensesService{client: c} return c } @@ -219,7 +224,7 @@ type Response struct { Rate } -// newResponse creats a new Response for the provided http.Response. +// newResponse creates a new Response for the provided http.Response. func newResponse(r *http.Response) *Response { response := &Response{Response: r} response.populatePageValues() @@ -333,10 +338,24 @@ type ErrorResponse struct { func (r *ErrorResponse) Error() string { return fmt.Sprintf("%v %v: %d %v %+v", - r.Response.Request.Method, r.Response.Request.URL, + r.Response.Request.Method, sanitizeURL(r.Response.Request.URL), r.Response.StatusCode, r.Message, r.Errors) } +// sanitizeURL redacts the client_id and client_secret tokens from the URL which +// may be exposed to the user, specifically in the ErrorResponse error message. +func sanitizeURL(uri *url.URL) *url.URL { + if uri == nil { + return nil + } + params := uri.Query() + if len(params.Get("client_secret")) > 0 { + params.Set("client_secret", "REDACTED") + uri.RawQuery = params.Encode() + } + return uri +} + /* An Error reports more details on an individual error in an ErrorResponse. These are the possible validation error codes: diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/github_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/github_test.go index 0fb2c18a1b..05c817b658 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/github_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/github_test.go @@ -430,6 +430,25 @@ func TestDo_rateLimit_errorResponse(t *testing.T) { } } +func TestSanitizeURL(t *testing.T) { + tests := []struct { + in, want string + }{ + {"/?a=b", "/?a=b"}, + {"/?a=b&client_secret=secret", "/?a=b&client_secret=REDACTED"}, + {"/?a=b&client_id=id&client_secret=secret", "/?a=b&client_id=id&client_secret=REDACTED"}, + } + + for _, tt := range tests { + inURL, _ := url.Parse(tt.in) + want, _ := url.Parse(tt.want) + + if got := sanitizeURL(inURL); !reflect.DeepEqual(got, want) { + t.Errorf("sanitizeURL(%v) returned %v, want %v", tt.in, got, want) + } + } +} + func TestCheckResponse(t *testing.T) { res := &http.Response{ Request: &http.Request{}, diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/issues.go b/Godeps/_workspace/src/github.com/google/go-github/github/issues.go index f92df6b560..05f5477f95 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/issues.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/issues.go @@ -49,12 +49,12 @@ func (i Issue) String() string { // It is separate from Issue above because otherwise Labels // and Assignee fail to serialize to the correct JSON. type IssueRequest struct { - Title *string `json:"title,omitempty"` - Body *string `json:"body,omitempty"` - Labels []string `json:"labels,omitempty"` - Assignee *string `json:"assignee,omitempty"` - State *string `json:"state,omitempty"` - Milestone *int `json:"milestone,omitempty"` + Title *string `json:"title,omitempty"` + Body *string `json:"body,omitempty"` + Labels *[]string `json:"labels,omitempty"` + Assignee *string `json:"assignee,omitempty"` + State *string `json:"state,omitempty"` + Milestone *int `json:"milestone,omitempty"` } // IssueListOptions specifies the optional parameters to the IssuesService.List @@ -72,7 +72,7 @@ type IssueListOptions struct { Labels []string `url:"labels,comma,omitempty"` // Sort specifies how to sort issues. Possible values are: created, updated, - // and comments. Default value is "assigned". + // and comments. Default value is "created". Sort string `url:"sort,omitempty"` // Direction in which to sort issues. Possible values are: asc, desc. @@ -166,7 +166,7 @@ type IssueListByRepoOptions struct { Labels []string `url:"labels,omitempty,comma"` // Sort specifies how to sort issues. Possible values are: created, updated, - // and comments. Default value is "assigned". + // and comments. Default value is "created". Sort string `url:"sort,omitempty"` // Direction in which to sort issues. Possible values are: asc, desc. diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/issues_labels.go b/Godeps/_workspace/src/github.com/google/go-github/github/issues_labels.go index 5ad25c1bbb..88f9f3ff96 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/issues_labels.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/issues_labels.go @@ -7,7 +7,7 @@ package github import "fmt" -// Label represents a GitHib label on an Issue +// Label represents a GitHub label on an Issue type Label struct { URL *string `json:"url,omitempty"` Name *string `json:"name,omitempty"` diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/issues_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/issues_test.go index 090cf1b1a2..f69efd3998 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/issues_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/issues_test.go @@ -176,7 +176,7 @@ func TestIssuesService_Create(t *testing.T) { Title: String("t"), Body: String("b"), Assignee: String("a"), - Labels: []string{"l1", "l2"}, + Labels: &[]string{"l1", "l2"}, } mux.HandleFunc("/repos/o/r/issues", func(w http.ResponseWriter, r *http.Request) { diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/licenses.go b/Godeps/_workspace/src/github.com/google/go-github/github/licenses.go new file mode 100644 index 0000000000..d2a5a50669 --- /dev/null +++ b/Godeps/_workspace/src/github.com/google/go-github/github/licenses.go @@ -0,0 +1,81 @@ +// Copyright 2013 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import "fmt" + +// LicensesService handles communication with the license related +// methods of the GitHub API. +// +// GitHub API docs: http://developer.github.com/v3/pulls/ +type LicensesService struct { + client *Client +} + +// License represents an open source license. +type License struct { + Key *string `json:"key,omitempty"` + Name *string `json:"name,omitempty"` + URL *string `json:"url,omitempty"` + + HTMLURL *string `json:"html_url",omitempty` + Featured *bool `json:"featured,omitempty"` + Description *string `json:"description,omitempty"` + Category *string `json:"category,omitempty"` + Implementation *string `json:"implementation,omitempty"` + Required *[]string `json:"required,omitempty"` + Permitted *[]string `json:"permitted,omitempty"` + Forbidden *[]string `json:"forbidden,omitempty"` + Body *string `json:"body,omitempty"` +} + +func (l License) String() string { + return Stringify(l) +} + +// List popular open source licenses. +// +// GitHub API docs: https://developer.github.com/v3/licenses/#list-all-licenses +func (s *LicensesService) List() ([]License, *Response, error) { + req, err := s.client.NewRequest("GET", "licenses", nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches + req.Header.Set("Accept", mediaTypeLicensesPreview) + + licenses := new([]License) + resp, err := s.client.Do(req, licenses) + if err != nil { + return nil, resp, err + } + + return *licenses, resp, err +} + +// Fetch extended metadata for one license. +// +// GitHub API docs: https://developer.github.com/v3/licenses/#get-an-individual-license +func (s *LicensesService) Get(licenseName string) (*License, *Response, error) { + u := fmt.Sprintf("licenses/%s", licenseName) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + // TODO: remove custom Accept header when this API fully launches + req.Header.Set("Accept", mediaTypeLicensesPreview) + + license := new(License) + resp, err := s.client.Do(req, license) + if err != nil { + return nil, resp, err + } + + return license, resp, err +} diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/licenses_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/licenses_test.go new file mode 100644 index 0000000000..72f6633b2b --- /dev/null +++ b/Godeps/_workspace/src/github.com/google/go-github/github/licenses_test.go @@ -0,0 +1,64 @@ +// Copyright 2013 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "fmt" + "net/http" + "reflect" + "testing" +) + +func TestLicensesService_List(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/licenses", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeLicensesPreview) + fmt.Fprint(w, `[{"key":"mit","name":"MIT","url":"https://api.github.com/licenses/mit"}]`) + }) + + licenses, _, err := client.Licenses.List() + if err != nil { + t.Errorf("Licenses.List returned error: %v", err) + } + + want := []License{License{ + Key: String("mit"), + Name: String("MIT"), + URL: String("https://api.github.com/licenses/mit"), + }} + if !reflect.DeepEqual(licenses, want) { + t.Errorf("Licenses.List returned %+v, want %+v", licenses, want) + } +} + +func TestLicensesService_Get(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/licenses/mit", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeLicensesPreview) + fmt.Fprint(w, `{"key":"mit","name":"MIT"}`) + }) + + license, _, err := client.Licenses.Get("mit") + if err != nil { + t.Errorf("Licenses.Get returned error: %v", err) + } + + want := &License{Key: String("mit"), Name: String("MIT")} + if !reflect.DeepEqual(license, want) { + t.Errorf("Licenses.Get returned %+v, want %+v", license, want) + } +} + +func TestLicensesService_Get_invalidTemplate(t *testing.T) { + _, _, err := client.Licenses.Get("%") + testURLParseError(t, err) +} diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/misc.go b/Godeps/_workspace/src/github.com/google/go-github/github/misc.go index 4a9bb99ef4..66e7f5239d 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/misc.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/misc.go @@ -98,6 +98,10 @@ type APIMeta struct { // username and password, sudo mode, and two-factor authentication are // not supported on these servers.) VerifiablePasswordAuthentication *bool `json:"verifiable_password_authentication,omitempty"` + + // An array of IP addresses in CIDR format specifying the addresses + // which serve GitHub Pages websites. + Pages []string `json:"pages,omitempty"` } // APIMeta returns information about GitHub.com, the service. Or, if you access @@ -159,3 +163,35 @@ func (c *Client) Zen() (string, *Response, error) { return buf.String(), resp, nil } + +// ServiceHook represents a hook that has configuration settings, a list of +// available events, and default events. +type ServiceHook struct { + Name *string `json:"name,omitempty"` + Events []string `json:"events,omitempty"` + SupportedEvents []string `json:"supported_events,omitempty"` + Schema [][]string `json:"schema,omitempty"` +} + +func (s *ServiceHook) String() string { + return Stringify(s) +} + +// ListServiceHooks lists all of the available service hooks. +// +// GitHub API docs: https://developer.github.com/webhooks/#services +func (c *Client) ListServiceHooks() ([]ServiceHook, *Response, error) { + u := "hooks" + req, err := c.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + hooks := new([]ServiceHook) + resp, err := c.Do(req, hooks) + if err != nil { + return nil, resp, err + } + + return *hooks, resp, err +} diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/misc_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/misc_test.go index 33c3db63d3..8ca58d251b 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/misc_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/misc_test.go @@ -72,7 +72,7 @@ func TestAPIMeta(t *testing.T) { mux.HandleFunc("/meta", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"hooks":["h"], "git":["g"], "verifiable_password_authentication": true}`) + fmt.Fprint(w, `{"hooks":["h"], "git":["g"], "pages":["p"], "verifiable_password_authentication": true}`) }) meta, _, err := client.APIMeta() @@ -83,6 +83,7 @@ func TestAPIMeta(t *testing.T) { want := &APIMeta{ Hooks: []string{"h"}, Git: []string{"g"}, + Pages: []string{"p"}, VerifiablePasswordAuthentication: Bool(true), } if !reflect.DeepEqual(want, meta) { @@ -135,3 +136,35 @@ func TestZen(t *testing.T) { t.Errorf("Zen returned %+v, want %+v", got, want) } } + +func TestRepositoriesService_ListServiceHooks(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/hooks", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{ + "name":"n", + "events":["e"], + "supported_events":["s"], + "schema":[ + ["a", "b"] + ] + }]`) + }) + + hooks, _, err := client.Repositories.ListServiceHooks() + if err != nil { + t.Errorf("Repositories.ListHooks returned error: %v", err) + } + + want := []ServiceHook{{ + Name: String("n"), + Events: []string{"e"}, + SupportedEvents: []string{"s"}, + Schema: [][]string{{"a", "b"}}, + }} + if !reflect.DeepEqual(hooks, want) { + t.Errorf("Repositories.ListServiceHooks returned %+v, want %+v", hooks, want) + } +} diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/orgs_hooks.go b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_hooks.go new file mode 100644 index 0000000000..3e7ad40ff2 --- /dev/null +++ b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_hooks.go @@ -0,0 +1,104 @@ +// Copyright 2015 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import "fmt" + +// ListHooks lists all Hooks for the specified organization. +// +// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#list-hooks +func (s *OrganizationsService) ListHooks(org string, opt *ListOptions) ([]Hook, *Response, error) { + u := fmt.Sprintf("orgs/%v/hooks", org) + u, err := addOptions(u, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + hooks := new([]Hook) + resp, err := s.client.Do(req, hooks) + if err != nil { + return nil, resp, err + } + + return *hooks, resp, err +} + +// GetHook returns a single specified Hook. +// +// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#get-single-hook +func (s *OrganizationsService) GetHook(org string, id int) (*Hook, *Response, error) { + u := fmt.Sprintf("orgs/%v/hooks/%d", org, id) + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + hook := new(Hook) + resp, err := s.client.Do(req, hook) + return hook, resp, err +} + +// CreateHook creates a Hook for the specified org. +// Name and Config are required fields. +// +// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#create-a-hook +func (s *OrganizationsService) CreateHook(org string, hook *Hook) (*Hook, *Response, error) { + u := fmt.Sprintf("orgs/%v/hooks", org) + req, err := s.client.NewRequest("POST", u, hook) + if err != nil { + return nil, nil, err + } + + h := new(Hook) + resp, err := s.client.Do(req, h) + if err != nil { + return nil, resp, err + } + + return h, resp, err +} + +// EditHook updates a specified Hook. +// +// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#edit-a-hook +func (s *OrganizationsService) EditHook(org string, id int, hook *Hook) (*Hook, *Response, error) { + u := fmt.Sprintf("orgs/%v/hooks/%d", org, id) + req, err := s.client.NewRequest("PATCH", u, hook) + if err != nil { + return nil, nil, err + } + h := new(Hook) + resp, err := s.client.Do(req, h) + return h, resp, err +} + +// PingHook triggers a 'ping' event to be sent to the Hook. +// +// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#ping-a-hook +func (s *OrganizationsService) PingHook(org string, id int) (*Response, error) { + u := fmt.Sprintf("orgs/%v/hooks/%d/pings", org, id) + req, err := s.client.NewRequest("POST", u, nil) + if err != nil { + return nil, err + } + return s.client.Do(req, nil) +} + +// DeleteHook deletes a specified Hook. +// +// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#delete-a-hook +func (s *OrganizationsService) DeleteHook(org string, id int) (*Response, error) { + u := fmt.Sprintf("orgs/%v/hooks/%d", org, id) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + return s.client.Do(req, nil) +} diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/orgs_hooks_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_hooks_test.go new file mode 100644 index 0000000000..1ebc07d5a4 --- /dev/null +++ b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_hooks_test.go @@ -0,0 +1,134 @@ +// Copyright 2015 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "encoding/json" + "fmt" + "net/http" + "reflect" + "testing" +) + +func TestOrganizationsService_ListHooks(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/orgs/o/hooks", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) + fmt.Fprint(w, `[{"id":1}, {"id":2}]`) + }) + + opt := &ListOptions{Page: 2} + + hooks, _, err := client.Organizations.ListHooks("o", opt) + if err != nil { + t.Errorf("Organizations.ListHooks returned error: %v", err) + } + + want := []Hook{{ID: Int(1)}, {ID: Int(2)}} + if !reflect.DeepEqual(hooks, want) { + t.Errorf("Organizations.ListHooks returned %+v, want %+v", hooks, want) + } +} + +func TestOrganizationsService_ListHooks_invalidOrg(t *testing.T) { + _, _, err := client.Organizations.ListHooks("%", nil) + testURLParseError(t, err) +} + +func TestOrganizationsService_GetHook(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/orgs/o/hooks/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{"id":1}`) + }) + + hook, _, err := client.Organizations.GetHook("o", 1) + if err != nil { + t.Errorf("Organizations.GetHook returned error: %v", err) + } + + want := &Hook{ID: Int(1)} + if !reflect.DeepEqual(hook, want) { + t.Errorf("Organizations.GetHook returned %+v, want %+v", hook, want) + } +} + +func TestOrganizationsService_GetHook_invalidOrg(t *testing.T) { + _, _, err := client.Organizations.GetHook("%", 1) + testURLParseError(t, err) +} + +func TestOrganizationsService_EditHook(t *testing.T) { + setup() + defer teardown() + + input := &Hook{Name: String("t")} + + mux.HandleFunc("/orgs/o/hooks/1", func(w http.ResponseWriter, r *http.Request) { + v := new(Hook) + json.NewDecoder(r.Body).Decode(v) + + testMethod(t, r, "PATCH") + if !reflect.DeepEqual(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + + fmt.Fprint(w, `{"id":1}`) + }) + + hook, _, err := client.Organizations.EditHook("o", 1, input) + if err != nil { + t.Errorf("Organizations.EditHook returned error: %v", err) + } + + want := &Hook{ID: Int(1)} + if !reflect.DeepEqual(hook, want) { + t.Errorf("Organizations.EditHook returned %+v, want %+v", hook, want) + } +} + +func TestOrganizationsService_EditHook_invalidOrg(t *testing.T) { + _, _, err := client.Organizations.EditHook("%", 1, nil) + testURLParseError(t, err) +} + +func TestOrganizationsService_PingHook(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/orgs/o/hooks/1/pings", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + }) + + _, err := client.Organizations.PingHook("o", 1) + if err != nil { + t.Errorf("Organizations.PingHook returned error: %v", err) + } +} + +func TestOrganizationsService_DeleteHook(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/orgs/o/hooks/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + }) + + _, err := client.Organizations.DeleteHook("o", 1) + if err != nil { + t.Errorf("Organizations.DeleteHook returned error: %v", err) + } +} + +func TestOrganizationsService_DeleteHook_invalidOrg(t *testing.T) { + _, err := client.Organizations.DeleteHook("%", 1) + testURLParseError(t, err) +} diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/orgs_members.go b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_members.go index ae6f57943f..64dcfcc3d0 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/orgs_members.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_members.go @@ -171,9 +171,6 @@ func (s *OrganizationsService) ListOrgMemberships(opt *ListOrgMembershipsOptions return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeMembershipPreview) - var memberships []Membership resp, err := s.client.Do(req, &memberships) if err != nil { @@ -194,9 +191,6 @@ func (s *OrganizationsService) GetOrgMembership(org string) (*Membership, *Respo return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeMembershipPreview) - membership := new(Membership) resp, err := s.client.Do(req, membership) if err != nil { @@ -217,9 +211,6 @@ func (s *OrganizationsService) EditOrgMembership(org string, membership *Members return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeMembershipPreview) - m := new(Membership) resp, err := s.client.Do(req, m) if err != nil { diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/orgs_members_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_members_test.go index 85cb987188..493488aa62 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/orgs_members_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_members_test.go @@ -217,7 +217,6 @@ func TestOrganizationsService_ListOrgMemberships(t *testing.T) { mux.HandleFunc("/user/memberships/orgs", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeMembershipPreview) testFormValues(t, r, values{ "state": "active", "page": "2", @@ -246,7 +245,6 @@ func TestOrganizationsService_GetOrgMembership(t *testing.T) { mux.HandleFunc("/user/memberships/orgs/o", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeMembershipPreview) fmt.Fprint(w, `{"url":"u"}`) }) @@ -272,7 +270,6 @@ func TestOrganizationsService_EditOrgMembership(t *testing.T) { json.NewDecoder(r.Body).Decode(v) testMethod(t, r, "PATCH") - testHeader(t, r, "Accept", mediaTypeMembershipPreview) if !reflect.DeepEqual(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/orgs_teams.go b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_teams.go index 0c0f7dbd93..dd01a7b22d 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/orgs_teams.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_teams.go @@ -158,32 +158,6 @@ func (s *OrganizationsService) IsTeamMember(team int, user string) (bool, *Respo return member, resp, err } -// AddTeamMember adds a user to a team. -// -// GitHub API docs: http://developer.github.com/v3/orgs/teams/#add-team-member -func (s *OrganizationsService) AddTeamMember(team int, user string) (*Response, error) { - u := fmt.Sprintf("teams/%v/members/%v", team, user) - req, err := s.client.NewRequest("PUT", u, nil) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) -} - -// RemoveTeamMember removes a user from a team. -// -// GitHub API docs: http://developer.github.com/v3/orgs/teams/#remove-team-member -func (s *OrganizationsService) RemoveTeamMember(team int, user string) (*Response, error) { - u := fmt.Sprintf("teams/%v/members/%v", team, user) - req, err := s.client.NewRequest("DELETE", u, nil) - if err != nil { - return nil, err - } - - return s.client.Do(req, nil) -} - // ListTeamRepos lists the repositories that the specified team has access to. // // GitHub API docs: http://developer.github.com/v3/orgs/teams/#list-team-repos @@ -286,9 +260,6 @@ func (s *OrganizationsService) GetTeamMembership(team int, user string) (*Member return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeMembershipPreview) - t := new(Membership) resp, err := s.client.Do(req, t) if err != nil { @@ -323,9 +294,6 @@ func (s *OrganizationsService) AddTeamMembership(team int, user string) (*Member return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeMembershipPreview) - t := new(Membership) resp, err := s.client.Do(req, t) if err != nil { @@ -345,8 +313,5 @@ func (s *OrganizationsService) RemoveTeamMembership(team int, user string) (*Res return nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeMembershipPreview) - return s.client.Do(req, nil) } diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/orgs_teams_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_teams_test.go index 1f45e8c1b1..1b18b623f0 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/orgs_teams_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/orgs_teams_test.go @@ -220,46 +220,6 @@ func TestOrganizationsService_IsTeamMember_invalidUser(t *testing.T) { testURLParseError(t, err) } -func TestOrganizationsService_AddTeamMember(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "PUT") - w.WriteHeader(http.StatusNoContent) - }) - - _, err := client.Organizations.AddTeamMember(1, "u") - if err != nil { - t.Errorf("Organizations.AddTeamMember returned error: %v", err) - } -} - -func TestOrganizationsService_AddTeamMember_invalidUser(t *testing.T) { - _, err := client.Organizations.AddTeamMember(1, "%") - testURLParseError(t, err) -} - -func TestOrganizationsService_RemoveTeamMember(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/teams/1/members/u", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "DELETE") - w.WriteHeader(http.StatusNoContent) - }) - - _, err := client.Organizations.RemoveTeamMember(1, "u") - if err != nil { - t.Errorf("Organizations.RemoveTeamMember returned error: %v", err) - } -} - -func TestOrganizationsService_RemoveTeamMember_invalidUser(t *testing.T) { - _, err := client.Organizations.RemoveTeamMember(1, "%") - testURLParseError(t, err) -} - func TestOrganizationsService_PublicizeMembership(t *testing.T) { setup() defer teardown() @@ -442,7 +402,6 @@ func TestOrganizationsService_GetTeamMembership(t *testing.T) { mux.HandleFunc("/teams/1/memberships/u", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - testHeader(t, r, "Accept", mediaTypeMembershipPreview) fmt.Fprint(w, `{"url":"u", "state":"active"}`) }) @@ -463,7 +422,6 @@ func TestOrganizationsService_AddTeamMembership(t *testing.T) { mux.HandleFunc("/teams/1/memberships/u", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PUT") - testHeader(t, r, "Accept", mediaTypeMembershipPreview) fmt.Fprint(w, `{"url":"u", "state":"pending"}`) }) @@ -484,7 +442,6 @@ func TestOrganizationsService_RemoveTeamMembership(t *testing.T) { mux.HandleFunc("/teams/1/memberships/u", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") - testHeader(t, r, "Accept", mediaTypeMembershipPreview) w.WriteHeader(http.StatusNoContent) }) diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/pulls.go b/Godeps/_workspace/src/github.com/google/go-github/github/pulls.go index 307562d708..71cf2e2484 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/pulls.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/pulls.go @@ -41,6 +41,8 @@ type PullRequest struct { HTMLURL *string `json:"html_url,omitempty"` IssueURL *string `json:"issue_url,omitempty"` StatusesURL *string `json:"statuses_url,omitempty"` + DiffURL *string `json:"diff_url,omitempty"` + PatchURL *string `json:"patch_url,omitempty"` Head *PullRequestBranch `json:"head,omitempty"` Base *PullRequestBranch `json:"base,omitempty"` @@ -73,6 +75,15 @@ type PullRequestListOptions struct { // Base filters pull requests by base branch name. Base string `url:"base,omitempty"` + // Sort specifies how to sort pull requests. Possible values are: created, + // updated, popularity, long-running. Default is "created". + Sort string `url:"sort,omitempty"` + + // Direction in which to sort pull requests. Possible values are: asc, desc. + // If Sort is "created" or not specified, Default is "desc", otherwise Default + // is "asc" + Direction string `url:"direction,omitempty"` + ListOptions } diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/pulls_comments.go b/Godeps/_workspace/src/github.com/google/go-github/github/pulls_comments.go index bfbad9af2d..35c7241b9a 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/pulls_comments.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/pulls_comments.go @@ -93,7 +93,7 @@ func (s *PullRequestsService) GetComment(owner string, repo string, number int) // CreateComment creates a new comment on the specified pull request. // -// GitHub API docs: https://developer.github.com/v3/pulls/comments/#get-a-single-comment +// GitHub API docs: https://developer.github.com/v3/pulls/comments/#create-a-comment func (s *PullRequestsService) CreateComment(owner string, repo string, number int, comment *PullRequestComment) (*PullRequestComment, *Response, error) { u := fmt.Sprintf("repos/%v/%v/pulls/%d/comments", owner, repo, number) req, err := s.client.NewRequest("POST", u, comment) diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/pulls_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/pulls_test.go index d0e976bc38..6ac0ddb172 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/pulls_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/pulls_test.go @@ -20,15 +20,17 @@ func TestPullRequestsService_List(t *testing.T) { mux.HandleFunc("/repos/o/r/pulls", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") testFormValues(t, r, values{ - "state": "closed", - "head": "h", - "base": "b", - "page": "2", + "state": "closed", + "head": "h", + "base": "b", + "sort": "created", + "direction": "desc", + "page": "2", }) fmt.Fprint(w, `[{"number":1}]`) }) - opt := &PullRequestListOptions{"closed", "h", "b", ListOptions{Page: 2}} + opt := &PullRequestListOptions{"closed", "h", "b", "created", "desc", ListOptions{Page: 2}} pulls, _, err := client.PullRequests.List("o", "r", opt) if err != nil { @@ -98,6 +100,29 @@ func TestPullRequestsService_Get_headAndBase(t *testing.T) { } } +func TestPullRequestService_Get_DiffURLAndPatchURL(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/pulls/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{"number":1, + "diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff", + "patch_url": "https://github.com/octocat/Hello-World/pull/1347.patch"}`) + }) + + pull, _, err := client.PullRequests.Get("o", "r", 1) + + if err != nil { + t.Errorf("PullRequests.Get returned error: %v", err) + } + + want := &PullRequest{Number: Int(1), DiffURL: String("https://github.com/octocat/Hello-World/pull/1347.diff"), PatchURL: String("https://github.com/octocat/Hello-World/pull/1347.patch")} + if !reflect.DeepEqual(pull, want) { + t.Errorf("PullRequests.Get returned %+v, want %+v", pull, want) + } +} + func TestPullRequestsService_Get_invalidOwner(t *testing.T) { _, _, err := client.PullRequests.Get("%", "r", 1) testURLParseError(t, err) diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/repos.go b/Godeps/_workspace/src/github.com/google/go-github/github/repos.go index 8d8d40fc1d..86d9ad0d0b 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/repos.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/repos.go @@ -49,6 +49,9 @@ type Repository struct { Organization *Organization `json:"organization,omitempty"` Permissions *map[string]bool `json:"permissions,omitempty"` + // Only provided when using RepositoriesService.Get while in preview + License *License `json:"license,omitempty"` + // Additional mutable fields when creating and editing a repository Private *bool `json:"private"` HasIssues *bool `json:"has_issues"` @@ -119,6 +122,11 @@ type RepositoryListOptions struct { // Default is "asc" when sort is "full_name", otherwise default is "desc". Direction string `url:"direction,omitempty"` + // Include orginization repositories the user has access to. + // This will become the default behavior in the future, but is opt-in for now. + // See https://developer.github.com/changes/2015-01-07-prepare-for-organization-permissions-changes/ + IncludeOrg bool `url:"-"` + ListOptions } @@ -143,6 +151,10 @@ func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]R return nil, nil, err } + if opt != nil && opt.IncludeOrg { + req.Header.Set("Accept", mediaTypeOrganizationsPreview) + } + repos := new([]Repository) resp, err := s.client.Do(req, repos) if err != nil { @@ -255,6 +267,10 @@ func (s *RepositoriesService) Get(owner, repo string) (*Repository, *Response, e return nil, nil, err } + // TODO: remove custom Accept header when the license support fully launches + // https://developer.github.com/v3/licenses/#get-a-repositorys-license + req.Header.Set("Accept", mediaTypeLicensesPreview) + repository := new(Repository) resp, err := s.client.Do(req, repository) if err != nil { diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/repos_commits.go b/Godeps/_workspace/src/github.com/google/go-github/github/repos_commits.go index 5a59146908..6401cb4ab8 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/repos_commits.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/repos_commits.go @@ -61,7 +61,8 @@ func (c CommitFile) String() string { // CommitsComparison is the result of comparing two commits. // See CompareCommits() for details. type CommitsComparison struct { - BaseCommit *RepositoryCommit `json:"base_commit,omitempty"` + BaseCommit *RepositoryCommit `json:"base_commit,omitempty"` + MergeBaseCommit *RepositoryCommit `json:"merge_base_commit,omitempty"` // Head can be 'behind' or 'ahead' Status *string `json:"status,omitempty"` diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/repos_contents.go b/Godeps/_workspace/src/github.com/google/go-github/github/repos_contents.go index d17c63e8ce..80776f2dac 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/repos_contents.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/repos_contents.go @@ -13,22 +13,25 @@ import ( "encoding/json" "errors" "fmt" + "io" "net/http" "net/url" + "path" ) // RepositoryContent represents a file or directory in a github repository. type RepositoryContent struct { - Type *string `json:"type,omitempty"` - Encoding *string `json:"encoding,omitempty"` - Size *int `json:"size,omitempty"` - Name *string `json:"name,omitempty"` - Path *string `json:"path,omitempty"` - Content *string `json:"content,omitempty"` - SHA *string `json:"sha,omitempty"` - URL *string `json:"url,omitempty"` - GitURL *string `json:"giturl,omitempty"` - HTMLURL *string `json:"htmlurl,omitempty"` + Type *string `json:"type,omitempty"` + Encoding *string `json:"encoding,omitempty"` + Size *int `json:"size,omitempty"` + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` + Content *string `json:"content,omitempty"` + SHA *string `json:"sha,omitempty"` + URL *string `json:"url,omitempty"` + GitURL *string `json:"git_url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + DownloadURL *string `json:"download_url,omitempty"` } // RepositoryContentResponse holds the parsed response from CreateFile, UpdateFile, and DeleteFile. @@ -90,6 +93,32 @@ func (s *RepositoriesService) GetReadme(owner, repo string, opt *RepositoryConte return readme, resp, err } +// DownloadContents returns an io.ReadCloser that reads the contents of the +// specified file. This function will work with files of any size, as opposed +// to GetContents which is limited to 1 Mb files. It is the caller's +// responsibility to close the ReadCloser. +func (s *RepositoriesService) DownloadContents(owner, repo, filepath string, opt *RepositoryContentGetOptions) (io.ReadCloser, error) { + dir := path.Dir(filepath) + filename := path.Base(filepath) + _, dirContents, _, err := s.GetContents(owner, repo, dir, opt) + if err != nil { + return nil, err + } + for _, contents := range dirContents { + if *contents.Name == filename { + if contents.DownloadURL == nil || *contents.DownloadURL == "" { + return nil, fmt.Errorf("No download link found for %s", filepath) + } + resp, err := s.client.client.Get(*contents.DownloadURL) + if err != nil { + return nil, err + } + return resp.Body, nil + } + } + return nil, fmt.Errorf("No file named %s found in %s", filename, dir) +} + // GetContents can return either the metadata and content of a single file // (when path references a file) or the metadata of all the files and/or // subdirectories of a directory (when path references a directory). To make it diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/repos_contents_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/repos_contents_test.go index 7376aea570..8ab3ecdaef 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/repos_contents_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/repos_contents_test.go @@ -2,6 +2,7 @@ package github import ( "fmt" + "io/ioutil" "net/http" "reflect" "testing" @@ -54,7 +55,70 @@ func TestRepositoriesService_GetReadme(t *testing.T) { } } -func TestRepositoriesService_GetContent_File(t *testing.T) { +func TestRepositoriesService_DownloadContents_Success(t *testing.T) { + setup() + defer teardown() + mux.HandleFunc("/repos/o/r/contents/d", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{ + "type": "file", + "name": "f", + "download_url": "`+server.URL+`/download/f" + }]`) + }) + mux.HandleFunc("/download/f", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, "foo") + }) + + r, err := client.Repositories.DownloadContents("o", "r", "d/f", nil) + if err != nil { + t.Errorf("Repositories.DownloadContents returned error: %v", err) + } + + bytes, err := ioutil.ReadAll(r) + if err != nil { + t.Errorf("Error reading response body: %v", err) + } + r.Close() + + if got, want := string(bytes), "foo"; got != want { + t.Errorf("Repositories.DownloadContents returned %v, want %v", got, want) + } +} + +func TestRepositoriesService_DownloadContents_NoDownloadURL(t *testing.T) { + setup() + defer teardown() + mux.HandleFunc("/repos/o/r/contents/d", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{ + "type": "file", + "name": "f", + }]`) + }) + + _, err := client.Repositories.DownloadContents("o", "r", "d/f", nil) + if err == nil { + t.Errorf("Repositories.DownloadContents did not return expected error") + } +} + +func TestRepositoriesService_DownloadContents_NoFile(t *testing.T) { + setup() + defer teardown() + mux.HandleFunc("/repos/o/r/contents/d", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[]`) + }) + + _, err := client.Repositories.DownloadContents("o", "r", "d/f", nil) + if err == nil { + t.Errorf("Repositories.DownloadContents did not return expected error") + } +} + +func TestRepositoriesService_GetContents_File(t *testing.T) { setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { @@ -69,7 +133,7 @@ func TestRepositoriesService_GetContent_File(t *testing.T) { }) fileContents, _, _, err := client.Repositories.GetContents("o", "r", "p", &RepositoryContentGetOptions{}) if err != nil { - t.Errorf("Repositories.GetContents_File returned error: %v", err) + t.Errorf("Repositories.GetContents returned error: %v", err) } want := &RepositoryContent{Type: String("file"), Name: String("LICENSE"), Size: Int(20678), Encoding: String("base64"), Path: String("LICENSE")} if !reflect.DeepEqual(fileContents, want) { @@ -77,7 +141,7 @@ func TestRepositoriesService_GetContent_File(t *testing.T) { } } -func TestRepositoriesService_GetContent_Directory(t *testing.T) { +func TestRepositoriesService_GetContents_Directory(t *testing.T) { setup() defer teardown() mux.HandleFunc("/repos/o/r/contents/p", func(w http.ResponseWriter, r *http.Request) { @@ -88,7 +152,7 @@ func TestRepositoriesService_GetContent_Directory(t *testing.T) { "path": "lib" }, { - "type": "file", + "type": "file", "size": 20678, "name": "LICENSE", "path": "LICENSE" @@ -96,7 +160,7 @@ func TestRepositoriesService_GetContent_Directory(t *testing.T) { }) _, directoryContents, _, err := client.Repositories.GetContents("o", "r", "p", &RepositoryContentGetOptions{}) if err != nil { - t.Errorf("Repositories.GetContents_Directory returned error: %v", err) + t.Errorf("Repositories.GetContents returned error: %v", err) } want := []*RepositoryContent{{Type: String("dir"), Name: String("lib"), Path: String("lib")}, {Type: String("file"), Name: String("LICENSE"), Size: Int(20678), Path: String("LICENSE")}} diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/repos_deployments.go b/Godeps/_workspace/src/github.com/google/go-github/github/repos_deployments.go index 2fdf15a763..77c79491d8 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/repos_deployments.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/repos_deployments.go @@ -27,13 +27,13 @@ type Deployment struct { // DeploymentRequest represents a deployment request type DeploymentRequest struct { - Ref *string `json:"ref,omitempty"` - Task *string `json:"task,omitempty"` - AutoMerge *bool `json:"auto_merge,omitempty"` - RequiredContexts []string `json:"required_contexts,omitempty"` - Payload *string `json:"payload,omitempty"` - Environment *string `json:"environment,omitempty"` - Description *string `json:"description,omitempty"` + Ref *string `json:"ref,omitempty"` + Task *string `json:"task,omitempty"` + AutoMerge *bool `json:"auto_merge,omitempty"` + RequiredContexts *[]string `json:"required_contexts,omitempty"` + Payload *string `json:"payload,omitempty"` + Environment *string `json:"environment,omitempty"` + Description *string `json:"description,omitempty"` } // DeploymentsListOptions specifies the optional parameters to the @@ -69,9 +69,6 @@ func (s *RepositoriesService) ListDeployments(owner, repo string, opt *Deploymen return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeDeploymentPreview) - deployments := new([]Deployment) resp, err := s.client.Do(req, deployments) if err != nil { @@ -92,9 +89,6 @@ func (s *RepositoriesService) CreateDeployment(owner, repo string, request *Depl return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeDeploymentPreview) - d := new(Deployment) resp, err := s.client.Do(req, d) if err != nil { @@ -138,9 +132,6 @@ func (s *RepositoriesService) ListDeploymentStatuses(owner, repo string, deploym return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeDeploymentPreview) - statuses := new([]DeploymentStatus) resp, err := s.client.Do(req, statuses) if err != nil { @@ -161,9 +152,6 @@ func (s *RepositoriesService) CreateDeploymentStatus(owner, repo string, deploym return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches - req.Header.Set("Accept", mediaTypeDeploymentPreview) - d := new(DeploymentStatus) resp, err := s.client.Do(req, d) if err != nil { diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/repos_hooks.go b/Godeps/_workspace/src/github.com/google/go-github/github/repos_hooks.go index 846867285e..bc4c8c5ddb 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/repos_hooks.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/repos_hooks.go @@ -164,6 +164,18 @@ func (s *RepositoriesService) DeleteHook(owner, repo string, id int) (*Response, return s.client.Do(req, nil) } +// PingHook triggers a 'ping' event to be sent to the Hook. +// +// GitHub API docs: https://developer.github.com/v3/repos/hooks/#ping-a-hook +func (s *RepositoriesService) PingHook(owner, repo string, id int) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/hooks/%d/pings", owner, repo, id) + req, err := s.client.NewRequest("POST", u, nil) + if err != nil { + return nil, err + } + return s.client.Do(req, nil) +} + // TestHook triggers a test Hook by github. // // GitHub API docs: http://developer.github.com/v3/repos/hooks/#test-a-push-hook @@ -176,34 +188,7 @@ func (s *RepositoriesService) TestHook(owner, repo string, id int) (*Response, e return s.client.Do(req, nil) } -// ServiceHook represents a hook that has configuration settings, a list of -// available events, and default events. -type ServiceHook struct { - Name *string `json:"name,omitempty"` - Events []string `json:"events,omitempty"` - SupportedEvents []string `json:"supported_events,omitempty"` - Schema [][]string `json:"schema,omitempty"` -} - -func (s *ServiceHook) String() string { - return Stringify(s) -} - -// ListServiceHooks lists all of the available service hooks. -// -// GitHub API docs: https://developer.github.com/webhooks/#services +// ListServiceHooks is deprecated. Use Client.ListServiceHooks instead. func (s *RepositoriesService) ListServiceHooks() ([]ServiceHook, *Response, error) { - u := "hooks" - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - hooks := new([]ServiceHook) - resp, err := s.client.Do(req, hooks) - if err != nil { - return nil, resp, err - } - - return *hooks, resp, err + return s.client.ListServiceHooks() } diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/repos_hooks_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/repos_hooks_test.go index b322e17ea1..c163a26b29 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/repos_hooks_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/repos_hooks_test.go @@ -153,6 +153,20 @@ func TestRepositoriesService_DeleteHook_invalidOwner(t *testing.T) { testURLParseError(t, err) } +func TestRepositoriesService_PingHook(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/hooks/1/pings", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + }) + + _, err := client.Repositories.PingHook("o", "r", 1) + if err != nil { + t.Errorf("Repositories.PingHook returned error: %v", err) + } +} + func TestRepositoriesService_TestHook(t *testing.T) { setup() defer teardown() @@ -171,35 +185,3 @@ func TestRepositoriesService_TestHook_invalidOwner(t *testing.T) { _, err := client.Repositories.TestHook("%", "%", 1) testURLParseError(t, err) } - -func TestRepositoriesService_ListServiceHooks(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/hooks", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `[{ - "name":"n", - "events":["e"], - "supported_events":["s"], - "schema":[ - ["a", "b"] - ] - }]`) - }) - - hooks, _, err := client.Repositories.ListServiceHooks() - if err != nil { - t.Errorf("Repositories.ListHooks returned error: %v", err) - } - - want := []ServiceHook{{ - Name: String("n"), - Events: []string{"e"}, - SupportedEvents: []string{"s"}, - Schema: [][]string{{"a", "b"}}, - }} - if !reflect.DeepEqual(hooks, want) { - t.Errorf("Repositories.ListServiceHooks returned %+v, want %+v", hooks, want) - } -} diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/repos_releases.go b/Godeps/_workspace/src/github.com/google/go-github/github/repos_releases.go index 1400114418..d0e041b810 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/repos_releases.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/repos_releases.go @@ -85,8 +85,27 @@ func (s *RepositoriesService) ListReleases(owner, repo string, opt *ListOptions) // GitHub API docs: http://developer.github.com/v3/repos/releases/#get-a-single-release func (s *RepositoriesService) GetRelease(owner, repo string, id int) (*RepositoryRelease, *Response, error) { u := fmt.Sprintf("repos/%s/%s/releases/%d", owner, repo, id) + return s.getSingleRelease(u) +} - req, err := s.client.NewRequest("GET", u, nil) +// GetLatestRelease fetches the latest published release for the repository. +// +// GitHub API docs: https://developer.github.com/v3/repos/releases/#get-the-latest-release +func (s *RepositoriesService) GetLatestRelease(owner, repo string) (*RepositoryRelease, *Response, error) { + u := fmt.Sprintf("repos/%s/%s/releases/latest", owner, repo) + return s.getSingleRelease(u) +} + +// GetLatestReleaseByTag fetches a release with the specified tag. +// +// GitHub API docs: https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name +func (s *RepositoriesService) GetReleaseByTag(owner, repo, tag string) (*RepositoryRelease, *Response, error) { + u := fmt.Sprintf("repos/%s/%s/releases/tags/%s", owner, repo, tag) + return s.getSingleRelease(u) +} + +func (s *RepositoriesService) getSingleRelease(url string) (*RepositoryRelease, *Response, error) { + req, err := s.client.NewRequest("GET", url, nil) if err != nil { return nil, nil, err } diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/repos_releases_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/repos_releases_test.go index 17c670235f..21808b7e63 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/repos_releases_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/repos_releases_test.go @@ -55,6 +55,46 @@ func TestRepositoriesService_GetRelease(t *testing.T) { } } +func TestRepositoriesService_GetLatestRelease(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/releases/latest", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{"id":3}`) + }) + + release, resp, err := client.Repositories.GetLatestRelease("o", "r") + if err != nil { + t.Errorf("Repositories.GetLatestRelease returned error: %v\n%v", err, resp.Body) + } + + want := &RepositoryRelease{ID: Int(3)} + if !reflect.DeepEqual(release, want) { + t.Errorf("Repositories.GetLatestRelease returned %+v, want %+v", release, want) + } +} + +func TestRepositoriesService_GetReleaseByTag(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/releases/tags/foo", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{"id":13}`) + }) + + release, resp, err := client.Repositories.GetReleaseByTag("o", "r", "foo") + if err != nil { + t.Errorf("Repositories.GetReleaseByTag returned error: %v\n%v", err, resp.Body) + } + + want := &RepositoryRelease{ID: Int(13)} + if !reflect.DeepEqual(release, want) { + t.Errorf("Repositories.GetReleaseByTag returned %+v, want %+v", release, want) + } +} + func TestRepositoriesService_CreateRelease(t *testing.T) { setup() defer teardown() diff --git a/Godeps/_workspace/src/github.com/google/go-github/github/repos_test.go b/Godeps/_workspace/src/github.com/google/go-github/github/repos_test.go index def211975f..2480b88b14 100644 --- a/Godeps/_workspace/src/github.com/google/go-github/github/repos_test.go +++ b/Godeps/_workspace/src/github.com/google/go-github/github/repos_test.go @@ -45,11 +45,11 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) { "direction": "asc", "page": "2", }) - + testHeader(t, r, "Accept", mediaTypeOrganizationsPreview) fmt.Fprint(w, `[{"id":1}]`) }) - opt := &RepositoryListOptions{"owner", "created", "asc", ListOptions{Page: 2}} + opt := &RepositoryListOptions{"owner", "created", "asc", true, ListOptions{Page: 2}} repos, _, err := client.Repositories.List("u", opt) if err != nil { t.Errorf("Repositories.List returned error: %v", err) @@ -191,7 +191,8 @@ func TestRepositoriesService_Get(t *testing.T) { mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"}}`) + testHeader(t, r, "Accept", mediaTypeLicensesPreview) + fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`) }) repo, _, err := client.Repositories.Get("o", "r") @@ -199,7 +200,7 @@ func TestRepositoriesService_Get(t *testing.T) { t.Errorf("Repositories.Get returned error: %v", err) } - want := &Repository{ID: Int(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}} + want := &Repository{ID: Int(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}} if !reflect.DeepEqual(repo, want) { t.Errorf("Repositories.Get returned %+v, want %+v", repo, want) } diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/acl_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/acl_test.go index 1e9641795a..2a5207a6ee 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/acl_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/acl_test.go @@ -1,25 +1,14 @@ package api import ( - "os" "testing" ) -// ROOT is a management token for the tests -var CONSUL_ROOT string - -func init() { - CONSUL_ROOT = os.Getenv("CONSUL_ROOT") -} - func TestACL_CreateDestroy(t *testing.T) { - if CONSUL_ROOT == "" { - t.SkipNow() - } - c, s := makeClient(t) + t.Parallel() + c, s := makeACLClient(t) defer s.Stop() - c.config.Token = CONSUL_ROOT acl := c.ACL() ae := ACLEntry{ @@ -61,16 +50,13 @@ func TestACL_CreateDestroy(t *testing.T) { } func TestACL_CloneDestroy(t *testing.T) { - if CONSUL_ROOT == "" { - t.SkipNow() - } - c, s := makeClient(t) + t.Parallel() + c, s := makeACLClient(t) defer s.Stop() - c.config.Token = CONSUL_ROOT acl := c.ACL() - id, wm, err := acl.Clone(CONSUL_ROOT, nil) + id, wm, err := acl.Clone(c.config.Token, nil) if err != nil { t.Fatalf("err: %v", err) } @@ -94,16 +80,13 @@ func TestACL_CloneDestroy(t *testing.T) { } func TestACL_Info(t *testing.T) { - if CONSUL_ROOT == "" { - t.SkipNow() - } - c, s := makeClient(t) + t.Parallel() + c, s := makeACLClient(t) defer s.Stop() - c.config.Token = CONSUL_ROOT acl := c.ACL() - ae, qm, err := acl.Info(CONSUL_ROOT, nil) + ae, qm, err := acl.Info(c.config.Token, nil) if err != nil { t.Fatalf("err: %v", err) } @@ -115,19 +98,16 @@ func TestACL_Info(t *testing.T) { t.Fatalf("bad: %v", qm) } - if ae == nil || ae.ID != CONSUL_ROOT || ae.Type != ACLManagementType { + if ae == nil || ae.ID != c.config.Token || ae.Type != ACLManagementType { t.Fatalf("bad: %#v", ae) } } func TestACL_List(t *testing.T) { - if CONSUL_ROOT == "" { - t.SkipNow() - } - c, s := makeClient(t) + t.Parallel() + c, s := makeACLClient(t) defer s.Stop() - c.config.Token = CONSUL_ROOT acl := c.ACL() acls, qm, err := acl.List(nil) diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/agent.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/agent.go index 4b144fe181..e56a18dcd2 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/agent.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/agent.go @@ -68,6 +68,7 @@ type AgentServiceCheck struct { Timeout string `json:",omitempty"` TTL string `json:",omitempty"` HTTP string `json:",omitempty"` + Status string `json:",omitempty"` } type AgentServiceChecks []*AgentServiceCheck diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/agent_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/agent_test.go index 5498420921..358c12a6c2 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/agent_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/agent_test.go @@ -6,6 +6,7 @@ import ( ) func TestAgent_Self(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -23,6 +24,7 @@ func TestAgent_Self(t *testing.T) { } func TestAgent_Members(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -39,6 +41,7 @@ func TestAgent_Members(t *testing.T) { } func TestAgent_Services(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -63,21 +66,91 @@ func TestAgent_Services(t *testing.T) { if _, ok := services["foo"]; !ok { t.Fatalf("missing service: %v", services) } - checks, err := agent.Checks() if err != nil { t.Fatalf("err: %v", err) } - if _, ok := checks["service:foo"]; !ok { + chk, ok := checks["service:foo"] + if !ok { t.Fatalf("missing check: %v", checks) } + // Checks should default to critical + if chk.Status != "critical" { + t.Fatalf("Bad: %#v", chk) + } + if err := agent.ServiceDeregister("foo"); err != nil { t.Fatalf("err: %v", err) } } +func TestAgent_Services_CheckPassing(t *testing.T) { + t.Parallel() + c, s := makeClient(t) + defer s.Stop() + + agent := c.Agent() + reg := &AgentServiceRegistration{ + Name: "foo", + Tags: []string{"bar", "baz"}, + Port: 8000, + Check: &AgentServiceCheck{ + TTL: "15s", + Status: "passing", + }, + } + if err := agent.ServiceRegister(reg); err != nil { + t.Fatalf("err: %v", err) + } + + services, err := agent.Services() + if err != nil { + t.Fatalf("err: %v", err) + } + if _, ok := services["foo"]; !ok { + t.Fatalf("missing service: %v", services) + } + + checks, err := agent.Checks() + if err != nil { + t.Fatalf("err: %v", err) + } + chk, ok := checks["service:foo"] + if !ok { + t.Fatalf("missing check: %v", checks) + } + + if chk.Status != "passing" { + t.Fatalf("Bad: %#v", chk) + } + if err := agent.ServiceDeregister("foo"); err != nil { + t.Fatalf("err: %v", err) + } +} + +func TestAgent_Services_CheckBadStatus(t *testing.T) { + t.Parallel() + c, s := makeClient(t) + defer s.Stop() + + agent := c.Agent() + reg := &AgentServiceRegistration{ + Name: "foo", + Tags: []string{"bar", "baz"}, + Port: 8000, + Check: &AgentServiceCheck{ + TTL: "15s", + Status: "fluffy", + }, + } + if err := agent.ServiceRegister(reg); err == nil { + t.Fatalf("bad status accepted") + } +} + func TestAgent_ServiceAddress(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -124,6 +197,7 @@ func TestAgent_ServiceAddress(t *testing.T) { } func TestAgent_Services_MultipleChecks(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -167,6 +241,7 @@ func TestAgent_Services_MultipleChecks(t *testing.T) { } func TestAgent_SetTTLStatus(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -207,6 +282,7 @@ func TestAgent_SetTTLStatus(t *testing.T) { } func TestAgent_Checks(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -224,9 +300,48 @@ func TestAgent_Checks(t *testing.T) { if err != nil { t.Fatalf("err: %v", err) } - if _, ok := checks["foo"]; !ok { + chk, ok := checks["foo"] + if !ok { t.Fatalf("missing check: %v", checks) } + if chk.Status != "critical" { + t.Fatalf("check not critical: %v", chk) + } + + if err := agent.CheckDeregister("foo"); err != nil { + t.Fatalf("err: %v", err) + } +} + +func TestAgent_CheckStartPassing(t *testing.T) { + t.Parallel() + c, s := makeClient(t) + defer s.Stop() + + agent := c.Agent() + + reg := &AgentCheckRegistration{ + Name: "foo", + AgentServiceCheck: AgentServiceCheck{ + Status: "passing", + }, + } + reg.TTL = "15s" + if err := agent.CheckRegister(reg); err != nil { + t.Fatalf("err: %v", err) + } + + checks, err := agent.Checks() + if err != nil { + t.Fatalf("err: %v", err) + } + chk, ok := checks["foo"] + if !ok { + t.Fatalf("missing check: %v", checks) + } + if chk.Status != "passing" { + t.Fatalf("check not passing: %v", chk) + } if err := agent.CheckDeregister("foo"); err != nil { t.Fatalf("err: %v", err) @@ -234,6 +349,7 @@ func TestAgent_Checks(t *testing.T) { } func TestAgent_Checks_serviceBound(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -272,6 +388,7 @@ func TestAgent_Checks_serviceBound(t *testing.T) { } func TestAgent_Join(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -291,6 +408,7 @@ func TestAgent_Join(t *testing.T) { } func TestAgent_ForceLeave(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -304,6 +422,7 @@ func TestAgent_ForceLeave(t *testing.T) { } func TestServiceMaintenance(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -358,6 +477,7 @@ func TestServiceMaintenance(t *testing.T) { } func TestNodeMaintenance(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/api_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/api_test.go index 9c86e17aea..56f9494f89 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/api_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/api_test.go @@ -20,6 +20,16 @@ func makeClient(t *testing.T) (*Client, *testutil.TestServer) { return makeClientWithConfig(t, nil, nil) } +func makeACLClient(t *testing.T) (*Client, *testutil.TestServer) { + return makeClientWithConfig(t, func(clientConfig *Config) { + clientConfig.Token = "root" + }, func(serverConfig *testutil.TestServerConfig) { + serverConfig.ACLMasterToken = "root" + serverConfig.ACLDatacenter = "dc1" + serverConfig.ACLDefaultPolicy = "deny" + }) +} + func makeClientWithConfig( t *testing.T, cb1 configCallback, @@ -59,6 +69,7 @@ func testKey() string { } func TestDefaultConfig_env(t *testing.T) { + t.Parallel() addr := "1.2.3.4:5678" token := "abcd1234" auth := "username:password" @@ -104,6 +115,7 @@ func TestDefaultConfig_env(t *testing.T) { } func TestSetQueryOptions(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -139,6 +151,7 @@ func TestSetQueryOptions(t *testing.T) { } func TestSetWriteOptions(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -158,6 +171,7 @@ func TestSetWriteOptions(t *testing.T) { } func TestRequestToHTTP(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -180,6 +194,7 @@ func TestRequestToHTTP(t *testing.T) { } func TestParseQueryMeta(t *testing.T) { + t.Parallel() resp := &http.Response{ Header: make(map[string][]string), } @@ -204,6 +219,7 @@ func TestParseQueryMeta(t *testing.T) { } func TestAPI_UnixSocket(t *testing.T) { + t.Parallel() if runtime.GOOS == "windows" { t.SkipNow() } diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/catalog_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/catalog_test.go index a0b950e5fb..bb8be25b00 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/catalog_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/catalog_test.go @@ -8,6 +8,7 @@ import ( ) func TestCatalog_Datacenters(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -30,6 +31,7 @@ func TestCatalog_Datacenters(t *testing.T) { } func TestCatalog_Nodes(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -56,6 +58,7 @@ func TestCatalog_Nodes(t *testing.T) { } func TestCatalog_Services(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -82,6 +85,7 @@ func TestCatalog_Services(t *testing.T) { } func TestCatalog_Service(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -108,6 +112,7 @@ func TestCatalog_Service(t *testing.T) { } func TestCatalog_Node(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -134,6 +139,7 @@ func TestCatalog_Node(t *testing.T) { } func TestCatalog_Registration(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/event_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/event_test.go index 9ebcb5397d..1ca92e2331 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/event_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/event_test.go @@ -2,9 +2,12 @@ package api import ( "testing" + + "github.com/hashicorp/consul/testutil" ) func TestEvent_FireList(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -24,16 +27,23 @@ func TestEvent_FireList(t *testing.T) { t.Fatalf("invalid: %v", id) } - events, qm, err := event.List("", nil) - if err != nil { - t.Fatalf("err: %v", err) + var events []*UserEvent + var qm *QueryMeta + testutil.WaitForResult(func() (bool, error) { + events, qm, err = event.List("", nil) + if err != nil { + t.Fatalf("err: %v", err) + } + return len(events) > 0, err + }, func(err error) { + t.Fatalf("err: %#v", err) + }) + + if events[len(events)-1].ID != id { + t.Fatalf("bad: %#v", events) } if qm.LastIndex != event.IDToIndex(id) { t.Fatalf("Bad: %#v", qm) } - - if events[len(events)-1].ID != id { - t.Fatalf("bad: %#v", events) - } } diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/health_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/health_test.go index df6eb0f666..d80a4693ae 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/health_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/health_test.go @@ -8,6 +8,7 @@ import ( ) func TestHealth_Node(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -38,6 +39,7 @@ func TestHealth_Node(t *testing.T) { } func TestHealth_Checks(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -74,6 +76,7 @@ func TestHealth_Checks(t *testing.T) { } func TestHealth_Service(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -98,6 +101,7 @@ func TestHealth_Service(t *testing.T) { } func TestHealth_State(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/kv.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/kv.go index ba74057fcc..c1a8923bef 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/kv.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/kv.go @@ -168,6 +168,10 @@ func (k *KV) Release(p *KVPair, q *WriteOptions) (bool, *WriteMeta, error) { } func (k *KV) put(key string, params map[string]string, body []byte, q *WriteOptions) (bool, *WriteMeta, error) { + if len(key) > 0 && key[0] == '/' { + return false, nil, fmt.Errorf("Invalid key. Key must not begin with a '/': %s", key) + } + r := k.c.newRequest("PUT", "/v1/kv/"+key) r.setWriteOptions(q) for param, val := range params { diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/kv_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/kv_test.go index a5a0b54e22..758595d895 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/kv_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/kv_test.go @@ -8,6 +8,7 @@ import ( ) func TestClientPutGetDelete(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -23,9 +24,17 @@ func TestClientPutGetDelete(t *testing.T) { t.Fatalf("unexpected value: %#v", pair) } - // Put the key value := []byte("test") - p := &KVPair{Key: key, Flags: 42, Value: value} + + // Put a key that begins with a '/', this should fail + invalidKey := "/test" + p := &KVPair{Key: invalidKey, Flags: 42, Value: value} + if _, err := kv.Put(p, nil); err == nil { + t.Fatalf("Invalid key not detected: %s", invalidKey) + } + + // Put the key + p = &KVPair{Key: key, Flags: 42, Value: value} if _, err := kv.Put(p, nil); err != nil { t.Fatalf("err: %v", err) } @@ -64,6 +73,7 @@ func TestClientPutGetDelete(t *testing.T) { } func TestClient_List_DeleteRecurse(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -118,6 +128,7 @@ func TestClient_List_DeleteRecurse(t *testing.T) { } func TestClient_DeleteCAS(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -163,6 +174,7 @@ func TestClient_DeleteCAS(t *testing.T) { } func TestClient_CAS(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -210,6 +222,7 @@ func TestClient_CAS(t *testing.T) { } func TestClient_WatchGet(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -261,6 +274,7 @@ func TestClient_WatchGet(t *testing.T) { } func TestClient_WatchList(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -314,6 +328,7 @@ func TestClient_WatchList(t *testing.T) { } func TestClient_Keys_DeleteRecurse(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -363,6 +378,7 @@ func TestClient_Keys_DeleteRecurse(t *testing.T) { } func TestClient_AcquireRelease(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock.go index 4b694789c4..a76685f04c 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock.go @@ -183,11 +183,23 @@ WAIT: // Handle the case of not getting the lock if !locked { - select { - case <-time.After(DefaultLockRetryTime): + // Determine why the lock failed + qOpts.WaitIndex = 0 + pair, meta, err = kv.Get(l.opts.Key, qOpts) + if pair != nil && pair.Session != "" { + //If the session is not null, this means that a wait can safely happen + //using a long poll + qOpts.WaitIndex = meta.LastIndex goto WAIT - case <-stopCh: - return nil, nil + } else { + // If the session is empty and the lock failed to acquire, then it means + // a lock-delay is in effect and a timed wait must be used + select { + case <-time.After(DefaultLockRetryTime): + goto WAIT + case <-stopCh: + return nil, nil + } } } diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock_test.go index 163372fe4a..0a8fa5172a 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/lock_test.go @@ -8,6 +8,7 @@ import ( ) func TestLock_LockUnlock(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -65,6 +66,7 @@ func TestLock_LockUnlock(t *testing.T) { } func TestLock_ForceInvalidate(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -99,6 +101,7 @@ func TestLock_ForceInvalidate(t *testing.T) { } func TestLock_DeleteKey(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -132,6 +135,7 @@ func TestLock_DeleteKey(t *testing.T) { } func TestLock_Contend(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -184,6 +188,7 @@ func TestLock_Contend(t *testing.T) { } func TestLock_Destroy(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -252,6 +257,7 @@ func TestLock_Destroy(t *testing.T) { } func TestLock_Conflict(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -289,6 +295,7 @@ func TestLock_Conflict(t *testing.T) { } func TestLock_ReclaimLock(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/semaphore.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/semaphore.go index 957f884a4d..ff4c2058ce 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/semaphore.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/semaphore.go @@ -22,11 +22,6 @@ const ( // a Semaphore acquisition. DefaultSemaphoreWaitTime = 15 * time.Second - // DefaultSemaphoreRetryTime is how long we wait after a failed lock acquisition - // before attempting to do the lock again. This is so that once a lock-delay - // is in affect, we do not hot loop retrying the acquisition. - DefaultSemaphoreRetryTime = 5 * time.Second - // DefaultSemaphoreKey is the key used within the prefix to // use for coordination between all the contenders. DefaultSemaphoreKey = ".lock" diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/semaphore_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/semaphore_test.go index cb5057df95..5e5e53588c 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/semaphore_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/semaphore_test.go @@ -8,6 +8,7 @@ import ( ) func TestSemaphore_AcquireRelease(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -65,6 +66,7 @@ func TestSemaphore_AcquireRelease(t *testing.T) { } func TestSemaphore_ForceInvalidate(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -99,6 +101,7 @@ func TestSemaphore_ForceInvalidate(t *testing.T) { } func TestSemaphore_DeleteKey(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -132,6 +135,7 @@ func TestSemaphore_DeleteKey(t *testing.T) { } func TestSemaphore_Contend(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -184,6 +188,7 @@ func TestSemaphore_Contend(t *testing.T) { } func TestSemaphore_BadLimit(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -214,6 +219,7 @@ func TestSemaphore_BadLimit(t *testing.T) { } func TestSemaphore_Destroy(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -269,6 +275,7 @@ func TestSemaphore_Destroy(t *testing.T) { } func TestSemaphore_Conflict(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/session.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/session.go index 63baa90e93..a99da511d6 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/session.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/session.go @@ -1,6 +1,7 @@ package api import ( + "fmt" "time" ) @@ -131,19 +132,32 @@ func (s *Session) RenewPeriodic(initialTTL string, id string, q *WriteOptions, d if err != nil { return err } + + waitDur := ttl / 2 + lastRenewTime := time.Now() + var lastErr error for { + if time.Since(lastRenewTime) > ttl { + return lastErr + } select { - case <-time.After(ttl / 2): + case <-time.After(waitDur): entry, _, err := s.Renew(id, q) if err != nil { - return err + waitDur = time.Second + lastErr = err + continue } if entry == nil { - return nil + waitDur = time.Second + lastErr = fmt.Errorf("No SessionEntry returned") + continue } // Handle the server updating the TTL ttl, _ = time.ParseDuration(entry.TTL) + waitDur = ttl / 2 + lastRenewTime = time.Now() case <-doneCh: // Attempt a session destroy diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/session_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/session_test.go index 194c45fb7f..c503c21a07 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/session_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/session_test.go @@ -5,6 +5,7 @@ import ( ) func TestSession_CreateDestroy(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -34,6 +35,7 @@ func TestSession_CreateDestroy(t *testing.T) { } func TestSession_CreateRenewDestroy(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -84,6 +86,7 @@ func TestSession_CreateRenewDestroy(t *testing.T) { } func TestSession_Info(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -137,6 +140,7 @@ func TestSession_Info(t *testing.T) { } func TestSession_Node(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -171,6 +175,7 @@ func TestSession_Node(t *testing.T) { } func TestSession_List(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() diff --git a/Godeps/_workspace/src/github.com/hashicorp/consul/api/status_test.go b/Godeps/_workspace/src/github.com/hashicorp/consul/api/status_test.go index cb0cca6728..62dc1550ff 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/consul/api/status_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/consul/api/status_test.go @@ -5,6 +5,7 @@ import ( ) func TestStatusLeader(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() @@ -20,6 +21,7 @@ func TestStatusLeader(t *testing.T) { } func TestStatusPeers(t *testing.T) { + t.Parallel() c, s := makeClient(t) defer s.Stop() diff --git a/Godeps/_workspace/src/github.com/hashicorp/go-multierror/flatten.go b/Godeps/_workspace/src/github.com/hashicorp/go-multierror/flatten.go new file mode 100644 index 0000000000..aab8e9abec --- /dev/null +++ b/Godeps/_workspace/src/github.com/hashicorp/go-multierror/flatten.go @@ -0,0 +1,26 @@ +package multierror + +// Flatten flattens the given error, merging any *Errors together into +// a single *Error. +func Flatten(err error) error { + // If it isn't an *Error, just return the error as-is + if _, ok := err.(*Error); !ok { + return err + } + + // Otherwise, make the result and flatten away! + flatErr := new(Error) + flatten(err, flatErr) + return flatErr +} + +func flatten(err error, flatErr *Error) { + switch err := err.(type) { + case *Error: + for _, e := range err.Errors { + flatten(e, flatErr) + } + default: + flatErr.Errors = append(flatErr.Errors, err) + } +} diff --git a/Godeps/_workspace/src/github.com/hashicorp/go-multierror/flatten_test.go b/Godeps/_workspace/src/github.com/hashicorp/go-multierror/flatten_test.go new file mode 100644 index 0000000000..75218f1031 --- /dev/null +++ b/Godeps/_workspace/src/github.com/hashicorp/go-multierror/flatten_test.go @@ -0,0 +1,48 @@ +package multierror + +import ( + "errors" + "fmt" + "reflect" + "strings" + "testing" +) + +func TestFlatten(t *testing.T) { + original := &Error{ + Errors: []error{ + errors.New("one"), + &Error{ + Errors: []error{ + errors.New("two"), + &Error{ + Errors: []error{ + errors.New("three"), + }, + }, + }, + }, + }, + } + + expected := strings.TrimSpace(` +3 error(s) occurred: + +* one +* two +* three + `) + actual := fmt.Sprintf("%s", Flatten(original)) + + if expected != actual { + t.Fatalf("expected: %s, got: %s", expected, actual) + } +} + +func TestFlatten_nonError(t *testing.T) { + err := errors.New("foo") + actual := Flatten(err) + if !reflect.DeepEqual(actual, err) { + t.Fatalf("bad: %#v", actual) + } +} diff --git a/Godeps/_workspace/src/github.com/hashicorp/golang-lru/lru.go b/Godeps/_workspace/src/github.com/hashicorp/golang-lru/lru.go index b97933da52..5f1e8a1af3 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/golang-lru/lru.go +++ b/Godeps/_workspace/src/github.com/hashicorp/golang-lru/lru.go @@ -49,7 +49,7 @@ func (c *Cache) Purge() { if c.onEvicted != nil { for k, v := range c.items { - c.onEvicted(k, v.Value) + c.onEvicted(k, v.Value.(*entry).value) } } @@ -94,6 +94,27 @@ func (c *Cache) Get(key interface{}) (value interface{}, ok bool) { return } +// Check if a key is in the cache, without updating the recent-ness or deleting it for being stale. +func (c *Cache) Contains(key interface{}) (ok bool) { + c.lock.RLock() + defer c.lock.RUnlock() + + _, ok = c.items[key] + return ok +} + +// Returns the key value (or undefined if not found) without updating the "recently used"-ness of the key. +// (If you find yourself using this a lot, you might be using the wrong sort of data structure, but there are some use cases where it's handy.) +func (c *Cache) Peek(key interface{}) (value interface{}, ok bool) { + c.lock.RLock() + defer c.lock.RUnlock() + + if ent, ok := c.items[key]; ok { + return ent.Value.(*entry).value, true + } + return nil, ok +} + // Remove removes the provided key from the cache. func (c *Cache) Remove(key interface{}) { c.lock.Lock() diff --git a/Godeps/_workspace/src/github.com/hashicorp/golang-lru/lru_test.go b/Godeps/_workspace/src/github.com/hashicorp/golang-lru/lru_test.go index cd0cd55d6c..b676cfd9db 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/golang-lru/lru_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/golang-lru/lru_test.go @@ -5,6 +5,9 @@ import "testing" func TestLRU(t *testing.T) { evictCounter := 0 onEvicted := func(k interface{}, v interface{}) { + if k != v { + t.Fatalf("Evict values not equal (%v!=%v)", k, v) + } evictCounter += 1 } l, err := NewWithEvict(128, onEvicted) @@ -65,7 +68,7 @@ func TestLRU(t *testing.T) { } } -// test that Add return true/false if an eviction occured +// test that Add returns true/false if an eviction occured func TestLRUAdd(t *testing.T) { evictCounter := 0 onEvicted := func(k interface{}, v interface{}) { @@ -84,3 +87,41 @@ func TestLRUAdd(t *testing.T) { t.Errorf("should have an eviction") } } + +// test that Contains doesn't update recent-ness +func TestLRUContains(t *testing.T) { + l, err := New(2) + if err != nil { + t.Fatalf("err: %v", err) + } + + l.Add(1, 1) + l.Add(2, 2) + if !l.Contains(1) { + t.Errorf("1 should be contained") + } + + l.Add(3, 3) + if l.Contains(1) { + t.Errorf("Contains should not have updated recent-ness of 1") + } +} + +// test that Peek doesn't update recent-ness +func TestLRUPeek(t *testing.T) { + l, err := New(2) + if err != nil { + t.Fatalf("err: %v", err) + } + + l.Add(1, 1) + l.Add(2, 2) + if v, ok := l.Peek(1); !ok || v != 1 { + t.Errorf("1 should be set to 1: %v, %v", v, ok) + } + + l.Add(3, 3) + if l.Contains(1) { + t.Errorf("should not have updated recent-ness of 1") + } +} diff --git a/Godeps/_workspace/src/github.com/hashicorp/hcl/README.md b/Godeps/_workspace/src/github.com/hashicorp/hcl/README.md index 55c43bd3ee..c69d17e9b3 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/hcl/README.md +++ b/Godeps/_workspace/src/github.com/hashicorp/hcl/README.md @@ -53,7 +53,9 @@ of the syntax and grammar are listed here. * Single line comments start with `#` or `//` - * Multi-line comments are wrapped in `/*` and `*/` + * Multi-line comments are wrapped in `/*` and `*/`. Nested block comments + are not allowed. A multi-line comment (also known as a block comment) + terminates at the first `*/` found. * Values are assigned with the syntax `key = value` (whitespace doesn't matter). The value can be any primitive: a string, number, boolean, diff --git a/Godeps/_workspace/src/github.com/hashicorp/hcl/decoder_test.go b/Godeps/_workspace/src/github.com/hashicorp/hcl/decoder_test.go index f4936ac7c5..a71163b19f 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/hcl/decoder_test.go +++ b/Godeps/_workspace/src/github.com/hashicorp/hcl/decoder_test.go @@ -188,6 +188,20 @@ func TestDecode_interface(t *testing.T) { }, }, }, + + { + "nested_block_comment.hcl", + false, + map[string]interface{}{ + "bar": "value", + }, + }, + + { + "unterminated_block_comment.hcl", + true, + nil, + }, } for _, tc := range cases { diff --git a/Godeps/_workspace/src/github.com/hashicorp/hcl/hcl/lex.go b/Godeps/_workspace/src/github.com/hashicorp/hcl/hcl/lex.go index 825b7da61e..c14165956c 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/hcl/hcl/lex.go +++ b/Godeps/_workspace/src/github.com/hashicorp/hcl/hcl/lex.go @@ -125,7 +125,14 @@ func (x *hclLex) consumeComment(c rune) bool { c = x.next() if c == lexEOF { x.backup() - return true + if single { + // Single line comments can end with an EOF + return true + } + + // Multi-line comments must end with a */ + x.createErr(fmt.Sprintf("end of multi-line comment expected, got EOF")) + return false } // Single line comments continue until a '\n' @@ -149,18 +156,13 @@ func (x *hclLex) consumeComment(c rune) bool { case '*': c = x.next() if c == '/' { - nested-- + return true } else { x.backup() } default: // Continue } - - // If we're done with the comment, return! - if nested == 0 { - return true - } } } diff --git a/Godeps/_workspace/src/github.com/hashicorp/hcl/hcl/valuetype_string.go b/Godeps/_workspace/src/github.com/hashicorp/hcl/hcl/valuetype_string.go index efe119a03a..83b39048ab 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/hcl/hcl/valuetype_string.go +++ b/Godeps/_workspace/src/github.com/hashicorp/hcl/hcl/valuetype_string.go @@ -9,7 +9,7 @@ const _ValueType_name = "ValueTypeUnknownValueTypeFloatValueTypeIntValueTypeStri var _ValueType_index = [...]uint8{0, 16, 30, 42, 57, 70, 82, 95, 110} func (i ValueType) String() string { - if i+1 >= ValueType(len(_ValueType_index)) { + if i >= ValueType(len(_ValueType_index)-1) { return fmt.Sprintf("ValueType(%d)", i) } return _ValueType_name[_ValueType_index[i]:_ValueType_index[i+1]] diff --git a/Godeps/_workspace/src/github.com/hashicorp/logutils/README.md b/Godeps/_workspace/src/github.com/hashicorp/logutils/README.md index 57cad4d1c2..49490eaeb6 100644 --- a/Godeps/_workspace/src/github.com/hashicorp/logutils/README.md +++ b/Godeps/_workspace/src/github.com/hashicorp/logutils/README.md @@ -21,7 +21,7 @@ import ( func main() { filter := &logutils.LevelFilter{ Levels: []logutils.LogLevel{"DEBUG", "WARN", "ERROR"}, - MinLevel: "WARN", + MinLevel: logutils.LogLevel("WARN"), Writer: os.Stderr, } log.SetOutput(filter) diff --git a/Godeps/_workspace/src/github.com/kardianos/osext/README.md b/Godeps/_workspace/src/github.com/kardianos/osext/README.md index 820e1ecb54..61350baba5 100644 --- a/Godeps/_workspace/src/github.com/kardianos/osext/README.md +++ b/Godeps/_workspace/src/github.com/kardianos/osext/README.md @@ -4,7 +4,9 @@ There is sometimes utility in finding the current executable file that is running. This can be used for upgrading the current executable -or finding resources located relative to the executable file. +or finding resources located relative to the executable file. Both +working directory and the os.Args[0] value are arbitrary and cannot +be relied on; os.Args[0] can be "faked". Multi-platform and supports: * Linux diff --git a/Godeps/_workspace/src/github.com/kardianos/osext/osext.go b/Godeps/_workspace/src/github.com/kardianos/osext/osext.go index 4ed4b9aa33..0eca579ec7 100644 --- a/Godeps/_workspace/src/github.com/kardianos/osext/osext.go +++ b/Godeps/_workspace/src/github.com/kardianos/osext/osext.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Extensions to the standard "os" package. -package osext +package osext // import "github.com/kardianos/osext" import "path/filepath" @@ -16,12 +16,12 @@ func Executable() (string, error) { } // Returns same path as Executable, returns just the folder -// path. Excludes the executable name. +// path. Excludes the executable name and any trailing slash. func ExecutableFolder() (string, error) { p, err := Executable() if err != nil { return "", err } - folder, _ := filepath.Split(p) - return folder, nil + + return filepath.Dir(p), nil } diff --git a/Godeps/_workspace/src/github.com/kardianos/osext/osext_test.go b/Godeps/_workspace/src/github.com/kardianos/osext/osext_test.go index 5aafa3af2d..77ccc28e9e 100644 --- a/Godeps/_workspace/src/github.com/kardianos/osext/osext_test.go +++ b/Godeps/_workspace/src/github.com/kardianos/osext/osext_test.go @@ -24,6 +24,29 @@ const ( executableEnvValueDelete = "delete" ) +func TestPrintExecutable(t *testing.T) { + ef, err := Executable() + if err != nil { + t.Fatalf("Executable failed: %v", err) + } + t.Log("Executable:", ef) +} +func TestPrintExecutableFolder(t *testing.T) { + ef, err := ExecutableFolder() + if err != nil { + t.Fatalf("ExecutableFolder failed: %v", err) + } + t.Log("Executable Folder:", ef) +} +func TestExecutableFolder(t *testing.T) { + ef, err := ExecutableFolder() + if err != nil { + t.Fatalf("ExecutableFolder failed: %v", err) + } + if ef[len(ef)-1] == filepath.Separator { + t.Fatal("ExecutableFolder ends with a trailing slash.") + } +} func TestExecutableMatch(t *testing.T) { ep, err := Executable() if err != nil { diff --git a/Godeps/_workspace/src/github.com/lib/pq/bench_test.go b/Godeps/_workspace/src/github.com/lib/pq/bench_test.go index 611edf87f7..e71f41d069 100644 --- a/Godeps/_workspace/src/github.com/lib/pq/bench_test.go +++ b/Godeps/_workspace/src/github.com/lib/pq/bench_test.go @@ -325,7 +325,7 @@ var testIntBytes = []byte("1234") func BenchmarkDecodeInt64(b *testing.B) { for i := 0; i < b.N; i++ { - decode(¶meterStatus{}, testIntBytes, oid.T_int8) + decode(¶meterStatus{}, testIntBytes, oid.T_int8, formatText) } } @@ -333,7 +333,7 @@ var testFloatBytes = []byte("3.14159") func BenchmarkDecodeFloat64(b *testing.B) { for i := 0; i < b.N; i++ { - decode(¶meterStatus{}, testFloatBytes, oid.T_float8) + decode(¶meterStatus{}, testFloatBytes, oid.T_float8, formatText) } } @@ -341,7 +341,7 @@ var testBoolBytes = []byte{'t'} func BenchmarkDecodeBool(b *testing.B) { for i := 0; i < b.N; i++ { - decode(¶meterStatus{}, testBoolBytes, oid.T_bool) + decode(¶meterStatus{}, testBoolBytes, oid.T_bool, formatText) } } @@ -358,7 +358,7 @@ var testTimestamptzBytes = []byte("2013-09-17 22:15:32.360754-07") func BenchmarkDecodeTimestamptz(b *testing.B) { for i := 0; i < b.N; i++ { - decode(¶meterStatus{}, testTimestamptzBytes, oid.T_timestamptz) + decode(¶meterStatus{}, testTimestamptzBytes, oid.T_timestamptz, formatText) } } @@ -371,7 +371,7 @@ func BenchmarkDecodeTimestamptzMultiThread(b *testing.B) { f := func(wg *sync.WaitGroup, loops int) { defer wg.Done() for i := 0; i < loops; i++ { - decode(¶meterStatus{}, testTimestamptzBytes, oid.T_timestamptz) + decode(¶meterStatus{}, testTimestamptzBytes, oid.T_timestamptz, formatText) } } diff --git a/Godeps/_workspace/src/github.com/lib/pq/buf.go b/Godeps/_workspace/src/github.com/lib/pq/buf.go index fd966c394d..e7ff577719 100644 --- a/Godeps/_workspace/src/github.com/lib/pq/buf.go +++ b/Godeps/_workspace/src/github.com/lib/pq/buf.go @@ -47,28 +47,44 @@ func (b *readBuf) byte() byte { return b.next(1)[0] } -type writeBuf []byte +type writeBuf struct { + buf []byte + pos int +} func (b *writeBuf) int32(n int) { x := make([]byte, 4) binary.BigEndian.PutUint32(x, uint32(n)) - *b = append(*b, x...) + b.buf = append(b.buf, x...) } func (b *writeBuf) int16(n int) { x := make([]byte, 2) binary.BigEndian.PutUint16(x, uint16(n)) - *b = append(*b, x...) + b.buf = append(b.buf, x...) } func (b *writeBuf) string(s string) { - *b = append(*b, (s + "\000")...) + b.buf = append(b.buf, (s + "\000")...) } func (b *writeBuf) byte(c byte) { - *b = append(*b, c) + b.buf = append(b.buf, c) } func (b *writeBuf) bytes(v []byte) { - *b = append(*b, v...) + b.buf = append(b.buf, v...) +} + +func (b *writeBuf) wrap() []byte { + p := b.buf[b.pos:] + binary.BigEndian.PutUint32(p, uint32(len(p))) + return b.buf +} + +func (b *writeBuf) next(c byte) { + p := b.buf[b.pos:] + binary.BigEndian.PutUint32(p, uint32(len(p))) + b.pos = len(b.buf) + 1 + b.buf = append(b.buf, c, 0, 0, 0, 0) } diff --git a/Godeps/_workspace/src/github.com/lib/pq/conn.go b/Godeps/_workspace/src/github.com/lib/pq/conn.go index 0c27984f31..3c26d01801 100644 --- a/Godeps/_workspace/src/github.com/lib/pq/conn.go +++ b/Godeps/_workspace/src/github.com/lib/pq/conn.go @@ -106,12 +106,41 @@ type conn struct { // If true, this connection is bad and all public-facing functions should // return ErrBadConn. bad bool + + // If set, this connection should never use the binary format when + // receiving query results from prepared statements. Only provided for + // debugging. + disablePreparedBinaryResult bool +} + +// Handle driver-side settings in parsed connection string. +func (c *conn) handleDriverSettings(o values) (err error) { + boolSetting := func(key string, val *bool) error { + if value := o.Get(key); value != "" { + if value == "yes" { + *val = true + } else if value == "no" { + *val = false + } else { + return fmt.Errorf("unrecognized value %q for disable_prepared_binary_result", value) + } + } + return nil + } + + err = boolSetting("disable_prepared_binary_result", &c.disablePreparedBinaryResult) + if err != nil { + return err + } + return nil } func (c *conn) writeBuf(b byte) *writeBuf { c.scratch[0] = b - w := writeBuf(c.scratch[:5]) - return &w + return &writeBuf{ + buf: c.scratch[:5], + pos: 1, + } } func Open(name string) (_ driver.Conn, err error) { @@ -119,22 +148,11 @@ func Open(name string) (_ driver.Conn, err error) { } func DialOpen(d Dialer, name string) (_ driver.Conn, err error) { - defer func() { - // Handle any panics during connection initialization. Note that we - // specifically do *not* want to use errRecover(), as that would turn - // any connection errors into ErrBadConns, hiding the real error - // message from the user. - e := recover() - if e == nil { - // Do nothing - return - } - var ok bool - err, ok = e.(error) - if !ok { - err = fmt.Errorf("pq: unexpected error: %#v", e) - } - }() + // Handle any panics during connection initialization. Note that we + // specifically do *not* want to use errRecover(), as that would turn any + // connection errors into ErrBadConns, hiding the real error message from + // the user. + defer errRecoverNoErrBadConn(&err) o := make(values) @@ -203,12 +221,16 @@ func DialOpen(d Dialer, name string) (_ driver.Conn, err error) { } } - c, err := dial(d, o) + cn := &conn{} + err = cn.handleDriverSettings(o) if err != nil { return nil, err } - cn := &conn{c: c} + cn.c, err = dial(d, o) + if err != nil { + return nil, err + } cn.ssl(o) cn.buf = bufio.NewReader(cn.c) cn.startup(o) @@ -505,7 +527,7 @@ func (cn *conn) simpleExec(q string) (res driver.Result, commandTag string, err } } -func (cn *conn) simpleQuery(q string) (res driver.Rows, err error) { +func (cn *conn) simpleQuery(q string) (res *rows, err error) { defer cn.errRecover(&err) st := &stmt{cn: cn, name: ""} @@ -526,7 +548,13 @@ func (cn *conn) simpleQuery(q string) (res driver.Rows, err error) { cn.bad = true errorf("unexpected message %q in simple query execution", t) } - res = &rows{st: st, done: true} + res = &rows{ + cn: cn, + cols: st.cols, + rowTyps: st.rowTyps, + rowFmts: st.rowFmts, + done: true, + } case 'Z': cn.processReadyForQuery(r) // done @@ -545,8 +573,8 @@ func (cn *conn) simpleQuery(q string) (res driver.Rows, err error) { case 'T': // res might be non-nil here if we received a previous // CommandComplete, but that's fine; just overwrite it - res = &rows{st: st} - st.cols, st.rowTyps = parseMeta(r) + res = &rows{cn: cn} + res.cols, res.rowFmts, res.rowTyps = parseMeta(r) // To work around a bug in QueryRow in Go 1.2 and earlier, wait // until the first DataRow has been received. @@ -557,6 +585,54 @@ func (cn *conn) simpleQuery(q string) (res driver.Rows, err error) { } } +// Decides which column formats to use for a prepared statement. The input is +// an array of type oids, one element per result column. +func decideColumnFormats(rowTyps []oid.Oid, forceText bool) (rowFmts []format, rowFmtData []byte) { + if len(rowTyps) == 0 { + return nil, rowFmtDataAllText + } + + rowFmts = make([]format, len(rowTyps)) + if forceText { + return rowFmts, rowFmtDataAllText + } + + allBinary := true + allText := true + for i, o := range rowTyps { + switch o { + // This is the list of types to use binary mode for when receiving them + // through a prepared statement. If a type appears in this list, it + // must also be implemented in binaryDecode in encode.go. + case oid.T_bytea: + fallthrough + case oid.T_int8: + fallthrough + case oid.T_int4: + fallthrough + case oid.T_int2: + rowFmts[i] = formatBinary + allText = false + + default: + allBinary = false + } + } + + if allBinary { + return rowFmts, rowFmtDataAllBinary + } else if allText { + return rowFmts, rowFmtDataAllText + } else { + rowFmtData = make([]byte, 2+len(rowFmts)*2) + binary.BigEndian.PutUint16(rowFmtData, uint16(len(rowFmts))) + for i, v := range rowFmts { + binary.BigEndian.PutUint16(rowFmtData[2+i*2:], uint16(v)) + } + return rowFmts, rowFmtData + } +} + func (cn *conn) prepareTo(q, stmtName string) (_ *stmt, err error) { st := &stmt{cn: cn, name: stmtName} @@ -564,14 +640,13 @@ func (cn *conn) prepareTo(q, stmtName string) (_ *stmt, err error) { b.string(st.name) b.string(q) b.int16(0) - cn.send(b) - b = cn.writeBuf('D') + b.next('D') b.byte('S') b.string(st.name) - cn.send(b) - cn.send(cn.writeBuf('S')) + b.next('S') + cn.send(b) for { t, r := cn.recv1() @@ -585,9 +660,11 @@ func (cn *conn) prepareTo(q, stmtName string) (_ *stmt, err error) { st.paramTyps[i] = r.oid() } case 'T': - st.cols, st.rowTyps = parseMeta(r) + st.cols, st.rowTyps = parseStatementRowDescribe(r) + st.rowFmts, st.rowFmtData = decideColumnFormats(st.rowTyps, cn.disablePreparedBinaryResult) case 'n': // no data + st.rowFmtData = rowFmtDataAllText case 'Z': cn.processReadyForQuery(r) return st, err @@ -647,7 +724,12 @@ func (cn *conn) Query(query string, args []driver.Value) (_ driver.Rows, err err } st.exec(args) - return &rows{st: st}, nil + return &rows{ + cn: cn, + cols: st.cols, + rowTyps: st.rowTyps, + rowFmts: st.rowFmts, + }, nil } // Implement the optional "Execer" interface for one-shot queries @@ -681,16 +763,20 @@ func (cn *conn) Exec(query string, args []driver.Value) (_ driver.Result, err er return r, err } -// Assumes len(*m) is > 5 func (cn *conn) send(m *writeBuf) { - b := (*m)[1:] - binary.BigEndian.PutUint32(b, uint32(len(b))) + _, err := cn.c.Write(m.wrap()) + if err != nil { + panic(err) + } +} - if (*m)[0] == 0 { - *m = b +func (cn *conn) sendStartupPacket(m *writeBuf) { + // sanity check + if m.buf[0] != 0 { + panic("oops") } - _, err := cn.c.Write(*m) + _, err := cn.c.Write((m.wrap())[1:]) if err != nil { panic(err) } @@ -830,7 +916,7 @@ func (cn *conn) ssl(o values) { w := cn.writeBuf(0) w.int32(80877103) - cn.send(w) + cn.sendStartupPacket(w) b := cn.scratch[:1] _, err := io.ReadFull(cn.c, b) @@ -967,6 +1053,8 @@ func isDriverSetting(key string) bool { return true case "connect_timeout": return true + case "disable_prepared_binary_result": + return true default: return false @@ -994,7 +1082,7 @@ func (cn *conn) startup(o values) { w.string(v) } w.string("") - cn.send(w) + cn.sendStartupPacket(w) for { t, r := cn.recv() @@ -1049,13 +1137,26 @@ func (cn *conn) auth(r *readBuf, o values) { } } +type format int + +const formatText format = 0 +const formatBinary format = 1 + +// One result-column format code with the value 1 (i.e. all binary). +var rowFmtDataAllBinary []byte = []byte{0, 1, 0, 1} + +// No result-column format codes (i.e. all text). +var rowFmtDataAllText []byte = []byte{0, 0} + type stmt struct { - cn *conn - name string - cols []string - rowTyps []oid.Oid - paramTyps []oid.Oid - closed bool + cn *conn + name string + cols []string + rowFmts []format + rowFmtData []byte + rowTyps []oid.Oid + paramTyps []oid.Oid + closed bool } func (st *stmt) Close() (err error) { @@ -1098,7 +1199,12 @@ func (st *stmt) Query(v []driver.Value) (r driver.Rows, err error) { defer st.cn.errRecover(&err) st.exec(v) - return &rows{st: st}, nil + return &rows{ + cn: st.cn, + cols: st.cols, + rowTyps: st.rowTyps, + rowFmts: st.rowFmts, + }, nil } func (st *stmt) Exec(v []driver.Value) (res driver.Result, err error) { @@ -1138,7 +1244,7 @@ func (st *stmt) exec(v []driver.Value) { } w := st.cn.writeBuf('B') - w.string("") + w.byte(0) w.string(st.name) w.int16(0) w.int16(len(v)) @@ -1151,15 +1257,14 @@ func (st *stmt) exec(v []driver.Value) { w.bytes(b) } } - w.int16(0) - st.cn.send(w) + w.bytes(st.rowFmtData) - w = st.cn.writeBuf('E') - w.string("") + w.next('E') + w.byte(0) w.int32(0) - st.cn.send(w) - st.cn.send(st.cn.writeBuf('S')) + w.next('S') + st.cn.send(w) var err error for { @@ -1271,9 +1376,12 @@ func (cn *conn) parseComplete(commandTag string) (driver.Result, string) { } type rows struct { - st *stmt - done bool - rb readBuf + cn *conn + cols []string + rowTyps []oid.Oid + rowFmts []format + done bool + rb readBuf } func (rs *rows) Close() error { @@ -1291,7 +1399,7 @@ func (rs *rows) Close() error { } func (rs *rows) Columns() []string { - return rs.st.cols + return rs.cols } func (rs *rows) Next(dest []driver.Value) (err error) { @@ -1299,7 +1407,7 @@ func (rs *rows) Next(dest []driver.Value) (err error) { return io.EOF } - conn := rs.st.cn + conn := rs.cn if conn.bad { return driver.ErrBadConn } @@ -1330,7 +1438,7 @@ func (rs *rows) Next(dest []driver.Value) (err error) { dest[i] = nil continue } - dest[i] = decode(&conn.parameterStatus, rs.rb.next(l), rs.st.rowTyps[i]) + dest[i] = decode(&conn.parameterStatus, rs.rb.next(l), rs.rowTyps[i], rs.rowFmts[i]) } return default: @@ -1392,7 +1500,7 @@ func (c *conn) processReadyForQuery(r *readBuf) { c.txnStatus = transactionStatus(r.byte()) } -func parseMeta(r *readBuf) (cols []string, rowTyps []oid.Oid) { +func parseStatementRowDescribe(r *readBuf) (cols []string, rowTyps []oid.Oid) { n := r.int16() cols = make([]string, n) rowTyps = make([]oid.Oid, n) @@ -1400,7 +1508,24 @@ func parseMeta(r *readBuf) (cols []string, rowTyps []oid.Oid) { cols[i] = r.string() r.next(6) rowTyps[i] = r.oid() - r.next(8) + r.next(6) + // format code not known; always 0 + r.next(2) + } + return +} + +func parseMeta(r *readBuf) (cols []string, rowFmts []format, rowTyps []oid.Oid) { + n := r.int16() + cols = make([]string, n) + rowFmts = make([]format, n) + rowTyps = make([]oid.Oid, n) + for i := range cols { + cols[i] = r.string() + r.next(6) + rowTyps[i] = r.oid() + r.next(6) + rowFmts[i] = format(r.int16()) } return } diff --git a/Godeps/_workspace/src/github.com/lib/pq/conn_test.go b/Godeps/_workspace/src/github.com/lib/pq/conn_test.go index 741fd761ab..ec0d55cd82 100644 --- a/Godeps/_workspace/src/github.com/lib/pq/conn_test.go +++ b/Godeps/_workspace/src/github.com/lib/pq/conn_test.go @@ -338,6 +338,7 @@ func TestEncodeDecode(t *testing.T) { '2000-1-1 01:02:03.04-7'::timestamptz, 0::boolean, 123, + -321, 3.14::float8 WHERE E'\\000\\001\\002'::bytea = $1 @@ -366,9 +367,9 @@ func TestEncodeDecode(t *testing.T) { var got2 string var got3 = sql.NullInt64{Valid: true} var got4 time.Time - var got5, got6, got7 interface{} + var got5, got6, got7, got8 interface{} - err = r.Scan(&got1, &got2, &got3, &got4, &got5, &got6, &got7) + err = r.Scan(&got1, &got2, &got3, &got4, &got5, &got6, &got7, &got8) if err != nil { t.Fatal(err) } @@ -397,8 +398,12 @@ func TestEncodeDecode(t *testing.T) { t.Fatalf("expected 123, got %d", got6) } - if got7 != float64(3.14) { - t.Fatalf("expected 3.14, got %f", got7) + if got7 != int64(-321) { + t.Fatalf("expected -321, got %d", got7) + } + + if got8 != float64(3.14) { + t.Fatalf("expected 3.14, got %f", got8) } } diff --git a/Godeps/_workspace/src/github.com/lib/pq/copy_test.go b/Godeps/_workspace/src/github.com/lib/pq/copy_test.go index 14cd8245e4..6af4c9c76d 100644 --- a/Godeps/_workspace/src/github.com/lib/pq/copy_test.go +++ b/Godeps/_workspace/src/github.com/lib/pq/copy_test.go @@ -387,12 +387,14 @@ func TestCopyRespLoopConnectionError(t *testing.T) { t.Fatal(err) } - // We have to try and send something over, since postgres won't process - // SIGTERMs while it's waiting for CopyData/CopyEnd messages; see - // tcop/postgres.c. - _, err = stmt.Exec(1) - if err != nil { - t.Fatal(err) + if getServerVersion(t, db) < 90500 { + // We have to try and send something over, since postgres before + // version 9.5 won't process SIGTERMs while it's waiting for + // CopyData/CopyEnd messages; see tcop/postgres.c. + _, err = stmt.Exec(1) + if err != nil { + t.Fatal(err) + } } _, err = stmt.Exec() if err == nil { diff --git a/Godeps/_workspace/src/github.com/lib/pq/encode.go b/Godeps/_workspace/src/github.com/lib/pq/encode.go index ad5f9683fd..6d8b5e4606 100644 --- a/Godeps/_workspace/src/github.com/lib/pq/encode.go +++ b/Godeps/_workspace/src/github.com/lib/pq/encode.go @@ -3,6 +3,7 @@ package pq import ( "bytes" "database/sql/driver" + "encoding/binary" "encoding/hex" "fmt" "math" @@ -44,7 +45,33 @@ func encode(parameterStatus *parameterStatus, x interface{}, pgtypOid oid.Oid) [ panic("not reached") } -func decode(parameterStatus *parameterStatus, s []byte, typ oid.Oid) interface{} { +func decode(parameterStatus *parameterStatus, s []byte, typ oid.Oid, f format) interface{} { + if f == formatBinary { + return binaryDecode(parameterStatus, s, typ) + } else { + return textDecode(parameterStatus, s, typ) + } +} + +func binaryDecode(parameterStatus *parameterStatus, s []byte, typ oid.Oid) interface{} { + switch typ { + case oid.T_bytea: + return s + case oid.T_int8: + return int64(binary.BigEndian.Uint64(s)) + case oid.T_int4: + return int64(int32(binary.BigEndian.Uint32(s))) + case oid.T_int2: + return int64(int16(binary.BigEndian.Uint16(s))) + + default: + errorf("don't know how to decode binary parameter of type %u", uint32(typ)) + } + + panic("not reached") +} + +func textDecode(parameterStatus *parameterStatus, s []byte, typ oid.Oid) interface{} { switch typ { case oid.T_bytea: return parseBytea(s) @@ -58,7 +85,7 @@ func decode(parameterStatus *parameterStatus, s []byte, typ oid.Oid) interface{} return mustParse("15:04:05-07", typ, s) case oid.T_bool: return s[0] == 't' - case oid.T_int8, oid.T_int2, oid.T_int4: + case oid.T_int8, oid.T_int4, oid.T_int2: i, err := strconv.ParseInt(string(s), 10, 64) if err != nil { errorf("%s", err) diff --git a/Godeps/_workspace/src/github.com/lib/pq/encode_test.go b/Godeps/_workspace/src/github.com/lib/pq/encode_test.go index 50fbaf33ff..abfc1156c6 100644 --- a/Godeps/_workspace/src/github.com/lib/pq/encode_test.go +++ b/Godeps/_workspace/src/github.com/lib/pq/encode_test.go @@ -2,6 +2,7 @@ package pq import ( "bytes" + "database/sql" "fmt" "testing" "time" @@ -460,7 +461,7 @@ func TestByteaOutputFormats(t *testing.T) { return } - testByteaOutputFormat := func(f string) { + testByteaOutputFormat := func(f string, usePrepared bool) { expectedData := []byte("\x5c\x78\x00\xff\x61\x62\x63\x01\x08") sqlQuery := "SELECT decode('5c7800ff6162630108', 'hex')" @@ -477,8 +478,18 @@ func TestByteaOutputFormats(t *testing.T) { if err != nil { t.Fatal(err) } - // use Query; QueryRow would hide the actual error - rows, err := txn.Query(sqlQuery) + var rows *sql.Rows + var stmt *sql.Stmt + if usePrepared { + stmt, err = txn.Prepare(sqlQuery) + if err != nil { + t.Fatal(err) + } + rows, err = stmt.Query() + } else { + // use Query; QueryRow would hide the actual error + rows, err = txn.Query(sqlQuery) + } if err != nil { t.Fatal(err) } @@ -496,13 +507,21 @@ func TestByteaOutputFormats(t *testing.T) { if err != nil { t.Fatal(err) } + if stmt != nil { + err = stmt.Close() + if err != nil { + t.Fatal(err) + } + } if !bytes.Equal(data, expectedData) { t.Errorf("unexpected bytea value %v for format %s; expected %v", data, f, expectedData) } } - testByteaOutputFormat("hex") - testByteaOutputFormat("escape") + testByteaOutputFormat("hex", false) + testByteaOutputFormat("escape", false) + testByteaOutputFormat("hex", true) + testByteaOutputFormat("escape", true) } func TestAppendEncodedText(t *testing.T) { diff --git a/Godeps/_workspace/src/github.com/lib/pq/error.go b/Godeps/_workspace/src/github.com/lib/pq/error.go index 0a49364d9e..b4bb44cee3 100644 --- a/Godeps/_workspace/src/github.com/lib/pq/error.go +++ b/Godeps/_workspace/src/github.com/lib/pq/error.go @@ -459,6 +459,19 @@ func errorf(s string, args ...interface{}) { panic(fmt.Errorf("pq: %s", fmt.Sprintf(s, args...))) } +func errRecoverNoErrBadConn(err *error) { + e := recover() + if e == nil { + // Do nothing + return + } + var ok bool + *err, ok = e.(error) + if !ok { + *err = fmt.Errorf("pq: unexpected error: %#v", e) + } +} + func (c *conn) errRecover(err *error) { e := recover() switch v := e.(type) { diff --git a/Godeps/_workspace/src/github.com/lib/pq/notify.go b/Godeps/_workspace/src/github.com/lib/pq/notify.go index e3b08d59a2..8cad578154 100644 --- a/Godeps/_workspace/src/github.com/lib/pq/notify.go +++ b/Godeps/_workspace/src/github.com/lib/pq/notify.go @@ -6,7 +6,6 @@ package pq import ( "errors" "fmt" - "io" "sync" "sync/atomic" "time" @@ -87,12 +86,16 @@ func NewListenerConn(name string, notificationChan chan<- *Notification) (*Liste // Returns an error if an unrecoverable error has occurred and the ListenerConn // should be abandoned. func (l *ListenerConn) acquireSenderLock() error { - l.connectionLock.Lock() - defer l.connectionLock.Unlock() - if l.err != nil { - return l.err - } + // we must acquire senderLock first to avoid deadlocks; see ExecSimpleQuery l.senderLock.Lock() + + l.connectionLock.Lock() + err := l.err + l.connectionLock.Unlock() + if err != nil { + l.senderLock.Unlock() + return err + } return nil } @@ -125,7 +128,7 @@ func (l *ListenerConn) setState(newState int32) bool { // away or should be discarded because we couldn't agree on the state with the // server backend. func (l *ListenerConn) listenerConnLoop() (err error) { - defer l.cn.errRecover(&err) + defer errRecoverNoErrBadConn(&err) r := &readBuf{} for { @@ -140,6 +143,9 @@ func (l *ListenerConn) listenerConnLoop() (err error) { // about the scratch buffer being overwritten. l.notificationChan <- recvNotification(r) + case 'T', 'D': + // only used by tests; ignore + case 'E': // We might receive an ErrorResponse even when not in a query; it // is expected that the server will close the connection after @@ -238,7 +244,7 @@ func (l *ListenerConn) Ping() error { // The caller must be holding senderLock (see acquireSenderLock and // releaseSenderLock). func (l *ListenerConn) sendSimpleQuery(q string) (err error) { - defer l.cn.errRecover(&err) + defer errRecoverNoErrBadConn(&err) // must set connection state before sending the query if !l.setState(connStateExpectResponse) { @@ -247,8 +253,10 @@ func (l *ListenerConn) sendSimpleQuery(q string) (err error) { // Can't use l.cn.writeBuf here because it uses the scratch buffer which // might get overwritten by listenerConnLoop. - data := writeBuf([]byte("Q\x00\x00\x00\x00")) - b := &data + b := &writeBuf{ + buf: []byte("Q\x00\x00\x00\x00"), + pos: 1, + } b.string(q) l.cn.send(b) @@ -277,13 +285,13 @@ func (l *ListenerConn) ExecSimpleQuery(q string) (executed bool, err error) { // We can't know what state the protocol is in, so we need to abandon // this connection. l.connectionLock.Lock() - defer l.connectionLock.Unlock() // Set the error pointer if it hasn't been set already; see // listenerConnMain. if l.err == nil { l.err = err } - l.cn.Close() + l.connectionLock.Unlock() + l.cn.c.Close() return false, err } @@ -292,8 +300,11 @@ func (l *ListenerConn) ExecSimpleQuery(q string) (executed bool, err error) { m, ok := <-l.replyChan if !ok { // We lost the connection to server, don't bother waiting for a - // a response. - return false, io.EOF + // a response. err should have been set already. + l.connectionLock.Lock() + err := l.err + l.connectionLock.Unlock() + return false, err } switch m.typ { case 'Z': @@ -320,12 +331,15 @@ func (l *ListenerConn) ExecSimpleQuery(q string) (executed bool, err error) { func (l *ListenerConn) Close() error { l.connectionLock.Lock() - defer l.connectionLock.Unlock() if l.err != nil { + l.connectionLock.Unlock() return errListenerConnClosed } l.err = errListenerConnClosed - return l.cn.Close() + l.connectionLock.Unlock() + // We can't send anything on the connection without holding senderLock. + // Simply close the net.Conn to wake up everyone operating on it. + return l.cn.c.Close() } // Err() returns the reason the connection was closed. It is not safe to call diff --git a/Godeps/_workspace/src/github.com/lib/pq/notify_test.go b/Godeps/_workspace/src/github.com/lib/pq/notify_test.go index 73dcb750d1..fe8941a4e0 100644 --- a/Godeps/_workspace/src/github.com/lib/pq/notify_test.go +++ b/Godeps/_workspace/src/github.com/lib/pq/notify_test.go @@ -5,6 +5,9 @@ import ( "fmt" "io" "os" + "runtime" + "sync" + "sync/atomic" "testing" "time" ) @@ -210,6 +213,75 @@ func TestConnPing(t *testing.T) { } } +// Test for deadlock where a query fails while another one is queued +func TestConnExecDeadlock(t *testing.T) { + l, _ := newTestListenerConn(t) + defer l.Close() + + var wg sync.WaitGroup + wg.Add(2) + + go func() { + l.ExecSimpleQuery("SELECT pg_sleep(60)") + wg.Done() + }() + runtime.Gosched() + go func() { + l.ExecSimpleQuery("SELECT 1") + wg.Done() + }() + // give the two goroutines some time to get into position + runtime.Gosched() + // calls Close on the net.Conn; equivalent to a network failure + l.Close() + + var done int32 = 0 + go func() { + time.Sleep(10 * time.Second) + if atomic.LoadInt32(&done) != 1 { + panic("timed out") + } + }() + wg.Wait() + atomic.StoreInt32(&done, 1) +} + +// Test for ListenerConn being closed while a slow query is executing +func TestListenerConnCloseWhileQueryIsExecuting(t *testing.T) { + l, _ := newTestListenerConn(t) + defer l.Close() + + var wg sync.WaitGroup + wg.Add(1) + + go func() { + sent, err := l.ExecSimpleQuery("SELECT pg_sleep(60)") + if sent { + panic("expected sent=false") + } + // could be any of a number of errors + if err == nil { + panic("expected error") + } + wg.Done() + }() + // give the above goroutine some time to get into position + runtime.Gosched() + err := l.Close() + if err != nil { + t.Fatal(err) + } + var done int32 = 0 + go func() { + time.Sleep(10 * time.Second) + if atomic.LoadInt32(&done) != 1 { + panic("timed out") + } + }() + wg.Wait() + atomic.StoreInt32(&done, 1) +} + func TestNotifyExtra(t *testing.T) { db := openTestConn(t) defer db.Close() diff --git a/Godeps/_workspace/src/github.com/mitchellh/cli/README.md b/Godeps/_workspace/src/github.com/mitchellh/cli/README.md index 60d46045dd..5afa0944ae 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/cli/README.md +++ b/Godeps/_workspace/src/github.com/mitchellh/cli/README.md @@ -10,6 +10,9 @@ cli is the library that powers the CLI for * Easy sub-command based CLIs: `cli foo`, `cli bar`, etc. +* Optional support for default subcommands so `cli` does something + other than error. + * Automatic help generation for listing subcommands * Automatic help flag recognition of `-h`, `--help`, etc. diff --git a/Godeps/_workspace/src/github.com/mitchellh/cli/cli.go b/Godeps/_workspace/src/github.com/mitchellh/cli/cli.go index 56459ed705..bb676e3210 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/cli/cli.go +++ b/Godeps/_workspace/src/github.com/mitchellh/cli/cli.go @@ -15,7 +15,9 @@ type CLI struct { Args []string // Commands is a mapping of subcommand names to a factory function - // for creating that Command implementation. + // for creating that Command implementation. If there is a command + // with a blank string "", then it will be used as the default command + // if no subcommand is specified. Commands map[string]CommandFactory // Name defines the name of the CLI. @@ -40,6 +42,7 @@ type CLI struct { isHelp bool subcommand string subcommandArgs []string + topFlags []string isVersion bool } @@ -78,10 +81,19 @@ func (c *CLI) Run() (int, error) { return 1, nil } + // If there is an invalid flag, then error + if len(c.topFlags) > 0 { + c.HelpWriter.Write([]byte( + "Invalid flags before the subcommand. If these flags are for\n" + + "the subcommand, please put them after the subcommand.\n\n")) + c.HelpWriter.Write([]byte(c.HelpFunc(c.Commands) + "\n")) + return 1, nil + } + // Attempt to get the factory function for creating the command // implementation. If the command is invalid or blank, it is an error. commandFunc, ok := c.Commands[c.Subcommand()] - if !ok || c.Subcommand() == "" { + if !ok { c.HelpWriter.Write([]byte(c.HelpFunc(c.Commands) + "\n")) return 1, nil } @@ -133,7 +145,6 @@ func (c *CLI) init() { func (c *CLI) processArgs() { for i, arg := range c.Args { - if c.subcommand == "" { // Check for version and help flags if not in a subcommand if arg == "-v" || arg == "-version" || arg == "--version" { @@ -144,15 +155,31 @@ func (c *CLI) processArgs() { c.isHelp = true continue } + + if arg != "" && arg[0] == '-' { + // Record the arg... + c.topFlags = append(c.topFlags, arg) + } } // If we didn't find a subcommand yet and this is the first non-flag // argument, then this is our subcommand. j - if c.subcommand == "" && arg[0] != '-' { + if c.subcommand == "" && arg != "" && arg[0] != '-' { c.subcommand = arg // The remaining args the subcommand arguments c.subcommandArgs = c.Args[i+1:] } } + + // If we never found a subcommand and support a default command, then + // switch to using that. + if c.subcommand == "" { + if _, ok := c.Commands[""]; ok { + args := c.topFlags + args = append(args, c.subcommandArgs...) + c.topFlags = nil + c.subcommandArgs = args + } + } } diff --git a/Godeps/_workspace/src/github.com/mitchellh/cli/cli_test.go b/Godeps/_workspace/src/github.com/mitchellh/cli/cli_test.go index 9ec5f9a199..8b0af00e05 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/cli/cli_test.go +++ b/Godeps/_workspace/src/github.com/mitchellh/cli/cli_test.go @@ -3,6 +3,7 @@ package cli import ( "bytes" "reflect" + "strings" "testing" ) @@ -87,11 +88,75 @@ func TestCLIRun(t *testing.T) { } } +func TestCLIRun_blank(t *testing.T) { + command := new(MockCommand) + cli := &CLI{ + Args: []string{"", "foo", "-bar", "-baz"}, + Commands: map[string]CommandFactory{ + "foo": func() (Command, error) { + return command, nil + }, + }, + } + + exitCode, err := cli.Run() + if err != nil { + t.Fatalf("err: %s", err) + } + + if exitCode != command.RunResult { + t.Fatalf("bad: %d", exitCode) + } + + if !command.RunCalled { + t.Fatalf("run should be called") + } + + if !reflect.DeepEqual(command.RunArgs, []string{"-bar", "-baz"}) { + t.Fatalf("bad args: %#v", command.RunArgs) + } +} + +func TestCLIRun_default(t *testing.T) { + commandBar := new(MockCommand) + commandBar.RunResult = 42 + + cli := &CLI{ + Args: []string{"-bar", "-baz"}, + Commands: map[string]CommandFactory{ + "": func() (Command, error) { + return commandBar, nil + }, + "foo": func() (Command, error) { + return new(MockCommand), nil + }, + }, + } + + exitCode, err := cli.Run() + if err != nil { + t.Fatalf("err: %s", err) + } + + if exitCode != commandBar.RunResult { + t.Fatalf("bad: %d", exitCode) + } + + if !commandBar.RunCalled { + t.Fatalf("run should be called") + } + + if !reflect.DeepEqual(commandBar.RunArgs, []string{"-bar", "-baz"}) { + t.Fatalf("bad args: %#v", commandBar.RunArgs) + } +} + func TestCLIRun_printHelp(t *testing.T) { testCases := [][]string{ {}, {"-h"}, {"i-dont-exist"}, + {"-bad-flag", "foo"}, } for _, testCase := range testCases { @@ -100,6 +165,11 @@ func TestCLIRun_printHelp(t *testing.T) { cli := &CLI{ Args: testCase, + Commands: map[string]CommandFactory{ + "foo": func() (Command, error) { + return new(MockCommand), nil + }, + }, HelpFunc: func(map[string]CommandFactory) string { return helpText }, @@ -117,7 +187,7 @@ func TestCLIRun_printHelp(t *testing.T) { continue } - if buf.String() != (helpText + "\n") { + if !strings.Contains(buf.String(), helpText) { t.Errorf("Args: %#v. Text: %v", testCase, buf.String()) } } diff --git a/Godeps/_workspace/src/github.com/mitchellh/mapstructure/.travis.yml b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/.travis.yml new file mode 100644 index 0000000000..7f3fe9a969 --- /dev/null +++ b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/.travis.yml @@ -0,0 +1,7 @@ +language: go + +go: + - 1.4 + +script: + - go test diff --git a/Godeps/_workspace/src/github.com/mitchellh/mapstructure/decode_hooks.go b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/decode_hooks.go index 087a392b91..aa91f76ce4 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/mapstructure/decode_hooks.go +++ b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/decode_hooks.go @@ -1,11 +1,59 @@ 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. // @@ -13,18 +61,18 @@ import ( // previous transformation. func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc { return func( - f reflect.Kind, - t reflect.Kind, + f reflect.Type, + t reflect.Type, data interface{}) (interface{}, error) { var err error for _, f1 := range fs { - data, err = f1(f, t, data) + 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 = getKind(reflect.ValueOf(data)) + f = reflect.ValueOf(data).Type() } return data, nil @@ -51,6 +99,25 @@ func StringToSliceHookFunc(sep string) DecodeHookFunc { } } +// 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, diff --git a/Godeps/_workspace/src/github.com/mitchellh/mapstructure/decode_hooks_test.go b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/decode_hooks_test.go index b417deeb64..53289afcfb 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/mapstructure/decode_hooks_test.go +++ b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/decode_hooks_test.go @@ -4,6 +4,7 @@ import ( "errors" "reflect" "testing" + "time" ) func TestComposeDecodeHookFunc(t *testing.T) { @@ -23,7 +24,8 @@ func TestComposeDecodeHookFunc(t *testing.T) { f := ComposeDecodeHookFunc(f1, f2) - result, err := f(reflect.String, reflect.Slice, "") + result, err := DecodeHookExec( + f, reflect.TypeOf(""), reflect.TypeOf([]byte("")), "") if err != nil { t.Fatalf("bad: %s", err) } @@ -43,7 +45,8 @@ func TestComposeDecodeHookFunc_err(t *testing.T) { f := ComposeDecodeHookFunc(f1, f2) - _, err := f(reflect.String, reflect.Slice, 42) + _, err := DecodeHookExec( + f, reflect.TypeOf(""), reflect.TypeOf([]byte("")), 42) if err.Error() != "foo" { t.Fatalf("bad: %s", err) } @@ -69,7 +72,8 @@ func TestComposeDecodeHookFunc_kinds(t *testing.T) { f := ComposeDecodeHookFunc(f1, f2) - _, err := f(reflect.String, reflect.Slice, "") + _, err := DecodeHookExec( + f, reflect.TypeOf(""), reflect.TypeOf([]byte("")), "") if err != nil { t.Fatalf("bad: %s", err) } @@ -81,24 +85,26 @@ func TestComposeDecodeHookFunc_kinds(t *testing.T) { func TestStringToSliceHookFunc(t *testing.T) { f := StringToSliceHookFunc(",") + strType := reflect.TypeOf("") + sliceType := reflect.TypeOf([]byte("")) cases := []struct { - f, t reflect.Kind + f, t reflect.Type data interface{} result interface{} err bool }{ - {reflect.Slice, reflect.Slice, 42, 42, false}, - {reflect.String, reflect.String, 42, 42, false}, + {sliceType, sliceType, 42, 42, false}, + {strType, strType, 42, 42, false}, { - reflect.String, - reflect.Slice, + strType, + sliceType, "foo,bar,baz", []string{"foo", "bar", "baz"}, false, }, { - reflect.String, - reflect.Slice, + strType, + sliceType, "", []string{}, false, @@ -106,7 +112,36 @@ func TestStringToSliceHookFunc(t *testing.T) { } for i, tc := range cases { - actual, err := f(tc.f, tc.t, tc.data) + actual, err := DecodeHookExec(f, tc.f, tc.t, tc.data) + if tc.err != (err != nil) { + t.Fatalf("case %d: expected err %#v", i, tc.err) + } + if !reflect.DeepEqual(actual, tc.result) { + t.Fatalf( + "case %d: expected %#v, got %#v", + i, tc.result, actual) + } + } +} + +func TestStringToTimeDurationHookFunc(t *testing.T) { + f := StringToTimeDurationHookFunc() + + strType := reflect.TypeOf("") + timeType := reflect.TypeOf(time.Duration(5)) + cases := []struct { + f, t reflect.Type + data interface{} + result interface{} + err bool + }{ + {strType, timeType, "5s", 5 * time.Second, false}, + {strType, timeType, "5", time.Duration(0), true}, + {strType, strType, "5", "5", false}, + } + + for i, tc := range cases { + actual, err := DecodeHookExec(f, tc.f, tc.t, tc.data) if tc.err != (err != nil) { t.Fatalf("case %d: expected err %#v", i, tc.err) } @@ -121,56 +156,59 @@ func TestStringToSliceHookFunc(t *testing.T) { func TestWeaklyTypedHook(t *testing.T) { var f DecodeHookFunc = WeaklyTypedHook + boolType := reflect.TypeOf(true) + strType := reflect.TypeOf("") + sliceType := reflect.TypeOf([]byte("")) cases := []struct { - f, t reflect.Kind + f, t reflect.Type data interface{} result interface{} err bool }{ // TO STRING { - reflect.Bool, - reflect.String, + boolType, + strType, false, "0", false, }, { - reflect.Bool, - reflect.String, + boolType, + strType, true, "1", false, }, { - reflect.Float32, - reflect.String, + reflect.TypeOf(float32(1)), + strType, float32(7), "7", false, }, { - reflect.Int, - reflect.String, + reflect.TypeOf(int(1)), + strType, int(7), "7", false, }, { - reflect.Slice, - reflect.String, + sliceType, + strType, []uint8("foo"), "foo", false, }, { - reflect.Uint, - reflect.String, + reflect.TypeOf(uint(1)), + strType, uint(7), "7", false, @@ -178,7 +216,7 @@ func TestWeaklyTypedHook(t *testing.T) { } for i, tc := range cases { - actual, err := f(tc.f, tc.t, tc.data) + actual, err := DecodeHookExec(f, tc.f, tc.t, tc.data) if tc.err != (err != nil) { t.Fatalf("case %d: expected err %#v", i, tc.err) } diff --git a/Godeps/_workspace/src/github.com/mitchellh/mapstructure/error.go b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/error.go index f97c4164db..47a99e5af3 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/mapstructure/error.go +++ b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/error.go @@ -1,6 +1,7 @@ package mapstructure import ( + "errors" "fmt" "sort" "strings" @@ -24,6 +25,21 @@ func (e *Error) Error() string { 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: diff --git a/Godeps/_workspace/src/github.com/mitchellh/mapstructure/mapstructure.go b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/mapstructure.go index 381ba5d487..40be5116db 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/mapstructure/mapstructure.go +++ b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/mapstructure.go @@ -19,10 +19,20 @@ import ( // DecodeHookFunc is the callback function that can be used for // data transformations. See "DecodeHook" in the DecoderConfig // struct. -type DecodeHookFunc func( - from reflect.Kind, - to reflect.Kind, - data interface{}) (interface{}, error) +// +// 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. @@ -40,6 +50,11 @@ type DecoderConfig struct { // (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: // @@ -51,6 +66,7 @@ type DecoderConfig struct { // - 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) // WeaklyTypedInput bool @@ -180,7 +196,9 @@ func (d *Decoder) decode(name string, data interface{}, val reflect.Value) error if d.config.DecodeHook != nil { // We have a DecodeHook, so let's pre-process the data. var err error - data, err = d.config.DecodeHook(getKind(dataVal), getKind(val), data) + data, err = DecodeHookExec( + d.config.DecodeHook, + dataVal.Type(), val.Type(), data) if err != nil { return err } @@ -319,11 +337,21 @@ func (d *Decoder) decodeUint(name string, data interface{}, val reflect.Value) e switch { case dataKind == reflect.Int: - val.SetUint(uint64(dataVal.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: - val.SetUint(uint64(dataVal.Float())) + 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) @@ -415,9 +443,15 @@ func (d *Decoder) decodeMap(name string, data interface{}, val reflect.Value) er valKeyType := valType.Key() valElemType := valType.Elem() - // Make a new map to hold our result - mapType := reflect.MapOf(valKeyType, valElemType) - valMap := reflect.MakeMap(mapType) + // 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)) @@ -530,6 +564,14 @@ func (d *Decoder) decodeSlice(name string, data interface{}, val reflect.Value) 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) @@ -575,22 +617,21 @@ func (d *Decoder) decodeStruct(name string, data interface{}, val reflect.Value) fmt.Errorf("%s: unsupported type: %s", fieldType.Name, fieldKind)) continue } + } - // We have an embedded field. We "squash" the fields down - // if specified in the tag. - squash := false - tagParts := strings.Split(fieldType.Tag.Get(d.config.TagName), ",") - for _, tag := range tagParts[1:] { - if tag == "squash" { - squash = true - break - } + // 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 { - structs = append(structs, val.FieldByName(fieldType.Name)) - continue - } + if squash { + structs = append(structs, val.FieldByName(fieldType.Name)) + continue } // Normal struct field, store it away diff --git a/Godeps/_workspace/src/github.com/mitchellh/mapstructure/mapstructure_test.go b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/mapstructure_test.go index 036e6b5f51..8a27647b58 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/mapstructure/mapstructure_test.go +++ b/Godeps/_workspace/src/github.com/mitchellh/mapstructure/mapstructure_test.go @@ -17,6 +17,10 @@ type Basic struct { Vdata interface{} } +type BasicSquash struct { + Test Basic `mapstructure:",squash"` +} + type Embedded struct { Basic Vunique string @@ -158,6 +162,47 @@ func TestBasic_IntWithFloat(t *testing.T) { } } +func TestBasic_Merge(t *testing.T) { + t.Parallel() + + input := map[string]interface{}{ + "vint": 42, + } + + var result Basic + result.Vuint = 100 + err := Decode(input, &result) + if err != nil { + t.Fatalf("got an err: %s", err) + } + + expected := Basic{ + Vint: 42, + Vuint: 100, + } + if !reflect.DeepEqual(result, expected) { + t.Fatalf("bad: %#v", result) + } +} + +func TestDecode_BasicSquash(t *testing.T) { + t.Parallel() + + input := map[string]interface{}{ + "vstring": "foo", + } + + var result BasicSquash + err := Decode(input, &result) + if err != nil { + t.Fatalf("got an err: %s", err.Error()) + } + + if result.Test.Vstring != "foo" { + t.Errorf("vstring value should be 'foo': %#v", result.Test.Vstring) + } +} + func TestDecode_Embedded(t *testing.T) { t.Parallel() @@ -261,6 +306,43 @@ func TestDecode_DecodeHook(t *testing.T) { } } +func TestDecode_DecodeHookType(t *testing.T) { + t.Parallel() + + input := map[string]interface{}{ + "vint": "WHAT", + } + + decodeHook := func(from reflect.Type, to reflect.Type, v interface{}) (interface{}, error) { + if from.Kind() == reflect.String && + to.Kind() != reflect.String { + return 5, nil + } + + return v, nil + } + + var result Basic + config := &DecoderConfig{ + DecodeHook: decodeHook, + Result: &result, + } + + decoder, err := NewDecoder(config) + if err != nil { + t.Fatalf("err: %s", err) + } + + err = decoder.Decode(input) + if err != nil { + t.Fatalf("got an err: %s", err) + } + + if result.Vint != 5 { + t.Errorf("vint should be 5: %#v", result.Vint) + } +} + func TestDecode_Nil(t *testing.T) { t.Parallel() @@ -298,6 +380,26 @@ func TestDecode_NonStruct(t *testing.T) { } } +func TestDecode_StructMatch(t *testing.T) { + t.Parallel() + + input := map[string]interface{}{ + "vbar": Basic{ + Vstring: "foo", + }, + } + + var result Nested + err := Decode(input, &result) + if err != nil { + t.Fatalf("got an err: %s", err.Error()) + } + + if result.Vbar.Vstring != "foo" { + t.Errorf("bad: %#v", result) + } +} + func TestDecode_TypeConversion(t *testing.T) { input := map[string]interface{}{ "IntToFloat": 42, @@ -460,6 +562,38 @@ func TestMap(t *testing.T) { } } +func TestMapMerge(t *testing.T) { + t.Parallel() + + input := map[string]interface{}{ + "vfoo": "foo", + "vother": map[interface{}]interface{}{ + "foo": "foo", + "bar": "bar", + }, + } + + var result Map + result.Vother = map[string]string{"hello": "world"} + err := Decode(input, &result) + if err != nil { + t.Fatalf("got an error: %s", err) + } + + if result.Vfoo != "foo" { + t.Errorf("vfoo value should be 'foo': %#v", result.Vfoo) + } + + expected := map[string]string{ + "foo": "foo", + "bar": "bar", + "hello": "world", + } + if !reflect.DeepEqual(result.Vother, expected) { + t.Errorf("bad: %#v", result.Vother) + } +} + func TestMapOfStruct(t *testing.T) { t.Parallel() @@ -658,6 +792,42 @@ func TestInvalidType(t *testing.T) { if derr.Errors[0] != "'Vstring' expected type 'string', got unconvertible type 'int'" { t.Errorf("got unexpected error: %s", err) } + + inputNegIntUint := map[string]interface{}{ + "vuint": -42, + } + + err = Decode(inputNegIntUint, &result) + if err == nil { + t.Fatal("error should exist") + } + + derr, ok = err.(*Error) + if !ok { + t.Fatalf("error should be kind of Error, instead: %#v", err) + } + + if derr.Errors[0] != "cannot parse 'Vuint', -42 overflows uint" { + t.Errorf("got unexpected error: %s", err) + } + + inputNegFloatUint := map[string]interface{}{ + "vuint": -42.0, + } + + err = Decode(inputNegFloatUint, &result) + if err == nil { + t.Fatal("error should exist") + } + + derr, ok = err.(*Error) + if !ok { + t.Fatalf("error should be kind of Error, instead: %#v", err) + } + + if derr.Errors[0] != "cannot parse 'Vuint', -42.000000 overflows uint" { + t.Errorf("got unexpected error: %s", err) + } } func TestMetadata(t *testing.T) { diff --git a/Godeps/_workspace/src/github.com/mitchellh/reflectwalk/reflectwalk.go b/Godeps/_workspace/src/github.com/mitchellh/reflectwalk/reflectwalk.go index 8c1dd55949..1f20665980 100644 --- a/Godeps/_workspace/src/github.com/mitchellh/reflectwalk/reflectwalk.go +++ b/Godeps/_workspace/src/github.com/mitchellh/reflectwalk/reflectwalk.go @@ -113,17 +113,7 @@ func walk(v reflect.Value, w interface{}) (err error) { switch k { // Primitives - case reflect.Bool: - fallthrough - case reflect.Chan: - fallthrough - case reflect.Func: - fallthrough - case reflect.Int: - fallthrough - case reflect.String: - fallthrough - case reflect.Invalid: + case reflect.Bool, reflect.Chan, reflect.Func, reflect.Int, reflect.String, reflect.Invalid: err = walkPrimitive(originalV, w) return case reflect.Map: diff --git a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/conn.go b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/conn.go index 47d5534a89..eef2572de0 100644 --- a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/conn.go +++ b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/conn.go @@ -1,3 +1,4 @@ +// Package zk is a native Go client library for the ZooKeeper orchestration service. package zk /* @@ -14,7 +15,6 @@ import ( "errors" "fmt" "io" - "log" "net" "strconv" "strings" @@ -23,8 +23,17 @@ import ( "time" ) +// ErrNoServer indicates that an operation cannot be completed +// because attempts to connect to all servers in the list failed. var ErrNoServer = errors.New("zk: could not connect to a server") +// ErrInvalidPath indicates that an operation was being attempted on +// an invalid path. (e.g. empty path) +var ErrInvalidPath = errors.New("zk: invalid path") + +// DefaultLogger uses the stdlib log package for logging. +var DefaultLogger = defaultLogger{} + const ( bufferSize = 1536 * 1024 eventChanSize = 6 @@ -47,6 +56,11 @@ type watchPathType struct { type Dialer func(network, address string, timeout time.Duration) (net.Conn, error) +// Logger is an interface that can be implemented to provide custom log output. +type Logger interface { + Printf(string, ...interface{}) +} + type Conn struct { lastZxid int64 sessionID int64 @@ -74,6 +88,8 @@ type Conn struct { // Debug (used by unit tests) reconnectDelay time.Duration + + logger Logger } type request struct { @@ -160,6 +176,7 @@ func ConnectWithDialer(servers []string, sessionTimeout time.Duration, dialer Di watchers: make(map[watchPathType][]chan Event), passwd: emptyPassword, timeout: int32(sessionTimeout.Nanoseconds() / 1e6), + logger: DefaultLogger, // Debug reconnectDelay: 0, @@ -182,10 +199,17 @@ func (c *Conn) Close() { } } +// States returns the current state of the connection. func (c *Conn) State() State { return State(atomic.LoadInt32((*int32)(&c.state))) } +// SetLogger sets the logger to be used for printing errors. +// Logger is an interface provided by this package. +func (c *Conn) SetLogger(l Logger) { + c.logger = l +} + func (c *Conn) setState(state State) { atomic.StoreInt32((*int32)(&c.state), int32(state)) select { @@ -221,7 +245,7 @@ func (c *Conn) connect() error { return nil } - log.Printf("Failed to connect to %s: %+v", c.servers[c.serverIndex], err) + c.logger.Printf("Failed to connect to %s: %+v", c.servers[c.serverIndex], err) } } @@ -267,7 +291,7 @@ func (c *Conn) loop() { // Yeesh if err != io.EOF && err != ErrSessionExpired && !strings.Contains(err.Error(), "use of closed network connection") { - log.Println(err) + c.logger.Printf(err.Error()) } select { @@ -367,7 +391,7 @@ func (c *Conn) sendSetWatches() { res := &setWatchesResponse{} _, err := c.request(opSetWatches, req, res, nil) if err != nil { - log.Printf("Failed to set previous watches: %s", err.Error()) + c.logger.Printf("Failed to set previous watches: %s", err.Error()) } }() } @@ -582,7 +606,7 @@ func (c *Conn) recvLoop(conn net.Conn) error { } else if res.Xid == -2 { // Ping response. Ignore. } else if res.Xid < 0 { - log.Printf("Xid < 0 (%d) but not ping or watcher event", res.Xid) + c.logger.Printf("Xid < 0 (%d) but not ping or watcher event", res.Xid) } else { if res.Zxid > 0 { c.lastZxid = res.Zxid @@ -596,7 +620,7 @@ func (c *Conn) recvLoop(conn net.Conn) error { c.requestsLock.Unlock() if !ok { - log.Printf("Response for unknown request with xid %d", res.Xid) + c.logger.Printf("Response for unknown request with xid %d", res.Xid) } else { if res.Err != 0 { err = res.Err.toError() @@ -694,6 +718,9 @@ func (c *Conn) GetW(path string) ([]byte, *Stat, <-chan Event, error) { } func (c *Conn) Set(path string, data []byte, version int32) (*Stat, error) { + if path == "" { + return nil, ErrInvalidPath + } res := &setDataResponse{} _, err := c.request(opSetData, &SetDataRequest{path, data, version}, res, nil) return &res.Stat, err diff --git a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/lock.go b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/lock.go index fb77e4a538..f13a8b0ba6 100644 --- a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/lock.go +++ b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/lock.go @@ -8,10 +8,13 @@ import ( ) var ( - ErrDeadlock = errors.New("zk: trying to acquire a lock twice") + // ErrDeadlock is returned by Lock when trying to lock twice without unlocking first + ErrDeadlock = errors.New("zk: trying to acquire a lock twice") + // ErrNotLocked is returned by Unlock when trying to release a lock that has not first be acquired. ErrNotLocked = errors.New("zk: not locked") ) +// Lock is a mutual exclusion lock. type Lock struct { c *Conn path string @@ -20,6 +23,9 @@ type Lock struct { seq int } +// NewLock creates a new lock instance using the provided connection, path, and acl. +// The path must be a node that is only used by this lock. A lock instances starts +// unlocked until Lock() is called. func NewLock(c *Conn, path string, acl []ACL) *Lock { return &Lock{ c: c, @@ -33,6 +39,9 @@ func parseSeq(path string) (int, error) { return strconv.Atoi(parts[len(parts)-1]) } +// Lock attempts to acquire the lock. It will wait to return until the lock +// is acquired or an error occurs. If this instance already has the lock +// then ErrDeadlock is returned. func (l *Lock) Lock() error { if l.lockPath != "" { return ErrDeadlock @@ -118,6 +127,8 @@ func (l *Lock) Lock() error { return nil } +// Unlock releases an acquired lock. If the lock is not currently acquired by +// this Lock instance than ErrNotLocked is returned. func (l *Lock) Unlock() error { if l.lockPath == "" { return ErrNotLocked diff --git a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/structs.go b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/structs.go index 3c9058adb7..8fbc069ee1 100644 --- a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/structs.go +++ b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/structs.go @@ -3,6 +3,7 @@ package zk import ( "encoding/binary" "errors" + "log" "reflect" "runtime" "time" @@ -14,6 +15,12 @@ var ( ErrShortBuffer = errors.New("zk: buffer too small") ) +type defaultLogger struct{} + +func (defaultLogger) Printf(format string, a ...interface{}) { + log.Printf(format, a...) +} + type ACL struct { Perms int32 Scheme string diff --git a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/structs_test.go b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/structs_test.go index 64f18e8d3e..cafbbd95c2 100644 --- a/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/structs_test.go +++ b/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk/structs_test.go @@ -58,3 +58,14 @@ func TestDecodeShortBuffer(t *testing.T) { return } } + +func BenchmarkEncode(b *testing.B) { + buf := make([]byte, 4096) + st := &connectRequest{Passwd: []byte("1234567890")} + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if _, err := encodePacket(buf, st); err != nil { + b.Fatal(err) + } + } +} diff --git a/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/util.go b/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/util.go index 0763c9a978..598e3df77e 100644 --- a/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/util.go +++ b/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/util.go @@ -14,7 +14,7 @@ // panic(err) // } // defer terminal.Restore(0, oldState) -package terminal +package terminal // import "golang.org/x/crypto/ssh/terminal" import ( "io" diff --git a/Godeps/_workspace/src/golang.org/x/net/context/context.go b/Godeps/_workspace/src/golang.org/x/net/context/context.go index ef2f3e86fe..e7ee376c47 100644 --- a/Godeps/_workspace/src/golang.org/x/net/context/context.go +++ b/Godeps/_workspace/src/golang.org/x/net/context/context.go @@ -34,7 +34,7 @@ // // See http://blog.golang.org/context for example code for a server that uses // Contexts. -package context +package context // import "golang.org/x/net/context" import ( "errors" diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/README.md b/Godeps/_workspace/src/golang.org/x/oauth2/README.md index a5afeca221..0d5141733f 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/README.md +++ b/Godeps/_workspace/src/golang.org/x/oauth2/README.md @@ -43,7 +43,7 @@ with the `oauth2` package. "golang.org/x/oauth2" "golang.org/x/oauth2/google" newappengine "google.golang.org/appengine" - newurlftech "google.golang.org/urlfetch" + newurlfetch "google.golang.org/appengine/urlfetch" "appengine" ) diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/clientcredentials/clientcredentials.go b/Godeps/_workspace/src/golang.org/x/oauth2/clientcredentials/clientcredentials.go index 452fb8c124..baebced2ae 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/clientcredentials/clientcredentials.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/clientcredentials/clientcredentials.go @@ -11,7 +11,7 @@ // server. // // See http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.4 -package clientcredentials +package clientcredentials // import "golang.org/x/oauth2/clientcredentials" import ( "net/http" diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/facebook/facebook.go b/Godeps/_workspace/src/golang.org/x/oauth2/facebook/facebook.go index 9c816ff805..962e86b0eb 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/facebook/facebook.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/facebook/facebook.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Package facebook provides constants for using OAuth2 to access Facebook. -package facebook +package facebook // import "golang.org/x/oauth2/facebook" import ( "golang.org/x/oauth2" diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/github/github.go b/Godeps/_workspace/src/golang.org/x/oauth2/github/github.go index 82ca623dd1..1648cb58da 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/github/github.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/github/github.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Package github provides constants for using OAuth2 to access Github. -package github +package github // import "golang.org/x/oauth2/github" import ( "golang.org/x/oauth2" diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/google/google.go b/Godeps/_workspace/src/golang.org/x/oauth2/google/google.go index 2077d9866f..74aa7d9119 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/google/google.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/google/google.go @@ -12,7 +12,7 @@ // https://developers.google.com/accounts/docs/OAuth2 // and // https://developers.google.com/accounts/docs/application-default-credentials. -package google +package google // import "golang.org/x/oauth2/google" import ( "encoding/json" diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/internal/token.go b/Godeps/_workspace/src/golang.org/x/oauth2/internal/token.go index 727d957ff6..ea6716c98c 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/internal/token.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/internal/token.go @@ -108,6 +108,7 @@ var brokenAuthHeaderProviders = []string{ "https://www.strava.com/oauth/", "https://app.box.com/", "https://test-sandbox.auth.corp.google.com", + "https://user.gini.net/", } // providerAuthHeaderWorks reports whether the OAuth2 server identified by the tokenURL diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/jws/jws.go b/Godeps/_workspace/src/golang.org/x/oauth2/jws/jws.go index 396b3fac82..362323c4e7 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/jws/jws.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/jws/jws.go @@ -4,7 +4,7 @@ // Package jws provides encoding and decoding utilities for // signed JWS messages. -package jws +package jws // import "golang.org/x/oauth2/jws" import ( "bytes" diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/linkedin/linkedin.go b/Godeps/_workspace/src/golang.org/x/oauth2/linkedin/linkedin.go index d93fded6ad..de91d5b940 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/linkedin/linkedin.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/linkedin/linkedin.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Package linkedin provides constants for using OAuth2 to access LinkedIn. -package linkedin +package linkedin // import "golang.org/x/oauth2/linkedin" import ( "golang.org/x/oauth2" diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/oauth2.go b/Godeps/_workspace/src/golang.org/x/oauth2/oauth2.go index 031b9d00cb..cca8b18030 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/oauth2.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/oauth2.go @@ -5,7 +5,7 @@ // Package oauth2 provides support for making // OAuth2 authorized and authenticated HTTP requests. // It can additionally grant authorization with Bearer JWT. -package oauth2 +package oauth2 // import "golang.org/x/oauth2" import ( "bytes" @@ -253,6 +253,22 @@ func (s *reuseTokenSource) Token() (*Token, error) { return t, nil } +// StaticTokenSource returns a TokenSource that always returns the same token. +// Because the provided token t is never refreshed, StaticTokenSource is only +// useful for tokens that never expire. +func StaticTokenSource(t *Token) TokenSource { + return staticTokenSource{t} +} + +// staticTokenSource is a TokenSource that always returns the same Token. +type staticTokenSource struct { + t *Token +} + +func (s staticTokenSource) Token() (*Token, error) { + return s.t, nil +} + // HTTPClient is the context key to use with golang.org/x/net/context's // WithValue function to associate an *http.Client value with a context. var HTTPClient internal.ContextKey diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/odnoklassniki/odnoklassniki.go b/Godeps/_workspace/src/golang.org/x/oauth2/odnoklassniki/odnoklassniki.go index f0b66f97de..2f7a9621e4 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/odnoklassniki/odnoklassniki.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/odnoklassniki/odnoklassniki.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Package odnoklassniki provides constants for using OAuth2 to access Odnoklassniki. -package odnoklassniki +package odnoklassniki // import "golang.org/x/oauth2/odnoklassniki" import ( "golang.org/x/oauth2" diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/paypal/paypal.go b/Godeps/_workspace/src/golang.org/x/oauth2/paypal/paypal.go index a99366b6e2..baeaa23727 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/paypal/paypal.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/paypal/paypal.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Package paypal provides constants for using OAuth2 to access PayPal. -package paypal +package paypal // import "golang.org/x/oauth2/paypal" import ( "golang.org/x/oauth2" diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/token.go b/Godeps/_workspace/src/golang.org/x/oauth2/token.go index 252cfc7d94..ebbdddbdce 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/token.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/token.go @@ -7,6 +7,7 @@ package oauth2 import ( "net/http" "net/url" + "strings" "time" "golang.org/x/net/context" @@ -53,6 +54,15 @@ type Token struct { // Type returns t.TokenType if non-empty, else "Bearer". func (t *Token) Type() string { + if strings.EqualFold(t.TokenType, "bearer") { + return "Bearer" + } + if strings.EqualFold(t.TokenType, "mac") { + return "MAC" + } + if strings.EqualFold(t.TokenType, "basic") { + return "Basic" + } if t.TokenType != "" { return t.TokenType } diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/transport_test.go b/Godeps/_workspace/src/golang.org/x/oauth2/transport_test.go index efb8232ac4..35cb25ed56 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/transport_test.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/transport_test.go @@ -32,6 +32,39 @@ func TestTransportTokenSource(t *testing.T) { client.Get(server.URL) } +// Test for case-sensitive token types, per https://github.com/golang/oauth2/issues/113 +func TestTransportTokenSourceTypes(t *testing.T) { + const val = "abc" + tests := []struct { + key string + val string + want string + }{ + {key: "bearer", val: val, want: "Bearer abc"}, + {key: "mac", val: val, want: "MAC abc"}, + {key: "basic", val: val, want: "Basic abc"}, + } + for _, tc := range tests { + ts := &tokenSource{ + token: &Token{ + AccessToken: tc.val, + TokenType: tc.key, + }, + } + tr := &Transport{ + Source: ts, + } + server := newMockServer(func(w http.ResponseWriter, r *http.Request) { + if got, want := r.Header.Get("Authorization"), tc.want; got != want { + t.Errorf("Authorization header (%q) = %q; want %q", val, got, want) + } + }) + defer server.Close() + client := http.Client{Transport: tr} + client.Get(server.URL) + } +} + func TestTokenValidNoAccessToken(t *testing.T) { token := &Token{} if token.Valid() { diff --git a/Godeps/_workspace/src/golang.org/x/oauth2/vk/vk.go b/Godeps/_workspace/src/golang.org/x/oauth2/vk/vk.go index 00e929357a..5acdeb18ff 100644 --- a/Godeps/_workspace/src/golang.org/x/oauth2/vk/vk.go +++ b/Godeps/_workspace/src/golang.org/x/oauth2/vk/vk.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Package vk provides constants for using OAuth2 to access VK.com. -package vk +package vk // import "golang.org/x/oauth2/vk" import ( "golang.org/x/oauth2" From 111856a00fe2a976c0814f519e18ed8bad3dc4b5 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 29 Jun 2015 15:11:35 -0700 Subject: [PATCH 12/19] vault: handle a panic while generating audit output --- vault/audit.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/vault/audit.go b/vault/audit.go index ad1a157558..9fd4f21d52 100644 --- a/vault/audit.go +++ b/vault/audit.go @@ -261,10 +261,16 @@ func (a *AuditBroker) IsRegistered(name string) bool { // LogRequest is used to ensure all the audit backends have an opportunity to // log the given request and that *at least one* succeeds. -func (a *AuditBroker) LogRequest(auth *logical.Auth, req *logical.Request) error { +func (a *AuditBroker) LogRequest(auth *logical.Auth, req *logical.Request) (reterr error) { defer metrics.MeasureSince([]string{"audit", "log_request"}, time.Now()) a.l.RLock() defer a.l.RUnlock() + defer func() { + if r := recover(); r != nil { + a.logger.Printf("[ERR] audit: panic logging: auth: %#v, req: %#v: %v", auth, req, r) + reterr = fmt.Errorf("panic generating audit log") + } + }() // Ensure at least one backend logs anyLogged := false @@ -287,10 +293,16 @@ func (a *AuditBroker) LogRequest(auth *logical.Auth, req *logical.Request) error // LogResponse is used to ensure all the audit backends have an opportunity to // log the given response and that *at least one* succeeds. func (a *AuditBroker) LogResponse(auth *logical.Auth, req *logical.Request, - resp *logical.Response, err error) error { + resp *logical.Response, err error) (reterr error) { defer metrics.MeasureSince([]string{"audit", "log_response"}, time.Now()) a.l.RLock() defer a.l.RUnlock() + defer func() { + if r := recover(); r != nil { + a.logger.Printf("[ERR] audit: panic logging: auth: %#v, req: %#v, resp: %#v: %v", auth, req, resp, r) + reterr = fmt.Errorf("panic generating audit log") + } + }() // Ensure at least one backend logs anyLogged := false From 1a085c1c89415d18bad1e52e0968873a5ed5d926 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 29 Jun 2015 15:27:28 -0700 Subject: [PATCH 13/19] vault: cleanups for the audit log changes --- audit/format_json.go | 35 ++++++++++++++++++++++------------- http/logical.go | 9 +++++---- vault/core.go | 5 ++--- vault/rollback.go | 1 - 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/audit/format_json.go b/audit/format_json.go index afa7e961d5..423242696e 100644 --- a/audit/format_json.go +++ b/audit/format_json.go @@ -5,7 +5,6 @@ import ( "io" "github.com/hashicorp/vault/logical" - "errors" ) // FormatJSON is a Formatter implementation that structures data into @@ -22,15 +21,16 @@ func (f *FormatJSON) FormatRequest( if auth == nil { auth = new(logical.Auth) } - if err == nil { - err = errors.New("") + var errString string + if err != nil { + errString = err.Error() } // Encode! enc := json.NewEncoder(w) return enc.Encode(&JSONRequestEntry{ - Type: "request", - Error: err.Error(), + Type: "request", + Error: errString, Auth: JSONAuth{ DisplayName: auth.DisplayName, @@ -42,7 +42,7 @@ func (f *FormatJSON) FormatRequest( Operation: req.Operation, Path: req.Path, Data: req.Data, - RemoteAddr: req.Connection.RemoteAddr, + RemoteAddr: getRemoteAddr(req), }, }) } @@ -60,8 +60,9 @@ func (f *FormatJSON) FormatResponse( if resp == nil { resp = new(logical.Response) } - if err == nil { - err = errors.New("") + var errString string + if err != nil { + errString = err.Error() } var respAuth *JSONAuth @@ -84,8 +85,8 @@ func (f *FormatJSON) FormatResponse( // Encode! enc := json.NewEncoder(w) return enc.Encode(&JSONResponseEntry{ - Type: "response", - Error: err.Error(), + Type: "response", + Error: errString, Auth: JSONAuth{ Policies: auth.Policies, @@ -96,7 +97,7 @@ func (f *FormatJSON) FormatResponse( Operation: req.Operation, Path: req.Path, Data: req.Data, - RemoteAddr: req.Connection.RemoteAddr, + RemoteAddr: getRemoteAddr(req), }, Response: JSONResponse{ @@ -133,8 +134,8 @@ type JSONRequest struct { } type JSONResponse struct { - Auth *JSONAuth `json:"auth,omitempty"` - Secret *JSONSecret `json:"secret,emitempty"` + Auth *JSONAuth `json:"auth,omitempty"` + Secret *JSONSecret `json:"secret,emitempty"` Data map[string]interface{} `json:"data"` Redirect string `json:"redirect"` } @@ -149,3 +150,11 @@ type JSONAuth struct { type JSONSecret struct { LeaseID string `json:"lease_id"` } + +// getRemoteAddr safely gets the remote address avoiding a nil pointer +func getRemoteAddr(req *logical.Request) string { + if req != nil && req.Connection != nil { + return req.Connection.RemoteAddr + } + return "" +} diff --git a/http/logical.go b/http/logical.go index a94edc372c..0f0b74b960 100644 --- a/http/logical.go +++ b/http/logical.go @@ -58,9 +58,9 @@ func handleLogical(core *vault.Core) http.Handler { // as well in case this is an authentication request that requires // it. Vault core handles stripping this if we need to. resp, ok := request(core, w, r, requestAuth(r, &logical.Request{ - Operation: op, - Path: path, - Data: req, + Operation: op, + Path: path, + Data: req, Connection: getConnection(r), })) if !ok { @@ -188,6 +188,8 @@ func respondRaw(w http.ResponseWriter, r *http.Request, path string, resp *logic w.Write(body) } +// getConnection is used to format the connection information for +// attaching to a logical request func getConnection(r *http.Request) (connection *logical.Connection) { var remoteAddr string @@ -200,7 +202,6 @@ func getConnection(r *http.Request) (connection *logical.Connection) { RemoteAddr: remoteAddr, ConnState: r.TLS, } - return } diff --git a/vault/core.go b/vault/core.go index d7ffe0b940..c97510b75f 100644 --- a/vault/core.go +++ b/vault/core.go @@ -355,7 +355,6 @@ func (c *Core) HandleRequest(req *logical.Request) (resp *logical.Response, err } var auth *logical.Auth - if c.router.LoginPath(req.Path) { resp, auth, err = c.handleLoginRequest(req) } else { @@ -410,7 +409,7 @@ func (c *Core) handleRequest(req *logical.Request) (*logical.Response, *logical. req.DisplayName = auth.DisplayName // Create an audit trail of the request - if err := c.auditBroker.LogRequest(auth, req, errors.New("")); err != nil { + if err := c.auditBroker.LogRequest(auth, req, nil); err != nil { c.logger.Printf("[ERR] core: failed to audit request (%#v): %v", req, err) return nil, auth, ErrInternalError @@ -482,7 +481,7 @@ func (c *Core) handleLoginRequest(req *logical.Request) (*logical.Response, *log defer metrics.MeasureSince([]string{"core", "handle_login_request"}, time.Now()) // Create an audit trail of the request, auth is not available on login requests - if err := c.auditBroker.LogRequest(nil, req, errors.New("")); err != nil { + if err := c.auditBroker.LogRequest(nil, req, nil); err != nil { c.logger.Printf("[ERR] core: failed to audit request (%#v): %v", req, err) return nil, nil, ErrInternalError diff --git a/vault/rollback.go b/vault/rollback.go index ac6391c27b..317e7c4aaa 100644 --- a/vault/rollback.go +++ b/vault/rollback.go @@ -140,7 +140,6 @@ func (m *RollbackManager) attemptRollback(path string, rs *rollbackState) (err e req := &logical.Request{ Operation: logical.RollbackOperation, Path: path, - Connection: &logical.Connection{}, } _, err = m.router.Route(req) From dfd75d7d79095529f96aa0e94004245c6154bef5 Mon Sep 17 00:00:00 2001 From: Christian Svensson Date: Sat, 20 Jun 2015 17:11:08 +0100 Subject: [PATCH 14/19] Allow almost all leagal LDAP names to be used Implement LDAP escaping according to RFC 4514 to allow complex LDAP usernames to be used. Leaving ASN BER encoded values unsupported for now. From 92d483004d8cefa256daf384ce025d9c92760be7 Mon Sep 17 00:00:00 2001 From: Christian Svensson Date: Sat, 20 Jun 2015 18:16:09 +0100 Subject: [PATCH 15/19] Use go-ldap/ldap's ParseDN to extract group name from DN From 1bd1fac70f6ba3c1346468f535f3bbbd21a6f569 Mon Sep 17 00:00:00 2001 From: Christian Svensson Date: Sat, 20 Jun 2015 18:39:08 +0100 Subject: [PATCH 16/19] Pass ServerName for LDAPS TLS connection validation From 8f53a187df408fab2fdf3a57ba4948a750de13e5 Mon Sep 17 00:00:00 2001 From: Christian Svensson Date: Sat, 20 Jun 2015 20:37:27 +0100 Subject: [PATCH 17/19] Update Godeps for go-ldap/ldap --- Godeps/Godeps.json | 5 +++++ .../src/github.com/go-ldap/ldap/conn.go | 1 + .../src/github.com/go-ldap/ldap/todo | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/todo diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 4757fa2de1..dd19cea36b 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -67,6 +67,11 @@ "Comment": "v1-14-g406aa05", "Rev": "406aa05eb8272fb8aa201e410afa6f9fdcb2bf68" }, + { + "ImportPath": "github.com/go-ldap/ldap", + "Comment": "v1-8-g4d41e0d", + "Rev": "4d41e0d546efa36b1500653d519d1b39fc007dbd" + }, { "ImportPath": "github.com/go-sql-driver/mysql", "Comment": "v1.2-112-gfb72997", diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go index a3b0fa4e22..e633473537 100644 --- a/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go @@ -7,6 +7,7 @@ package ldap import ( "crypto/tls" "errors" + "flag" "fmt" "gopkg.in/asn1-ber.v1" "log" diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/todo b/Godeps/_workspace/src/github.com/go-ldap/ldap/todo new file mode 100644 index 0000000000..4a7be3d26b --- /dev/null +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/todo @@ -0,0 +1,19 @@ +"" => [] +sep is always , +multivalue is + + +type=value + +type is numericoid or keystring: + keystring = leadkeychar *keychar + leadkeychar = ALPHA + keychar = ALPHA / DIGIT / HYPHEN + numericoid = number 1*( DOT number ) + +example oid: +givenname = 2.5.4.42 + + If the AttributeType is of the dotted-decimal form, the + AttributeValue is represented by an number sign ('#' U+0023) + character followed by the hexadecimal encoding of each of the octets + of the BER encoding of the X.500 AttributeValue. From 4776825e2074f2f261cf21d6ce85f3843c4633be Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 29 Jun 2015 16:44:02 -0700 Subject: [PATCH 18/19] Updating godep --- Godeps/Godeps.json | 4 ++-- .../src/github.com/go-ldap/ldap/conn.go | 1 - .../src/github.com/go-ldap/ldap/todo | 19 ------------------- 3 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 Godeps/_workspace/src/github.com/go-ldap/ldap/todo diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index dd19cea36b..3b0d52184d 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -69,8 +69,8 @@ }, { "ImportPath": "github.com/go-ldap/ldap", - "Comment": "v1-8-g4d41e0d", - "Rev": "4d41e0d546efa36b1500653d519d1b39fc007dbd" + "Comment": "v1-14-g406aa05", + "Rev": "406aa05eb8272fb8aa201e410afa6f9fdcb2bf68" }, { "ImportPath": "github.com/go-sql-driver/mysql", diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go b/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go index e633473537..a3b0fa4e22 100644 --- a/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go +++ b/Godeps/_workspace/src/github.com/go-ldap/ldap/conn.go @@ -7,7 +7,6 @@ package ldap import ( "crypto/tls" "errors" - "flag" "fmt" "gopkg.in/asn1-ber.v1" "log" diff --git a/Godeps/_workspace/src/github.com/go-ldap/ldap/todo b/Godeps/_workspace/src/github.com/go-ldap/ldap/todo deleted file mode 100644 index 4a7be3d26b..0000000000 --- a/Godeps/_workspace/src/github.com/go-ldap/ldap/todo +++ /dev/null @@ -1,19 +0,0 @@ -"" => [] -sep is always , -multivalue is + - -type=value - -type is numericoid or keystring: - keystring = leadkeychar *keychar - leadkeychar = ALPHA - keychar = ALPHA / DIGIT / HYPHEN - numericoid = number 1*( DOT number ) - -example oid: -givenname = 2.5.4.42 - - If the AttributeType is of the dotted-decimal form, the - AttributeValue is represented by an number sign ('#' U+0023) - character followed by the hexadecimal encoding of each of the octets - of the BER encoding of the X.500 AttributeValue. From b49683a40b3b3f8fceb911e8b04e1bf0132f7b16 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 29 Jun 2015 17:16:17 -0700 Subject: [PATCH 19/19] audit: fixing panic caused by tls connection state. Fixes #322 --- builtin/audit/file/backend.go | 20 ++++++++++++++++++++ builtin/audit/syslog/backend.go | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/builtin/audit/file/backend.go b/builtin/audit/file/backend.go index d99010daba..9c95dd3ea8 100644 --- a/builtin/audit/file/backend.go +++ b/builtin/audit/file/backend.go @@ -53,6 +53,16 @@ func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request, outerErr return err } if !b.LogRaw { + // Before we copy the structure we must nil out some data + // otherwise we will cause reflection to panic and die + if req.Connection != nil && req.Connection.ConnState != nil { + origState := req.Connection.ConnState + req.Connection.ConnState = nil + defer func() { + req.Connection.ConnState = origState + }() + } + // Copy the structures cp, err := copystructure.Copy(auth) if err != nil { @@ -88,6 +98,16 @@ func (b *Backend) LogResponse( return err } if !b.LogRaw { + // Before we copy the structure we must nil out some data + // otherwise we will cause reflection to panic and die + if req.Connection != nil && req.Connection.ConnState != nil { + origState := req.Connection.ConnState + req.Connection.ConnState = nil + defer func() { + req.Connection.ConnState = origState + }() + } + // Copy the structure cp, err := copystructure.Copy(auth) if err != nil { diff --git a/builtin/audit/syslog/backend.go b/builtin/audit/syslog/backend.go index 79f6eb740f..cf3c6ceaa0 100644 --- a/builtin/audit/syslog/backend.go +++ b/builtin/audit/syslog/backend.go @@ -54,6 +54,16 @@ type Backend struct { func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request, outerErr error) error { if !b.logRaw { + // Before we copy the structure we must nil out some data + // otherwise we will cause reflection to panic and die + if req.Connection != nil && req.Connection.ConnState != nil { + origState := req.Connection.ConnState + req.Connection.ConnState = nil + defer func() { + req.Connection.ConnState = origState + }() + } + // Copy the structures cp, err := copystructure.Copy(auth) if err != nil { @@ -91,6 +101,16 @@ func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request, outerErr func (b *Backend) LogResponse(auth *logical.Auth, req *logical.Request, resp *logical.Response, err error) error { if !b.logRaw { + // Before we copy the structure we must nil out some data + // otherwise we will cause reflection to panic and die + if req.Connection != nil && req.Connection.ConnState != nil { + origState := req.Connection.ConnState + req.Connection.ConnState = nil + defer func() { + req.Connection.ConnState = origState + }() + } + // Copy the structure cp, err := copystructure.Copy(auth) if err != nil {