summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mailru
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/mailru')
-rw-r--r--vendor/github.com/mailru/easyjson/.gitignore1
-rw-r--r--vendor/github.com/mailru/easyjson/Makefile4
-rw-r--r--vendor/github.com/mailru/easyjson/helpers.go10
-rw-r--r--vendor/github.com/mailru/easyjson/jwriter/writer.go43
-rw-r--r--vendor/github.com/mailru/easyjson/unknown_fields.go34
5 files changed, 79 insertions, 13 deletions
diff --git a/vendor/github.com/mailru/easyjson/.gitignore b/vendor/github.com/mailru/easyjson/.gitignore
index 26156fb4b4..fbfaf7a3f4 100644
--- a/vendor/github.com/mailru/easyjson/.gitignore
+++ b/vendor/github.com/mailru/easyjson/.gitignore
@@ -3,3 +3,4 @@
*.iml
.idea
*.swp
+bin/*
diff --git a/vendor/github.com/mailru/easyjson/Makefile b/vendor/github.com/mailru/easyjson/Makefile
index 7b9ac94535..80449f0d27 100644
--- a/vendor/github.com/mailru/easyjson/Makefile
+++ b/vendor/github.com/mailru/easyjson/Makefile
@@ -18,10 +18,13 @@ generate: build
./tests/custom_map_key_type.go \
./tests/embedded_type.go \
./tests/reference_to_pointer.go \
+ ./tests/html.go \
+ ./tests/unknown_fields.go \
bin/easyjson -all ./tests/data.go
bin/easyjson -all ./tests/nothing.go
bin/easyjson -all ./tests/errors.go
+ bin/easyjson -all ./tests/html.go
bin/easyjson -snake_case ./tests/snake.go
bin/easyjson -omit_empty ./tests/omitempty.go
bin/easyjson -build_tags=use_easyjson ./benchmark/data.go
@@ -32,6 +35,7 @@ generate: build
bin/easyjson ./tests/reference_to_pointer.go
bin/easyjson ./tests/key_marshaler_map.go
bin/easyjson -disallow_unknown_fields ./tests/disallow_unknown.go
+ bin/easyjson ./tests/unknown_fields.go
test: generate
go test \
diff --git a/vendor/github.com/mailru/easyjson/helpers.go b/vendor/github.com/mailru/easyjson/helpers.go
index b86b87d228..04ac635628 100644
--- a/vendor/github.com/mailru/easyjson/helpers.go
+++ b/vendor/github.com/mailru/easyjson/helpers.go
@@ -26,6 +26,16 @@ type Optional interface {
IsDefined() bool
}
+// UnknownsUnmarshaler provides a method to unmarshal unknown struct fileds and save them as you want
+type UnknownsUnmarshaler interface {
+ UnmarshalUnknown(in *jlexer.Lexer, key string)
+}
+
+// UnknownsMarshaler provides a method to write additional struct fields
+type UnknownsMarshaler interface {
+ MarshalUnknowns(w *jwriter.Writer, first bool)
+}
+
// Marshal returns data as a single byte slice. Method is suboptimal as the data is likely to be copied
// from a chain of smaller chunks.
func Marshal(v Marshaler) ([]byte, error) {
diff --git a/vendor/github.com/mailru/easyjson/jwriter/writer.go b/vendor/github.com/mailru/easyjson/jwriter/writer.go
index b9ed7ccaa8..eb8547ccc2 100644
--- a/vendor/github.com/mailru/easyjson/jwriter/writer.go
+++ b/vendor/github.com/mailru/easyjson/jwriter/writer.go
@@ -270,16 +270,25 @@ func (w *Writer) Bool(v bool) {
const chars = "0123456789abcdef"
-func isNotEscapedSingleChar(c byte, escapeHTML bool) bool {
- // Note: might make sense to use a table if there are more chars to escape. With 4 chars
- // it benchmarks the same.
- if escapeHTML {
- return c != '<' && c != '>' && c != '&' && c != '\\' && c != '"' && c >= 0x20 && c < utf8.RuneSelf
- } else {
- return c != '\\' && c != '"' && c >= 0x20 && c < utf8.RuneSelf
+func getTable(falseValues ...int) [128]bool {
+ table := [128]bool{}
+
+ for i := 0; i < 128; i++ {
+ table[i] = true
+ }
+
+ for _, v := range falseValues {
+ table[v] = false
}
+
+ return table
}
+var (
+ htmlEscapeTable = getTable(0, 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, 26, 27, 28, 29, 30, 31, '"', '&', '<', '>', '\\')
+ htmlNoEscapeTable = getTable(0, 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, 26, 27, 28, 29, 30, 31, '"', '\\')
+)
+
func (w *Writer) String(s string) {
w.Buffer.AppendByte('"')
@@ -288,15 +297,23 @@ func (w *Writer) String(s string) {
p := 0 // last non-escape symbol
+ var escapeTable [128]bool
+ if w.NoEscapeHTML {
+ escapeTable = htmlNoEscapeTable
+ } else {
+ escapeTable = htmlEscapeTable
+ }
+
for i := 0; i < len(s); {
c := s[i]
- if isNotEscapedSingleChar(c, !w.NoEscapeHTML) {
- // single-width character, no escaping is required
- i++
- continue
- } else if c < utf8.RuneSelf {
- // single-with character, need to escape
+ if c < utf8.RuneSelf {
+ if escapeTable[c] {
+ // single-width character, no escaping is required
+ i++
+ continue
+ }
+
w.Buffer.AppendString(s[p:i])
switch c {
case '\t':
diff --git a/vendor/github.com/mailru/easyjson/unknown_fields.go b/vendor/github.com/mailru/easyjson/unknown_fields.go
new file mode 100644
index 0000000000..6cfdf8300b
--- /dev/null
+++ b/vendor/github.com/mailru/easyjson/unknown_fields.go
@@ -0,0 +1,34 @@
+package easyjson
+
+import (
+ json "encoding/json"
+
+ jlexer "github.com/mailru/easyjson/jlexer"
+ "github.com/mailru/easyjson/jwriter"
+)
+
+// UnknownFieldsProxy implemets UnknownsUnmarshaler and UnknownsMarshaler
+// use it as embedded field in your structure to parse and then serialize unknown struct fields
+type UnknownFieldsProxy struct {
+ unknownFields map[string]interface{}
+}
+
+func (s *UnknownFieldsProxy) UnmarshalUnknown(in *jlexer.Lexer, key string) {
+ if s.unknownFields == nil {
+ s.unknownFields = make(map[string]interface{}, 1)
+ }
+ s.unknownFields[key] = in.Interface()
+}
+
+func (s UnknownFieldsProxy) MarshalUnknowns(out *jwriter.Writer, first bool) {
+ for key, val := range s.unknownFields {
+ if first {
+ first = false
+ } else {
+ out.RawByte(',')
+ }
+ out.String(string(key))
+ out.RawByte(':')
+ out.Raw(json.Marshal(val))
+ }
+}