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 {
103func (t readerSizeSyncliteral) pack(c *conn) string {
104 buf, err := io.ReadAll(t.r)
112 return fmt.Sprintf("%s{%d}\r\n", lit, t.size) + string(buf)
115func (t readerSizeSyncliteral) writeTo(c *conn, w io.Writer) {
120 fmt.Fprintf(w, "%s{%d}\r\n", lit, t.size)
121 defer c.xtrace(mlog.LevelTracedata)()
122 if _, err := io.Copy(w, io.LimitReader(t.r, t.size)); err != nil {
127// data from reader without known size.
128type readerSyncliteral struct {
132func (t readerSyncliteral) pack(c *conn) string {
133 buf, err := io.ReadAll(t.r)
137 return fmt.Sprintf("{%d}\r\n", len(buf)) + string(buf)
140func (t readerSyncliteral) writeTo(c *conn, w io.Writer) {
141 buf, err := io.ReadAll(t.r)
145 fmt.Fprintf(w, "{%d}\r\n", len(buf))
146 defer c.xtrace(mlog.LevelTracedata)()
147 _, err = w.Write(buf)
153// list with tokens space-separated
154type listspace []token
156func (t listspace) pack(c *conn) string {
158 for i, e := range t {
168func (t listspace) writeTo(c *conn, w io.Writer) {
170 for i, e := range t {
179// Concatenated tokens, no spaces or list syntax.
182func (t concat) pack(c *conn) string {
184 for _, e := range t {
190func (t concat) writeTo(c *conn, w io.Writer) {
191 for _, e := range t {
198func (t astring) pack(c *conn) string {
200 return string0(t).pack(c)
203 for _, ch := range t {
204 for _, x := range atomChar {
209 return string0(t).pack(c)
214func (t astring) writeTo(c *conn, w io.Writer) {
215 w.Write([]byte(t.pack(c)))
220func (t number) pack(c *conn) string {
221 return fmt.Sprintf("%d", t)
224func (t number) writeTo(c *conn, w io.Writer) {
225 w.Write([]byte(t.pack(c)))