2020-08-20 06:38:50 +03:00
|
|
|
package json
|
|
|
|
|
2020-11-19 06:47:42 +03:00
|
|
|
import "unsafe"
|
|
|
|
|
2020-08-20 06:38:50 +03:00
|
|
|
type wrappedStringDecoder struct {
|
|
|
|
dec decoder
|
|
|
|
stringDecoder *stringDecoder
|
2020-11-23 11:16:31 +03:00
|
|
|
structName string
|
|
|
|
fieldName string
|
2020-08-20 06:38:50 +03:00
|
|
|
}
|
|
|
|
|
2020-11-23 11:16:31 +03:00
|
|
|
func newWrappedStringDecoder(dec decoder, structName, fieldName string) *wrappedStringDecoder {
|
2020-08-20 06:38:50 +03:00
|
|
|
return &wrappedStringDecoder{
|
|
|
|
dec: dec,
|
2020-11-23 11:16:31 +03:00
|
|
|
stringDecoder: newStringDecoder(structName, fieldName),
|
|
|
|
structName: structName,
|
|
|
|
fieldName: fieldName,
|
2020-08-20 06:38:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 06:47:42 +03:00
|
|
|
func (d *wrappedStringDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
2020-08-20 06:38:50 +03:00
|
|
|
bytes, err := d.stringDecoder.decodeStreamByte(s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// save current state
|
|
|
|
buf := s.buf
|
|
|
|
length := s.length
|
|
|
|
cursor := s.cursor
|
|
|
|
|
|
|
|
// set content in string to stream
|
|
|
|
bytes = append(bytes, nul)
|
|
|
|
s.buf = bytes
|
|
|
|
s.cursor = 0
|
|
|
|
s.length = int64(len(bytes))
|
|
|
|
if err := d.dec.decodeStream(s, p); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// restore state
|
|
|
|
s.buf = buf
|
|
|
|
s.length = length
|
|
|
|
s.cursor = cursor
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 06:47:42 +03:00
|
|
|
func (d *wrappedStringDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
2020-08-20 06:38:50 +03:00
|
|
|
bytes, c, err := d.stringDecoder.decodeByte(buf, cursor)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
bytes = append(bytes, nul)
|
|
|
|
if _, err := d.dec.decode(bytes, 0, p); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return c, nil
|
|
|
|
}
|