Skip to content

Commit

Permalink
objects: chan/map plain coding
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-cotton committed Aug 22, 2021
1 parent 85e87c2 commit 7905e91
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
9 changes: 9 additions & 0 deletions objects/chan.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package objects
import (
"io"

"github.com/go-air/pal/internal/plain"
"github.com/go-air/pal/memory"
)

Expand All @@ -40,6 +41,10 @@ func (c *Chan) Send(src memory.Loc, mm *memory.Model) {

func (c *Chan) PlainEncode(w io.Writer) error {
var err error
err = plain.Put(w, "c")
if err != nil {
return err
}
if err = c.object.plainEncode(w); err != nil {
return err
}
Expand All @@ -48,6 +53,10 @@ func (c *Chan) PlainEncode(w io.Writer) error {

func (c *Chan) PlainDecode(r io.Reader) error {
var err error
err = plain.Expect(r, "c")
if err != nil {
return err
}
p := &c.object
if err = p.plainDecode(r); err != nil {
return err
Expand Down
24 changes: 22 additions & 2 deletions objects/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package objects
import (
"io"

"github.com/go-air/pal/internal/plain"
"github.com/go-air/pal/memory"
)

Expand Down Expand Up @@ -45,9 +46,28 @@ func (m *Map) Lookup(dst memory.Loc, mm *memory.Model) {
}

func (m *Map) PlainEncode(w io.Writer) error {
return nil
var err error
err = plain.Put(w, "m")
if err != nil {
return err
}
err = m.object.plainEncode(w)
if err != nil {
return err
}
return plain.EncodeJoin(w, " ", m.key, m.elem)
}

func (m *Map) PlainDecode(r io.Reader) error {
return nil
var err error
err = plain.Expect(r, "m")
if err != nil {
return err
}
pobj := &m.object
err = pobj.plainDecode(r)
if err != nil {
return err
}
return plain.DecodeJoin(r, " ", &m.key, &m.elem)
}

0 comments on commit 7905e91

Please sign in to comment.