Documentation ¶
Overview ¶
Package ratecache provides functions to efficiently store rate and availability data in a buffer or a file.
Index ¶
- Constants
- func AddRateBlockToFile(f *os.File, byteStr []byte) (uint32, error)
- func CreateRateBlock(fhdr *FileHeader, rbhdr *RateBlockHeader) []byte
- func DirExists(path string) (bool, error)
- func DirIsEmpty(path string) (bool, error)
- func DirIsWritable(path string) (bool, error)
- func InitRateFile(fhdr *FileHeader, folder string, filename string, blockCount int) (string, error)
- func PackRate(rate uint32, avail uint8) []byte
- func StrToTime(s string) (time.Time, error)
- func TimeToStr(t time.Time) string
- func UnpackRate(buf []byte) (uint32, uint8)
- type AccoRoomRate
- type Ages
- type CacheIndex
- func (idx *CacheIndex) AddRoomOccIdx(accoCode string, roomRateCode string, roomOccIdx RoomOccIdx) error
- func (idx *CacheIndex) Find(searchRq *SearchRq) []IdxResult
- func (idx *CacheIndex) Get(q IndexQuery) (uint32, bool)
- func (idx *CacheIndex) GetAccoCount() int
- func (idx *CacheIndex) GetAccoList() []string
- func (idx *CacheIndex) GetAccommodation(AccoCode string) map[string][][]OccupancyItem
- func (idx *CacheIndex) Load(fhdr *FileHeader, filename string) error
- func (idx *CacheIndex) LoadFromCache(filename string) error
- func (idx *CacheIndex) Save(fhdr *FileHeader, filename string) error
- type DateRangeAvail
- type DateRangeRate
- type DateRate
- type FileHeader
- func (fhdr *FileHeader) GetBlockHeaderSize() int
- func (fhdr *FileHeader) GetRateBlockSize() int
- func (fhdr *FileHeader) GetRateBlockStart(index uint32) int64
- func (fhdr *FileHeader) GetRateInfo(f *os.File, idx uint32, date time.Time, los uint8) (uint32, uint8, error)
- func (fhdr *FileHeader) GetRateInfoFromMap(m mmap.ReaderAt, idx uint32, date time.Time, los uint8) (uint32, uint8, error)
- func (fhdr *FileHeader) GetRatePos(idx uint32, date time.Time, los uint8) (int64, error)
- func (fhdr *FileHeader) SetRateInfo(f *os.File, idx uint32, date time.Time, los uint8, rate uint32, avail uint8) error
- func (fhdr *FileHeader) ToByteStr() []byte
- type IdxResult
- type IndexQuery
- type JSONDate
- type OccupancyItem
- type RateBlockHeader
- type RoomIdx
- type RoomOccIdx
- func (roomOccIdx *RoomOccIdx) AddOccItem(MinAge uint8, MaxAge uint8, Count uint8) error
- func (roomOccIdx *RoomOccIdx) AppendToIdxFile(fhdr FileHeader, filename string, accoCode string, roomRateCode string) error
- func (roomOccIdx *RoomOccIdx) Match(guests []uint8) bool
- func (roomOccIdx *RoomOccIdx) ToByteStr() *[]byte
- type RoomRates
- type SearchRq
- type SearchRs
- type SearchRsAccoOption
- type SearchRsRoomOption
Constants ¶
const AvailMask uint32 = 4026531840
AvailMask masks the lower 28 bits of an uint32
const FileHeaderSize = 37
FileHeaderSize is the size of the rate file header in bytes
const FixBlockHeaderSize = 24
FixBlockHeaderSize is the portion of the block header size that does not chane, i.e. without room rate code and acco code
const FixIdxRecSize = 28
FixIdxRecSize is the portion of the record size in the index file that does not change, i.e. without room rate code and acco code.
const RateMask uint32 = 268435455
RateMask masks the upper 4 bytes of an uint32 which is used to transport availability
const Release = "1.0 Beta"
Release version of this Open RateCache implementation
const Signature = "LOSRATES"
Signature is the signature string for rate files
const Version = 8
Version is the format version of the rate file
Variables ¶
This section is empty.
Functions ¶
func AddRateBlockToFile ¶
AddRateBlockToFile adds a rate block to cache file. The block position is determined by the RateBlockCount. Method will return the index, not the count! Do not forget to update the rateBlockCount on your FileHeader object!
func CreateRateBlock ¶
func CreateRateBlock(fhdr *FileHeader, rbhdr *RateBlockHeader) []byte
CreateRateBlock creates an empty rate block for padding.
func DirIsEmpty ¶
DirIsEmpty checks if the directory is empty
func DirIsWritable ¶
DirIsWritable checks if the current user can access and write in the directory
func InitRateFile ¶
InitRateFile creates a new rate file on disc and resets the rateBlockCount of file header object. folder is the folder, where the file is going to live.
func PackRate ¶
PackRate packs rate and availability into a single uint32 and returns the value as a 4 byte string (big endian) that can be written to the rate cache.
func StrToTime ¶
StrToTime takes a date string in rate header format and returns a time.Time object.
func TimeToStr ¶
TimeToStr converts the Time object into a date string as used in the rate file header.
func UnpackRate ¶
UnpackRate takes a 4 byte string, unpacks values for rate and availability and returns them separately.
Types ¶
type AccoRoomRate ¶
type AccoRoomRate struct { AccoCode string `json:"accoCode"` RoomRateCodes []string `json:"roomRateCodes"` }
AccoRoomRate represents one Accommodation and all possible. RoomRates.
type Ages ¶
type Ages []uint8
Ages represents a specific occupancy (i.e. a specific group of guests) as a slice of ages, e.g. [8, 40, 38] represents an eigth year old child and two adults aged 40 and 38.
func (Ages) MarshalJSON ¶
func (*Ages) UnmarshalJSON ¶
type CacheIndex ¶
CacheIndex contains a map with the nested map and slice structure for the cache index, protected by a mutex.
func NewCacheIndex ¶
func NewCacheIndex() *CacheIndex
NewCacheIndex returns a pointer to a new CacheIndex instance. Returning a pointer is necessary because returning a copy of a mutex is not safe.
func (*CacheIndex) AddRoomOccIdx ¶
func (idx *CacheIndex) AddRoomOccIdx(accoCode string, roomRateCode string, roomOccIdx RoomOccIdx) error
AddRoomOccIdx adds a new RoomOccIdx to the index.
func (*CacheIndex) Find ¶
func (idx *CacheIndex) Find(searchRq *SearchRq) []IdxResult
func (*CacheIndex) Get ¶
func (idx *CacheIndex) Get(q IndexQuery) (uint32, bool)
func (*CacheIndex) GetAccoCount ¶
func (idx *CacheIndex) GetAccoCount() int
GetAccoCount returns the number of accommodations in the idx.
func (*CacheIndex) GetAccoList ¶
func (idx *CacheIndex) GetAccoList() []string
Get AccoList returns a slice of all accommodations in the idx.
func (*CacheIndex) GetAccommodation ¶
func (idx *CacheIndex) GetAccommodation(AccoCode string) map[string][][]OccupancyItem
func (*CacheIndex) Load ¶
func (idx *CacheIndex) Load(fhdr *FileHeader, filename string) error
Load reads the cache index from a file.
func (*CacheIndex) LoadFromCache ¶
func (idx *CacheIndex) LoadFromCache(filename string) error
func (*CacheIndex) Save ¶
func (idx *CacheIndex) Save(fhdr *FileHeader, filename string) error
Save saves the whole index to a file. Index format is: - AccoCode (length as of FileHeader object) - RoomCode (length as of FileHeader object) - 8 Occupancy items (1 MinAge, 1 MaxAge, 1 Count) - Index (uint16)
type DateRangeAvail ¶
type DateRangeAvail struct { FirstCheckIn JSONDate `json:"firstCheckIn"` LastCheckIn JSONDate `json:"lastCheckIn"` LengthOfStay uint8 `json:"lengthOfStay"` Available uint8 `json:"available"` }
DateRangeAvail represents the number of available rooms for a range of check-in dates.
func (*DateRangeAvail) ExplodeAvail ¶
func (dra *DateRangeAvail) ExplodeAvail(cacheDate time.Time, hdrSize int, days uint16) (int, []uint8)
ExplodeAvail is similar to ExplodeRates but returns a slice with the availabilities instead of rates
type DateRangeRate ¶
type DateRangeRate struct { FirstCheckIn JSONDate `json:"firstCheckIn"` LastCheckIn JSONDate `json:"lastCheckIn"` LengthOfStay uint8 `json:"lengthOfStay"` Rate float32 `json:"rate"` }
DateRangeRate represents a rate that is valid for various checkin dates.
func (DateRangeRate) ExplodeRate ¶
func (drr DateRangeRate) ExplodeRate(cacheDate time.Time, hdrSize int, days uint16, DecimalPlaces uint8) (int, []uint32)
ExplodeRate returns the exploded rates as a uint32 slice and the offset for the first rate in the room rate block. Check-in dates that are beyond the valid scope of the cache, i.e. the configured check-in dates in the future, will be cut off.
type DateRate ¶
type DateRate struct { CheckIn JSONDate `json:"checkIn"` LengthOfStay uint8 `json:"lengthOfStay"` Rate float32 `json:"rate"` }
DateRate represents a rate or an availability for one specific day.
type FileHeader ¶
type FileHeader struct { Signature string Supplier string Version uint8 StartDate time.Time Currency string MaxLos uint8 Days uint16 AccoCodeLength uint8 RoomRateCodeLength uint8 RateBlockCount uint32 }
FileHeader represents header information from a rate cache file which can be read from and written to a byte string.
func FileHeaderFromByteStr ¶
func FileHeaderFromByteStr(byteStr []byte) (*FileHeader, error)
FileHeaderFromByteStr parse a file header into a FileHeader object.
func NewFileHeader ¶
func NewFileHeader(Supplier string, StartDate time.Time, Currency string, MaxLos uint8, Days uint16, AccoCodeLength uint8, RoomRateCodeLength uint8) (*FileHeader, error)
NewFileHeader returns a pointer to a new FileHeader object.
func (*FileHeader) GetBlockHeaderSize ¶
func (fhdr *FileHeader) GetBlockHeaderSize() int
GetBlockHeaderSize calculates the rate block header size.
func (*FileHeader) GetRateBlockSize ¶
func (fhdr *FileHeader) GetRateBlockSize() int
GetRateBlockSize returns the total size of a rate block including the header
func (*FileHeader) GetRateBlockStart ¶
func (fhdr *FileHeader) GetRateBlockStart(index uint32) int64
GetRateBlockStart returns offset of rate block from its index. First block has index 0.
func (*FileHeader) GetRateInfo ¶
func (fhdr *FileHeader) GetRateInfo(f *os.File, idx uint32, date time.Time, los uint8) (uint32, uint8, error)
GetRateInfo gets one rate/avail from rate cache.
func (*FileHeader) GetRateInfoFromMap ¶
func (*FileHeader) GetRatePos ¶
GetRatePos gets position of rate in rate cache
func (*FileHeader) SetRateInfo ¶
func (fhdr *FileHeader) SetRateInfo(f *os.File, idx uint32, date time.Time, los uint8, rate uint32, avail uint8) error
SetRateInfo writes one rate/avail to rate cache.
func (*FileHeader) ToByteStr ¶
func (fhdr *FileHeader) ToByteStr() []byte
ToByteStr creates a file header as byte string from object.
type IdxResult ¶
A slice of IdexResult is returned by "Find" as a result to the search. This slice is used as input to get the actual rate information from the rate cache.
type IndexQuery ¶
type IndexQuery struct { AccoCode string RoomRateCode string Occupancy []OccupancyItem OccTotal uint8 }
func (*IndexQuery) AddOccItem ¶
func (indexQuery *IndexQuery) AddOccItem(MinAge uint8, MaxAge uint8, Count uint8) error
AddOccItem adds an Occupancy item, consisting of MinAge, MaxAge and Count to the requested occupancy. This method should always be used as setter instead of directly appending to the Occupancy attribute.
type JSONDate ¶
JSONDate represents date in ISO 8601 date format: YYYY-MM-DD.
func (JSONDate) MarshalJSON ¶
MarshalJSON returns date as ISO 8601 date.
func (*JSONDate) UnmarshalJSON ¶
UnmarshalJSON takes an ISO 8601 date string and returns a JSONDate object.
type OccupancyItem ¶
type OccupancyItem struct { MinAge uint8 `json:"minAge"` MaxAge uint8 `json:"maxAge"` Count uint8 `json:"count"` }
OccupancyItem represents a guest type identified by an age range that can occupy a room. One occupancy is made up of one or more OccupancyItems.
func NewOccupancyItem ¶
func NewOccupancyItem(MinAge uint8, MaxAge uint8, Count uint8) (*OccupancyItem, error)
NewOccupancyItem returns a pointer to a new OccupancyItem object.
func (*OccupancyItem) ToByteStr ¶
func (item *OccupancyItem) ToByteStr() *[]byte
ToByteStr returns a representation of OccupancyItem as byte string which can be written to the rate cache.
type RateBlockHeader ¶
type RateBlockHeader struct {
// contains filtered or unexported fields
}
RateBlockHeader represents a rate block header information which can be read from and written to byte string.
func NewRateBlockHeader ¶
func NewRateBlockHeader(accoCode string, roomRateCode string) (*RateBlockHeader, error)
NewRateBlockHeader returns a pointer to a new RateBlockHeader object.
func RateBlockHeaderFromByteStr ¶
func RateBlockHeaderFromByteStr(byteStr []byte, AccoCodeLength uint8, RoomRateCodeLength uint8) (*RateBlockHeader, error)
RateBlockHeaderFromByteStr creates a rate block header object from byte string.
func (*RateBlockHeader) AddOccupancyItem ¶
func (rbhdr *RateBlockHeader) AddOccupancyItem(MinAge uint8, MaxAge uint8, Count uint8) error
AddOccupancyItem Adds an occupancy item to the rate block header.
type RoomIdx ¶
RoomIdx is part of IdxResult and contains a room rate code and the corresponding index of the room rate block
type RoomOccIdx ¶
type RoomOccIdx struct { Occupancy []OccupancyItem Total uint8 Idx uint32 }
RoomOccIdx is one possible occupancy for a room or room rate. idx points to the rate block in the cache file.
func (*RoomOccIdx) AddOccItem ¶
func (roomOccIdx *RoomOccIdx) AddOccItem(MinAge uint8, MaxAge uint8, Count uint8) error
AddOccItem adds one occupuncy item to the occupancy.
func (*RoomOccIdx) AppendToIdxFile ¶
func (roomOccIdx *RoomOccIdx) AppendToIdxFile(fhdr FileHeader, filename string, accoCode string, roomRateCode string) error
AppendToIdxFile appends a new index entry to the index file without having to re-write the whole index on disk
func (*RoomOccIdx) Match ¶
func (roomOccIdx *RoomOccIdx) Match(guests []uint8) bool
Match matches a specific group of guests, represented by a slice of ages against a room occupancy and returns true if the group matches the occupancy requirements.
func (*RoomOccIdx) ToByteStr ¶
func (roomOccIdx *RoomOccIdx) ToByteStr() *[]byte
ToByteStr returns a byte string representation of RoomOccIdx which can be written to the rate cache.
type RoomRates ¶
type RoomRates struct { AccoCode string `json:"accommodationCode"` RoomRateCode string `json:"roomRateCode"` Occupancy []OccupancyItem Rates []DateRangeRate `json:"rates"` Availabilities []DateRangeAvail `json:"availabilities"` }
RoomRates represents partially or completely the rates and availabilities for a room.
func (*RoomRates) AddAvail ¶
func (roomRates *RoomRates) AddAvail(FirstCheckIn time.Time, LastCheckIn time.Time, LengthOfStay uint8, Available uint8) error
AddAvail adds a DateRangeAvail to RoomRates.Rates.
type SearchRq ¶
type SearchRq struct { CheckIn JSONDate `json:"checkIn"` FirstCheckIn JSONDate `json:"firstCheckIn"` LastCheckIn JSONDate `json:"lastCheckIn"` LengthOfStay uint8 `json:"lengthOfStay"` MinLengthOfStay uint8 `json:"minLengthOfStay"` MaxLengthOfStay uint8 `json:"maxLengthOfStay"` Occupancy Ages `json:"occupancy"` Accommodations []AccoRoomRate `json:"accommodations"` }
SearchRq transports a set of search parameters.
func (*SearchRq) Validate ¶
Validate checks the request for valid entries and returns a list of message strings each of which represents a validation error. The error return value does not refer to semantic validation errors! In order to check, if the request is semantically correct and can be processed check if first return value == 0. If CheckIn is set then First and Last are meant to be ignored; if LengthOfStay is set then Min and Max are meant to be ignored.
type SearchRs ¶
type SearchRs struct { CheckIn JSONDate `json:"checkIn"` LengthOfStay uint8 `json:"lengthOfStay"` Options []SearchRsAccoOption `json:"options"` }
SearchRs transports a search result.
type SearchRsAccoOption ¶
type SearchRsAccoOption struct { AccoCode string `json:"accoCode"` Rooms []SearchRsRoomOption }
SearchRsAccoOption groups accommodation with different rooms for one specific combination of check-in and los.
type SearchRsRoomOption ¶
type SearchRsRoomOption struct { RoomRateCode string `json:"roomRateCode"` Rate float64 `json:"rate"` Availability uint8 `json:"availability"` }
SearchRsRoomOption represents one room with the corresponding rate and availability for one specific los and stay