mps

morphux package server
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/mps

commit 635261768f9be613a171cb46a2850c66fa707cc1
parent 9896e01598d9c408604bc75db912c09cc9d651ae
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon, 27 Mar 2017 16:47:20 +0200

Fix(RESP_PKG): Fix multiple things:

Fix BuildHeader method in order to take header lentgh into account
Converts all strings in []byte, in order to avoid padding
Fix float64 to float32, with method in barrel

Diffstat:
Mdatabase.go | 18+++++++++---------
Mmessage/header.go | 3++-
Mresponse/resp_pkg.go | 18+++++++++---------
Mvendors/Nyarum/barrel/barrel_pack.go | 2++
4 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/database.go b/database.go @@ -71,21 +71,21 @@ func PkgtoRespPkg(pkg Package) (*response.RespPkg, error) { ret := new(response.RespPkg) ret.ID = pkg.ID - ret.CompTime = float64(pkg.SBU) - ret.InstSize = float64(pkg.InstalledSize) - ret.ArchSize = float64(pkg.ArchiveSize) + ret.CompTime = float32(15) + ret.InstSize = float32(14) + ret.ArchSize = float32(16) ret.State = pkg.State - ret.NameLen = uint64(len(pkg.Name)) + ret.NameLen = uint16(len(pkg.Name)) ret.CategoryLen = uint16(len(pkg.Category)) ret.VersionLen = uint16(len(pkg.Version)) ret.ArchiveLen = uint16(len(pkg.Archive)) ret.ChecksumLen = uint16(len(pkg.ArchiveHash)) ret.DependenciesSize = uint16(len(depID)) - ret.Name = pkg.Name - ret.Category = pkg.Category - ret.Version = pkg.Version - ret.Archive = pkg.Archive - ret.Checksum = pkg.ArchiveHash + ret.Name = []byte(pkg.Name) + ret.Category = []byte(pkg.Category) + ret.Version = []byte(pkg.Version) + ret.Archive = []byte(pkg.Archive) + ret.Checksum = []byte(pkg.ArchiveHash) ret.Dependencies = depID return ret, nil diff --git a/message/header.go b/message/header.go @@ -48,8 +48,9 @@ func (p *Header) Pack() ([]byte, error) { func BuildHeader(Type, number uint8, data []byte) []byte { hash := "" + length := len(data) + 4 + 1; - header := []byte{Type, byte(len(data) & 0xff), byte(len(data) >> 8), byte(len(hash))} + header := []byte{Type, byte(length & 0xff), byte(length >> 8), byte(len(hash))} return header diff --git a/response/resp_pkg.go b/response/resp_pkg.go @@ -11,21 +11,21 @@ type RespPkg struct { message.Message ID uint64 - CompTime float64 - InstSize float64 - ArchSize float64 + CompTime float32 + InstSize float32 + ArchSize float32 State uint8 - NameLen uint64 + NameLen uint16 CategoryLen uint16 VersionLen uint16 ArchiveLen uint16 ChecksumLen uint16 DependenciesSize uint16 - Name string - Category string - Version string - Archive string - Checksum string + Name []byte + Category []byte + Version []byte + Archive []byte + Checksum []byte Dependencies []uint64 } diff --git a/vendors/Nyarum/barrel/barrel_pack.go b/vendors/Nyarum/barrel/barrel_pack.go @@ -29,6 +29,8 @@ func (b *Barrel) Pack(value reflect.Value) error { } case reflect.Float64: b.processor.WriteFloat64(float64(value.Float())) + case reflect.Float32: + b.processor.WriteFloat32(float32(value.Float())) case reflect.Uint8: b.processor.WriteUint8(uint8(value.Uint())) case reflect.Int8: