7	"github.com/mjl-/mox/mlog"
 
12	xwriteTo(c *conn, xw io.Writer) // Writes to xw panic on error.
 
17func (t bare) pack(c *conn) string {
 
21func (t bare) xwriteTo(c *conn, xw io.Writer) {
 
22	xw.Write([]byte(t.pack(c)))
 
29func (t niltoken) pack(c *conn) string {
 
33func (t niltoken) xwriteTo(c *conn, xw io.Writer) {
 
34	xw.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) xwriteTo(c *conn, xw io.Writer) {
 
64	xw.Write([]byte(t.pack(c)))
 
69func (t dquote) pack(c *conn) string {
 
72		if c == '\\' || c == '"' {
 
81func (t dquote) xwriteTo(c *conn, xw io.Writer) {
 
82	xw.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) xwriteTo(c *conn, xw io.Writer) {
 
92	fmt.Fprintf(xw, "{%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) xwriteTo(c *conn, xw io.Writer) {
 
120	fmt.Fprintf(xw, "%s{%d}\r\n", lit, t.size)
 
121	defer c.xtracewrite(mlog.LevelTracedata)()
 
122	if _, err := io.Copy(xw, 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) xwriteTo(c *conn, xw io.Writer) {
 
141	buf, err := io.ReadAll(t.r)
 
145	fmt.Fprintf(xw, "{%d}\r\n", len(buf))
 
146	defer c.xtracewrite(mlog.LevelTracedata)()
 
150// list with tokens space-separated
 
151type listspace []token
 
153func (t listspace) pack(c *conn) string {
 
155	for i, e := range t {
 
165func (t listspace) xwriteTo(c *conn, xw io.Writer) {
 
167	for i, e := range t {
 
176// concatenate tokens space-separated
 
177type concatspace []token
 
179func (t concatspace) pack(c *conn) string {
 
181	for i, e := range t {
 
190func (t concatspace) xwriteTo(c *conn, xw io.Writer) {
 
191	for i, e := range t {
 
199// Concatenated tokens, no spaces or list syntax.
 
202func (t concat) pack(c *conn) string {
 
204	for _, e := range t {
 
210func (t concat) xwriteTo(c *conn, xw io.Writer) {
 
211	for _, e := range t {
 
218func (t astring) pack(c *conn) string {
 
220		return string0(t).pack(c)
 
223	for _, ch := range t {
 
224		for _, x := range atomChar {
 
229		return string0(t).pack(c)
 
234func (t astring) xwriteTo(c *conn, xw io.Writer) {
 
235	xw.Write([]byte(t.pack(c)))
 
238// mailbox with utf7 encoding if connection requires it, or utf8 otherwise.
 
241func (t mailboxt) pack(c *conn) string {
 
243	if !c.utf8strings() {
 
246	return astring(s).pack(c)
 
249func (t mailboxt) xwriteTo(c *conn, xw io.Writer) {
 
250	xw.Write([]byte(t.pack(c)))
 
255func (t number) pack(c *conn) string {
 
256	return fmt.Sprintf("%d", t)
 
259func (t number) xwriteTo(c *conn, xw io.Writer) {
 
260	xw.Write([]byte(t.pack(c)))