mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-30 21:30:16 +00:00 
			
		
		
		
	github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329
Used only by github.com/go-openapi/..., all expecting 60711f1a8329
This commit is contained in:
		
							
								
								
									
										79
									
								
								vendor/github.com/mailru/easyjson/jlexer/lexer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										79
									
								
								vendor/github.com/mailru/easyjson/jlexer/lexer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -6,6 +6,7 @@ package jlexer | ||||
|  | ||||
| import ( | ||||
| 	"encoding/base64" | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| @@ -239,7 +240,7 @@ func (r *Lexer) fetchNumber() { | ||||
|  | ||||
| // findStringLen tries to scan into the string literal for ending quote char to determine required size. | ||||
| // The size will be exact if no escapes are present and may be inexact if there are escaped chars. | ||||
| func findStringLen(data []byte) (hasEscapes bool, length int) { | ||||
| func findStringLen(data []byte) (isValid, hasEscapes bool, length int) { | ||||
| 	delta := 0 | ||||
|  | ||||
| 	for i := 0; i < len(data); i++ { | ||||
| @@ -251,11 +252,11 @@ func findStringLen(data []byte) (hasEscapes bool, length int) { | ||||
| 				delta++ | ||||
| 			} | ||||
| 		case '"': | ||||
| 			return (delta > 0), (i - delta) | ||||
| 			return true, (delta > 0), (i - delta) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return false, len(data) | ||||
| 	return false, false, len(data) | ||||
| } | ||||
|  | ||||
| // getu4 decodes \uXXXX from the beginning of s, returning the hex value, | ||||
| @@ -341,7 +342,12 @@ func (r *Lexer) fetchString() { | ||||
| 	r.pos++ | ||||
| 	data := r.Data[r.pos:] | ||||
|  | ||||
| 	hasEscapes, length := findStringLen(data) | ||||
| 	isValid, hasEscapes, length := findStringLen(data) | ||||
| 	if !isValid { | ||||
| 		r.pos += length | ||||
| 		r.errParse("unterminated string literal") | ||||
| 		return | ||||
| 	} | ||||
| 	if !hasEscapes { | ||||
| 		r.token.byteValue = data[:length] | ||||
| 		r.pos += length + 1 | ||||
| @@ -648,7 +654,7 @@ func (r *Lexer) Bytes() []byte { | ||||
| 		return nil | ||||
| 	} | ||||
| 	ret := make([]byte, base64.StdEncoding.DecodedLen(len(r.token.byteValue))) | ||||
| 	len, err := base64.StdEncoding.Decode(ret, r.token.byteValue) | ||||
| 	n, err := base64.StdEncoding.Decode(ret, r.token.byteValue) | ||||
| 	if err != nil { | ||||
| 		r.fatalError = &LexerError{ | ||||
| 			Reason: err.Error(), | ||||
| @@ -657,7 +663,7 @@ func (r *Lexer) Bytes() []byte { | ||||
| 	} | ||||
|  | ||||
| 	r.consume() | ||||
| 	return ret[:len] | ||||
| 	return ret[:n] | ||||
| } | ||||
|  | ||||
| // Bool reads a true or false boolean keyword. | ||||
| @@ -903,6 +909,10 @@ func (r *Lexer) UintStr() uint { | ||||
| 	return uint(r.Uint64Str()) | ||||
| } | ||||
|  | ||||
| func (r *Lexer) UintptrStr() uintptr { | ||||
| 	return uintptr(r.Uint64Str()) | ||||
| } | ||||
|  | ||||
| func (r *Lexer) Int8Str() int8 { | ||||
| 	s, b := r.unsafeString() | ||||
| 	if !r.Ok() { | ||||
| @@ -992,6 +1002,22 @@ func (r *Lexer) Float32() float32 { | ||||
| 	return float32(n) | ||||
| } | ||||
|  | ||||
| func (r *Lexer) Float32Str() float32 { | ||||
| 	s, b := r.unsafeString() | ||||
| 	if !r.Ok() { | ||||
| 		return 0 | ||||
| 	} | ||||
| 	n, err := strconv.ParseFloat(s, 32) | ||||
| 	if err != nil { | ||||
| 		r.addNonfatalError(&LexerError{ | ||||
| 			Offset: r.start, | ||||
| 			Reason: err.Error(), | ||||
| 			Data:   string(b), | ||||
| 		}) | ||||
| 	} | ||||
| 	return float32(n) | ||||
| } | ||||
|  | ||||
| func (r *Lexer) Float64() float64 { | ||||
| 	s := r.number() | ||||
| 	if !r.Ok() { | ||||
| @@ -1009,6 +1035,22 @@ func (r *Lexer) Float64() float64 { | ||||
| 	return n | ||||
| } | ||||
|  | ||||
| func (r *Lexer) Float64Str() float64 { | ||||
| 	s, b := r.unsafeString() | ||||
| 	if !r.Ok() { | ||||
| 		return 0 | ||||
| 	} | ||||
| 	n, err := strconv.ParseFloat(s, 64) | ||||
| 	if err != nil { | ||||
| 		r.addNonfatalError(&LexerError{ | ||||
| 			Offset: r.start, | ||||
| 			Reason: err.Error(), | ||||
| 			Data:   string(b), | ||||
| 		}) | ||||
| 	} | ||||
| 	return n | ||||
| } | ||||
|  | ||||
| func (r *Lexer) Error() error { | ||||
| 	return r.fatalError | ||||
| } | ||||
| @@ -1043,6 +1085,31 @@ func (r *Lexer) GetNonFatalErrors() []*LexerError { | ||||
| 	return r.multipleErrors | ||||
| } | ||||
|  | ||||
| // JsonNumber fetches and json.Number from 'encoding/json' package. | ||||
| // Both int, float or string, contains them are valid values | ||||
| func (r *Lexer) JsonNumber() json.Number { | ||||
| 	if r.token.kind == tokenUndef && r.Ok() { | ||||
| 		r.FetchToken() | ||||
| 	} | ||||
| 	if !r.Ok() { | ||||
| 		r.errInvalidToken("json.Number") | ||||
| 		return json.Number("") | ||||
| 	} | ||||
|  | ||||
| 	switch r.token.kind { | ||||
| 	case tokenString: | ||||
| 		return json.Number(r.String()) | ||||
| 	case tokenNumber: | ||||
| 		return json.Number(r.Raw()) | ||||
| 	case tokenNull: | ||||
| 		r.Null() | ||||
| 		return json.Number("") | ||||
| 	default: | ||||
| 		r.errSyntax() | ||||
| 		return json.Number("") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Interface fetches an interface{} analogous to the 'encoding/json' package. | ||||
| func (r *Lexer) Interface() interface{} { | ||||
| 	if r.token.kind == tokenUndef && r.Ok() { | ||||
|   | ||||
							
								
								
									
										70
									
								
								vendor/github.com/mailru/easyjson/jwriter/writer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										70
									
								
								vendor/github.com/mailru/easyjson/jwriter/writer.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -2,7 +2,6 @@ | ||||
| package jwriter | ||||
|  | ||||
| import ( | ||||
| 	"encoding/base64" | ||||
| 	"io" | ||||
| 	"strconv" | ||||
| 	"unicode/utf8" | ||||
| @@ -105,9 +104,7 @@ func (w *Writer) Base64Bytes(data []byte) { | ||||
| 		return | ||||
| 	} | ||||
| 	w.Buffer.AppendByte('"') | ||||
| 	dst := make([]byte, base64.StdEncoding.EncodedLen(len(data))) | ||||
| 	base64.StdEncoding.Encode(dst, data) | ||||
| 	w.Buffer.AppendBytes(dst) | ||||
| 	w.base64(data) | ||||
| 	w.Buffer.AppendByte('"') | ||||
| } | ||||
|  | ||||
| @@ -196,6 +193,13 @@ func (w *Writer) Uint64Str(n uint64) { | ||||
| 	w.Buffer.Buf = append(w.Buffer.Buf, '"') | ||||
| } | ||||
|  | ||||
| func (w *Writer) UintptrStr(n uintptr) { | ||||
| 	w.Buffer.EnsureSpace(20) | ||||
| 	w.Buffer.Buf = append(w.Buffer.Buf, '"') | ||||
| 	w.Buffer.Buf = strconv.AppendUint(w.Buffer.Buf, uint64(n), 10) | ||||
| 	w.Buffer.Buf = append(w.Buffer.Buf, '"') | ||||
| } | ||||
|  | ||||
| func (w *Writer) Int8Str(n int8) { | ||||
| 	w.Buffer.EnsureSpace(4) | ||||
| 	w.Buffer.Buf = append(w.Buffer.Buf, '"') | ||||
| @@ -236,11 +240,25 @@ func (w *Writer) Float32(n float32) { | ||||
| 	w.Buffer.Buf = strconv.AppendFloat(w.Buffer.Buf, float64(n), 'g', -1, 32) | ||||
| } | ||||
|  | ||||
| func (w *Writer) Float32Str(n float32) { | ||||
| 	w.Buffer.EnsureSpace(20) | ||||
| 	w.Buffer.Buf = append(w.Buffer.Buf, '"') | ||||
| 	w.Buffer.Buf = strconv.AppendFloat(w.Buffer.Buf, float64(n), 'g', -1, 32) | ||||
| 	w.Buffer.Buf = append(w.Buffer.Buf, '"') | ||||
| } | ||||
|  | ||||
| func (w *Writer) Float64(n float64) { | ||||
| 	w.Buffer.EnsureSpace(20) | ||||
| 	w.Buffer.Buf = strconv.AppendFloat(w.Buffer.Buf, n, 'g', -1, 64) | ||||
| } | ||||
|  | ||||
| func (w *Writer) Float64Str(n float64) { | ||||
| 	w.Buffer.EnsureSpace(20) | ||||
| 	w.Buffer.Buf = append(w.Buffer.Buf, '"') | ||||
| 	w.Buffer.Buf = strconv.AppendFloat(w.Buffer.Buf, float64(n), 'g', -1, 64) | ||||
| 	w.Buffer.Buf = append(w.Buffer.Buf, '"') | ||||
| } | ||||
|  | ||||
| func (w *Writer) Bool(v bool) { | ||||
| 	w.Buffer.EnsureSpace(5) | ||||
| 	if v { | ||||
| @@ -326,3 +344,47 @@ func (w *Writer) String(s string) { | ||||
| 	w.Buffer.AppendString(s[p:]) | ||||
| 	w.Buffer.AppendByte('"') | ||||
| } | ||||
|  | ||||
| const encode = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" | ||||
| const padChar = '=' | ||||
|  | ||||
| func (w *Writer) base64(in []byte) { | ||||
|  | ||||
| 	if len(in) == 0 { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	w.Buffer.EnsureSpace(((len(in)-1)/3 + 1) * 4) | ||||
|  | ||||
| 	si := 0 | ||||
| 	n := (len(in) / 3) * 3 | ||||
|  | ||||
| 	for si < n { | ||||
| 		// Convert 3x 8bit source bytes into 4 bytes | ||||
| 		val := uint(in[si+0])<<16 | uint(in[si+1])<<8 | uint(in[si+2]) | ||||
|  | ||||
| 		w.Buffer.Buf = append(w.Buffer.Buf, encode[val>>18&0x3F], encode[val>>12&0x3F], encode[val>>6&0x3F], encode[val&0x3F]) | ||||
|  | ||||
| 		si += 3 | ||||
| 	} | ||||
|  | ||||
| 	remain := len(in) - si | ||||
| 	if remain == 0 { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	// Add the remaining small block | ||||
| 	val := uint(in[si+0]) << 16 | ||||
| 	if remain == 2 { | ||||
| 		val |= uint(in[si+1]) << 8 | ||||
| 	} | ||||
|  | ||||
| 	w.Buffer.Buf = append(w.Buffer.Buf, encode[val>>18&0x3F], encode[val>>12&0x3F]) | ||||
|  | ||||
| 	switch remain { | ||||
| 	case 2: | ||||
| 		w.Buffer.Buf = append(w.Buffer.Buf, encode[val>>6&0x3F], byte(padChar)) | ||||
| 	case 1: | ||||
| 		w.Buffer.Buf = append(w.Buffer.Buf, byte(padChar), byte(padChar)) | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user