예제 #1
0
파일: cf.go 프로젝트: khevse/ConfRobber
// Получить данные для записи конфигурационного файла
func (c ConfCf) GetDataForConfigFile() (fileData []byte) {

	fileData = []byte{}
	addresses := []addresInTOC{}

	for _, b := range c.blocksList {
		attrsData, data := b.GetDataForConfigFile()

		headerAndAttrs := []byte{}
		utils.AddToSlice(&headerAndAttrs,
			getHeaderForCf(len(attrsData), len(attrsData)),
			attrsData)

		headerAndData := []byte{}
		utils.AddToSlice(&headerAndData,
			getHeaderForCf(len(data), len(data)),
			data)

		pos := utils.AddToSlice(&fileData, headerAndAttrs, headerAndData)
		addresses = append(addresses,
			addresInTOC{AttrsPos: int32(pos[0]), DataPos: int32(pos[1])})
	}

	addTableOfContent(&fileData, addresses)
	return
}
예제 #2
0
func getTestData_File() (fileData []byte, addresses []addresInTOC) {

	addresses = []addresInTOC{}
	fileData = []byte{}

	for i := 0; i < countBloks; i++ {
		pos := utils.AddToSlice(&fileData,
			getTestData_HeaderAndAttrs(),
			getTestData_HeaderAndBlockData())

		addresses = append(addresses,
			addresInTOC{AttrsPos: int32(pos[0]), DataPos: int32(pos[1])})
	}

	fileDataLenWithoutTOC := len(fileData)
	addTableOfContent(&fileData, addresses)
	TOCLen := len(fileData) - fileDataLenWithoutTOC

	for i, _ := range addresses {
		addresses[i].AttrsPos += int32(TOCLen)
		addresses[i].DataPos += int32(TOCLen)
	}

	return
}
예제 #3
0
파일: block.go 프로젝트: khevse/ConfRobber
func (b block) GetDataForConfigFile() (attrsForCf []byte, dataForCf []byte) {

	if b.blockType == blockType_simply {
		dataForCf = b.data
	} else {

		dataForCf = []byte{}
		addresses := []addresInTOC{}
		for _, sb := range b.subBlocks {

			headerAndAttrs := []byte{}
			subBlockAttrs := sb.Attrs.getData()
			utils.AddToSlice(&headerAndAttrs,
				getHeaderForCf(len(subBlockAttrs), len(subBlockAttrs)),
				subBlockAttrs)

			headerAndData := []byte{}
			utils.AddToSlice(&headerAndData,
				getHeaderForCf(len(sb.Data), len(sb.Data)),
				sb.Data)

			pos := utils.AddToSlice(&dataForCf, headerAndAttrs, headerAndData)

			addresses = append(addresses,
				addresInTOC{AttrsPos: int32(pos[0]), DataPos: int32(pos[1])})
		}

		addTableOfContent(&dataForCf, addresses)

	}

	if len(dataForCf) > 0 {
		var err error
		var newData []byte
		if newData, err = zlibwrapper.Compress(dataForCf); err != nil {
			panic("Ошибка сжатия данных блока: " + b.attrs.name)
		}

		prepareDataForConfigFile(&newData)
		dataForCf = newData
	}

	attrsForCf = b.attrs.getData()

	return
}
예제 #4
0
func getTestData_HeaderAndAttrs() []byte {

	blockAttrs := getTestData_AttrsCF()

	data := []byte{}
	utils.AddToSlice(&data,
		getHeaderForCf(len(blockAttrs), len(blockAttrs)),
		blockAttrs)
	return data
}
예제 #5
0
func getTestData_HeaderAndBlockData() []byte {

	blockData := getTestData_BlockCF()

	data := []byte{}
	utils.AddToSlice(&data,
		getHeaderForCf(len(blockData), len(blockData)),
		blockData)

	return data
}
예제 #6
0
파일: cf.go 프로젝트: khevse/ConfRobber
// Добавляет оглавление группового блока
func addTableOfContent(fileData *[]byte, addresses []addresInTOC) {

	utils.AddTextToLog(utils.LogLevel_TRACE, "Начало добавления оглавления")

	addres := addresInTOC{}
	delimetr := utils.Int32ToBytes(emptyValue)
	countBlocks := len(addresses)
	valuableTOCSize := addres.getSize() * countBlocks
	fullTOCSize := valuableTOCSize

	if fullTOCSize < defaultBlockSize {
		fullTOCSize = defaultBlockSize
	}

	data := []byte{}
	utils.AddToSlice(&data,
		groupBlocksFlag,                              // маркер группы
		utils.Int32ToBytes(defaultBlockSize),         // размер блока по умолчанию
		[]byte{0x00, 0x00, 0x00, 0x00},               // unknown
		[]byte{0x00, 0x00, 0x00, 0x00},               // unknown
		getHeaderForCf(valuableTOCSize, fullTOCSize)) // Заголовок области оглавления

	beginFileDataLen := int32(len(data) + fullTOCSize)

	for _, v := range addresses {
		utils.AddToSlice(&data,
			utils.Int32ToBytes(v.AttrsPos+beginFileDataLen), // позиция заголовка атрибутов блока
			utils.Int32ToBytes(v.DataPos+beginFileDataLen),  // позиция заголовка данных блока
			delimetr) // макер разделителя адресов
	}

	emptyData := []byte{}
	if valuableTOCSize < fullTOCSize {
		emptyData = make([]byte, fullTOCSize-valuableTOCSize)
	}

	data = append(data, emptyData...)
	*fileData = append(data, (*fileData)...)

	utils.AddTextToLog(utils.LogLevel_TRACE, "-Окончание добавления оглавления")
}
예제 #7
0
파일: header.go 프로젝트: khevse/ConfRobber
// Возвращает заголовок области данных
// @param - полезный размер области
// @param - полный размер области
func getHeaderForCf(valuableRegionSize int, fullRegionSize int) []byte {

	delim := []byte{' '}
	fullSize := utils.Int32ToHexToBytes(int32(fullRegionSize))
	valuableSize := utils.Int32ToHexToBytes(int32(valuableRegionSize))

	data := []byte{}
	utils.AddToSlice(&data,
		beginHeaderMarker,
		valuableSize,
		delim,
		fullSize,
		delim,
		emptyHeaderValue,
		endHeaderMarker)
	return data
}
예제 #8
0
// Возвращает данные атрибутов для конфигурационного файла
func (a attributes) getData() []byte {

	var unknowBlock []byte
	if len(a.name) == 0 {
		unknowBlock = utils.Int32ToBytes(emptyValue)
	} else {
		unknowBlock = []byte{0x00, 0x00, 0x00, 0x00}
	}

	data := []byte{}
	utils.AddToSlice(&data,
		utils.Int64ToBytes(a.creationDate),
		utils.Int64ToBytes(a.modificationDate),
		utils.Int32ToBytes(a.groupType),
		utils.Utf8ToUtf16([]rune(a.name)),
		unknowBlock)

	return data
}