-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support MessagePack (in addition to CBOR)
With improvements to ARD XML encoding
- Loading branch information
Showing
20 changed files
with
312 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package ard | ||
|
||
// TODO: not very efficient | ||
|
||
func Canonicalize(value Value) (Value, error) { | ||
// Try CBOR first (faster), then YAML, and finally Compatible JSON | ||
// Try CBOR first (fastest), then Compatible JSON, and finally YAML | ||
if value, err := RoundtripCBOR(value); err == nil { | ||
return value, nil | ||
} else if value, err := RoundtripCompatibleJSON(value); err == nil { | ||
return value, nil | ||
} else { | ||
if value, err := RoundtripYAML(value); err == nil { | ||
return value, nil | ||
} else { | ||
return RoundtripCompatibleJSON(value) | ||
} | ||
return RoundtripYAML(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package ard | ||
|
||
import "github.com/tliron/yamlkeys" | ||
import ( | ||
"github.com/tliron/yamlkeys" | ||
) | ||
|
||
// | ||
// Node | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,39 @@ | ||
package ard | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/tliron/kutil/util" | ||
) | ||
|
||
func ValueToString(data Value) string { | ||
switch data_ := data.(type) { | ||
func ValueToString(value Value) string { | ||
switch value_ := value.(type) { | ||
case bool: | ||
return strconv.FormatBool(data_) | ||
return strconv.FormatBool(value_) | ||
case int64: | ||
return strconv.FormatInt(data_, 10) | ||
return strconv.FormatInt(value_, 10) | ||
case int32: | ||
return strconv.FormatInt(int64(data_), 10) | ||
return strconv.FormatInt(int64(value_), 10) | ||
case int8: | ||
return strconv.FormatInt(int64(data_), 10) | ||
return strconv.FormatInt(int64(value_), 10) | ||
case int: | ||
return strconv.FormatInt(int64(data_), 10) | ||
return strconv.FormatInt(int64(value_), 10) | ||
case uint64: | ||
return strconv.FormatUint(data_, 10) | ||
return strconv.FormatUint(value_, 10) | ||
case uint32: | ||
return strconv.FormatUint(uint64(data_), 10) | ||
return strconv.FormatUint(uint64(value_), 10) | ||
case uint8: | ||
return strconv.FormatUint(uint64(data_), 10) | ||
return strconv.FormatUint(uint64(value_), 10) | ||
case uint: | ||
return strconv.FormatUint(uint64(data_), 10) | ||
return strconv.FormatUint(uint64(value_), 10) | ||
case float64: | ||
return strconv.FormatFloat(data_, 'g', -1, 64) | ||
return strconv.FormatFloat(value_, 'g', -1, 64) | ||
case float32: | ||
return strconv.FormatFloat(float64(data_), 'g', -1, 32) | ||
return strconv.FormatFloat(float64(value_), 'g', -1, 32) | ||
case time.Time: | ||
return data_.String() | ||
return value_.String() | ||
default: | ||
return fmt.Sprintf("%s", data_) | ||
return util.ToString(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package ard | ||
|
||
func IsValid(value Value) bool { | ||
// TODO | ||
return true | ||
} |
Oops, something went wrong.