...

Source file src/github.com/sassoftware/relic/lib/comdoc/structs.go

Documentation: github.com/sassoftware/relic/lib/comdoc

     1  //
     2  // Copyright (c) SAS Institute Inc.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package comdoc
    18  
    19  import (
    20  	"unicode/utf16"
    21  )
    22  
    23  type SecID int32
    24  type DirType uint8
    25  type Color uint8
    26  
    27  const (
    28  	SecIDFree       SecID = -1
    29  	SecIDEndOfChain SecID = -2
    30  	SecIDSAT        SecID = -3
    31  	SecIDMSAT       SecID = -4
    32  
    33  	DirEmpty   DirType = 0
    34  	DirStorage DirType = 1
    35  	DirStream  DirType = 2
    36  	DirRoot    DirType = 5
    37  
    38  	Red   Color = 0
    39  	Black Color = 1
    40  
    41  	byteOrderMarker uint16 = 0xfffe
    42  	msatInHeader           = 109
    43  )
    44  
    45  var fileMagic = []byte{0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1}
    46  
    47  // Raw CDF file header
    48  type Header struct {
    49  	Magic            [8]byte
    50  	UID              [16]byte
    51  	Revision         uint16
    52  	Version          uint16
    53  	ByteOrder        uint16
    54  	SectorSize       uint16 // power of 2
    55  	ShortSectorSize  uint16 // power of 2
    56  	Reserved1        [6]byte
    57  	DirSectorCount   uint32 // undocumented?
    58  	SATSectors       uint32
    59  	DirNextSector    SecID
    60  	Reserved2        uint32
    61  	MinStdStreamSize uint32
    62  	SSATNextSector   SecID
    63  	SSATSectorCount  uint32
    64  	MSATNextSector   SecID
    65  	MSATSectorCount  uint32
    66  	MSAT             [msatInHeader]SecID
    67  }
    68  
    69  // Raw CDF directory entry
    70  type RawDirEnt struct {
    71  	NameRunes   [32]uint16
    72  	NameLength  uint16
    73  	Type        DirType
    74  	Color       Color
    75  	LeftChild   int32
    76  	RightChild  int32
    77  	StorageRoot int32
    78  	UID         [16]byte
    79  	UserFlags   uint32
    80  	CreateTime  uint64
    81  	ModifyTime  uint64
    82  	NextSector  SecID
    83  	StreamSize  uint32
    84  	_           uint32
    85  }
    86  
    87  // Return the UTF8 name of this entry
    88  func (e RawDirEnt) Name() string {
    89  	used := e.NameLength/2 - 1
    90  	if e.Type == DirEmpty || used > 32 {
    91  		return ""
    92  	}
    93  	return string(utf16.Decode(e.NameRunes[:used]))
    94  }
    95  
    96  // Parsed CDF directory entry
    97  type DirEnt struct {
    98  	RawDirEnt
    99  	// Index into the directory stream holding this entry
   100  	Index int
   101  	name  string
   102  }
   103  
   104  // Return the UTF8 name of this entry
   105  func (e DirEnt) Name() string {
   106  	return e.name
   107  }
   108  

View as plain text