add some omp data to serde

This commit is contained in:
2023-01-10 21:40:21 +01:00
parent 57bb9ba17c
commit 83debb7459
5 changed files with 193 additions and 3 deletions

View File

@ -6,4 +6,6 @@ type BPC struct {
func (s BPC) Init() {
}
}
// InitPatch()

View File

@ -4,6 +4,8 @@ type Header struct {
Data []byte
}
//TODO: It must be create dynamically for different kinds of entities (patch, maquette, etc)
func (h *Header) Init() {
h.Data = []byte(`; OM File Header - Saved 2022/12/29 14:43:16
; (6.19 :patc (om-make-point 10 10) (om-make-point 50 50) (om-make-point 500 400) "" 183 0 "2022/12/29 14:43:16" "2022/12/29 14:43:16")

View File

@ -1,6 +1,9 @@
package omp
import "bytes"
import (
"bytes"
"fmt"
)
type OMP struct {
Header Header
@ -12,12 +15,14 @@ func (s OMP) Build() []byte {
buff.Write(s.Header.GetData())
buff.Write(s.Data.GetIntro())
buff.Write(s.Data.GetLibFor())
buff.Write(s.Data.GetOMCurrentPersistent())
return buff.Bytes()
}
type Data struct {
Intro []byte
LibFor []byte
CurrentPersistent []byte
}
func (s *Data) GetIntro() []byte {
@ -35,3 +40,11 @@ func (s *Data) GetLibFor() []byte {
func (s *Data) SetLibFor() {
s.LibFor = []byte("(load-lib-for (quote nil))")
}
func (s *Data) SetOMCurrentPersistent(kind string, name string) {
s.CurrentPersistent = []byte(fmt.Sprintf("(setf *om-current-persistent* (%s \"%s\" (quote nil) (quote nil) nil 6.19))", kind, name))
}
func (s *Data) GetOMCurrentPersistent() []byte{
return s.CurrentPersistent
}

View File

@ -8,12 +8,13 @@ import (
const ompExample = `; OM File Header - Saved 2022/12/29 14:43:16
; (6.19 :patc (om-make-point 10 10) (om-make-point 50 50) (om-make-point 500 400) "" 183 0 "2022/12/29 14:43:16" "2022/12/29 14:43:16")
; End File Header
(in-package :om)(load-lib-for (quote nil))`
(in-package :om)(load-lib-for (quote nil))(setf *om-current-persistent* (om-load-patch1 "Test Patch" (quote nil) (quote nil) nil 6.19))`
func TestOmpBuilder(t *testing.T) {
header := &omp.OMP{}
header.Data.SetIntro()
header.Data.SetLibFor()
header.Data.SetOMCurrentPersistent("om-load-patch1", "Test Patch")
header.Header.Init()
str := string(header.Build())
if str != ompExample {