Initial Bitbucket→GitHub migration commit, based on release v2.0.0.

This commit is contained in:
Thomas M. Edwards 2019-12-23 13:45:15 -06:00
commit 57e1aa52ff
36 changed files with 5026 additions and 0 deletions

42
passagedata.go Normal file
View file

@ -0,0 +1,42 @@
/*
Copyright © 20142019 Thomas Michael Edwards. All rights reserved.
Use of this source code is governed by a Simplified BSD License which
can be found in the LICENSE file.
*/
package main
import (
"encoding/json"
)
type passageMetadataJSON struct {
Position string `json:"position,omitempty"` // Twine 2 (`position`) & Twine 1 (`twine-position`).
Size string `json:"size,omitempty"` // Twine 2 (`size`).
}
func (p *passage) marshalMetadata() []byte {
marshaled, err := json.Marshal(&passageMetadataJSON{
p.metadata.position,
p.metadata.size,
})
if err != nil {
// NOTE: We should never be able to see an error here. If we do,
// then something truly exceptional—in a bad way—has happened, so
// we get our panic on.
panic(err)
}
return marshaled
}
func (p *passage) unmarshalMetadata(marshaled []byte) error {
metadata := passageMetadataJSON{}
if err := json.Unmarshal(marshaled, &metadata); err != nil {
return err
}
p.metadata = &passageMetadata{
position: metadata.Position,
size: metadata.Size,
}
return nil
}