aboutsummaryrefslogtreecommitdiff
path: root/objects
diff options
context:
space:
mode:
Diffstat (limited to 'objects')
-rw-r--r--objects/id.go2
-rw-r--r--objects/object.go22
-rw-r--r--objects/object_test.go10
3 files changed, 17 insertions, 17 deletions
diff --git a/objects/id.go b/objects/id.go
index 22eeaa2..e651801 100644
--- a/objects/id.go
+++ b/objects/id.go
@@ -101,7 +101,7 @@ func (h hashObjectIdGenerator) GetId() ObjectId {
}
}
-func (oid ObjectId) VerifyObject(o Object) bool {
+func (oid ObjectId) VerifyObject(o RawObject) bool {
gen := oid.Algo.Generator()
if err := o.Serialize(gen); err != nil {
panic(err)
diff --git a/objects/object.go b/objects/object.go
index a1d2335..fbe1f98 100644
--- a/objects/object.go
+++ b/objects/object.go
@@ -16,13 +16,13 @@ const (
OTSnapshot ObjectType = "snapshot"
)
-type Object struct {
+type RawObject struct {
Type ObjectType
Payload []byte
}
-// SerialiteObject writes the binary representation of an object to a io.Writer
-func (o Object) Serialize(w io.Writer) error {
+// Serialize writes the binary representation of an object to a io.Writer
+func (o RawObject) Serialize(w io.Writer) error {
if _, err := fmt.Fprintf(w, "%s %d\n", o.Type, len(o.Payload)); err != nil {
return err
}
@@ -31,7 +31,7 @@ func (o Object) Serialize(w io.Writer) error {
return err
}
-func (o Object) SerializeAndId(w io.Writer, algo ObjectIdAlgo) (ObjectId, error) {
+func (o RawObject) SerializeAndId(w io.Writer, algo ObjectIdAlgo) (ObjectId, error) {
gen := algo.Generator()
if err := o.Serialize(io.MultiWriter(w, gen)); err != nil {
@@ -72,9 +72,9 @@ func (br *bytewiseReader) ReadByte() (b byte, err error) {
return
}
-// UnserializeObject attempts to read an object from a stream.
+// Unserialize attempts to read an object from a stream.
// It is advisable to pass a buffered reader, if feasible.
-func UnserializeObject(r io.Reader) (Object, error) {
+func Unserialize(r io.Reader) (RawObject, error) {
br := newBytewiseReader(r)
line := []byte{}
@@ -82,7 +82,7 @@ func UnserializeObject(r io.Reader) (Object, error) {
for {
b, err := br.ReadByte()
if err != nil {
- return Object{}, UnserializeError{err}
+ return RawObject{}, UnserializeError{err}
}
if b == '\n' {
@@ -93,21 +93,21 @@ func UnserializeObject(r io.Reader) (Object, error) {
parts := strings.SplitN(string(line), " ", 2)
if len(parts) != 2 {
- return Object{}, UnserializeError{}
+ return RawObject{}, UnserializeError{}
}
size, err := strconv.ParseUint(parts[1], 10, 64)
if err != nil {
- return Object{}, UnserializeError{err}
+ return RawObject{}, UnserializeError{err}
}
- o := Object{
+ o := RawObject{
Type: ObjectType(parts[0]),
Payload: make([]byte, size),
}
if _, err := io.ReadFull(r, o.Payload); err != nil {
- return Object{}, UnserializeError{err}
+ return RawObject{}, UnserializeError{err}
}
return o, nil
diff --git a/objects/object_test.go b/objects/object_test.go
index 54b33db..3808d13 100644
--- a/objects/object_test.go
+++ b/objects/object_test.go
@@ -9,7 +9,7 @@ import (
func TestUnserializeSuccess(t *testing.T) {
r := bufio.NewReader(bytes.NewBuffer([]byte("blob 16\n0123456789abcdef")))
- o, err := UnserializeObject(r)
+ o, err := Unserialize(r)
if err != nil {
t.Fatalf("Unserialize failed: %s", err)
}
@@ -26,7 +26,7 @@ func TestUnserializeSuccess(t *testing.T) {
func TestUnserializeSuccess0Payload(t *testing.T) {
r := bufio.NewReader(bytes.NewBuffer([]byte("blob 0\n")))
- o, err := UnserializeObject(r)
+ o, err := Unserialize(r)
if err != nil {
t.Fatalf("Unserialize failed: %s", err)
}
@@ -43,7 +43,7 @@ func TestUnserializeSuccess0Payload(t *testing.T) {
func unserializeMustFail(b []byte, t *testing.T) {
r := bufio.NewReader(bytes.NewBuffer(b))
- o, err := UnserializeObject(r)
+ o, err := Unserialize(r)
if err == nil {
t.Fatalf("Expected an error, but object was successfully read: %#v", o)
}
@@ -71,7 +71,7 @@ func TestUnserializePayloadTooSmall(t *testing.T) {
}
func TestSerialize(t *testing.T) {
- o := Object{
+ o := RawObject{
Type: OTBlob,
Payload: []byte("foo bar\nbaz"),
}
@@ -88,7 +88,7 @@ func TestSerialize(t *testing.T) {
}
func TestSerializeAndId(t *testing.T) {
- o := Object{
+ o := RawObject{
Type: OTBlob,
Payload: []byte("foo bar\nbaz"),
}