mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
avoid data convertion during encodig
This commit is contained in:
+2
-2
@@ -68,8 +68,8 @@ func (g *Generator) genTypeDecoder(t reflect.Type, out string, tags fieldTags, i
|
||||
|
||||
unmarshalerIface = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
|
||||
if reflect.PtrTo(t).Implements(unmarshalerIface) {
|
||||
fmt.Fprintln(g.out, ws+"if data := in.UnsafeString(); in.Ok() {")
|
||||
fmt.Fprintln(g.out, ws+" in.AddError( ("+out+").UnmarshalText([]byte(data)) )")
|
||||
fmt.Fprintln(g.out, ws+"if data := in.UnsafeBytes(); in.Ok() {")
|
||||
fmt.Fprintln(g.out, ws+" in.AddError( ("+out+").UnmarshalText(data) )")
|
||||
fmt.Fprintln(g.out, ws+"}")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -618,6 +618,12 @@ func (r *Lexer) UnsafeString() string {
|
||||
return ret
|
||||
}
|
||||
|
||||
// UnsafeBytes returns the byte slice if the token is a string literal.
|
||||
func (r *Lexer) UnsafeBytes() []byte {
|
||||
_, ret := r.unsafeString()
|
||||
return ret
|
||||
}
|
||||
|
||||
// String reads a string literal.
|
||||
func (r *Lexer) String() string {
|
||||
if r.token.kind == tokenUndef && r.Ok() {
|
||||
|
||||
Reference in New Issue
Block a user