rename v1 to v01 for git tag

master
bel 2023-03-24 22:27:56 -06:00
parent 1ef3afd647
commit ed2b7b7cb9
4 changed files with 16 additions and 16 deletions

View File

@ -12,8 +12,8 @@ type Parser interface {
}
func New(ctx context.Context, src raw.Raw) Parser {
if os.Getenv("BUTTON_PARSER_V1") == "true" {
return NewV1(src)
if os.Getenv("BUTTON_PARSER_V01") == "true" {
return NewV01(src)
}
return NewPlaintext(src)
}

View File

@ -7,5 +7,5 @@ import (
func TestParser(t *testing.T) {
var _ button.Parser = button.Plaintext{}
var _ button.Parser = button.V1{}
var _ button.Parser = button.V01{}
}

View File

@ -10,10 +10,10 @@ import (
var debugging = os.Getenv("DEBUG") == "true"
type (
V1 struct {
V01 struct {
src raw.Raw
}
v1Msg struct {
v01Msg struct {
T int64
U string
Y string
@ -21,26 +21,26 @@ type (
}
)
func NewV1(src raw.Raw) V1 {
return V1{
func NewV01(src raw.Raw) V01 {
return V01{
src: src,
}
}
func (v1 V1) Close() {
v1.src.Close()
func (v01 V01) Close() {
v01.src.Close()
}
func (v1 V1) Read() []Button {
line := v1.src.Read()
var msg v1Msg
func (v01 V01) Read() []Button {
line := v01.src.Read()
var msg v01Msg
if err := json.Unmarshal(line, &msg); err != nil {
log.Printf("%v: %s", err, line)
}
return msg.buttons()
}
func (msg v1Msg) buttons() []Button {
func (msg v01Msg) buttons() []Button {
buttons := make([]Button, len(msg.Y)+len(msg.N))
for i := range msg.Y {
buttons[i] = Button{Char: msg.Y[i], Down: true}

View File

@ -5,11 +5,11 @@ import (
"testing"
)
func TestV1(t *testing.T) {
func TestV01(t *testing.T) {
src := constSrc(`{"T":1,"U":"bel","Y":"abc","N":"cde"}`)
t.Logf("(%v) %s", len(src), src.Read())
v1 := button.NewV1(src)
got := v1.Read()
v01 := button.NewV01(src)
got := v01.Read()
want := []button.Button{
{Down: true, Char: 'a'},
{Down: true, Char: 'b'},