1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4******************************************************************************
5*
6* Copyright (C) 1999-2011, International Business Machines
7* Corporation and others. All Rights Reserved.
8*
9******************************************************************************/
10
11
12/*----------------------------------------------------------------------------------
13 *
14 * UCommonData An abstract interface for dealing with ICU Common Data Files.
15 * ICU Common Data Files are a grouping of a number of individual
16 * data items (resources, converters, tables, anything) into a
17 * single file or dll. The combined format includes a table of
18 * contents for locating the individual items by name.
19 *
20 * Two formats for the table of contents are supported, which is
21 * why there is an abstract inteface involved.
22 *
23 * These functions are part of the ICU internal implementation, and
24 * are not inteded to be used directly by applications.
25 */
26
27#ifndef __UCMNDATA_H__
28#define __UCMNDATA_H__
29
30#include "unicode/udata.h"
31#include "umapfile.h"
32
33
34#define COMMON_DATA_NAME U_ICUDATA_NAME
35
36typedef struct {
37 uint16_t headerSize;
38 uint8_t magic1;
39 uint8_t magic2;
40} MappedData;
41
42
43typedef struct {
44 MappedData dataHeader;
45 UDataInfo info;
46} DataHeader;
47
48typedef struct {
49 DataHeader hdr;
50 char padding[8];
51 uint32_t count, reserved;
52 /*
53 const struct {
54 const char *const name;
55 const void *const data;
56 } toc[1];
57 */
58 int fakeNameAndData[4]; /* TODO: Change this header type from */
59 /* pointerTOC to OffsetTOC. */
60} ICU_Data_Header;
61
62typedef struct {
63 uint32_t nameOffset;
64 uint32_t dataOffset;
65} UDataOffsetTOCEntry;
66
67typedef struct {
68 uint32_t count;
69 /**
70 * Variable-length array declared with length 1 to disable bounds checkers.
71 * The actual array length is in the count field.
72 */
73 UDataOffsetTOCEntry entry[1];
74} UDataOffsetTOC;
75
76/**
77 * Get the header size from a const DataHeader *udh.
78 * Handles opposite-endian data.
79 *
80 * @internal
81 */
82U_CFUNC uint16_t
83udata_getHeaderSize(const DataHeader *udh);
84
85/**
86 * Get the UDataInfo.size from a const UDataInfo *info.
87 * Handles opposite-endian data.
88 *
89 * @internal
90 */
91U_CFUNC uint16_t
92udata_getInfoSize(const UDataInfo *info);
93
94U_CDECL_BEGIN
95/*
96 * "Virtual" functions for data lookup.
97 * To call one, given a UDataMemory *p, the code looks like this:
98 * p->vFuncs.Lookup(p, tocEntryName, pErrorCode);
99 * (I sure do wish this was written in C++, not C)
100 */
101
102typedef const DataHeader *
103(U_CALLCONV * LookupFn)(const UDataMemory *pData,
104 const char *tocEntryName,
105 int32_t *pLength,
106 UErrorCode *pErrorCode);
107
108typedef uint32_t
109(U_CALLCONV * NumEntriesFn)(const UDataMemory *pData);
110
111U_CDECL_END
112
113typedef struct {
114 LookupFn Lookup;
115 NumEntriesFn NumEntries;
116} commonDataFuncs;
117
118
119/*
120 * Functions to check whether a UDataMemory refers to memory containing
121 * a recognizable header and table of contents a Common Data Format
122 *
123 * If a valid header and TOC are found,
124 * set the CommonDataFuncs function dispatch vector in the UDataMemory
125 * to point to the right functions for the TOC type.
126 * otherwise
127 * set an errorcode.
128 */
129U_CFUNC void udata_checkCommonData(UDataMemory *pData, UErrorCode *pErrorCode);
130
131#endif
132