7 "github.com/mjl-/mox/mlog"
12 writeTo(c *conn, w io.Writer)
17func (t bare) pack(c *conn) string {
21func (t bare) writeTo(c *conn, w io.Writer) {
22 w.Write([]byte(t.pack(c)))
29func (t niltoken) pack(c *conn) string {
33func (t niltoken) writeTo(c *conn, w io.Writer) {
34 w.Write([]byte(t.pack(c)))
37func nilOrString(s string) token {
48func (t string0) pack(c *conn) string {
50 for _, ch := range t {
51 if ch == '\x00' || ch == '\r' || ch == '\n' || ch > 0x7f && !c.utf8strings() {
52 return syncliteral(t).pack(c)
54 if ch == '\\' || ch == '"' {
63func (t string0) writeTo(c *conn, w io.Writer) {
64 w.Write([]byte(t.pack(c)))
69func (t dquote) pack(c *conn) string {
72 if c == '\\' || c == '"' {
81func (t dquote) writeTo(c *conn, w io.Writer) {
82 w.Write([]byte(t.pack(c)))
85type syncliteral string
87func (t syncliteral) pack(c *conn) string {
88 return fmt.Sprintf("{%d}\r\n", len(t)) + string(t)
91func (t syncliteral) writeTo(c *conn, w io.Writer) {
92 fmt.Fprintf(w, "{%d}\r\n", len(t))
96// data from reader with known size.
97type readerSizeSyncliteral struct {
102func (t readerSizeSyncliteral) pack(c *conn) string {
103 buf, err := io.ReadAll(t.r)
107 return fmt.Sprintf("{%d}\r\n", t.size) + string(buf)
110func (t readerSizeSyncliteral) writeTo(c *conn, w io.Writer) {
111 fmt.Fprintf(w, "{%d}\r\n", t.size)
112 defer c.xtrace(mlog.LevelTracedata)()
113 if _, err := io.Copy(w, io.LimitReader(t.r, t.size)); err != nil {
118// data from reader without known size.
119type readerSyncliteral struct {
123func (t readerSyncliteral) pack(c *conn) string {
124 buf, err := io.ReadAll(t.r)
128 return fmt.Sprintf("{%d}\r\n", len(buf)) + string(buf)
131func (t readerSyncliteral) writeTo(c *conn, w io.Writer) {
132 buf, err := io.ReadAll(t.r)
136 fmt.Fprintf(w, "{%d}\r\n", len(buf))
137 defer c.xtrace(mlog.LevelTracedata)()
138 _, err = w.Write(buf)
144// list with tokens space-separated
145type listspace []token
147func (t listspace) pack(c *conn) string {
149 for i, e := range t {
159func (t listspace) writeTo(c *conn, w io.Writer) {
161 for i, e := range t {
170// Concatenated tokens, no spaces or list syntax.
173func (t concat) pack(c *conn) string {
175 for _, e := range t {
181func (t concat) writeTo(c *conn, w io.Writer) {
182 for _, e := range t {
189func (t astring) pack(c *conn) string {
191 return string0(t).pack(c)
194 for _, ch := range t {
195 for _, x := range atomChar {
200 return string0(t).pack(c)
205func (t astring) writeTo(c *conn, w io.Writer) {
206 w.Write([]byte(t.pack(c)))
211func (t number) pack(c *conn) string {
212 return fmt.Sprintf("%d", t)
215func (t number) writeTo(c *conn, w io.Writer) {
216 w.Write([]byte(t.pack(c)))